Skip to content

Commit 51eca27

Browse files
committed
apply data to breadcrumbs
1 parent be4699f commit 51eca27

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,
@@ -170,21 +170,19 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
170170

171171
let fetchPromise: Promise<Response>;
172172

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

180+
if (createSpan) {
181181
fetchPromise = trace(
182182
{
183183
name: `${method} ${sanitizedUrl}`, // this will become the description of the span
184184
op: 'http.client',
185-
data: {
186-
...spanData,
187-
},
185+
data: spanData,
188186
parentSpanId: activeSpan && activeSpan.spanId,
189187
},
190188
async span => {
@@ -200,19 +198,18 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
200198
}
201199

202200
if (shouldAddFetchBreadcrumbs) {
203-
addFetchBreadcrumbs(fetchPromise, method, sanitizedUrl, args);
201+
addFetchBreadcrumb(fetchPromise, spanData, args);
204202
}
205203

206204
return fetchPromise;
207205
},
208206
});
209207
}
210208

211-
/* Adds breadcrumbs for the given fetch result */
212-
function addFetchBreadcrumbs(
209+
/* Adds a breadcrumb for the given fetch result */
210+
function addFetchBreadcrumb(
213211
fetchResult: Promise<Response>,
214-
method: string,
215-
sanitizedUrl: string,
212+
spanData: SanitizedRequestData,
216213
args: Parameters<SvelteKitFetch>,
217214
): void {
218215
const breadcrumbStartTimestamp = Date.now();
@@ -223,8 +220,7 @@ function addFetchBreadcrumbs(
223220
type: 'http',
224221
category: 'fetch',
225222
data: {
226-
method: method,
227-
url: sanitizedUrl,
223+
...spanData,
228224
status_code: response.status,
229225
},
230226
},
@@ -242,10 +238,7 @@ function addFetchBreadcrumbs(
242238
type: 'http',
243239
category: 'fetch',
244240
level: 'error',
245-
data: {
246-
method: method,
247-
url: sanitizedUrl,
248-
},
241+
data: spanData,
249242
},
250243
{
251244
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)