Correlated Logs in Spring Apps with Reactive Parts
Being able to identify application logs that belong to the same transaction is essential in understanding how your application behaves in production. The most common logging facade, SLF4J, uses ThreadLocal storage to implicitly provide contextual information for use in your logs in the form of mapped diagnostic context (MDC). Asynchronous paradigm makes it difficult to use MDC reliably.
We will show how to use Reactor 3.5 with MDC and still be able to log, without losing the correlation aspect. We will build a Spring Boot 3 MVC application that uses WebClient. Learn how to transport the correlation information in a reactive chain using the latest API and add logs in a reactive pipeline. We will also show the differences faced with a WebFlux-based server.