Skip to content

Commit d1e4a11

Browse files
committed
Support Trace Context extraction from Lambda Context object, and respect user-configured OTEL_PROPAGATORS (#1191)
*Issue #, if available:* - In latest `com.amazonaws:aws-lambda-java-core:1.4.0`, Lambda Context has a new `lambdaContext.getXrayTraceId()` method. We need to use this over SystemProperty/EnvVar to support multi-concurrency in Lambda. *Description of changes:* - respect OTEL_PROPAGATORS Env Var priority - Priority logic BEFORE: - Create `carrierA` to contain headers from Lambda request http headers and the custom client context - get X-Ray Trace ID from (in order or priority) SystemProperty or EnvVar, add it to new `carrierB` - Use Global Propagator to extract trace context from `carrierB` (trace extraction only works if xray propagator is configured) - If above trace extraction results in a context that is not valid&sampled, try again with Global Propagator using `carrierA` - Priority logic AFTER: - Create `carrierA` to contain headers from Lambda request http headers and the custom client context - get X-Ray Trace ID from (in order or priority) Lambda Context, SystemProperty, or EnvVar, add it to `carrierA` (will overwrite x-ray header value if present from Lambda request http headers). - Use Global Propagator to extract trace context from `carrierA` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent af94b77 commit d1e4a11

File tree

3 files changed

+366
-53
lines changed

3 files changed

+366
-53
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ For any change that affects end users of this package, please add an entry under
1212
If your change does not need a CHANGELOG entry, add the "skip changelog" label to your PR.
1313

1414
## Unreleased
15+
16+
### Enhancements
17+
18+
- Support X-Ray Trace Id extraction from Lambda Context object, and respect user-configured OTEL_PROPAGATORS in AWS Lamdba instrumentation
19+
([#1191](https://github.com/aws-observability/aws-otel-java-instrumentation/pull/1191))

lambda-layer/otel-instrument

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export OTEL_INSTRUMENTATION_AWS_SDK_EXPERIMENTAL_SPAN_ATTRIBUTES=true
44

5-
export OTEL_PROPAGATORS="${OTEL_PROPAGATORS:-baggage,xray,tracecontext}"
5+
export OTEL_PROPAGATORS="${OTEL_PROPAGATORS:-baggage,tracecontext,xray}"
66

77
export OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME:-${AWS_LAMBDA_FUNCTION_NAME}}
88

0 commit comments

Comments
 (0)