@@ -449,6 +449,48 @@ describe('startSpan', () => {
449
449
} ) ;
450
450
} ) ;
451
451
452
+ describe ( 'parentSpanIsAlwaysRootSpan' , ( ) => {
453
+ it ( 'creates a span as child of root span if parentSpanIsAlwaysRootSpan=true' , ( ) => {
454
+ const options = getDefaultTestClientOptions ( {
455
+ tracesSampleRate : 1 ,
456
+ parentSpanIsAlwaysRootSpan : true ,
457
+ } ) ;
458
+ client = new TestClient ( options ) ;
459
+ setCurrentClient ( client ) ;
460
+ client . init ( ) ;
461
+
462
+ startSpan ( { name : 'parent span' } , span => {
463
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
464
+ startSpan ( { name : 'child span' } , childSpan => {
465
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
466
+ startSpan ( { name : 'grand child span' } , grandChildSpan => {
467
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
468
+ } ) ;
469
+ } ) ;
470
+ } ) ;
471
+ } ) ;
472
+
473
+ it ( 'does not creates a span as child of root span if parentSpanIsAlwaysRootSpan=false' , ( ) => {
474
+ const options = getDefaultTestClientOptions ( {
475
+ tracesSampleRate : 1 ,
476
+ parentSpanIsAlwaysRootSpan : false ,
477
+ } ) ;
478
+ client = new TestClient ( options ) ;
479
+ setCurrentClient ( client ) ;
480
+ client . init ( ) ;
481
+
482
+ startSpan ( { name : 'parent span' } , span => {
483
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
484
+ startSpan ( { name : 'child span' } , childSpan => {
485
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
486
+ startSpan ( { name : 'grand child span' } , grandChildSpan => {
487
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( childSpan . spanContext ( ) . spanId ) ;
488
+ } ) ;
489
+ } ) ;
490
+ } ) ;
491
+ } ) ;
492
+ } ) ;
493
+
452
494
it ( 'samples with a tracesSampler' , ( ) => {
453
495
const tracesSampler = jest . fn ( ( ) => {
454
496
return true ;
@@ -754,6 +796,54 @@ describe('startSpanManual', () => {
754
796
} ) ;
755
797
} ) ;
756
798
799
+ describe ( 'parentSpanIsAlwaysRootSpan' , ( ) => {
800
+ it ( 'creates a span as child of root span if parentSpanIsAlwaysRootSpan=true' , ( ) => {
801
+ const options = getDefaultTestClientOptions ( {
802
+ tracesSampleRate : 1 ,
803
+ parentSpanIsAlwaysRootSpan : true ,
804
+ } ) ;
805
+ client = new TestClient ( options ) ;
806
+ setCurrentClient ( client ) ;
807
+ client . init ( ) ;
808
+
809
+ startSpanManual ( { name : 'parent span' } , span => {
810
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
811
+ startSpanManual ( { name : 'child span' } , childSpan => {
812
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
813
+ startSpanManual ( { name : 'grand child span' } , grandChildSpan => {
814
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
815
+ grandChildSpan . end ( ) ;
816
+ } ) ;
817
+ childSpan . end ( ) ;
818
+ } ) ;
819
+ span . end ( ) ;
820
+ } ) ;
821
+ } ) ;
822
+
823
+ it ( 'does not creates a span as child of root span if parentSpanIsAlwaysRootSpan=false' , ( ) => {
824
+ const options = getDefaultTestClientOptions ( {
825
+ tracesSampleRate : 1 ,
826
+ parentSpanIsAlwaysRootSpan : false ,
827
+ } ) ;
828
+ client = new TestClient ( options ) ;
829
+ setCurrentClient ( client ) ;
830
+ client . init ( ) ;
831
+
832
+ startSpanManual ( { name : 'parent span' } , span => {
833
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
834
+ startSpanManual ( { name : 'child span' } , childSpan => {
835
+ expect ( spanToJSON ( childSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
836
+ startSpanManual ( { name : 'grand child span' } , grandChildSpan => {
837
+ expect ( spanToJSON ( grandChildSpan ) . parent_span_id ) . toBe ( childSpan . spanContext ( ) . spanId ) ;
838
+ grandChildSpan . end ( ) ;
839
+ } ) ;
840
+ childSpan . end ( ) ;
841
+ } ) ;
842
+ span . end ( ) ;
843
+ } ) ;
844
+ } ) ;
845
+ } ) ;
846
+
757
847
it ( 'sets a child span reference on the parent span' , ( ) => {
758
848
expect . assertions ( 1 ) ;
759
849
startSpan ( { name : 'outer' } , ( outerSpan : any ) => {
@@ -966,6 +1056,64 @@ describe('startInactiveSpan', () => {
966
1056
} ) ;
967
1057
} ) ;
968
1058
1059
+ describe ( 'parentSpanIsAlwaysRootSpan' , ( ) => {
1060
+ it ( 'creates a span as child of root span if parentSpanIsAlwaysRootSpan=true' , ( ) => {
1061
+ const options = getDefaultTestClientOptions ( {
1062
+ tracesSampleRate : 1 ,
1063
+ parentSpanIsAlwaysRootSpan : true ,
1064
+ } ) ;
1065
+ client = new TestClient ( options ) ;
1066
+ setCurrentClient ( client ) ;
1067
+ client . init ( ) ;
1068
+
1069
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1070
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( undefined ) ;
1071
+
1072
+ startSpan ( { name : 'parent span' } , span => {
1073
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1074
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1075
+
1076
+ startSpan ( { name : 'child span' } , ( ) => {
1077
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1078
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1079
+
1080
+ startSpan ( { name : 'grand child span' } , ( ) => {
1081
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1082
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( span . spanContext ( ) . spanId ) ;
1083
+ } ) ;
1084
+ } ) ;
1085
+ } ) ;
1086
+ } ) ;
1087
+
1088
+ it ( 'does not creates a span as child of root span if parentSpanIsAlwaysRootSpan=false' , ( ) => {
1089
+ const options = getDefaultTestClientOptions ( {
1090
+ tracesSampleRate : 1 ,
1091
+ parentSpanIsAlwaysRootSpan : false ,
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' } , childSpan => {
1105
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1106
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( childSpan . spanContext ( ) . spanId ) ;
1107
+
1108
+ startSpan ( { name : 'grand child span' } , grandChildSpan => {
1109
+ const inactiveSpan = startInactiveSpan ( { name : 'inactive span' } ) ;
1110
+ expect ( spanToJSON ( inactiveSpan ) . parent_span_id ) . toBe ( grandChildSpan . spanContext ( ) . spanId ) ;
1111
+ } ) ;
1112
+ } ) ;
1113
+ } ) ;
1114
+ } ) ;
1115
+ } ) ;
1116
+
969
1117
it ( 'includes the scope at the time the span was started when finished' , async ( ) => {
970
1118
const beforeSendTransaction = jest . fn ( event => event ) ;
971
1119
0 commit comments