Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(propagator/aws-xray): Extract X-Ray header in a case-insensitive fashion #1328

Merged
merged 16 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to implement that logic in a new proprietary TextMapGetter

Copy link
Contributor Author

@NPellet NPellet Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osherv I don't think that's advisable.
If, as a platform engineer, I use the SDK to register an AWS XRay propagator, or a B3 propagator, that's my problem. It should be invisible to the API consumer.

The developer who then uses the API to extract or inject the context should only concern himself with the serialisation/deserialisation of the context into/from the payload. It should not be concerned whether or not the propagator is expecting a lowercase string or not. It can't know if the expected key should be lower case, upper case, camel-case, kebab-case, etc. That's the responsibly of the propagator.

If you stand your point, then the AWS Lambda instrumentation has to be modified to use case-independent header keys, because at the moment, using both appears to be incompatible.


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