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