Trace Serverless Functions
New announcements from Dash: Incident Management, Continuous Profiler, and more! New announcements from Dash!

Trace Serverless Functions

In hybrid architectures, serverless functions are a key part of your application. Including these functions in your distributed traces can be critical for detecting performance bottlenecks and service outages in your distributed systems.

Choose your Tracing Library

Depending on your language and configuration, choose between setting up Datadog APM or AWS X-Ray for your traces. Click the link in the appropriate column heading to see set-up instructions for the solution that suits you:

Datadog APMAWS X-Ray
Uses Datadog APM’s integration libraries for end-to-end tracing.Pulls traces from AWS X-Ray.
Set up using your developer tools without making any changes to your code with Serverless Framework and AWS SAM Integrations.Install the AWS X-Ray client library for your Lambda runtime.
Support for Python, Node.js, Ruby.Support for all Lambda runtimes.

Augment AWS X-Ray Tracing with Datadog APM

You might also configure both AWS X-Ray Tracing and Datadog APM. Note that this may result in higher usage bills. You can find setup instructions for this case when you want to do both below:

Tracing in a serverless-first environment

AWS X-Ray provides both a backend AWS service and a set of client libraries. Enabling the backend AWS service alone gives you an Invocation span for your AWS Lambda functions as well as traces across Amazon API Gateways and message queues.

Both the AWS X-Ray and Datadog APM client libraries trace the integrations in your code. If you are using the Datadog APM client library instead of the AWS X-Ray client library to trace and visualize traces, follow the below two steps:

  1. Enable the AWS X-Ray integration for tracing your Lambda functions.
  2. Set up Datadog APM on your Lambda functions.
  3. Merge traces generated by the AWS X-Ray integration and Datadog APM.
module.exports.hello = datadog(
    (event, context, callback) => {

        callback(null, {
            statusCode: 200,
            body: 'Hello from serverless!'
    { mergeDatadogXrayTraces: true }

Set the DD_MERGE_XRAY_TRACES environment variable to True on your Lambda function.

Set the DD_MERGE_DATADOG_XRAY_TRACES environment variable to True on your Lambda function.

Tracing across AWS Lambda and hosts

When applicable, Datadog merges AWS X-Ray traces with native Datadog APM traces. This means that your traces will show the complete picture of requests that cross infrastructure boundaries, whether it be AWS Lambda, containers, on-prem hosts, or managed services.

  1. Enable the AWS X-Ray integration for tracing your Lambda functions.
  2. Set up Datadog APM on your hosts and container-based infrastructure.

Note: Distributed Tracing is supported for any runtime for your host or container-based applications.

Note: For X-Ray and Datadog APM traces to appear in the same flame graph, all services must have the same env tag.

Further Reading

Additional helpful documentation, links, and articles: