AWS Distro for OpenTelemetry
AWS Distro for OpenTelemetry Lambda Support For JavaScript
AWS Distro for OpenTelemetry Lambda Support For JavaScript
The AWS managed Lambda layer for ADOT JavaScript provides a plug and play user experience by automatically instrumenting a Lambda function, by packaging OpenTelemetry JavaScript together with an out-of-the-box configuration for AWS Lambda and AWS X-Ray. Users can enable and disable OpenTelemetry for their Lambda function without changing code.
Requirements
The Lambda layer supports Node.JS v14+ Lambda runtimes. For more information about supported JavaScript and Node.JS versions, see the OpenTelemetry JavaScript documentation.
For TypeScript users, if you are using esbuild
(either directly or through tools such as the AWS CDK), you must export your handler function through module.exports
rather than with the export
keyword! The AWS mananaged layer for ADOT JavaScript needs to hot-patch your handler at runtime, but can't because esbuild
makes your handler immutable when using the export
keyword.
Add the ARN of the Lambda Layer
In this section, we consume the Lambda layer for use with Node.JS Lambda Functions. This includes a reduced version of the AWS Distro for OpenTelemetry Collector (ADOT Collector), which runs as a Lambda extension.
Note: Lambda layers are a regionalized resource, meaning that they can only be used in the Region in which they are published. Make sure to use the layer in the same region as your Lambda functions.
Find the supported regions and amd64/arm64 layer ARN in the table below for the ARNs to consume. Use amd64
as architecture for x86-based processors.
Supported Regions | Lambda layer ARN format | Contents |
---|---|---|
ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-1 ap-southeast-2 ca-central-1 eu-central-1 eu-north-1 eu-west-1 eu-west-2 eu-west-3 sa-east-1 us-east-1 us-east-2 us-west-1 us-west-2 | arn:aws:lambda:<region>:901920570463:layer:aws-otel-nodejs-<architecture>-ver-1-18-1:4 | Contains OpenTelemetry for JavaScript v1.18.1 with Lambda instrumentation v0.41.0 Contains ADOT Collector v0.40.0 |
Enable auto-instrumentation for your Lambda function
To enable the AWS Distro for OpenTelemetry in your Lambda function, you need to add and configure the layer, and then enable tracing.
- Open the Lambda function you intend to instrument in the AWS console.
- In the Layers in Designer section, choose Add a layer.
- Under specify an ARN, paste the layer ARN, and then choose Add.
- Add the environment variable
AWS_LAMBDA_EXEC_WRAPPER
and set it to/opt/otel-handler
. - Enable active tracing for your AWS Lambda function.
Tips:
- By default, the layer is configured to export traces to AWS X-Ray. Make sure your Lambda role has the required AWS X-Ray permissions. For more on AWS X-Ray permissions for AWS Lambda, see the AWS Lambda documentation.
- Also note that, the
OTEL_EXPORTER_OTLP_ENDPOINT
environment variable does not need to be set. The default value ishttp://localhost:4318
, as the ADOT Node.JS lambda layer only supports OTLP over HTTP.
Remove OpenTelemetry from your Lambda function
To disable OpenTelemetry for your Lambda function, remove the Lambda layer,
remove the environment variable AWS_LAMBDA_EXEC_WRAPPER
, and disable active tracing, as explained in the section above.
Configuration
The ADOT Node.JS layer combines both OpenTelemetry JavaScript and the ADOT Collector. The configuration of the ADOT Collector follows the OpenTelemetry standard.
By default, the ADOT Lambda layer uses the config.yaml, which exports telemetry data to AWS X-Ray. To customize the Collector config, see the main Lambda section for custom configuration instructions
Additional Instrumentation
For additional instrumentation, see the OpenTelemetry JavaScript documentation.