@@ -329,9 +329,7 @@ describe('trace', () => {
329329 it ( 'allows to pass parentSpan=null' , ( ) => {
330330 startSpan ( { name : 'GET users/[id' } , ( ) => {
331331 startSpan ( { name : 'child' , parentSpan : null } , span => {
332- // Due to the way we propagate the scope in OTEL,
333- // the parent_span_id is not actually undefined here, but comes from the propagation context
334- expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( getCurrentScope ( ) . getPropagationContext ( ) . spanId ) ;
332+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
335333 } ) ;
336334 } ) ;
337335 } ) ;
@@ -591,10 +589,7 @@ describe('trace', () => {
591589 it ( 'allows to pass parentSpan=null' , ( ) => {
592590 startSpan ( { name : 'outer' } , ( ) => {
593591 const span = startInactiveSpan ( { name : 'test span' , parentSpan : null } ) ;
594-
595- // Due to the way we propagate the scope in OTEL,
596- // the parent_span_id is not actually undefined here, but comes from the propagation context
597- expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( getCurrentScope ( ) . getPropagationContext ( ) . spanId ) ;
592+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
598593 span . end ( ) ;
599594 } ) ;
600595 } ) ;
@@ -881,9 +876,7 @@ describe('trace', () => {
881876 it ( 'allows to pass parentSpan=null' , ( ) => {
882877 startSpan ( { name : 'outer' } , ( ) => {
883878 startSpanManual ( { name : 'GET users/[id]' , parentSpan : null } , span => {
884- // Due to the way we propagate the scope in OTEL,
885- // the parent_span_id is not actually undefined here, but comes from the propagation context
886- expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( getCurrentScope ( ) . getPropagationContext ( ) . spanId ) ;
879+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
887880 span . end ( ) ;
888881 } ) ;
889882 } ) ;
@@ -1016,36 +1009,45 @@ describe('trace', () => {
10161009 } ) ;
10171010
10181011 describe ( 'propagation' , ( ) => {
1019- it ( 'picks up the trace context from the scope , if there is no parent' , ( ) => {
1012+ it ( 'starts new trace, if there is no parent' , ( ) => {
10201013 withScope ( scope => {
10211014 const propagationContext = scope . getPropagationContext ( ) ;
10221015 const span = startInactiveSpan ( { name : 'test span' } ) ;
10231016
10241017 expect ( span ) . toBeDefined ( ) ;
1025- expect ( spanToJSON ( span ) . trace_id ) . toEqual ( propagationContext . traceId ) ;
1026- expect ( spanToJSON ( span ) . parent_span_id ) . toEqual ( propagationContext . spanId ) ;
1018+ const traceId = spanToJSON ( span ) . trace_id ;
1019+ expect ( traceId ) . toMatch ( / [ a - f 0 - 9 ] { 32 } / ) ;
1020+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
1021+ expect ( spanToJSON ( span ) . trace_id ) . not . toEqual ( propagationContext . traceId ) ;
10271022
10281023 expect ( getDynamicSamplingContextFromSpan ( span ) ) . toEqual ( {
1029- ...getDynamicSamplingContextFromClient ( propagationContext . traceId , getClient ( ) ! ) ,
1024+ trace_id : traceId ,
1025+ environment : 'production' ,
1026+ public_key : 'username' ,
10301027 sample_rate : '1' ,
10311028 sampled : 'true' ,
10321029 transaction : 'test span' ,
10331030 } ) ;
10341031 } ) ;
10351032 } ) ;
10361033
1037- it ( 'picks up the trace context from the scope, including parentSpanId, if there is no parent' , ( ) => {
1034+ // Note: This _should_ never happen, when we have an incoming trace, we should always have a parent span
1035+ it ( 'starts new trace, ignoring parentSpanId, if there is no parent' , ( ) => {
10381036 withScope ( scope => {
10391037 const propagationContext = scope . getPropagationContext ( ) ;
10401038 propagationContext . parentSpanId = '1121201211212012' ;
10411039 const span = startInactiveSpan ( { name : 'test span' } ) ;
10421040
10431041 expect ( span ) . toBeDefined ( ) ;
1044- expect ( spanToJSON ( span ) . trace_id ) . toEqual ( propagationContext . traceId ) ;
1045- expect ( spanToJSON ( span ) . parent_span_id ) . toEqual ( '1121201211212012' ) ;
1042+ const traceId = spanToJSON ( span ) . trace_id ;
1043+ expect ( traceId ) . toMatch ( / [ a - f 0 - 9 ] { 32 } / ) ;
1044+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
1045+ expect ( spanToJSON ( span ) . trace_id ) . not . toEqual ( propagationContext . traceId ) ;
10461046
10471047 expect ( getDynamicSamplingContextFromSpan ( span ) ) . toEqual ( {
1048- ...getDynamicSamplingContextFromClient ( propagationContext . traceId , getClient ( ) ! ) ,
1048+ environment : 'production' ,
1049+ public_key : 'username' ,
1050+ trace_id : traceId ,
10491051 sample_rate : '1' ,
10501052 sampled : 'true' ,
10511053 transaction : 'test span' ,
0 commit comments