Datadog CDK: Ensuring shared trace_id across API Gateway and Lambda


We’re using datadog with cdk to enable distributed tracing across our serverless application.

We recently changed our exposed interface from a lambda to an api-gateway URL with lambda integration. This has caused requests to be split into separate traces: one attached to api-gateway and its associated lambda, another attached to the actual backend of our application. How can I ensure that one trace_id is shared across the api-gateway boundary into my actual application?

The data flow looks like this:

“POST” request → api-gateway → POST lambda → Compute Step function

Not seeing the trace being shared from the POST lambda into the step function lambdas

After spending more time with this problem, it seems that its our custom authorizer that is preventing the traces from being connected.

In the interim (assuming that we cannot change the custom authorizer at this time), I am attempting to inject the trace information into the lambda payload and extract it in the handler. I’ve been using this doc as a guide, however I find the DD_TRACE_EXTRACTOR method to be a bit clunky while using cdk (would prefer to just pass the datadog context in as an event and override the trace with that information using the datadog_lambda extension library.

Does anyone have a suggestion for the best/easiest way to manually override the trace_id using the datadog_lambda and/or dd_trace libraries in python?