This page describes how to merge your AWS Step Functions traces with related AWS Lambda traces or nested Step Functions traces. These instructions assume that you have already instrumented these AWS Step Functions and Lambda functions to send traces to Datadog.
Datadog recommends using JSONata to define your Step Function definitions for the most complete end-to-end tracing experience. This approach ensures that any context upstream to the Step Function is preserved and passed down.
The JSONata expression merges the upstream service’s context with the current Step Functions context object and the Lambda state’s input payload.
Alternatively, if you have business logic defined in the payload, you can replace $states.input at the end of the JSONata expression with your intended value for the Payload key.
Ensure you have deployed the Datadog Lambda Forwarder, a Lambda function that ships logs from AWS to Datadog, and that you are using v3.130.0+. You might need to update your Forwarder.
Replace <DATADOG_SITE> with datadoghq.com (ensure the correct SITE is selected on the right).
Replace <DATADOG_API_KEY_SECRET_ARN> with the ARN of the AWS secret where your Datadog API key is securely stored. The key needs to be stored as a plaintext string (not a JSON blob). The secretsmanager:GetSecretValue permission is required. For testing, you can instead use apiKey and set the Datadog API key in plaintext.
Replace <FORWARDER_ARN> with the ARN of your Datadog Lambda Forwarder. This step configures the log stream subscription for the Forwarder. Ensure that the Step Function log group name begins with /aws/vendedlogs/states/. If it does not, you must set it up manually.
If you have not already, install the [Datadog CLI][9] v2.18.0+.
npm install -g @datadog/datadog-ci
Ensure you have deployed the Datadog Lambda Forwarder, a Lambda function that ships logs from AWS to Datadog, and that you are using v3.130.0+. You may need to update your Forwarder.
Replace <STEP_FUNCTION_ARN> with the ARN of your Step Function. Repeat the --step-function flag for each Step Function you wish to instrument.
Replace <FORWARDER_ARN> with the ARN of your Datadog Lambda Forwarder, as noted previously. This step configures the log stream subscription for the Forwarder. Ensure that the Step Function log group name begins with “/aws/vendedlogs/states/”. If it does not, you will need to set it up manually.
Replace <ENVIRONMENT> with the environment tag you would like to apply to your Step Functions.
The JsonMerge [intrinsic function][14] merges the Step Functions context object ($$) with the original Lambda’s input payload ($). Fields of the original payload overwrite the Step Functions context object if their keys are the same.
Example:
"Lambda Read From DynamoDB":{"Type":"Task","Resource":"arn:aws:states:::lambda:invoke","Parameters":{"Payload.$":"States.JsonMerge($$, $, false)","FunctionName":"${lambdaArn}"},"End":true}
Alternatively, if you have business logic defined in the payload, you can also use the following format:
"Lambda Read From DynamoDB":{"Type":"Task","Resource":"arn:aws:states:::lambda:invoke","Parameters":{"Payload":{..."Execution.$":"$$.Execution","State.$":"$$.State","StateMachine.$":"$$.StateMachine"},"FunctionName":"${lambdaArn}"},"End":true}
Follow these instructions if your Step Function indirectly invokes a Lambda through EventBridge, SQS, or SNS. To trace through another managed AWS service, contact Datadog Support to open a feature request.