---
schema_version: "1"
id: 0abb134a43997e1829aec1f8a7f0f91763ba2b430005c71785699492d3a327ff
title: Change the Correlation ID During Flow Execution with Tracing Module
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/tracing-module/latest/tracing-module-with-correlationid.md
canonical_url: https://docs.mulesoft.com/tracing-module/latest/tracing-module-with-correlationid
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 26dd25fc28d7b1130bd4f08ecacb4548a41b56b1e0f545b138746a170b8a0002
description: MuleSoft Documentation Site
release: "1.3"
latest: true
---
---
product: Tracing Module
version: 1.3
is-latest-version: true
---

# Change the Correlation ID During Flow Execution with Tracing Module

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

You might want to change the correlation ID of the event for a given scope or a set of operations
if:

- You are processing the results of a database query inside a **For Each** scope and you want to
  correlate the event with the register you are processing.

- You are consuming a JMS message queue and you want to proceed using the JMS correlation ID for
  traceability purposes.

For these scenarios, the Tracing module **With CorrelationID** scope enables you to modify the
correlation ID during the execution of that scope.

## Configure the With CorrelationID Scope

In the following Mule app example, you configure the **With CorrelationID** scope in Anypoint Code
Builder:

![A flow showing a With CorrelationID scope flow](/mulesoft/current/en-us/tracing-module/latest/_images/tracing-module-scope-flow-acb.png)

1.  In the canvas UI, click the
    ![Add component icon](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-plus.png) (**Add component**)
    icon, search for `Listener`, and select **Listener** from the **HTTP** results.

2.  On the **General** tab, set **Path** to `/test`.

3.  Add an HTTP Listener configuration (`<http:listener-config>`) that listens on port `8081`. See
    [Add a Global Configuration](https://docs.mulesoft.com/tracing-module/latest/tracing-module-config-acb#add-global-config).

4.  Click the ![Add component icon](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-plus.png) (**Add
    component**) icon after **Listener**, search for `Set Payload`, and select it.

5.  On the **General** tab, set **Value** to `some`.

6.  Click the ![Add component icon](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-plus.png) (**Add
    component**) icon after **Set Payload**, search for `Logger`, and select it.

7.  On the **General** tab, set **Message** to `#[payload]` and **Level** to `WARN`.

8.  Click the ![Add component icon](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-plus.png) (**Add
    component**) icon after **Logger**, search for `Tracing`, and select **With CorrelationID**.

9.  On the **General** tab, set **Correlation id** to `#[correlationId ++ '-Example']`:

    ![The With CorrelationID scope General tab with the Correlation id field set](/mulesoft/current/en-us/tracing-module/latest/_images/tracing-module-with-correlationid-acb.png)

10. Inside the **With CorrelationID** scope, click the
    ![Add component icon](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-plus.png) (**Add component**)
    icon, search for `Logger`, and select it.

11. On the **General** tab, set **Message** to `#[payload]` and **Level** to `WARN`.

12. Run your application in debug mode.

13. In a terminal, run `curl localhost:8081/test`.

The application output logs are:

```xml
WARN  2021-03-30 16:46:11,269 [[MuleRuntime].uber.05: [test-project-app].example.CPU_LITE @6d3b5ad] [processor: example/processors/1; event: bad0e5b0-9191-11eb-a0b3-36548d51aeee] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: some
WARN  2021-03-30 16:46:11,271 [[MuleRuntime].uber.05: [test-project-app].example.CPU_LITE @6d3b5ad] [processor: example/processors/2/processors/0; event: bad0e5b0-9191-11eb-a0b3-36548d51aeee-Example] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: some
WARN  2021-03-30 16:46:11,274 [[MuleRuntime].uber.05: [test-project-app].example.CPU_LITE @6d3b5ad] [processor: example/processors/3; event: bad0e5b0-9191-11eb-a0b3-36548d51aeee] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: some
```

## XML for Configuring With CorrelationID Scope

Paste this code into the configuration XML file of your integration project to quickly load the flow
for this example into your Mule app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:tracing="http://www.mulesoft.org/schema/mule/tracing"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/tracing http://www.mulesoft.org/schema/mule/tracing/current/mule-tracing.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
	<http:listener-config name="HTTP_Listener_config" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<flow name="tracingmodule2Flow"  >
		<http:listener config-ref="HTTP_Listener_config" path="/test"/>
		<set-payload value="some" />
		<logger level="WARN" message="#[payload]"/>
		<tracing:with-correlation-id correlationId="#[correlationId ++ '-Example']">
			<logger level="WARN"  message="#[payload]"/>
		</tracing:with-correlation-id>
	</flow>
</mule>
```

## See Also

- [Tracing Module Examples](https://docs.mulesoft.com/tracing-module/latest/tracing-module-examples)

- [Salesforce Help](https://help.salesforce.com)
