Saturday, December 16, 2023

What is Tracing Module and how to use it in Mule 4.x?

Before we look into Tracing module, we need to discuss on Correlation Id and it's importance..!

What is Correlation Id.?

For eg, In a trip planning application, we send customer_details request to various applications (apis), so this message is consumed by Hotel API, Airline API and Car-Rental microservices. These separate services respond asynchronously. Where multiple responses and requests are flowing across distributed microservices, so with the help of Correlation Id we can track the particular transaction easily.

When Mule creates a new event, it generates a unique identifier string called a correlation ID before sending the event to the next processor. This ID enables us to correlate different log entries with a particular execution.

Use the correlation ID to understand the entire history of an event that resulted in an issue or an unhandled error (all errors include the correlation ID of the event that triggered it). Also, knowing the correlation ID helps you perform a memory analysis of heap dumps.

To obtain a correlation ID, Mule first checks for one in the source message (for example, a JMS message or an HTTP listener with the X-CORRELATION-ID header). If the source does not set a correlation ID, Mule generates one using the correlation ID generator.




In earlier version of Mule Runtime, Correlation Id can't be modified.
But in Mule 4.4.0 or later version, Correlation Id can be modified with the help of Tracing Module.
Tracing module enables us to enhance the logs by adding, removing, and clearing all variables from the logging context for a given Mule event. It also enables us to modify the correlation ID during flow execution.

Tracking Module:
You need to download this module from Exchange.
  • Clear all the logging variables from the event logging context.
  • Remove a logging variable from logging context.
  • Set logging variables to logging context.
  • Modify the correlation ID during flow execution
Create a simple flow, drag and drop With CorrelationID and specify correlation Id as shown in below screenshot.

Source code: Correlation-id-project.
Ref: docs.mulesoft.com

Thanks for reading :-)