@@ -19,6 +19,15 @@ import { TraceState } from '../src/utils/TraceState';
1919import { mockSdkInit } from './helpers/mockSdkInit' ;
2020
2121describe ( 'asyncContextStrategy' , ( ) => {
22+ // `withIsolationScope` gives the forked current scope a fresh propagation context (unless it is
23+ // continuing an incoming trace), so scope data is expected to match apart from that context.
24+ function scopeDataWithoutPropagationContext (
25+ scope : Scope ,
26+ ) : Omit < ReturnType < Scope [ 'getScopeData' ] > , 'propagationContext' > {
27+ const { propagationContext : _propagationContext , ...rest } = scope . getScopeData ( ) ;
28+ return rest ;
29+ }
30+
2231 beforeEach ( ( ) => {
2332 getCurrentScope ( ) . clear ( ) ;
2433 getIsolationScope ( ) . clear ( ) ;
@@ -45,7 +54,8 @@ describe('asyncContextStrategy', () => {
4554 expect ( scope1 ) . not . toBe ( initialScope ) ;
4655 expect ( isolationScope1 ) . not . toBe ( initialIsolationScope ) ;
4756
48- expect ( scope1 . getScopeData ( ) ) . toEqual ( initialScope . getScopeData ( ) ) ;
57+ expect ( scopeDataWithoutPropagationContext ( scope1 ) ) . toEqual ( scopeDataWithoutPropagationContext ( initialScope ) ) ;
58+ expect ( scope1 . getPropagationContext ( ) . traceId ) . not . toBe ( initialScope . getPropagationContext ( ) . traceId ) ;
4959 expect ( isolationScope1 . getScopeData ( ) ) . toEqual ( initialIsolationScope . getScopeData ( ) ) ;
5060
5161 scope1 . setExtra ( 'b' , 'b' ) ;
@@ -162,7 +172,8 @@ describe('asyncContextStrategy', () => {
162172 expect ( scope1 ) . not . toBe ( initialScope ) ;
163173 expect ( isolationScope1 ) . not . toBe ( initialIsolationScope ) ;
164174
165- expect ( scope1 . getScopeData ( ) ) . toEqual ( initialScope . getScopeData ( ) ) ;
175+ expect ( scopeDataWithoutPropagationContext ( scope1 ) ) . toEqual ( scopeDataWithoutPropagationContext ( initialScope ) ) ;
176+ expect ( scope1 . getPropagationContext ( ) . traceId ) . not . toBe ( initialScope . getPropagationContext ( ) . traceId ) ;
166177 expect ( isolationScope1 . getScopeData ( ) ) . toEqual ( initialIsolationScope . getScopeData ( ) ) ;
167178
168179 await asyncSetExtra ( scope1 , 'b' , 'b' ) ;
@@ -207,7 +218,8 @@ describe('asyncContextStrategy', () => {
207218 expect ( scope1 ) . not . toBe ( initialScope ) ;
208219 expect ( isolationScope1 ) . not . toBe ( initialIsolationScope ) ;
209220
210- expect ( scope1 . getScopeData ( ) ) . toEqual ( initialScope . getScopeData ( ) ) ;
221+ expect ( scopeDataWithoutPropagationContext ( scope1 ) ) . toEqual ( scopeDataWithoutPropagationContext ( initialScope ) ) ;
222+ expect ( scope1 . getPropagationContext ( ) . traceId ) . not . toBe ( initialScope . getPropagationContext ( ) . traceId ) ;
211223 expect ( isolationScope1 . getScopeData ( ) ) . toEqual ( initialIsolationScope . getScopeData ( ) ) ;
212224
213225 scope1 . setExtra ( 'b' , 'b' ) ;
@@ -244,7 +256,8 @@ describe('asyncContextStrategy', () => {
244256 expect ( scope1 ) . not . toBe ( initialScope ) ;
245257 expect ( isolationScope1 ) . not . toBe ( initialIsolationScope ) ;
246258
247- expect ( scope1 . getScopeData ( ) ) . toEqual ( initialScope . getScopeData ( ) ) ;
259+ expect ( scopeDataWithoutPropagationContext ( scope1 ) ) . toEqual ( scopeDataWithoutPropagationContext ( initialScope ) ) ;
260+ expect ( scope1 . getPropagationContext ( ) . traceId ) . not . toBe ( initialScope . getPropagationContext ( ) . traceId ) ;
248261 expect ( isolationScope1 . getScopeData ( ) ) . toEqual ( initialIsolationScope . getScopeData ( ) ) ;
249262
250263 scope1 . setExtra ( 'b2' , 'b' ) ;
@@ -294,7 +307,8 @@ describe('asyncContextStrategy', () => {
294307 expect ( scope1 ) . not . toBe ( initialScope ) ;
295308 expect ( isolationScope1 ) . not . toBe ( initialIsolationScope ) ;
296309
297- expect ( scope1 . getScopeData ( ) ) . toEqual ( initialScope . getScopeData ( ) ) ;
310+ expect ( scopeDataWithoutPropagationContext ( scope1 ) ) . toEqual ( scopeDataWithoutPropagationContext ( initialScope ) ) ;
311+ expect ( scope1 . getPropagationContext ( ) . traceId ) . not . toBe ( initialScope . getPropagationContext ( ) . traceId ) ;
298312 expect ( isolationScope1 . getScopeData ( ) ) . toEqual ( initialIsolationScope . getScopeData ( ) ) ;
299313
300314 await asyncSetExtra ( scope1 , 'b' , 'b' ) ;
@@ -331,7 +345,8 @@ describe('asyncContextStrategy', () => {
331345 expect ( scope1 ) . not . toBe ( initialScope ) ;
332346 expect ( isolationScope1 ) . not . toBe ( initialIsolationScope ) ;
333347
334- expect ( scope1 . getScopeData ( ) ) . toEqual ( initialScope . getScopeData ( ) ) ;
348+ expect ( scopeDataWithoutPropagationContext ( scope1 ) ) . toEqual ( scopeDataWithoutPropagationContext ( initialScope ) ) ;
349+ expect ( scope1 . getPropagationContext ( ) . traceId ) . not . toBe ( initialScope . getPropagationContext ( ) . traceId ) ;
335350 expect ( isolationScope1 . getScopeData ( ) ) . toEqual ( initialIsolationScope . getScopeData ( ) ) ;
336351
337352 scope1 . setExtra ( 'b2' , 'b' ) ;
0 commit comments