AWS Distro for OpenTelemetry

AWS Distro for OpenTelemetry Lambda Support For Java (Auto-instrumentation Agent)

AWS Distro for OpenTelemetry Lambda Support For Java (Auto-instrumentation Agent)

The AWS managed Lambda layer for ADOT Java Auto-instumentation Agent provides a plug-and-play user experience by automatically instrumenting a Lambda function, by packaging the ADOT Java Agent 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.


The Lambda layer supports the Java 11 (Corretto) Lambda runtime. It does not support the Java 8 Lambda runtimes. For more information about supported Java versions, see the OpenTelemetry Java documentation.

Note: ADOT Lambda Layer for Java Auto-instrumentation Agent - Automatic instrumentation has a notable impact on startup time on AWS Lambda and you will generally need to use this along with provisioned concurrency and warmup requests to serve production requests without causing timeouts on initial requests while it initializes.

Add the ARN of the Lambda Layer

In this section, we consume the Lambda layer for use with Java 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 RegionsLambda layer ARN formatContents
arn:aws:lambda:<region>:901920570463:layer:aws-otel-java-agent-<architecture>-ver-1-32-0:2Contains ADOT Java Auto-Instrumentation Agent v1.32.0

Contains ADOT Collector v0.39.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.

  1. Open the Lambda function you intend to instrument in the AWS console.
  2. In the Layers in Designer section, choose Add a layer.
  3. Under specify an ARN, paste the layer ARN, and then choose Add.
  4. Add the environment variable AWS_LAMBDA_EXEC_WRAPPER and set it to one of the following options:
    1. /opt/otel-handler - for wrapping regular handlers (implementing RequestHandler)
  5. Enable active tracing for your AWS Lambda function.


  • 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.

  • By default, the ADOT Java Agent in the Layer will try to auto-instrument all the code in your application. This can have a negative impact on the Lambda cold startup time.

    We recommend that you only enable auto-instrumentation for the libraries/frameworks that are used by your application.

    To enable only specific instrumentations you can use the following environment variables:

    • OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED - When set to false, disables auto-instrumentation in the Layer, requiring each instrumentation to be enabled individually.
    • OTEL_INSTRUMENTATION_[NAME]_ENABLED - Set to true to enable auto-instrumentation for a specific library or framework. [NAME] should be replaced by the instrumentation that you want to enable. The full list of available instrumentations can be found in this link.

    For example, to only enable auto-instrumentation for Lambda and the AWS SDK, you would have to set the following environment variables:


Metric Instrumentation in your Lambda Function

Metric auto instrumentation is supported in OpenTelemetry. You would have to instrument your code in your Lambda application in order to generate application metrics. We will be using the OpenTelemetry Java Metrics API to define our metrics. You can define your metric types in a file. To enable exporting metrics for use with backends like Amazon Managed Prometheus, set the environment variable OTEL_METRICS_EXPORTER=otlp.

  1. Import the OpenTelemetry Java Metrics API into your dependency file
dependencies {
implementation platform("io.opentelemetry:opentelemetry-bom:1.19.0")
  1. Create Metric instruments by using the OpenTelemetry Java Metrics API
// get meter
Meter meter = GlobalOpenTelemetry.getMeterProvider()
// creating a Counter metric to count total API payload bytes sent
LongUpDownCounter apiBytesSentCounter = meter
.setDescription("API request payload sent in bytes")
// creating a Histogram metric to record API latency in timeseries
LongValueRecorder apiLatencyRecorder = meter
.setDescription("API latency time")
// creating a Gauge metric to record memory usage at every collection interval
LongValueObserver memoryObserver = meter
.setDescription("Reports JVM memory usage.")
  1. Record Metric measurements
// record your metrics
apiBytesSentCounter.add(100, Labels.of("apiName", apiName));
apiLatencyRecorder.record(248, Labels.of("apiName", apiName));, Attributes.empty());
  1. The Lambda layer will take care of exporting the metrics to the Collector and then to AMP.

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.


The ADOT Java Auto-instrumentation Agent layer combines both OpenTelemetry Auto Agent 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.

Exporting Metrics to AMP

The layer is not configured by default to export Prometheus metrics, see Amazon Managed Service for Prometheus (AMP)[]. To enable it:

  1. Upload a custom collector configuration file collector.yaml with your Lambda application, like the example shown below, with the prometheusremotewriteexporter and the sigv4authextension enabled. Set up the endpoint of your own AMP workspace, and region of the sigv4authextension.
# collector.yaml
service: "aps"
region: <workspace_region>
endpoint: <workspace_remote_write_url>
authenticator: sigv4auth
extensions: [sigv4auth]
receivers: [otlp]
exporters: [awsxray]
receivers: [otlp]
exporters: [logging, prometheusremotewrite]
  1. Upload this collector config as the OPENTELEMETRY_CONFIG_FILE environment variable to configure the Lambda Layer to export metrics to your workspace, following these instructions.

Note: If enabling metrics, make sure your Lambda role has the required AWS Prometheus permissions. For more on permissions and policies required on AMP for AWS Lambda, see the AWS Managed Service for Prometheus documentation.

AMP and AWS Lambda Service Quotas when using the Lambda Layer for Metrics

To learn more about the limits for the number of metrics that can be sent through this Lambda Layer to Amazon Service for Prometheus, refer to the AMP service quotas. The layer has been tested to output up to the posted service Quotas of AMP without requesting for an increase. This layer has been tested with the maximum concurrency levels of AWS Lambda, of 1000 concurrent invocations and is able to receive all metrics in AMP. Any higher levels of concurrency or of the posted service quota is not guaranteed.

Additional Instrumentation

For additional instrumentation, see the OpenTelemetry Java documentation.


Keep up to date with the development of the ADOT Lambda layers here. If you’re interested in building your own custom Lambda Layers, visit the upstream opentelemetry-lambda repository.

To participate in the discussions to address compatibility gaps between OpenTelemetry and Prometheus, you can also join the OpenTelemetry Prometheus workgroup.