File tree Expand file tree Collapse file tree 2 files changed +32
-24
lines changed
packages/tracing-internal/src Expand file tree Collapse file tree 2 files changed +32
-24
lines changed Original file line number Diff line number Diff line change 11/* eslint-disable max-lines */
22import {
33 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
4+ getActiveSpan ,
45 getClient ,
56 getCurrentScope ,
67 getDynamicSamplingContextFromClient ,
@@ -279,18 +280,21 @@ export function xhrCallback(
279280 const scope = getCurrentScope ( ) ;
280281 const isolationScope = getIsolationScope ( ) ;
281282
282- const span = shouldCreateSpanResult
283- ? startInactiveSpan ( {
284- attributes : {
285- type : 'xhr' ,
286- 'http.method' : sentryXhrData . method ,
287- url : sentryXhrData . url ,
288- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.http.browser' ,
289- } ,
290- name : `${ sentryXhrData . method } ${ sentryXhrData . url } ` ,
291- op : 'http.client' ,
292- } )
293- : undefined ;
283+ // only create a child span if there is an active span. This is because
284+ // `startInactiveSpan` can still create a transaction under the hood
285+ const span =
286+ shouldCreateSpanResult && getActiveSpan ( )
287+ ? startInactiveSpan ( {
288+ attributes : {
289+ type : 'xhr' ,
290+ 'http.method' : sentryXhrData . method ,
291+ url : sentryXhrData . url ,
292+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.http.browser' ,
293+ } ,
294+ name : `${ sentryXhrData . method } ${ sentryXhrData . url } ` ,
295+ op : 'http.client' ,
296+ } )
297+ : undefined ;
294298
295299 if ( span ) {
296300 xhr . __sentry_xhr_span_id__ = span . spanContext ( ) . spanId ;
Original file line number Diff line number Diff line change 11import {
22 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
3+ getActiveSpan ,
34 getClient ,
45 getCurrentScope ,
56 getDynamicSamplingContextFromClient ,
@@ -81,18 +82,21 @@ export function instrumentFetchRequest(
8182
8283 const { method, url } = handlerData . fetchData ;
8384
84- const span = shouldCreateSpanResult
85- ? startInactiveSpan ( {
86- attributes : {
87- url,
88- type : 'fetch' ,
89- 'http.method' : method ,
90- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : spanOrigin ,
91- } ,
92- name : `${ method } ${ url } ` ,
93- op : 'http.client' ,
94- } )
95- : undefined ;
85+ // only create a child span if there is an active span. This is because
86+ // `startInactiveSpan` can still create a transaction under the hood
87+ const span =
88+ shouldCreateSpanResult && getActiveSpan ( )
89+ ? startInactiveSpan ( {
90+ attributes : {
91+ url,
92+ type : 'fetch' ,
93+ 'http.method' : method ,
94+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : spanOrigin ,
95+ } ,
96+ name : `${ method } ${ url } ` ,
97+ op : 'http.client' ,
98+ } )
99+ : undefined ;
96100
97101 if ( span ) {
98102 handlerData . fetchData . __span = span . spanContext ( ) . spanId ;
You can’t perform that action at this time.
0 commit comments