@@ -24,6 +24,7 @@ import {
2424 TraceFlags ,
2525 trace ,
2626 TextMapGetter ,
27+ propagation ,
2728} from '@opentelemetry/api' ;
2829import { TraceState } from '@opentelemetry/core' ;
2930
@@ -33,6 +34,7 @@ describe('AWSXRayPropagator', () => {
3334 const xrayPropagator = new AWSXRayPropagator ( ) ;
3435 const TRACE_ID = '8a3c60f7d188f8fa79d48a391a778fa6' ;
3536 const SPAN_ID = '53995c3f42cd8ad8' ;
37+ const LINEAGE_ID = '100:e3b0c442:11' ;
3638 const SAMPLED_TRACE_FLAG = TraceFlags . SAMPLED ;
3739 const NOT_SAMPLED_TRACE_FLAG = TraceFlags . NONE ;
3840
@@ -119,6 +121,26 @@ describe('AWSXRayPropagator', () => {
119121
120122 assert . deepStrictEqual ( carrier , { } ) ;
121123 } ) ;
124+
125+ it ( 'should inject with lineage' , ( ) => {
126+ const spanContext : SpanContext = {
127+ traceId : TRACE_ID ,
128+ spanId : SPAN_ID ,
129+ traceFlags : SAMPLED_TRACE_FLAG ,
130+ } ;
131+ xrayPropagator . inject (
132+ propagation . setBaggage ( trace . setSpan ( ROOT_CONTEXT , trace . wrapSpanContext ( spanContext ) ) , propagation . createBaggage ( {
133+ 'Lineage' : { value : LINEAGE_ID }
134+ } ) ) ,
135+ carrier ,
136+ defaultTextMapSetter
137+ ) ;
138+
139+ assert . deepStrictEqual (
140+ carrier [ AWSXRAY_TRACE_ID_HEADER ] ,
141+ 'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Lineage=100:e3b0c442:11'
142+ ) ;
143+ } ) ;
122144 } ) ;
123145
124146 describe ( '.extract()' , ( ) => {
@@ -345,6 +367,36 @@ describe('AWSXRayPropagator', () => {
345367 } ) ;
346368 } ) ;
347369
370+ it ( 'should extract lineage into baggage' , ( ) => {
371+ carrier [ AWSXRAY_TRACE_ID_HEADER ] =
372+ 'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Lineage=100:e3b0c442:11' ;
373+ const extractedContext = xrayPropagator . extract ( ROOT_CONTEXT , carrier , defaultTextMapGetter )
374+
375+ assert . deepStrictEqual ( propagation . getBaggage ( extractedContext ) ?. getEntry ( 'Lineage' ) , {
376+ "value" : LINEAGE_ID
377+ } ) ;
378+ } ) ;
379+
380+ const invalidLineageHeaders = [
381+ "" ,
382+ "::" ,
383+ "1::" ,
384+ "1::1" ,
385+ "1:badc0de:13" ,
386+ ":fbadc0de:13" ,
387+ "65535:fbadc0de:255"
388+ ] ;
389+
390+ invalidLineageHeaders . forEach ( ( lineageHeader ) => {
391+ it ( `should ignore invalid lineage header: ${ lineageHeader } ` , ( ) => {
392+ carrier [ AWSXRAY_TRACE_ID_HEADER ] =
393+ `Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Lineage=${ lineageHeader } ` ;
394+ const extractedContext = xrayPropagator . extract ( ROOT_CONTEXT , carrier , defaultTextMapGetter )
395+
396+ assert . deepStrictEqual ( propagation . getBaggage ( extractedContext ) , undefined ) ;
397+ } ) ;
398+ } ) ;
399+
348400 describe ( '.fields()' , ( ) => {
349401 it ( 'should return a field with AWS X-Ray Trace ID header' , ( ) => {
350402 const expectedField = xrayPropagator . fields ( ) ;
0 commit comments