Skip to content

Commit 6d9eeca

Browse files
NPelletblumamirdyladan
authored
feat(propagator/aws-xray): Extract X-Ray header in a case-insensitive fashion (#1328)
* Extract X-Ray header in a case-insensitive fashion * Back to apostrophes * Switch to 1 tab = 2 spaces * Add semis * Apply prettier to tests as well * chore: fix lint --------- Co-authored-by: Amir Blum <[email protected]> Co-authored-by: Daniel Dyla <[email protected]>
1 parent 7f569ed commit 6d9eeca

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/AWSXRayPropagator.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ export class AWSXRayPropagator implements TextMapPropagator {
9292
carrier: unknown,
9393
getter: TextMapGetter
9494
): SpanContext {
95-
const traceHeader = getter.get(carrier, AWSXRAY_TRACE_ID_HEADER);
96-
if (!traceHeader || typeof traceHeader !== 'string')
95+
const headerKeys = getter.keys(carrier);
96+
const relevantHeaderKey = headerKeys.find(e => {
97+
return e.toLowerCase() === AWSXRAY_TRACE_ID_HEADER;
98+
});
99+
if (!relevantHeaderKey) {
97100
return INVALID_SPAN_CONTEXT;
101+
}
102+
const traceHeader = getter.get(carrier, relevantHeaderKey);
103+
104+
if (!traceHeader || typeof traceHeader !== 'string') {
105+
return INVALID_SPAN_CONTEXT;
106+
}
98107

99108
let pos = 0;
100109
let trimmedPart: string;

test/AWSXRayPropagator.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,24 @@ describe('AWSXRayPropagator', () => {
299299

300300
assert.deepStrictEqual(extractedSpanContext, undefined);
301301
});
302+
303+
it('extracts context in a case-insensitive fashion', () => {
304+
carrier[AWSXRAY_TRACE_ID_HEADER.toUpperCase()] =
305+
'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar';
306+
const extractedSpanContext = trace
307+
.getSpan(
308+
xrayPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
309+
)
310+
?.spanContext();
311+
312+
assert.deepStrictEqual(extractedSpanContext, {
313+
traceId: TRACE_ID,
314+
spanId: SPAN_ID,
315+
isRemote: true,
316+
traceFlags: TraceFlags.SAMPLED,
317+
});
318+
});
319+
302320
describe('.fields()', () => {
303321
it('should return a field with AWS X-Ray Trace ID header', () => {
304322
const expectedField = xrayPropagator.fields();

0 commit comments

Comments
 (0)