Serverless trace merging is required to see a single, connected trace when you configure both Datadog’s tracing libraries (
dd-trace) and AWS X-Ray tracing libraries in your application. If you aren’t sure which tracing library to use, read this page on choosing your tracing library.
There are two primary reasons for instrumenting both
dd-trace and AWS X-Ray tracing libraries:
dd-trace, you require AWS X-Ray active tracing for AWS managed services such as API Gateway or Step Functions, and you want to visualize the
dd-traceand AWS X-Ray spans in one single trace.
dd-traceinstruments your hosts, AWS X-Ray instruments your Lambda functions, and you want to visualize connected traces for transactions across Lambda functions and hosts.
Note that this may result in higher usage bills. X-Ray spans will continue to be available in your merged traces after 2-5 minutes. In many cases, we recommend only using a single tracing library. Learn more about choosing your tracing library here.
You can find setup instructions for each of the above use cases below:
AWS X-Ray provides both a backend AWS service (AWS X-Ray active tracing) and a set of client libraries. Enabling the backend AWS service alone in the Lambda console gives you
Invocation spans for your AWS Lambda functions. You can also enable AWS X-Ray active tracing from the API Gateway and Step Function consoles.
Both the AWS X-Ray SDK and Datadog APM client libraries (
dd-trace) add medatada and spans for downstream calls by accessing the function directly. Assuming you are using
dd-trace to trace at the handler level, your setup should be similar to the following:
dd-trace) by following the installation instructions for your Lambda runtime.
dd-trace, so the AWS X-Ray client libraries do not need to be installed.
DD_MERGE_XRAY_TRACESenvironment variable to
trueon your Lambda functions to merge the X-Ray and
If you have installed Datadog’s tracing libraries (
dd-trace) on both your Lambda functions and hosts, your traces will automatically show you the complete picture of requests that cross infrastructure boundaries, whether it be AWS Lambda, containers, on-prem hosts, or managed services.
dd-trace is installed on your hosts with the Datadog Agent, and your serverless functions are traced with AWS X-Ray, your setup should be similar to the following:
DD_TRACE_ENABLEDenvironment variable is set to
Then, for X-Ray and Datadog APM traces to appear in the same flame graph, all services must have the same
Note: Distributed Tracing is supported for any runtime for your host or container-based applications. Your hosts and Lambda functions do not need to be in the same runtime.
Additional helpful documentation, links, and articles: