Skip to content

ADOT lambda layer does not work for handlers in folders #1128

@DCzajkowski

Description

@DCzajkowski

name: Bug report
about: Create a report to help us improve
title: 'ADOT lambda layer does not work for handlers in folders'
labels: bug
assignees: ''


Describe the bug
I have a Lambda Function that uses ADOT Lambda Layer (arn:aws:lambda:us-east-1:615299751070:layer:AWSOpenTelemetryDistroJs:10).

When the Function handler is defined in index.mjs, everything works (requests made using node:https are reported to X-Ray in traces).

However, Function handler defined in folder/index.mjs, stops working (there is a trace, but it does not contain requests made using node:https).

Steps to reproduce

  1. Create a lambda function with Active Tracing and everything required for OTEL to work. Use Node.js 22 (newest supported at the time of writing). Use the official arn:aws:lambda:us-east-1:615299751070:layer:AWSOpenTelemetryDistroJs:10 lambda layer.
  2. Move the index.mjs to any folder, e.g. folder/index.mjs.
  3. Change handler from index.handler to folder/index.handler.
  4. You can use this code for your lambda implementation:
index.mjs
import https from 'node:https'

export async function handler() {
  const traceIdEnv = process.env._X_AMZN_TRACE_ID
  const traceId = traceIdEnv.split(';')[0].split('=')[1]

  const data = await new Promise((resolve, reject) => {
    https.get('https://jsonplaceholder.typicode.com/todos/2', (res) => {
      let body = ''
      res.on('data', chunk => body += chunk)
      res.on('end', () => resolve(JSON.parse(body)))
    }).on('error', reject)
  })

  console.log('Status API response:', data)

  return {
    statusCode: 200,
    body: JSON.stringify({ traceId }),
  }
}
  1. Invoke the lambda function. Note the trace id. Open the trace id in X-Ray console.

What did you expect to see?

The request inside the trace as below (screenshot with handler in index.mjs):

Trace screenshot in X-Ray console Image
Lambda CloudWatch logs
INIT_START Runtime Version: nodejs:22.v70	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:dd849bc5eb759042eb9a87d38a406e763aeb7832756f411e38151c6c27e4afa2
(node:2) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("import-in-the-middle/hook.mjs", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
OTEL_TRACES_EXPORTER is empty. Using default otlp exporter.
OTEL_LOGS_EXPORTER contains "none". Logger provider will not be initialized.
AWS Application Signals enabled.
AWS Application Signals metrics export interval capped to 60000
Enabled batch unsampled span processor for Lambda environment.
OTEL_METRICS_EXPORTER contains "none". Metric provider will not be initialized.
Setting TraceProvider for instrumentations at the end of initialization
AWS Distro of OpenTelemetry automatic instrumentation started successfully
(node:2) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
2026-01-06T16:10:10.435Z	undefined	WARN	Failed extracting version /var/task
2026-01-06T16:10:10.439Z	undefined	WARN	WARN: AWS Lambda has removed support for callback-based function handlers starting with Node.js 24. You will need to modify this function to use a supported handler signature when upgrading to Node.js 24 or later. To disable this warning, set the AWS_LAMBDA_NODEJS_DISABLE_CALLBACK_WARNING environment variable. For more information see https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html.
START RequestId: 19031439-f1fb-453e-891c-469e755d03e6 Version: $LATEST
2026-01-06T16:10:10.626Z	19031439-f1fb-453e-891c-469e755d03e6	INFO	Status API response: {
  userId: 1,
  id: 2,
  title: 'quis ut nam facilis et officia qui',
  completed: false
}
END RequestId: 19031439-f1fb-453e-891c-469e755d03e6
REPORT RequestId: 19031439-f1fb-453e-891c-469e755d03e6	Duration: 235.27 ms	Billed Duration: 1820 ms	Memory Size: 512 MB	Max Memory Used: 163 MB	Init Duration: 1584.04 ms	
XRAY TraceId: 1-695d33e0-525532ef3c71d954322c3241	SegmentId: 02511b6ad8c6a541	Sampled: true	

What did you see instead?

The request is not inside the trace (screenshot with handler in folder/index.mjs):

Trace screenshot in X-Ray console

Image

Lambda CloudWatch logs

INIT_START Runtime Version: nodejs:22.v70	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:dd849bc5eb759042eb9a87d38a406e763aeb7832756f411e38151c6c27e4afa2
OTEL_TRACES_EXPORTER is empty. Using default otlp exporter.
OTEL_LOGS_EXPORTER contains "none". Logger provider will not be initialized.
AWS Application Signals enabled.
AWS Application Signals metrics export interval capped to 60000
Enabled batch unsampled span processor for Lambda environment.
OTEL_METRICS_EXPORTER contains "none". Metric provider will not be initialized.
Setting TraceProvider for instrumentations at the end of initialization
AWS Distro of OpenTelemetry automatic instrumentation started successfully
(node:2) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
START RequestId: 97ea3491-14c7-4463-8519-7564f29716d1 Version: $LATEST
2026-01-06T16:15:07.269Z	97ea3491-14c7-4463-8519-7564f29716d1	INFO	Status API response: {
  userId: 1,
  id: 2,
  title: 'quis ut nam facilis et officia qui',
  completed: false
}
END RequestId: 97ea3491-14c7-4463-8519-7564f29716d1
REPORT RequestId: 97ea3491-14c7-4463-8519-7564f29716d1	Duration: 140.16 ms	Billed Duration: 535 ms	Memory Size: 512 MB	Max Memory Used: 114 MB	Init Duration: 394.56 ms	
XRAY TraceId: 1-695d350a-7303de1437e832c23aaf7883	SegmentId: 98977f3c480471d2	Sampled: true	

What version of collector/language SDK version did you use?
No SDK, just the lambda layer

What language layer did you use?
Config: Node.js 22.x, layer arn:aws:lambda:us-east-1:615299751070:layer:AWSOpenTelemetryDistroJs:10

Additional context
empty

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions