@@ -79,9 +79,8 @@ describe('AWSXRayPropagator', () => {
7979 ) ;
8080 } ) ;
8181
82- it ( 'should inject with TraceState' , ( ) => {
83- const traceState = new TraceState ( ) ;
84- traceState . set ( 'foo' , 'bar' ) ;
82+ it ( 'should not inject with TraceState' , ( ) => {
83+ const traceState = new TraceState ( ) . set ( 'foo' , 'bar' ) . set ( 'key' , 'val' ) ;
8584 const spanContext : SpanContext = {
8685 traceId : TRACE_ID ,
8786 spanId : SPAN_ID ,
@@ -94,7 +93,8 @@ describe('AWSXRayPropagator', () => {
9493 defaultTextMapSetter
9594 ) ;
9695
97- // TODO: assert trace state when the propagator supports it
96+ // Rely on W3CTraceContextPropagator to propagate trace state
97+ // As such, it's expected that trace state is not populated here
9898 assert . deepStrictEqual (
9999 carrier [ AWSXRAY_TRACE_ID_HEADER ] ,
100100 'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1'
@@ -345,6 +345,36 @@ describe('AWSXRayPropagator', () => {
345345 } ) ;
346346 } ) ;
347347
348+ it ( 'should extract with TraceState previously propagated' , ( ) => {
349+ carrier [ AWSXRAY_TRACE_ID_HEADER ] =
350+ 'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1' ;
351+
352+ const spanContextWithTraceState : SpanContext = {
353+ traceId : 'existing-trace-id' ,
354+ spanId : 'existing-span-id' ,
355+ traceFlags : TraceFlags . SAMPLED ,
356+ traceState : new TraceState ( ) . set ( 'foo' , 'bar' ) . set ( 'from' , 'context' ) ,
357+ } ;
358+ const incomingContext = trace . setSpan (
359+ ROOT_CONTEXT ,
360+ trace . wrapSpanContext ( spanContextWithTraceState )
361+ ) ;
362+
363+ const extractedSpanContext = trace
364+ . getSpan (
365+ xrayPropagator . extract ( incomingContext , carrier , defaultTextMapGetter )
366+ )
367+ ?. spanContext ( ) ;
368+
369+ assert . deepStrictEqual ( extractedSpanContext , {
370+ traceId : TRACE_ID ,
371+ spanId : SPAN_ID ,
372+ isRemote : true ,
373+ traceFlags : TraceFlags . SAMPLED ,
374+ traceState : new TraceState ( ) . set ( 'foo' , 'bar' ) . set ( 'from' , 'context' ) ,
375+ } ) ;
376+ } ) ;
377+
348378 describe ( '.fields()' , ( ) => {
349379 it ( 'should return a field with AWS X-Ray Trace ID header' , ( ) => {
350380 const expectedField = xrayPropagator . fields ( ) ;
0 commit comments