Skip to content

Commit 1525375

Browse files
committed
apply data to breadcrumbs
1 parent 27ff806 commit 1525375

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

packages/node/src/integrations/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Hub } from '@sentry/core';
22
import { getCurrentHub } from '@sentry/core';
3-
import type { EventProcessor, Integration, RequestSpanData, Span, TracePropagationTargets } from '@sentry/types';
3+
import type { EventProcessor, Integration, SanitizedRequestData, Span, TracePropagationTargets } from '@sentry/types';
44
import {
55
dynamicSamplingContextToSentryBaggageHeader,
66
fill,
@@ -194,7 +194,7 @@ function _createWrappedRequestMethodFactory(
194194

195195
const scope = getCurrentHub().getScope();
196196

197-
const requestSpanData: RequestSpanData = {
197+
const requestSpanData: SanitizedRequestData = {
198198
url: requestUrl,
199199
method: requestOptions.method || 'GET',
200200
};

packages/sveltekit/src/client/load.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BaseClient } from '@sentry/core';
22
import { getCurrentHub, trace } from '@sentry/core';
33
import type { Breadcrumbs, BrowserTracing } from '@sentry/svelte';
44
import { captureException } from '@sentry/svelte';
5-
import type { ClientOptions, RequestSpanData } from '@sentry/types';
5+
import type { ClientOptions, SanitizedRequestData } from '@sentry/types';
66
import {
77
addExceptionMechanism,
88
addTracingHeadersToFetchRequest,
@@ -168,21 +168,19 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
168168

169169
let fetchPromise: Promise<Response>;
170170

171-
if (createSpan) {
172-
const spanData: RequestSpanData = {
173-
url: sanitizedUrl,
174-
method,
175-
'http.query': urlObject.search,
176-
'http.fragment': urlObject.hash,
177-
};
171+
const spanData: SanitizedRequestData = {
172+
url: sanitizedUrl,
173+
method,
174+
'http.query': urlObject.search,
175+
'http.fragment': urlObject.hash,
176+
};
178177

178+
if (createSpan) {
179179
fetchPromise = trace(
180180
{
181181
name: `${method} ${sanitizedUrl}`, // this will become the description of the span
182182
op: 'http.client',
183-
data: {
184-
...spanData,
185-
},
183+
data: spanData,
186184
parentSpanId: activeSpan && activeSpan.spanId,
187185
},
188186
async span => {
@@ -198,19 +196,18 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
198196
}
199197

200198
if (shouldAddFetchBreadcrumbs) {
201-
addFetchBreadcrumbs(fetchPromise, method, sanitizedUrl, args);
199+
addFetchBreadcrumb(fetchPromise, spanData, args);
202200
}
203201

204202
return fetchPromise;
205203
},
206204
});
207205
}
208206

209-
/* Adds breadcrumbs for the given fetch result */
210-
function addFetchBreadcrumbs(
207+
/* Adds a breadcrumb for the given fetch result */
208+
function addFetchBreadcrumb(
211209
fetchResult: Promise<Response>,
212-
method: string,
213-
sanitizedUrl: string,
210+
spanData: SanitizedRequestData,
214211
args: Parameters<SvelteKitFetch>,
215212
): void {
216213
const breadcrumbStartTimestamp = Date.now();
@@ -221,8 +218,7 @@ function addFetchBreadcrumbs(
221218
type: 'http',
222219
category: 'fetch',
223220
data: {
224-
method: method,
225-
url: sanitizedUrl,
221+
...spanData,
226222
status_code: response.status,
227223
},
228224
},
@@ -240,10 +236,7 @@ function addFetchBreadcrumbs(
240236
type: 'http',
241237
category: 'fetch',
242238
level: 'error',
243-
data: {
244-
method: method,
245-
url: sanitizedUrl,
246-
},
239+
data: spanData,
247240
},
248241
{
249242
input: args,

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type { ClientOptions, Options } from './options';
4848
export type { Package } from './package';
4949
export type { PolymorphicEvent, PolymorphicRequest } from './polymorphics';
5050
export type { ReplayEvent, ReplayRecordingData, ReplayRecordingMode } from './replay';
51-
export type { QueryParams, Request, RequestSpanData } from './request';
51+
export type { QueryParams, Request, SanitizedRequestData } from './request';
5252
export type { Runtime } from './runtime';
5353
export type { CaptureContext, Scope, ScopeContext } from './scope';
5454
export type { SdkInfo } from './sdkinfo';

packages/types/src/request.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export interface Request {
1212
export type QueryParams = string | { [key: string]: string } | Array<[string, string]>;
1313

1414
/**
15-
* span.data type for http.client spans
15+
* Request data that is considered safe for `span.data` on `http.client` spans
16+
* and for `http` breadcrumbs
1617
* See https://develop.sentry.dev/sdk/data-handling/#structuring-data
1718
*/
18-
export type RequestSpanData = {
19+
export type SanitizedRequestData = {
1920
url: string;
2021
method: string;
2122
'http.fragment'?: string;

0 commit comments

Comments
 (0)