@@ -25,7 +25,13 @@ import {
25
25
} from '@sentry/core' ;
26
26
import type { Client , IntegrationFn , StartSpanOptions , TransactionSource } from '@sentry/types' ;
27
27
import type { Span } from '@sentry/types' ;
28
- import { browserPerformanceTimeOrigin , getDomElement , logger , uuid4 } from '@sentry/utils' ;
28
+ import {
29
+ browserPerformanceTimeOrigin ,
30
+ getDomElement ,
31
+ logger ,
32
+ propagationContextFromHeaders ,
33
+ uuid4 ,
34
+ } from '@sentry/utils' ;
29
35
30
36
import { DEBUG_BUILD } from '../debug-build' ;
31
37
import { WINDOW } from '../helpers' ;
@@ -263,31 +269,19 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
263
269
const sentryTrace = traceOptions . sentryTrace || getMetaContent ( 'sentry-trace' ) ;
264
270
const baggage = traceOptions . baggage || getMetaContent ( 'baggage' ) ;
265
271
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 ( ) ;
272
+ const propagationContext = propagationContextFromHeaders ( sentryTrace , baggage ) ;
273
+ getCurrentScope ( ) . setPropagationContext ( propagationContext ) ;
270
274
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 , ( ) => {
279
- return _createRouteSpan ( client , {
280
- op : 'pageload' ,
281
- ...startSpanOptions ,
282
- } ) ;
283
- } ) ;
275
+ activeSpan = _createRouteSpan ( client , {
276
+ op : 'pageload' ,
277
+ ...startSpanOptions ,
284
278
} ) ;
285
279
} ) ;
286
280
287
281
// 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
282
+ // Therefore, when the initial pageload or navigation root span ends, we update the
289
283
// 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.
284
+ // the dynamic sampling context valid, even after the root span has ended.
291
285
// This ensures that the trace data is consistent for the entire duration of the route.
292
286
client . on ( 'spanEnd' , span => {
293
287
const op = spanToJSON ( span ) . op ;
0 commit comments