Distributed Tracing with Serverless Applications

Trace Serverless Functions

By connecting your serverless traces to metrics, Datadog provides a context-rich picture of your application’s performance, allowing you to better troubleshoot performance issues given the distributed nature of serverless applications.

The Datadog Python, Node.js, Ruby, Go, Java, and .NET tracing libraries support distributed tracing for AWS Lambda.

Choose your tracing solution

Architecture diagram for tracing AWS Lambda with Datadog
New to serverless monitoring? Follow the installation steps here to get started.

To start using Datadog APM with your serverless application, you can choose between generating traces using Datadog’s tracing client (dd-trace) or pulling X-Ray traces from AWS.

Datadog APM with dd-traceDatadog APM with AWS X-Ray
Uses Datadog APM’s integration libraries for end-to-end tracing.Pulls traces from AWS X-Ray.
Visualize your traces in Datadog in real-time.Trace data available in Datadog after a few minutes.
Tail-based sampling and fully customizable tag-based retention filters.Sampling rate cannot be configured.
Support for all Lambda runtimes.Support for all Lambda runtimes.

Runtime recommendations

Python
Node.js
Ruby
Java
Go
.NET

Python and Node.js

The Datadog Lambda Library and tracing libraries for Python and Node.js support:

  • Automatic correlation of Lambda logs and traces with trace ID and tag injection.
  • Installation without any code changes using Serverless Framework, AWS SAM and AWS CDK integrations.
  • Tracing HTTP requests invoking downstream Lambda functions or containers.
  • Tracing consecutive Lambda invocations made via the AWS SDK.
  • Tracing asynchronous Lambda invocations through AWS Managed Services
    • API Gateway
    • SQS
    • SNS
    • SNS and SQS direct integration
    • Kinesis
    • EventBridge
  • Tracing dozens of additional out-of-the-box Python and Node.js libraries.

For Python and Node.js serverless applications, Datadog recommends you install Datadog’s tracing libraries. If your application requires AWS X-Ray active tracing in AWS managed services such as AppSync or Step Functions, Datadog recommends you augment AWS X-Ray traces with Datadog APM by configuring both AWS X-Ray and Datadog APM tracing libraries as described in Serverless Trace Merging.

If you are already tracing your serverless functions with X-Ray and want to continue using X-Ray, you can install the AWS X-Ray integration.

Looking to trace through serverless resources not listed above? Open a feature request.

Ruby

The Datadog Lambda Library and tracing libraries for Ruby support:

  • Automatic correlation of Lambda logs and traces with trace ID and tag injection.
  • Tracing HTTP requests invoking downstream Lambda functions or containers.
  • Tracing dozens of additional out-of-the-box Ruby libraries.

You can trace your serverless functions in Datadog with Datadog’s tracing libraries or by installing the AWS X-Ray integration. If you are using Datadog’s tracing libraries, and need to connect Lambda function traces across AWS managed services, Datadog recommends you augment your traces by configuring both AWS X-Ray and Datadog APM tracing libraries.

Looking to trace through serverless resources not listed above? Open a feature request.

Go

The Datadog Lambda Library and tracing libraries for Go support:

  • Manual correlation of Lambda logs and traces with trace ID and tag injection.
  • Tracing HTTP requests invoking downstream Lambda functions or containers.
  • Tracing dozens of additional out-of-the-box Go libraries.

For Go serverless applications, Datadog recommends installing Datadog’s tracing libraries. If your application requires AWS X-Ray active tracing in AWS managed services such as API Gateway or Step Functions, you may want to consider instead using Datadog APM with AWS X-Ray tracing.

Looking to trace through serverless resources not listed above? Open a feature request.

Java

The Datadog Lambda Library and tracing libraries for Java support:

  • Correlation of Lambda logs and traces with trace ID and tag injection. See Connecting Java logs and traces for more details.
  • Tracing HTTP requests invoking downstream Lambda functions or containers.
  • Tracing dozens of additional out-of-the-box Java libraries.

For Java serverless applications, Datadog recommends installing Datadog’s tracing libraries. If your application requires AWS X-Ray active tracing in AWS managed services such as API Gateway or Step Functions, you may want to consider instead using Datadog APM with AWS X-Ray tracing.

Have feedback on the Datadog’s tracing libraries for Java Lambda functions? Make sure to check out discussions going on in the #serverless channel in the Datadog Slack community.

.NET

The tracing library for .NET supports:

  • Tracing HTTP requests invoking downstream Lambda functions or containers.
  • Tracing dozens of additional out-of-the-box .NET libraries.

For .NET serverless applications, Datadog recommends installing Datadog’s tracing libraries. If your application requires AWS X-Ray active tracing in AWS managed services such as API Gateway or Step Functions, you may want to consider instead using Datadog APM with AWS X-Ray tracing.

Learn more about tracing through .NET Azure serverless applications.

Hybrid environments

If you have installed Datadog’s tracing libraries (dd-trace) on both your Lambda functions and hosts, your traces automatically show you the complete picture of requests that cross infrastructure boundaries, whether it be AWS Lambda, containers, on-prem hosts, or managed services.

If dd-trace is installed on your hosts with the Datadog Agent, and your serverless functions are traced with AWS X-Ray, trace merging is required to see a single, connected trace across your infrastructure. See the Serverless Trace Merging documentation to learn more about merging traces from dd-trace and AWS X-Ray.

Datadog’s AWS X-Ray integration only provides traces for Lambda functions. See the Datadog APM documentation to learn more about tracing in container or host-based environments.

Enable Datadog APM

The Datadog Python, Node.js, Ruby, Go, Java, and .NET tracing libraries support distributed tracing for AWS Lambda. To enable tracing on your functions, follow the installation instructions.

Further Reading