@@ -10,7 +10,6 @@ import {
1010  SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , 
1111  SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , 
1212  TRACING_DEFAULTS , 
13-   continueTrace , 
1413  getActiveSpan , 
1514  getClient , 
1615  getCurrentScope , 
@@ -21,11 +20,16 @@ import {
2120  spanIsSampled , 
2221  spanToJSON , 
2322  startIdleSpan , 
24-   withScope , 
2523}  from  '@sentry/core' ; 
2624import  type  {  Client ,  IntegrationFn ,  StartSpanOptions ,  TransactionSource  }  from  '@sentry/types' ; 
2725import  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' ; 
2933
3034import  {  DEBUG_BUILD  }  from  '../debug-build' ; 
3135import  {  WINDOW  }  from  '../helpers' ; 
@@ -263,31 +267,19 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
263267        const  sentryTrace  =  traceOptions . sentryTrace  ||  getMetaContent ( 'sentry-trace' ) ; 
264268        const  baggage  =  traceOptions . baggage  ||  getMetaContent ( 'baggage' ) ; 
265269
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 ) ; 
270272
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-           } ) ; 
273+         activeSpan  =  _createRouteSpan ( client ,  { 
274+           op : 'pageload' , 
275+           ...startSpanOptions , 
284276        } ) ; 
285277      } ) ; 
286278
287279      // 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 
289281      // 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. 
291283      // This ensures that the trace data is consistent for the entire duration of the route. 
292284      client . on ( 'spanEnd' ,  span  =>  { 
293285        const  op  =  spanToJSON ( span ) . op ; 
0 commit comments