Support Lambda PassThrough trace header propagation #409
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Lambda is implementing PassThrough mode which allows customers to send traces through instrumented lambda functions without those functions being traced. The way this is done is by changing the trace header structure from
Root=...;Parent=...;Sampled=1
in the active tracing case toRoot=...
in the PassThrough case. As such, our SDK needs to be updated to handle this.Changes
SuppressWarnings("nullness")
becauseTraceHeader.getRootTraceId()
returns an@Nullable TraceId
butSegment.noOp()
expects a@NonNull TraceId
Root
if we're not actively samplingTesting
Ran many extensive tests using v2.16.0, v2.17.0, and these changes to compare the outcomes. In these tests I configured 3 lambda functions to interact with each other ALL instrumented with the new changes:
GetAccountSettings
The trace headers in the below cases are from logging
System.getenv("_X_AMZN_TRACE_ID")
in the lambda functions themselvesThe following are some important cases that prove the functionality of the code change
Case 1.a: Lambda A Active → Lambda B PassThrough → Lambda C Active
Case 1.b: Same thing but Lambda A Active sets
Sampled=0
Case 2: Lambda A PassThrough → Lambda B Active → Lambda C PassThrough
GetAccountSettings
call IS TRACED; this is expected behaviour because we entered Active tracing mode in Lambda B and this is meant to propagate to downstream services. If the downstream service has its own version of passive tracing/X-Ray integration, it should be configured as such, but PassThrough functionality should only apply to Lambda functions and not the downstream calls they trigger unless the entire pathway has been in PassThroughCase 3.a: Calling Lambda B PassThrough → Lambda C PassThrough
GetAccountSettings
call since we never entered Active tracing mode.Case 3.b: Calling Lambda B Active → Lambda C Active
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.