Skip to content

Commit

Permalink
apply data to breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Mar 31, 2023
1 parent be4699f commit 51eca27
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Hub } from '@sentry/core';
import { getCurrentHub } from '@sentry/core';
import type { EventProcessor, Integration, RequestSpanData, Span, TracePropagationTargets } from '@sentry/types';
import type { EventProcessor, Integration, SanitizedRequestData, Span, TracePropagationTargets } from '@sentry/types';
import {
dynamicSamplingContextToSentryBaggageHeader,
fill,
Expand Down Expand Up @@ -194,7 +194,7 @@ function _createWrappedRequestMethodFactory(

const scope = getCurrentHub().getScope();

const requestSpanData: RequestSpanData = {
const requestSpanData: SanitizedRequestData = {
url: requestUrl,
method: requestOptions.method || 'GET',
};
Expand Down
37 changes: 15 additions & 22 deletions packages/sveltekit/src/client/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BaseClient } from '@sentry/core';
import { getCurrentHub, trace } from '@sentry/core';
import type { Breadcrumbs, BrowserTracing } from '@sentry/svelte';
import { captureException } from '@sentry/svelte';
import type { ClientOptions, RequestSpanData } from '@sentry/types';
import type { ClientOptions, SanitizedRequestData } from '@sentry/types';
import {
addExceptionMechanism,
addTracingHeadersToFetchRequest,
Expand Down Expand Up @@ -170,21 +170,19 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch

let fetchPromise: Promise<Response>;

if (createSpan) {
const spanData: RequestSpanData = {
url: sanitizedUrl,
method,
'http.query': urlObject.search,
'http.fragment': urlObject.hash,
};
const spanData: SanitizedRequestData = {
url: sanitizedUrl,
method,
'http.query': urlObject.search,
'http.fragment': urlObject.hash,
};

if (createSpan) {
fetchPromise = trace(
{
name: `${method} ${sanitizedUrl}`, // this will become the description of the span
op: 'http.client',
data: {
...spanData,
},
data: spanData,
parentSpanId: activeSpan && activeSpan.spanId,
},
async span => {
Expand All @@ -200,19 +198,18 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
}

if (shouldAddFetchBreadcrumbs) {
addFetchBreadcrumbs(fetchPromise, method, sanitizedUrl, args);
addFetchBreadcrumb(fetchPromise, spanData, args);
}

return fetchPromise;
},
});
}

/* Adds breadcrumbs for the given fetch result */
function addFetchBreadcrumbs(
/* Adds a breadcrumb for the given fetch result */
function addFetchBreadcrumb(
fetchResult: Promise<Response>,
method: string,
sanitizedUrl: string,
spanData: SanitizedRequestData,
args: Parameters<SvelteKitFetch>,
): void {
const breadcrumbStartTimestamp = Date.now();
Expand All @@ -223,8 +220,7 @@ function addFetchBreadcrumbs(
type: 'http',
category: 'fetch',
data: {
method: method,
url: sanitizedUrl,
...spanData,
status_code: response.status,
},
},
Expand All @@ -242,10 +238,7 @@ function addFetchBreadcrumbs(
type: 'http',
category: 'fetch',
level: 'error',
data: {
method: method,
url: sanitizedUrl,
},
data: spanData,
},
{
input: args,
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type { ClientOptions, Options } from './options';
export type { Package } from './package';
export type { PolymorphicEvent, PolymorphicRequest } from './polymorphics';
export type { ReplayEvent, ReplayRecordingData, ReplayRecordingMode } from './replay';
export type { QueryParams, Request, RequestSpanData } from './request';
export type { QueryParams, Request, SanitizedRequestData } from './request';
export type { Runtime } from './runtime';
export type { CaptureContext, Scope, ScopeContext } from './scope';
export type { SdkInfo } from './sdkinfo';
Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export interface Request {
export type QueryParams = string | { [key: string]: string } | Array<[string, string]>;

/**
* span.data type for http.client spans
* Request data that is considered safe for `span.data` on `http.client` spans
* and for `http` breadcrumbs
* See https://develop.sentry.dev/sdk/data-handling/#structuring-data
*/
export type RequestSpanData = {
export type SanitizedRequestData = {
url: string;
method: string;
'http.fragment'?: string;
Expand Down

0 comments on commit 51eca27

Please sign in to comment.