Contact Us 1-800-596-4880

Change the Correlation ID During Flow Execution with Tracing Module

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 Studio:

With CorrelationID scope flow
  1. In the Mule Palette view of Studio, select HTTP > Listener.

  2. Drag Listener to the Studio canvas.

  3. Set Path to /test.

  4. Click the plus sign (+) next to the Connector configuration field to configure a global element that can be used by all instances of the source in the app.

  5. Configure the HTTP Listener global element and click OK.

  6. Drag a Set Payload component to the right of HTTP Listener.

  7. Set Value to some.

  8. In the Mule Palette view of Studio, select Logger.

  9. Drag Logger to the right of Set Payload.

  10. Set Message to #[payload].

  11. Set Level to WARN.

  12. Drag the With CorrelationID scope to the Studio canvas.

  13. Set Correlation id to #[correlationId ++ '-EXAMPLE']:

    With CorrelationID scope configuration window with Correlation id field
  14. Drag another Logger component into the With CorrelationID scope.

  15. Set Message to #[payload].

  16. Set Level to WARN.

  17. Save and run your Mule app.

  18. Test the app by running curl localhost:8081/test at the command line.

The application output logs are:

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 your Studio XML editor to quickly load the flow for this example into your Mule app:

<?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>
View on GitHub