Skip to content

Commit

Permalink
feat(propagator/aws-xray): Extract X-Ray header in a case-insensitive…
Browse files Browse the repository at this point in the history
… 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 <amirgiraffe@gmail.com>
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 7, 2023
1 parent d23c329 commit 4227d8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,18 @@ export class AWSXRayPropagator implements TextMapPropagator {
carrier: unknown,
getter: TextMapGetter
): SpanContext {
const traceHeader = getter.get(carrier, AWSXRAY_TRACE_ID_HEADER);
if (!traceHeader || typeof traceHeader !== 'string')
const headerKeys = getter.keys(carrier);
const relevantHeaderKey = headerKeys.find(e => {
return e.toLowerCase() === AWSXRAY_TRACE_ID_HEADER;
});
if (!relevantHeaderKey) {
return INVALID_SPAN_CONTEXT;
}
const traceHeader = getter.get(carrier, relevantHeaderKey);

if (!traceHeader || typeof traceHeader !== 'string') {
return INVALID_SPAN_CONTEXT;
}

let pos = 0;
let trimmedPart: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ describe('AWSXRayPropagator', () => {

assert.deepStrictEqual(extractedSpanContext, undefined);
});

it('extracts context in a case-insensitive fashion', () => {
carrier[AWSXRAY_TRACE_ID_HEADER.toUpperCase()] =
'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar';
const extractedSpanContext = trace
.getSpan(
xrayPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
)
?.spanContext();

assert.deepStrictEqual(extractedSpanContext, {
traceId: TRACE_ID,
spanId: SPAN_ID,
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});

describe('.fields()', () => {
it('should return a field with AWS X-Ray Trace ID header', () => {
const expectedField = xrayPropagator.fields();
Expand Down

0 comments on commit 4227d8a

Please sign in to comment.