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 1
1
/* eslint-disable max-lines */
2
2
import {
3
3
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
4
+ getActiveSpan ,
4
5
getClient ,
5
6
getCurrentScope ,
6
7
getDynamicSamplingContextFromClient ,
@@ -279,18 +280,21 @@ export function xhrCallback(
279
280
const scope = getCurrentScope ( ) ;
280
281
const isolationScope = getIsolationScope ( ) ;
281
282
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 ;
294
298
295
299
if ( span ) {
296
300
xhr . __sentry_xhr_span_id__ = span . spanContext ( ) . spanId ;
Original file line number Diff line number Diff line change 1
1
import {
2
2
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
3
+ getActiveSpan ,
3
4
getClient ,
4
5
getCurrentScope ,
5
6
getDynamicSamplingContextFromClient ,
@@ -81,18 +82,21 @@ export function instrumentFetchRequest(
81
82
82
83
const { method, url } = handlerData . fetchData ;
83
84
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 ;
96
100
97
101
if ( span ) {
98
102
handlerData . fetchData . __span = span . spanContext ( ) . spanId ;
You can’t perform that action at this time.
0 commit comments