Kelly X.Y. wrote:What is the good way to trace a message in its message path in an asynchronous event-driven Microservice architecture?
Hi Kelly! One way I have used to trace incoming messages throughout its lifecycle within a system is to add a correlation id to the message. This could be auto-generated upon receipt at the first entry point, or the client publishing the message could provide one. Many languages support creating a UUID, and because they are unique, make great identifiers. I would then, at every boundary in the system that interacts with the message, write a log message containing the correlation id and any other relevant information you would want to know about the message at that given time. One requirement of this approach would be to ensure that the correlation id would need to be passed across each boundary.
As Nitish mentioned in his post, you could use a library like
Spring Cloud Sleuth that provides distributed tracing around ingress and egress for some top level components. It can help collect logs related to a request and measure the execution time (which is helpful to troubleshoot bottlenecks in the system).
If you are already using a monitoring solution like
DataDog or
AppDynamics, they have Application Performance Monitoring (APM) capabilities that you could use to instrument your code for traceability.