Skip to main content

1. Add the OpenTelemetry Lambda Layer

Find the latest layer-nodejs ARN for your AWS region from the opentelemetry-lambda releases page. Add the layer ARN to your function.

2. Add the Collector Lambda Extension

Find the latest layer-collector ARN for your AWS region from the opentelemetry-lambda releases page. Add the layer ARN to your function and then add the following collector.yaml file to the root of your Lambda deployment folder. Replace YOUR_TRACE0_ENV_API_KEY with the API key from your Trace0 environment.

3. Set Environment Variables

Add the following environment variables to your Lambda function.

4. Add Logger

To correlate logs with traces in Trace0, your application must use an OpenTelemetry-supported logger. We recommend using Pino, a low overhead JavaScript logger for Node.js. The instructions below use Pino, but the same approach applies to other supported loggers such as Winston. First, install the library:
Then create a logger.js file:
You can now use the logger in your app:
All logs will now be exported to the local collector, which will in turn export them to the Trace0 ingest endpoint. Enable Trace Context Injection in Pino Logs To inject trace context (trace ID, span ID) into Pino log records, the Pino instrumentation must be loaded, as it is not loaded by default. Enable it by setting this environment variable on your Lambda:
Setting OTEL_NODE_ENABLED_INSTRUMENTATIONS disables all the default instrumentation libraries and only enables the ones you specify, except the AWS SDK v3 instrumentation, which is always loaded regardless. See here for full details on configuring the auto instrumentation for Node.js Lambda.

5. Set HTTP request spans

For lambdas triggered via API Gateway, the HTTP request and response attributes are not set automatically on the lambda invocation span by the OTel Lambda auto-instrumentation. Therefore, they need to be set manually in your lambda code handler.

6. Deploy service

Deploy your service and watch traces, metrics, and logs appear in the Trace0 dashboard within seconds.

Example service

See our Node.js Lambda example app for a working service you can deploy to your AWS account.