Skip to content

Commit 52495c0

Browse files
authored
ref(tracing): Remove startChild calls from fetch/xhr instrumentation (#10236)
1 parent 0d09983 commit 52495c0

File tree

3 files changed

+28
-409
lines changed

3 files changed

+28
-409
lines changed

packages/tracing-internal/src/browser/request.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable max-lines */
22
import {
3-
getActiveSpan,
43
getClient,
54
getCurrentScope,
65
getDynamicSamplingContextFromClient,
@@ -9,6 +8,7 @@ import {
98
hasTracingEnabled,
109
spanToJSON,
1110
spanToTraceHeader,
11+
startInactiveSpan,
1212
} from '@sentry/core';
1313
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest, Span } from '@sentry/types';
1414
import {
@@ -275,22 +275,19 @@ export function xhrCallback(
275275
}
276276

277277
const scope = getCurrentScope();
278-
const parentSpan = getActiveSpan();
279-
280-
const span =
281-
shouldCreateSpanResult && parentSpan
282-
? // eslint-disable-next-line deprecation/deprecation
283-
parentSpan.startChild({
284-
data: {
285-
type: 'xhr',
286-
'http.method': sentryXhrData.method,
287-
url: sentryXhrData.url,
288-
},
289-
description: `${sentryXhrData.method} ${sentryXhrData.url}`,
290-
op: 'http.client',
291-
origin: 'auto.http.browser',
292-
})
293-
: undefined;
278+
279+
const span = shouldCreateSpanResult
280+
? startInactiveSpan({
281+
attributes: {
282+
type: 'xhr',
283+
'http.method': sentryXhrData.method,
284+
url: sentryXhrData.url,
285+
},
286+
name: `${sentryXhrData.method} ${sentryXhrData.url}`,
287+
op: 'http.client',
288+
origin: 'auto.http.browser',
289+
})
290+
: undefined;
294291

295292
if (span) {
296293
xhr.__sentry_xhr_span_id__ = span.spanContext().spanId;

packages/tracing-internal/src/common/fetch.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
2-
getActiveSpan,
32
getClient,
43
getCurrentScope,
54
getDynamicSamplingContextFromClient,
65
getDynamicSamplingContextFromSpan,
76
getRootSpan,
87
hasTracingEnabled,
98
spanToTraceHeader,
9+
startInactiveSpan,
1010
} from '@sentry/core';
1111
import type { Client, HandlerDataFetch, Scope, Span, SpanOrigin } from '@sentry/types';
1212
import {
@@ -76,24 +76,21 @@ export function instrumentFetchRequest(
7676

7777
const scope = getCurrentScope();
7878
const client = getClient();
79-
const parentSpan = getActiveSpan();
8079

8180
const { method, url } = handlerData.fetchData;
8281

83-
const span =
84-
shouldCreateSpanResult && parentSpan
85-
? // eslint-disable-next-line deprecation/deprecation
86-
parentSpan.startChild({
87-
data: {
88-
url,
89-
type: 'fetch',
90-
'http.method': method,
91-
},
92-
description: `${method} ${url}`,
93-
op: 'http.client',
94-
origin: spanOrigin,
95-
})
96-
: undefined;
82+
const span = shouldCreateSpanResult
83+
? startInactiveSpan({
84+
attributes: {
85+
url,
86+
type: 'fetch',
87+
'http.method': method,
88+
},
89+
name: `${method} ${url}`,
90+
op: 'http.client',
91+
origin: spanOrigin,
92+
})
93+
: undefined;
9794

9895
if (span) {
9996
handlerData.fetchData.__span = span.spanContext().spanId;

0 commit comments

Comments
 (0)