Correlation ID

  • A CorrelationID is a Unique identifier assigned to a request that allows tracking it through various components.
  • We can print CorrelationID along with Our logs.
  • It is easier to debug across micro services using correlation ID.
  • Helps to the request in a distributed system.
  • Each client will have a unique CorrelationID Corresponding to its request.
  • Since 3.2.1 spring boot adds this ID using simple configuration as follows
    • Add the dependency of “micrometer – tracing – bridge – brave” or “ Spring boot actuator”
    • Add property management.tracing.enabled=true.
  • Example
  • Correlated logs in Spring Apps With reactive parts
    • We use MDC I.e. Mapped Diagnostics Context.
    • MDC is map Backed by thread, local storage.
    • We add correlation ID in MDC and response header So that we can correlate logs corresponding to request/Response
    • We can use a correlation Filter() as a bean in oncePerRequestFilter()
    • Add a logging pattern with correlation key in properties.
    • Context. Write() and context.store helps To store data in context reactor.
      • To access data back we use tap() or handle().
    • Example : https://github.com/gauravmatta/springmvc/tree/master/springredis

No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...