fix(nodejs): make aws-lambda and aws-sdk instrumentations respect OTEL_NODE_DISABLED_INSTRUMENTATIONS #2012
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.
Problem
DynamoDB Streams and other AWS event sources lack metadata carriers for trace propagation. Unlike SQS (message attributes) or API Gateway (HTTP headers), DynamoDB Streams only contain the changed record data.
The Trace Propagation Issue
When using OpenTelemetry with DynamoDB Streams:
Producer writes to DynamoDB with trace context stored in record:
{ "data": "data", "_otel": { "traceparent": "00-7d7836d35ab7da657d35c2b5f889c3be-de0931d210e214b3-01" } }Consumer Lambda needs to extract and restore this context
Problem:
AwsLambdaInstrumentationcreates automatic wrapper span with NEW trace ID before handler code runs:Result: Distributed trace is broken - cannot correlate stream processing with original operation
Solution
This PR extends the functionality added in the base implementation to make
aws-lambdaandaws-sdkinstrumentations respectOTEL_NODE_DISABLED_INSTRUMENTATIONS.Previously, PR #1653 added the ability to disable instrumentations via
OTEL_NODE_DISABLED_INSTRUMENTATIONS, but the AWS Lambda and AWS SDK instrumentations were always loaded unconditionally in thecreateInstrumentations()function. This meant users couldn't disable these instrumentations even when setting the environment variable.Usage:
export OTEL_NODE_DISABLED_INSTRUMENTATIONS=aws-lambdaEffect: Disables automatic Lambda wrapper span, allowing handler to manually restore trace context from event data before creating spans.
Use Case: DynamoDB Streams Trace Propagation
Producer (stores trace context):
Consumer (restores trace context with disabled AwsLambdaInstrumentation):
Result: Full trace continuity from producer → DynamoDB → stream → consumer
Related Issues
Event Sources Affected
This enables manual trace propagation for AWS event sources without metadata carriers:
Industry Pattern
This approach aligns with industry best practices for DynamoDB Streams trace propagation:
Testing
aws-lambdaandaws-sdkadded todefaultInstrumentationListgetActiveInstumentations()OTEL_NODE_DISABLED_INSTRUMENTATIONS=aws-lambdaBenefits