@@ -417,6 +417,48 @@ describe('startSpan', () => {
417
417
} ) ;
418
418
} ) ;
419
419
420
+ describe ( 'parentSpanIsAlwaysRootSpan' , ( ) => {
421
+ it ( 'creates a span as child of root span if parentSpanIsAlwaysRootSpan=true' , ( ) => {
422
+ const options = getDefaultTestClientOptions ( {
423
+ tracesSampleRate : 1 ,
424
+ parentSpanIsAlwaysRootSpan : true ,
425
+ } ) ;
426
+ client = new TestClient ( options ) ;
427
+ setCurrentClient ( client ) ;
428
+ client . init ( ) ;
429
+
430
+ startSpan ( { name : 'parent span' } , span => {
431
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
432
+ startSpan ( { name : 'child span' } , childSpan => {
433
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
434
+ startSpan ( { name : 'grand child span' } , grandChildSpan => {
435
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
436
+ } ) ;
437
+ } ) ;
438
+ } ) ;
439
+ } ) ;
440
+
441
+ it ( 'does not creates a span as child of root span if parentSpanIsAlwaysRootSpan=false' , ( ) => {
442
+ const options = getDefaultTestClientOptions ( {
443
+ tracesSampleRate : 1 ,
444
+ parentSpanIsAlwaysRootSpan : false ,
445
+ } ) ;
446
+ client = new TestClient ( options ) ;
447
+ setCurrentClient ( client ) ;
448
+ client . init ( ) ;
449
+
450
+ startSpan ( { name : 'parent span' } , span => {
451
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
452
+ startSpan ( { name : 'child span' } , childSpan => {
453
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
454
+ startSpan ( { name : 'grand child span' } , grandChildSpan => {
455
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( childSpan . spanContext ( ) . spanId ) ;
456
+ } ) ;
457
+ } ) ;
458
+ } ) ;
459
+ } ) ;
460
+ } ) ;
461
+
420
462
it ( 'samples with a tracesSampler' , ( ) => {
421
463
const tracesSampler = jest . fn ( ( ) => {
422
464
return true ;
@@ -751,6 +793,54 @@ describe('startSpanManual', () => {
751
793
} ) ;
752
794
} ) ;
753
795
796
+ describe ( 'parentSpanIsAlwaysRootSpan' , ( ) => {
797
+ it ( 'creates a span as child of root span if parentSpanIsAlwaysRootSpan=true' , ( ) => {
798
+ const options = getDefaultTestClientOptions ( {
799
+ tracesSampleRate : 1 ,
800
+ parentSpanIsAlwaysRootSpan : true ,
801
+ } ) ;
802
+ client = new TestClient ( options ) ;
803
+ setCurrentClient ( client ) ;
804
+ client . init ( ) ;
805
+
806
+ startSpanManual ( { name : 'parent span' } , span => {
807
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
808
+ startSpanManual ( { name : 'child span' } , childSpan => {
809
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
810
+ startSpanManual ( { name : 'grand child span' } , grandChildSpan => {
811
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
812
+ grandChildSpan . end ( ) ;
813
+ } ) ;
814
+ childSpan . end ( ) ;
815
+ } ) ;
816
+ span . end ( ) ;
817
+ } ) ;
818
+ } ) ;
819
+
820
+ it ( 'does not creates a span as child of root span if parentSpanIsAlwaysRootSpan=false' , ( ) => {
821
+ const options = getDefaultTestClientOptions ( {
822
+ tracesSampleRate : 1 ,
823
+ parentSpanIsAlwaysRootSpan : false ,
824
+ } ) ;
825
+ client = new TestClient ( options ) ;
826
+ setCurrentClient ( client ) ;
827
+ client . init ( ) ;
828
+
829
+ startSpanManual ( { name : 'parent span' } , span => {
830
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
831
+ startSpanManual ( { name : 'child span' } , childSpan => {
832
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
833
+ startSpanManual ( { name : 'grand child span' } , grandChildSpan => {
834
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( childSpan . spanContext ( ) . spanId ) ;
835
+ grandChildSpan . end ( ) ;
836
+ } ) ;
837
+ childSpan . end ( ) ;
838
+ } ) ;
839
+ span . end ( ) ;
840
+ } ) ;
841
+ } ) ;
842
+ } ) ;
843
+
754
844
it ( 'sets a child span reference on the parent span' , ( ) => {
755
845
expect . assertions ( 1 ) ;
756
846
startSpan ( { name : 'outer' } , ( outerSpan : any ) => {
@@ -995,6 +1085,64 @@ describe('startInactiveSpan', () => {
995
1085
} ) ;
996
1086
} ) ;
997
1087
1088
+ describe ( 'parentSpanIsAlwaysRootSpan' , ( ) => {
1089
+ it ( 'creates a span as child of root span if parentSpanIsAlwaysRootSpan=true' , ( ) => {
1090
+ const options = getDefaultTestClientOptions ( {
1091
+ tracesSampleRate : 1 ,
1092
+ parentSpanIsAlwaysRootSpan : true ,
1093
+ } ) ;
1094
+ client = new TestClient ( options ) ;
1095
+ setCurrentClient ( client ) ;
1096
+ client . init ( ) ;
1097
+
1098
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1099
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( undefined ) ;
1100
+
1101
+ startSpan ( { name : 'parent span' } , span => {
1102
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1103
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1104
+
1105
+ startSpan ( { name : 'child span' } , ( ) => {
1106
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1107
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1108
+
1109
+ startSpan ( { name : 'grand child span' } , ( ) => {
1110
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1111
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1112
+ } ) ;
1113
+ } ) ;
1114
+ } ) ;
1115
+ } ) ;
1116
+
1117
+ it ( 'does not creates a span as child of root span if parentSpanIsAlwaysRootSpan=false' , ( ) => {
1118
+ const options = getDefaultTestClientOptions ( {
1119
+ tracesSampleRate : 1 ,
1120
+ parentSpanIsAlwaysRootSpan : false ,
1121
+ } ) ;
1122
+ client = new TestClient ( options ) ;
1123
+ setCurrentClient ( client ) ;
1124
+ client . init ( ) ;
1125
+
1126
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1127
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( undefined ) ;
1128
+
1129
+ startSpan ( { name : 'parent span' } , span => {
1130
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1131
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1132
+
1133
+ startSpan ( { name : 'child span' } , childSpan => {
1134
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1135
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( childSpan . spanContext ( ) . spanId ) ;
1136
+
1137
+ startSpan ( { name : 'grand child span' } , grandChildSpan => {
1138
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1139
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( grandChildSpan . spanContext ( ) . spanId ) ;
1140
+ } ) ;
1141
+ } ) ;
1142
+ } ) ;
1143
+ } ) ;
1144
+ } ) ;
1145
+
998
1146
it ( 'includes the scope at the time the span was started when finished' , async ( ) => {
999
1147
const beforeSendTransaction = jest . fn ( event => event ) ;
1000
1148
0 commit comments