Skip to content
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

OpenTelemetry AWS Lambda Layer Not Propagating Parent Span ID in TypeScript Lambdas #1742

Open
nirvana620 opened this issue Mar 13, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@nirvana620
Copy link

Describe the Bug
OpenTelemetry auto-instrumentation for AWS Lambda is not correctly propagating parent span IDs when using the AWS Lambda Layer (otel-nodejs) in a TypeScript-based Lambda.

  • JavaScript Lambdas work correctly.
  • TypeScript Lambdas drop parent spans, causing traces to appear disconnected in the tracing backend.

What did you expect to see?

  • The parent span ID should be propagated correctly.
  • Traces should be connected to the parent spans.

What did you see instead?

  • No parent span ID is retained.
  • The trace appears disconnected in the tracing backend.

This is a single lambda invocation with no parent ID and every span is seperated.

Timestamp (Local) Level Service span_id trace_id Message
  Mar 12 4:37:55.769 PM ok hasEligibleMacAddressHandler 36b4fac9cbc266b5 67531b345b422befaa60232c084627f2 dns.lookup
  Mar 12 4:37:55.750 PM ok hasEligibleMacAddressHandler 3885f329e9bebb07 2c3d9bfa77566d65f5c38f5da7d93a4a 200 GET http://localhost:2773/secretsmanager/get?secretId=qa/account-vehicle-service
  Mar 12 4:37:54.410 PM ok hasEligibleMacAddressHandler 52b262ff58a7ea20 cf72478ab8a4685ee978993d68836472 tcp.connect
  Mar 12 4:37:54.410 PM ok hasEligibleMacAddressHandler 65e34bc896c4cf37 a07d26a6688312bcfeba166c529a1789 dns.lookup
  Mar 12 4:37:54.170 PM ok hasEligibleMacAddressHandler 31c1c10fdb703664 b1c852b61f035eebdfd3a0e270344b61 tcp.connect
  Mar 12 4:37:54.170 PM ok hasEligibleMacAddressHandler dff7c0e0a8f2980e e7a3992157fa443137799f0e1a6e3cf5 dns.lookup

What version of collector/language SDK version did you use?

  • Lambda Layer (OTel Node.js):
    • arn:aws:lambda:us-east-2:184161586896:layer:opentelemetry-nodejs-0_12_0:1
  • Lambda Layer (OTel Collector):
    • arn:aws:lambda:us-east-2:184161586896:layer:opentelemetry-collector-amd64-0_13_0:1

What language layer did you use?
nodejs

Additional context
If I manually propagate a parent trace through the lambda we'll be able to preserve the parent ID and trace continuity, I expect the lambda layer to autoinstrument the parent ID.

` // Extract traceparent from headers
const headers = event.headers || {};
const traceparentHeader = headers['traceparent'];

// Propagate traceparent if available
let ctx = context.active();
if (traceparentHeader) {
ctx = propagation.extract(ctx, { traceparent: traceparentHeader });
}
`
This forces a parent span and connects the traces, but shouldn't be necessary if the OpenTelemetry AWS Lambda layer is functioning correctly.

We've ruled out

  • lambda layer configuration
  • node versioning
  • layer version
  • secretsmanager lambda layer
  • custom logging packages
  • potential async issues

Questions for Maintainers

  • Is this a known issue with OpenTelemetry auto-instrumentation in TypeScript-based AWS Lambdas?
  • Is there a recommended workaround to ensure traces remain linked without requiring manual propagation?
  • Could ESBuild bundling or Lambda execution order interfere with OpenTelemetry’s automatic instrumentation?
@nirvana620 nirvana620 added the bug Something isn't working label Mar 13, 2025
@serkan-ozal
Copy link
Contributor

Hi @nirvana620,

As far as I see from your example (listed spans), there is no AWS Lambda invocation span for the TypeScript Lambda. So it thinks me that your Lambda handler is not auto instrumented (wrapped) and it might be caused by ESBuild.

So, can you be sure that when you build your TypeScript Lambda with ESBuild, the handler name you set to Lambda configuration points to the valid point in the built/generated JS file by the ESBuild?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants