@@ -20,15 +20,18 @@ import {
20
20
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
21
21
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE ,
22
22
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
23
+ SentryNonRecordingSpan ,
23
24
TRACING_DEFAULTS ,
24
25
getActiveSpan ,
25
26
getCurrentScope ,
26
27
getDynamicSamplingContextFromSpan ,
27
28
getIsolationScope ,
29
+ getTraceData ,
28
30
setCurrentClient ,
29
31
spanIsSampled ,
30
32
spanToJSON ,
31
33
startInactiveSpan ,
34
+ updateSpanName ,
32
35
} from '@sentry/core' ;
33
36
import type { Span , StartSpanOptions } from '@sentry/core' ;
34
37
import { JSDOM } from 'jsdom' ;
@@ -265,6 +268,10 @@ describe('browserTracingIntegration', () => {
265
268
266
269
expect ( span ) . toBeDefined ( ) ;
267
270
expect ( spanIsSampled ( span ! ) ) . toBe ( false ) ;
271
+
272
+ // Ensure getTraceData is correct in this case
273
+ const traceData = getTraceData ( ) ;
274
+ expect ( traceData [ 'sentry-trace' ] ) . toEqual ( `${ span ?. spanContext ( ) . traceId } -${ span ?. spanContext ( ) . spanId } -0` ) ;
268
275
} ) ;
269
276
270
277
it ( 'works with integration setup' , ( ) => {
@@ -365,7 +372,7 @@ describe('browserTracingIntegration', () => {
365
372
366
373
const client = new BrowserClient (
367
374
getDefaultBrowserClientOptions ( {
368
- tracesSampleRate : 0 ,
375
+ tracesSampleRate : 1 ,
369
376
integrations : [
370
377
browserTracingIntegration ( {
371
378
instrumentPageLoad : false ,
@@ -378,9 +385,7 @@ describe('browserTracingIntegration', () => {
378
385
setCurrentClient ( client ) ;
379
386
client . init ( ) ;
380
387
381
- startBrowserTracingPageLoadSpan ( client , { name : 'test span' } ) ;
382
-
383
- const pageloadSpan = getActiveSpan ( ) ;
388
+ const pageloadSpan = startBrowserTracingPageLoadSpan ( client , { name : 'test span' } ) ;
384
389
385
390
expect ( spanToJSON ( pageloadSpan ! ) . op ) . toBe ( 'test op' ) ;
386
391
} ) ;
@@ -408,7 +413,7 @@ describe('browserTracingIntegration', () => {
408
413
409
414
const client = new BrowserClient (
410
415
getDefaultBrowserClientOptions ( {
411
- tracesSampleRate : 0 ,
416
+ tracesSampleRate : 1 ,
412
417
integrations : [
413
418
browserTracingIntegration ( {
414
419
instrumentPageLoad : false ,
@@ -458,6 +463,10 @@ describe('browserTracingIntegration', () => {
458
463
459
464
expect ( span ) . toBeDefined ( ) ;
460
465
expect ( spanIsSampled ( span ! ) ) . toBe ( false ) ;
466
+
467
+ // Ensure getTraceData is correct in this case
468
+ const traceData = getTraceData ( ) ;
469
+ expect ( traceData [ 'sentry-trace' ] ) . toEqual ( `${ span ?. spanContext ( ) . traceId } -${ span ?. spanContext ( ) . spanId } -0` ) ;
461
470
} ) ;
462
471
463
472
it ( 'works with integration setup' , ( ) => {
@@ -562,7 +571,7 @@ describe('browserTracingIntegration', () => {
562
571
563
572
const client = new BrowserClient (
564
573
getDefaultBrowserClientOptions ( {
565
- tracesSampleRate : 0 ,
574
+ tracesSampleRate : 1 ,
566
575
integrations : [
567
576
browserTracingIntegration ( {
568
577
instrumentPageLoad : false ,
@@ -575,9 +584,7 @@ describe('browserTracingIntegration', () => {
575
584
setCurrentClient ( client ) ;
576
585
client . init ( ) ;
577
586
578
- startBrowserTracingNavigationSpan ( client , { name : 'test span' } ) ;
579
-
580
- const navigationSpan = getActiveSpan ( ) ;
587
+ const navigationSpan = startBrowserTracingNavigationSpan ( client , { name : 'test span' } ) ;
581
588
582
589
expect ( spanToJSON ( navigationSpan ! ) . op ) . toBe ( 'test op' ) ;
583
590
} ) ;
@@ -590,7 +597,7 @@ describe('browserTracingIntegration', () => {
590
597
591
598
const client = new BrowserClient (
592
599
getDefaultBrowserClientOptions ( {
593
- tracesSampleRate : 0 ,
600
+ tracesSampleRate : 1 ,
594
601
integrations : [
595
602
browserTracingIntegration ( {
596
603
instrumentPageLoad : false ,
@@ -628,7 +635,7 @@ describe('browserTracingIntegration', () => {
628
635
it ( "updates the scopes' propagationContexts on a navigation" , ( ) => {
629
636
const client = new BrowserClient (
630
637
getDefaultBrowserClientOptions ( {
631
- integrations : [ browserTracingIntegration ( ) ] ,
638
+ integrations : [ browserTracingIntegration ( { instrumentPageLoad : false } ) ] ,
632
639
} ) ,
633
640
) ;
634
641
setCurrentClient ( client ) ;
@@ -637,7 +644,8 @@ describe('browserTracingIntegration', () => {
637
644
const oldIsolationScopePropCtx = getIsolationScope ( ) . getPropagationContext ( ) ;
638
645
const oldCurrentScopePropCtx = getCurrentScope ( ) . getPropagationContext ( ) ;
639
646
640
- startBrowserTracingNavigationSpan ( client , { name : 'test navigation span' } ) ;
647
+ const span = startBrowserTracingNavigationSpan ( client , { name : 'test navigation span' } ) ;
648
+ const traceId = span ! . spanContext ( ) . traceId ;
641
649
642
650
const newIsolationScopePropCtx = getIsolationScope ( ) . getPropagationContext ( ) ;
643
651
const newCurrentScopePropCtx = getCurrentScope ( ) . getPropagationContext ( ) ;
@@ -657,6 +665,22 @@ describe('browserTracingIntegration', () => {
657
665
658
666
expect ( newIsolationScopePropCtx . traceId ) . not . toEqual ( oldIsolationScopePropCtx . traceId ) ;
659
667
expect ( newCurrentScopePropCtx . traceId ) . not . toEqual ( oldCurrentScopePropCtx . traceId ) ;
668
+
669
+ const span2 = startBrowserTracingNavigationSpan ( client , { name : 'test navigation span 2' } ) ;
670
+ const traceId2 = span2 ! . spanContext ( ) . traceId ;
671
+ expect ( traceId2 ) . not . toEqual ( traceId ) ;
672
+
673
+ const newCurrentScopePropCtx2 = getCurrentScope ( ) . getPropagationContext ( ) ;
674
+ expect ( newCurrentScopePropCtx2 ) . toEqual ( {
675
+ traceId : traceId2 ,
676
+ sampled : false ,
677
+ dsc : {
678
+ environment : 'production' ,
679
+ public_key : 'examplePublicKey' ,
680
+ sample_rate : '0' ,
681
+ trace_id : traceId2 ,
682
+ } ,
683
+ } ) ;
660
684
} ) ;
661
685
662
686
it ( "saves the span's positive sampling decision and its DSC on the propagationContext when the span finishes" , ( ) => {
@@ -679,6 +703,7 @@ describe('browserTracingIntegration', () => {
679
703
traceId : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
680
704
} ) ;
681
705
706
+ updateSpanName ( navigationSpan ! , 'mySpan2' ) ;
682
707
navigationSpan ! . end ( ) ;
683
708
684
709
const propCtxAfterEnd = getCurrentScope ( ) . getPropagationContext ( ) ;
@@ -690,7 +715,7 @@ describe('browserTracingIntegration', () => {
690
715
public_key : 'examplePublicKey' ,
691
716
sample_rate : '1' ,
692
717
sampled : 'true' ,
693
- transaction : 'mySpan ' ,
718
+ transaction : 'mySpan2 ' ,
694
719
trace_id : propCtxBeforeEnd . traceId ,
695
720
} ,
696
721
} ) ;
@@ -758,18 +783,19 @@ describe('browserTracingIntegration', () => {
758
783
const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( idleSpan ! ) ;
759
784
const propagationContext = getCurrentScope ( ) . getPropagationContext ( ) ;
760
785
761
- // Span is correct
762
- expect ( spanToJSON ( idleSpan ) . op ) . toBe ( 'pageload' ) ;
763
- expect ( spanToJSON ( idleSpan ) . trace_id ) . toEqual ( '12312012123120121231201212312012' ) ;
764
- expect ( spanToJSON ( idleSpan ) . parent_span_id ) . toEqual ( '1121201211212012' ) ;
765
- expect ( spanIsSampled ( idleSpan ) ) . toBe ( false ) ;
786
+ // Span is non-recording
787
+ expect ( idleSpan instanceof SentryNonRecordingSpan ) . toBe ( true ) ;
766
788
767
789
expect ( dynamicSamplingContext ) . toBeDefined ( ) ;
768
790
expect ( dynamicSamplingContext ) . toStrictEqual ( { release : '2.1.14' } ) ;
769
791
770
792
// Propagation context keeps the meta tag trace data for later events on the same route to add them to the trace
771
793
expect ( propagationContext . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
772
794
expect ( propagationContext . parentSpanId ) . toEqual ( '1121201211212012' ) ;
795
+
796
+ // Ensure getTraceData is correct in this case
797
+ const traceData = getTraceData ( ) ;
798
+ expect ( traceData [ 'sentry-trace' ] ) . toMatch ( / 1 2 3 1 2 0 1 2 1 2 3 1 2 0 1 2 1 2 3 1 2 0 1 2 1 2 3 1 2 0 1 2 - [ a - f 0 - 9 ] { 16 } - 0 / ) ;
773
799
} ) ;
774
800
775
801
it ( 'puts frozen Dynamic Sampling Context on pageload span if sentry-trace data and only 3rd party baggage is present' , ( ) => {
@@ -795,18 +821,19 @@ describe('browserTracingIntegration', () => {
795
821
const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( idleSpan ) ;
796
822
const propagationContext = getCurrentScope ( ) . getPropagationContext ( ) ;
797
823
798
- // Span is correct
799
- expect ( spanToJSON ( idleSpan ) . op ) . toBe ( 'pageload' ) ;
800
- expect ( spanToJSON ( idleSpan ) . trace_id ) . toEqual ( '12312012123120121231201212312012' ) ;
801
- expect ( spanToJSON ( idleSpan ) . parent_span_id ) . toEqual ( '1121201211212012' ) ;
802
- expect ( spanIsSampled ( idleSpan ) ) . toBe ( false ) ;
824
+ // Span is NonRecordingSpan
825
+ expect ( idleSpan instanceof SentryNonRecordingSpan ) . toBe ( true ) ;
803
826
804
827
expect ( dynamicSamplingContext ) . toBeDefined ( ) ;
805
828
expect ( dynamicSamplingContext ) . toStrictEqual ( { } ) ;
806
829
807
830
// Propagation context keeps the meta tag trace data for later events on the same route to add them to the trace
808
831
expect ( propagationContext . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
809
832
expect ( propagationContext . parentSpanId ) . toEqual ( '1121201211212012' ) ;
833
+
834
+ // Ensure getTraceData is correct in this case
835
+ const traceData = getTraceData ( ) ;
836
+ expect ( traceData [ 'sentry-trace' ] ) . toMatch ( / 1 2 3 1 2 0 1 2 1 2 3 1 2 0 1 2 1 2 3 1 2 0 1 2 1 2 3 1 2 0 1 2 - [ a - f 0 - 9 ] { 16 } - 0 / ) ;
810
837
} ) ;
811
838
812
839
it ( 'ignores the meta tag data for navigation spans' , ( ) => {
0 commit comments