top of page



  • Writer's picture

Tracing Module in Mule 4


In this post:


The tracing module enables you to enhance your logs by adding, removing, and clearing all variables from the logging context for a given Mule event. It also enables you to modify the correlation ID during flow execution.

Uses Of Tracing Module

  • Clear all the logging variables from the event logging context.

  • Remove a logging variable from the logging context.

  • Set logging variables to logging context.

  • Modify the correlation ID during flow execution

Tracing Module Application

1 - Create Mule application: Go to Anypoint studio and create a mule project with the name mulesoft-tracing-module-integration.

2 - Add Tracing module: In the mule palette view, click on + Add Modules and search for tracing modules. Drag the Tracing module to your modules.

3 - HTTP Listener: Create an HTTP listener with the default configuration and specify the /trace base path.

4 - MDC Logging: Mapped Diagnostic Context (MDC) enriches logging and improves tracking by providing more context or information in the logs for the current Mule event. By default, Mule logs two MDC entries: processor, which shows the location of the current event; and event, which shows the correlation ID of the event. Open the log4j.xml file and replace [processor: %X{processorPath}; event: %X{correlationId}] with [%MDC].

5 - Create set variable logging: Create a set logging variable for customerId and request path as below. In the logger, we will print the payload.

6 - Run application: Run the application and test it out with the below command.

7 - Verify logs: Verify the logs customerId and request path will be printed in the context path logs. The below log will be printed in the file location mentioned in log4j.xml.


Note: You will see different logs in the console with processor and event.


8 - Console log4j changes: Open log4j.xml, add Console logging in Appenders tag. Also, add this reference to the AsyncRoot tag.

9 - Run application: Re-run the Mule application and verify the logger. The same logging will be printed in the console.

10 - Remove logging variable: After the logger, let’s remove one of the logging variables i.e request path. Also after this, remove the logging variable, and add the logger for payload.