@@ -10,7 +10,6 @@ import {
10
10
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
11
11
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
12
12
TRACING_DEFAULTS ,
13
- continueTrace ,
14
13
getActiveSpan ,
15
14
getClient ,
16
15
getCurrentScope ,
@@ -21,11 +20,16 @@ import {
21
20
spanIsSampled ,
22
21
spanToJSON ,
23
22
startIdleSpan ,
24
- withScope ,
25
23
} from '@sentry/core' ;
26
24
import type { Client , IntegrationFn , StartSpanOptions , TransactionSource } from '@sentry/types' ;
27
25
import type { Span } from '@sentry/types' ;
28
- import { browserPerformanceTimeOrigin , getDomElement , logger , uuid4 } from '@sentry/utils' ;
26
+ import {
27
+ browserPerformanceTimeOrigin ,
28
+ getDomElement ,
29
+ logger ,
30
+ propagationContextFromHeaders ,
31
+ uuid4 ,
32
+ } from '@sentry/utils' ;
29
33
30
34
import { DEBUG_BUILD } from '../debug-build' ;
31
35
import { WINDOW } from '../helpers' ;
@@ -263,31 +267,19 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
263
267
const sentryTrace = traceOptions . sentryTrace || getMetaContent ( 'sentry-trace' ) ;
264
268
const baggage = traceOptions . baggage || getMetaContent ( 'baggage' ) ;
265
269
266
- // Continue trace updates the scope in the callback only, but we want to break out of it again...
267
- // This is a bit hacky, because we want to get the span to use both the correct scope _and_ the correct propagation context
268
- // but afterwards, we want to reset it to avoid this also applying to other spans
269
- const scope = getCurrentScope ( ) ;
270
+ const propagationContext = propagationContextFromHeaders ( sentryTrace , baggage ) ;
271
+ getCurrentScope ( ) . setPropagationContext ( propagationContext ) ;
270
272
271
- activeSpan = continueTrace ( { sentryTrace, baggage } , ( ) => {
272
- // We update the outer current scope to have the correct propagation context
273
- // this means, the scope active when the pageload span is created will continue to hold the
274
- // propagationContext from the incoming trace, even after the pageload span ended.
275
- scope . setPropagationContext ( getCurrentScope ( ) . getPropagationContext ( ) ) ;
276
-
277
- // Ensure we are on the original current scope again, so the span is set as active on it
278
- return withScope ( scope ,
8000
( ) => {
279
- return _createRouteSpan ( client , {
280
- op : 'pageload' ,
281
- ...startSpanOptions ,
282
- } ) ;
283
- } ) ;
273
+ activeSpan = _createRouteSpan ( client , {
274
+ op : 'pageload' ,
275
+ ...startSpanOptions ,
284
276
} ) ;
285
277
} ) ;
286
278
287
279
// A trace should to stay the consistent over the entire time span of one route.
288
- // Therefore, when the initial pageload or navigation transaction ends, we update the
280
+ // Therefore, when the initial pageload or navigation root span ends, we update the
289
281
// scope's propagation context to keep span-specific attributes like the `sampled` decision and
290
- // the dynamic sampling context valid, even after the transaction has ended.
282
+ // the dynamic sampling context valid, even after the root span has ended.
291
283
// This ensures that the trace data is consistent for the entire duration of the route.
292
284
client . on ( 'spanEnd' , span => {
293
285
const op = spanToJSON ( span ) . op ;
0 commit comments