Correlation ID can be very useful for Logging in Microservices. We can benefit from Mapped Diagnostic Context or MDC manages contextual information on a per-thread basis. Especially when logging in a multi-threaded application.
For example, we can store the IP address of each request in a web application and insert this data to each log statement.
- In our case, we’ll introduce a unique correlation id for each request.
- -We must maintain the MDC to prevent data corruption. More specifically, after adding an entry to MDC, we must remove it when the request ends.
Here are means to achieve in various framework:
- MdcFilter extends HttpFilter // WebApplcation
- MdcInterceptor implements HandlerInterceptor //Spring MVC
- public class MDCMessagePropertiesConverter extends DefaultMessagePropertiesConverter // RabbitMQ Listener
No comments:
Post a Comment