---
title: Tracing Distributed Map States
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Serverless > Serverless Monitoring for AWS Step Functions > Tracing
  Distributed Map States
---

# Tracing Distributed Map States

In AWS Step Functions, you can set up a large-scale parallel workload by including a [`Map` state in *Distributed* mode](https://docs.aws.amazon.com/step-functions/latest/dg/state-map-distributed.html). Datadog supports tracing your Distributed Map states.

{% image
   source="https://docs.dd-static.net/images/serverless/step_functions/distributed_map.abc0d1a402deec46d69d093419ff905e.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/serverless/step_functions/distributed_map.abc0d1a402deec46d69d093419ff905e.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="A visualization of a Step Function with a Distributed Map state in the AWS console." /%}

## Set up trace merging{% #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](https://docs.aws.amazon.com/step-functions/latest/dg/input-output-itembatcher.html?icmpid=docs_console_unmapped). If you don't want to use Item Batching, you can set `MaxItemsPerBatch` to 1 as a workaround.

1. Your State Machine definition must use [JSONata](https://docs.aws.amazon.com/step-functions/latest/dg/transforming-data.html) as the query language. To enable this, set your definition's top-level `QueryLanguage` field to `JSONata`.

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

   ```json
   "ItemBatcher": {
     "MaxItemsPerBatch": N,
     "BatchInput": {
       "_datadog": "{% ($ddctx := ($states.context.**._datadog)[0];$maybeSnsCtx := ($parse($parse(($states.context.**.body)[0]).**._datadog.Value))[0];$ddctx := $exists($maybeSnsCtx) ? $maybeSnsCtx : $ddctx;$ddTraceContext := $exists($ddctx.`x-datadog-trace-id`) ? {'x-datadog-trace-id': $ddctx.`x-datadog-trace-id`, 'x-datadog-tags': $ddctx.`x-datadog-tags`} : {'RootExecutionId': $exists($ddctx.RootExecutionId) ? $ddctx.RootExecutionId : $states.context.Execution.Id};$merge([$ddTraceContext, {'serverless-version': 'v1', 'timestamp': $millis()}])) %}"
     }
   }
```

{% image
   source="https://docs.dd-static.net/images/serverless/step_functions/distributed_map_trace.50dd54d23c38a5db98c16b58e8457e89.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/serverless/step_functions/distributed_map_trace.50dd54d23c38a5db98c16b58e8457e89.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="An example Datadog trace of a Step Function with a Distributed Map state." /%}

## Troubleshooting{% #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](https://docs.datadoghq.com/serverless/step_functions/merge-step-functions-lambda.md). Also, validate the setup of any Lambda or nested Step Function invocations from within the Distributed Map.
