-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[serverless] Support trace context propagation for ALB target groups with MultiValueHeaders #30764
Conversation
@@ -253,6 +253,16 @@ func headersCarrier(hdrs map[string]string) (tracer.TextMapReader, error) { | |||
return tracer.TextMapCarrier(hdrs), nil | |||
} | |||
|
|||
// multiValueHeadersCarrier returns the tracer.TextMapReader used to extract trace | |||
// context from a MultiValueHeaders field of form map[string][]string. | |||
func multiValueHeadersCarrier(hdrs map[string][]string) (tracer.TextMapReader, error) { |
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.
I suspect you can probably use https://pkg.go.dev/github.com/DataDog/[email protected]/ddtrace/tracer#HTTPHeadersCarrier which won't require you to reinvent the wheel or do extra allocations.
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.
Thank you for your suggestion!
I've made the changes in the commit 270eb93 to use HTTPHeadersCarrier from dd-trace-go.
I've removed the multiValueHeadersCarrier function and its associated tests, while ensuring that the final context extraction behavior remains covered by the existing tests.
datadog-agent/pkg/serverless/trace/propagation/extractor_test.go
Lines 544 to 553 in 6eda679
{ | |
name: "ALBTargetGroupRequestMultiValueHeaders", | |
events: []interface{}{ | |
events.ALBTargetGroupRequest{ | |
MultiValueHeaders: toMultiValueHeaders(headersMapAll), | |
}, | |
}, | |
expCtx: ddTraceContext, | |
expNoErr: true, | |
}, |
pkg/serverless/trigger/extractor.go
Outdated
} | ||
if ua := event.Headers["User-Agent"]; ua != "" { | ||
} |
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.
You can do this without an extra allocation by checking event.MultiValueHeaders["Referer"] != nil && len(event.MultiValueHeaders["Referer"]) > 0
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.
Thank you for the suggestion!
I've implemented this improvement in commit aaaa24f.
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.
Thanks so much for this PR. It's a great improvement and we really appreciate your willingness to implement it. I've made just a couple of requests for changes but otherwise this looks great.
Signed-off-by: SATO Taiki <[email protected]>
…ltiValueHeaders Signed-off-by: SATO Taiki <[email protected]>
I reopened this PR as #31542 so the tests will run and we can merge it. |
What does this PR do?
Adds support for extracting trace context from MultiValueHeaders in ALBTargetGroupRequest
Motivation
Currently, Datadog APM context propagation doesn't work when MultiValueHeaders is enabled in ALB target groups. This PR resolves this issue by allowing trace context propagation even when using MultiValueHeaders configuration.
Describe how to test/QA your changes
Possible Drawbacks / Trade-offs
Additional Notes
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers-request