In AWS Step Functions, you can set up a large-scale parallel workload by including a Map state in Distributed mode. Datadog supports tracing your Distributed Map states.

A visualization of a Step Function with a Distributed Map state.

Set up trace merging

  1. To ensure that child workflows are correctly linked to their parents, enable the Item Batching option for your Distributed Map state. For more information, see ItemBatcher. If you don’t want to use Item Batching, you can set MaxItemsPerBatch to 1 as a workaround.

  2. Your State Machine definition must use JSONata as the query language. To enable this, set your definition’s top-level QueryLanguage field to JSONata.

  3. On the Distributed Map state, set _datadog in the BatchInput field as follows:

    "ItemBatcher": {
      "MaxItemsPerBatch": N,
      "BatchInput": {
        "_datadog": "{% ($execInput := $states.context.Execution.Input; $hasDatadogTraceId := $exists($execInput._datadog.`x-datadog-trace-id`); $hasDatadogRootExecutionId := $exists($execInput._datadog.RootExecutionId); $ddTraceContext := $hasDatadogTraceId ? {'x-datadog-trace-id': $execInput._datadog.`x-datadog-trace-id`, 'x-datadog-tags': $execInput._datadog.`x-datadog-tags`} : {'RootExecutionId': $hasDatadogRootExecutionId ?  $execInput._datadog.RootExecutionId : $states.context.Execution.Id}; $merge([$ddTraceContext, {'serverless-version': 'v1', 'timestamp': $millis()}])) %}"
      }
    }

Limitations

Executions from a child map run are in the same invocation table as the parent Step Function. As a result, the child table in the Step Functions page is empty.

Troubleshooting

If trace merging is broken because there is another upstream service, ensure the upstream setup is correct according to the Step Function Trace Merging documentation.

PREVIEWING: flavien/gcp-se-terraform-doc