@@ -12,6 +12,21 @@ describe('Scope', () => {
1212 GLOBAL_OBJ . __SENTRY__ . globalEventProcessors = undefined ;
1313 } ) ;
1414
15+ describe ( 'init' , ( ) => {
16+ test ( 'it creates a propagation context' , ( ) => {
17+ const scope = new Scope ( ) ;
18+
19+ // @ts -ignore asserting on private properties
20+ expect ( scope . _propagationContext ) . toEqual ( {
21+ traceId : expect . any ( String ) ,
22+ spanId : expect . any ( String ) ,
23+ sampled : false ,
24+ dsc : undefined ,
25+ parentSpanId : undefined ,
26+ } ) ;
27+ } ) ;
28+ } ) ;
29+
1530 describe ( 'attributes modification' , ( ) => {
1631 test ( 'setFingerprint' , ( ) => {
1732 const scope = new Scope ( ) ;
@@ -193,6 +208,14 @@ describe('Scope', () => {
193208 expect ( parentScope . getRequestSession ( ) ) . toEqual ( { status : 'ok' } ) ;
194209 expect ( scope . getRequestSession ( ) ) . toEqual ( { status : 'ok' } ) ;
195210 } ) ;
211+
212+ test ( 'should clone propagation context' , ( ) => {
213+ const parentScope = new Scope ( ) ;
214+ const scope = Scope . clone ( parentScope ) ;
215+
216+ // @ts -ignore accessing private property for test
217+ expect ( scope . _propagationContext ) . toEqual ( parentScope . _propagationContext ) ;
218+ } ) ;
196219 } ) ;
197220
198221 describe ( 'applyToEvent' , ( ) => {
@@ -220,7 +243,11 @@ describe('Scope', () => {
220243 expect ( processedEvent ! . transaction ) . toEqual ( '/abc' ) ;
221244 expect ( processedEvent ! . breadcrumbs ! [ 0 ] ) . toHaveProperty ( 'message' , 'test' ) ;
222245 expect ( processedEvent ! . contexts ) . toEqual ( { os : { id : '1' } } ) ;
223- expect ( processedEvent ! . sdkProcessingMetadata ) . toEqual ( { dogs : 'are great!' } ) ;
246+ expect ( processedEvent ! . sdkProcessingMetadata ) . toEqual ( {
247+ dogs : 'are great!' ,
248+ // @ts -expect-error accessing private property for test
249+ propagationContext : scope . _propagationContext ,
250+ } ) ;
224251 } ) ;
225252 } ) ;
226253
@@ -339,7 +366,7 @@ describe('Scope', () => {
339366 scope . setSpan ( span ) ;
340367 const event : Event = {
341368 contexts : {
342- trace : { a : 'c' } ,
369+ trace : { a : 'c' } as any ,
343370 } ,
344371 } ;
345372 return scope . applyToEvent ( event ) . then ( processedEvent => {
@@ -383,6 +410,8 @@ describe('Scope', () => {
383410
384411 test ( 'clear' , ( ) => {
385412 const scope = new Scope ( ) ;
413+ // @ts -expect-error accessing private property
414+ const oldPropagationContext = scope . _propagationContext ;
386415 scope . setExtra ( 'a' , 2 ) ;
387416 scope . setTag ( 'a' , 'b' ) ;
388417 scope . setUser ( { id : '1' } ) ;
@@ -393,6 +422,14 @@ describe('Scope', () => {
393422 scope . clear ( ) ;
394423 expect ( ( scope as any ) . _extra ) . toEqual ( { } ) ;
395424 expect ( ( scope as any ) . _requestSession ) . toEqual ( undefined ) ;
425+ // @ts -expect-error accessing private property
426+ expect ( scope . _propagationContext ) . toEqual ( {
427+ traceId : expect . any ( String ) ,
428+ spanId : expect . any ( String ) ,
429+ sampled : false ,
430+ } ) ;
431+ // @ts -expect-error accessing private property
432+ expect ( scope . _propagationContext ) . not . toEqual ( oldPropagationContext ) ;
396433 } ) ;
397434
398435 test ( 'clearBreadcrumbs' , ( ) => {
@@ -486,6 +523,8 @@ describe('Scope', () => {
486523 expect ( updatedScope . _level ) . toEqual ( 'warning' ) ;
487524 expect ( updatedScope . _fingerprint ) . toEqual ( [ 'bar' ] ) ;
488525 expect ( updatedScope . _requestSession . status ) . toEqual ( 'ok' ) ;
526+ // @ts -ignore accessing private property for test
527+ expect ( updatedScope . _propagationContext ) . toEqual ( localScope . _propagationContext ) ;
489528 } ) ;
490529
491530 test ( 'given an empty instance of Scope, it should preserve all the original scope data' , ( ) => {
@@ -518,7 +557,13 @@ describe('Scope', () => {
518557 tags : { bar : '3' , baz : '4' } ,
519558 user : { id : '42' } ,
520559 requestSession : { status : 'errored' as RequestSessionStatus } ,
560+ propagationContext : {
561+ traceId : '8949daf83f4a4a70bee4c1eb9ab242ed' ,
562+ spanId : 'a024ad8fea82680e' ,
563+ sampled : true ,
564+ } ,
521565 } ;
566+
522567 const updatedScope = scope . update ( localAttributes ) as any ;
523568
524569 expect ( updatedScope . _tags ) . toEqual ( {
@@ -540,6 +585,11 @@ describe('Scope', () => {
540585 expect ( updatedScope . _level ) . toEqual ( 'warning' ) ;
541586 expect ( updatedScope . _fingerprint ) . toEqual ( [ 'bar' ] ) ;
542587 expect ( updatedScope . _requestSession ) . toEqual ( { status : 'errored' } ) ;
588+ expect ( updatedScope . _propagationContext ) . toEqual ( {
589+ traceId : '8949daf83f4a4a70bee4c1eb9ab242ed' ,
590+ spanId : 'a024ad8fea82680e' ,
591+ sampled : true ,
592+ } ) ;
543593 } ) ;
544594 } ) ;
545595
0 commit comments