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

Conversation

NPellet
Copy link
Contributor

@NPellet NPellet commented Dec 12, 2022

Which problem is this PR solving?

We observed that we receive API Gateway triggers where the X-Ray header is in camel case (despite having injected() with the same propagator).
This PR allows the X-Ray propagator to extract from a object with a case-insensitive key.

Short description of the changes

  1. Extract the keys from the carrier
  2. Match the lower case key with the lower case reference key and extract the first match
  3. Carry on with that key instead of the reference lower-case key

@NPellet NPellet requested a review from a team December 12, 2022 13:39
@NPellet NPellet changed the title feat(aws-xray-extractory) Extract X-Ray header in a case-insensitive fashion feat(propagator/aws-xray): Extract X-Ray header in a case-insensitive fashion Dec 12, 2022
Comment on lines 95 to 106
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.

Copy link
Contributor

@willarmiros willarmiros left a comment

Choose a reason for hiding this comment

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

LGTM - the header should be case-insensitive

@codecov
Copy link

codecov bot commented Jan 1, 2023

Codecov Report

Merging #1328 (7223439) into main (d23c329) will decrease coverage by 0.43%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1328      +/-   ##
==========================================
- Coverage   96.08%   95.65%   -0.43%     
==========================================
  Files          14       16       +2     
  Lines         893     1105     +212     
  Branches      191      230      +39     
==========================================
+ Hits          858     1057     +199     
- Misses         35       48      +13     
Impacted Files Coverage Δ
...metry-propagator-aws-xray/src/AWSXRayPropagator.ts 100.00% <100.00%> (ø)
...tapackages/auto-instrumentations-node/src/utils.ts 98.21% <0.00%> (ø)
...-instrumentation-aws-lambda/src/instrumentation.ts 92.05% <0.00%> (ø)

@blumamir
Copy link
Member

blumamir commented Jan 1, 2023

@NPellet can you please fix the lint issue so CI is green and we can merge? Thanks

@blumamir blumamir merged commit 4227d8a into open-telemetry:main Feb 7, 2023
@dyladan dyladan mentioned this pull request Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants