-
Notifications
You must be signed in to change notification settings - Fork 36
Extract trace context from ALB multiValueHeaders #647
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
Extract trace context from ALB multiValueHeaders #647
Conversation
@@ -97,6 +97,35 @@ describe("HTTPEventTraceExtractor", () => { | |||
expect(traceContext?.source).toBe("event"); | |||
}); | |||
|
|||
it("extracts trace context from payload with multiValueHeaders", () => { | |||
mockSpanContext = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an event from either ALB or API GW with real values to ensure this works? That way we can re-use it in Bottlecap too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just commenting for visibility -- as discussed, this change only applies to ALB. API GW can have multiValueHeaders, but trace context is always injected under the regular headers
so no changes needed for API GW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I added a real event from ALB!
55e24fb
to
032f3ca
Compare
8000 if (Array.isArray(val)) { | ||
// MultiValueHeaders: take the first value | ||
lowerCaseHeaders[key.toLowerCase()] = val[0] ?? ""; | ||
} else if (typeof val === "string") { | ||
// Single‐value header | ||
lowerCaseHeaders[key.toLowerCase()] = val; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Array.isArray(val)) { | |
// MultiValueHeaders: take the first value | |
lowerCaseHeaders[key.toLowerCase()] = val[0] ?? ""; | |
} else if (typeof val === "string") { | |
// Single‐value header | |
lowerCaseHeaders[key.toLowerCase()] = val; | |
} | |
if (Array.isArray(val)) { | |
// MultiValueHeaders: take the first value | |
lowerCaseHeaders[key.toLowerCase()] = val[0] ?? ""; | |
continue; | |
} | |
// Single‐value header | |
lowerCaseHeaders[key.toLowerCase()] = val; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to type check key
and make sure it's a string first; otherwise typescript errors TS2322: Type unknown is not assignable to type string
### What Support trace extraction when we receive `multiValueHeaders` instead of `headers`. This can happen if multi value headers are turned on in ALB. We do this by creating an ALB event in `span_inferrer` -- even though there's no inferred spans, this is still a common event type. The event payload structure for multiValueHeaders is defined here: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html This also has the benefit of creating these trigger tags: <img width="400" alt="Screenshot 2025-05-01 at 4 55 34 PM" src="https://github.com/user-attachments/assets/d02ba864-3ee3-43d8-9f4b-bdb6650544a5" /> <img width="250" alt="Screenshot 2025-05-01 at 4 56 38 PM" src="https://github.com/user-attachments/assets/15c56afe-d314-4c42-a828-908d499ab62f" /> ### Motivation Porting DataDog/datadog-lambda-js#647 and DataDog/datadog-agent#31542 https://datadoghq.atlassian.net/browse/SVLS-6757
What does this PR do?
Support trace extraction when we receive
multiValueHeaders
instead ofheaders
. This can happen if multi value headers are turned on in ALB.The event payload structure for multiValueHeaders is defined here: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
Motivation
#603
https://datadoghq.atlassian.net/browse/SVLS-6725
Testing Guidelines
Manually, unit tests
Additional Notes
Types of Changes
Check all that apply