Datadog’s support of OpenTelemetry—a vendor-agnostic, open source set of APIs and libraries for collecting system and application telemetry data—has helped thousands of organizations implement monitoring strategies that complement their existing workflows. Many of our customers leverage OpenTelemetry for their server- and container-based deployments, but also need visibility into the health and performance of their serverless applications running on AWS Lambda.
AWS managed Lambda Layer for OpenTelemetry as a Lambda Extension
Lambda Extensions, released as a preview late last year, offers a new and seamless way for monitoring and security tools to plug into the Lambda execution environment. Before Lambda Extensions, third-party tools could not integrate easily with Lambda without adding latency or cost.
The AWS managed Lambda Layer for OpenTelemetry (built as a Lambda Extension) lets you collect OpenTelemetry traces from your Python, Node.js, and Java Lambda functions in the background, when they are not actively responding to events. The Layer contains the OpenTelemetry SDK, which generates traces, and the OpenTelemetry Collector, which sends those traces to AWS X-Ray via the OpenTelemetry Collector X-Ray Exporter. AWS has carefully developed and tested the Layer so your teams don’t have to worry about maintaining it or optimizing its performance—and can focus on building out your application.
In the next section, we’ll walk through how to instrument your Python functions with the managed Lambda Layer. If you’re looking to instrument your Node.js or Java functions, see the official AWS documentation.
Trace functions in Datadog with the AWS managed Lambda Layer for OpenTelemetry
First, add the managed Lambda Layer for OpenTelemetry to your Python function (
arn:aws:lambda:<AWS_REGION>:901920570463:layer:aws-otel-python38-ver-1-1-0:1) via the AWS Management Console, the AWS Command Line Interface (AWS CLI), or an infrastructure-as-code tool such as the Serverless Framework or AWS Serverless Application Model (SAM). You can use this sample function, if you don’t already have one set up.
Next, add the environment variable
AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument to trace your Lambda function without any application code changes, and enable X-Ray Active Tracing on the function. Then, install our AWS 1-click integration to forward traces to Datadog.
Once you’ve enabled our integration, you should begin to see OpenTelemetry traces from your Lambda function flowing into your Datadog account. X-Ray automatically stitches together each OpenTelemetry trace with X-Ray segments from the other AWS components that were involved in the request (e.g., Amazon API Gateway), so you can easily pinpoint bottlenecks.
View traces in context with enhanced metrics and logs
Traces are useful for troubleshooting an issue, but viewing them alongside Lambda metrics and logs gives you the context you need to identify the root cause as quickly as possible.
To generate and forward enhanced Lambda metrics and logs to Datadog, you’ll need to install and configure two additional Lambda Layers:
- Datadog Lambda Library (
- Datadog Lambda Extension (
Next, add the following environment variables:
You can find your Datadog API key here. If you need to create one, see our documentation for instructions.
Lastly, modify your Lambda function handler to
Once you’ve completed these steps, you’ll be able to visualize key Lambda metrics (e.g., errors, timeouts, memory usage) together with OpenTelemetry traces and Lambda logs in our Serverless View. In addition, our enhanced metrics contain additional function metadata—and are collected at a higher granularity and lower latency than standard CloudWatch metrics—so you can investigate issues as soon as they crop up.
Native tracing with Datadog APM
Datadog customers can choose to trace their Lambda functions with either OpenTelemetry and X-Ray or our native tracing libraries (
dd-trace). Datadog’s tracing libraries automatically propagate trace context across service boundaries, so you get end-to-end visibility into every request, regardless of whether it flows through functions, containers, or other infrastructure components. These traces appear in your account in real time, and no Lambda function code changes are required to begin collecting them.
If you’d like to learn more about Datadog Serverless monitoring and our native tracing capabilities, see our dedicated blog post.
Start monitoring AWS Lambda OpenTelemetry traces today
At Datadog, we’re constantly working to deliver comprehensive visibility into your serverless environment in a way that minimizes cost, operational complexity, and performance impact. The AWS managed Lambda Layer for OpenTelemetry, together with our AWS X-Ray integration, enables you to collect traces from your Lambda functions without any changes to your function code. To learn more, visit the AWS Distro for OpenTelemetry developer portal. And if you’re new to Datadog, sign up for a 14-day free trial today.