@@ -24,6 +24,7 @@ import {
24
24
TraceFlags ,
25
25
trace ,
26
26
TextMapGetter ,
27
+ propagation ,
27
28
} from '@opentelemetry/api' ;
28
29
import { TraceState } from '@opentelemetry/core' ;
29
30
@@ -33,6 +34,7 @@ describe('AWSXRayPropagator', () => {
33
34
const xrayPropagator = new AWSXRayPropagator ( ) ;
34
35
const TRACE_ID = '8a3c60f7d188f8fa79d48a391a778fa6' ;
35
36
const SPAN_ID = '53995c3f42cd8ad8' ;
37
+ const LINEAGE_ID = '100:e3b0c442:11' ;
36
38
const SAMPLED_TRACE_FLAG = TraceFlags . SAMPLED ;
37
39
const NOT_SAMPLED_TRACE_FLAG = TraceFlags . NONE ;
38
40
@@ -119,6 +121,26 @@ describe('AWSXRayPropagator', () => {
119
121
120
122
assert . deepStrictEqual ( carrier , { } ) ;
121
123
} ) ;
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
+ } ) ;
122
144
} ) ;
123
145
124
146
describe ( '.extract()' , ( ) => {
@@ -345,6 +367,36 @@ describe('AWSXRayPropagator', () => {
345
367
} ) ;
346
368
} ) ;
347
369
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
+
348
400
describe ( '.fields()' , ( ) => {
349
401
it ( 'should return a field with AWS X-Ray Trace ID header' , ( ) => {
350
402
const expectedField = xrayPropagator . fields ( ) ;
0 commit comments