Skip to main content

Introduction

For Java applications running on AWS Lambda, OpenTelemetry provides two instrumentation options:
  1. Java Agent layer
  2. Wrapper layer
See the OpenTelemetry Lambda Java documentation for details on each layer and guidance on choosing between them. The rest of this guide covers instrumentation using the Java Agent layer.

1. Add the OpenTelemetry Lambda Layer

Find the latest layer-javaagent ARN for your AWS region from the opentelemetry-lambda releases page. Add the JavaAgent layer ARN to your function. Do not also add the Collector layer, as Trace0 handles ingestion directly.

2. Set Environment Variables

Add the following environment variables to your Lambda function. Replace YOUR_TRACE0_ENV_API_KEY with the API key from your Trace0 environment.

3. 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. First, add the opentelemetry-api dependency to your project:
Then add the HTTP request and response attributes to the Lambda invocation span in your handler:

4. Deploy service

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

Example service

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