title: Spring boot 2.1.5, WebFlux, Reactor: How to deal properly with MDC
body: <p>Spring boot 2.1.5
  Project Reactor 3.2.9</p>
  
  <p>I am setting up a bunch of rest reactive APIs using the above-mentioned frameworks and I am running into an annoying problem with MDC (mapped diagnostic context). My applications are in JAVA.</p>
  
  <p>MDC relies on thread locals to store the current query's mapped context to put in the logs. That system, obviously, is not perfect and contradicts the reactive pattern since the different steps of your execution will be executed through different threads.</p>
  
  <p>I have run into the same problem with the Play Reactive framework but found a workaround there by copying the mapped context transparently from one actor to another.</p>
  
  <p>For spring and reactor, I could not find a satisfying solution yet.</p>
  
  <p>Some random examples found on the internet:</p>
  
  <p><a href="https://ndportmann.com/logging-with-context-in-spring-webflux/" rel="noreferrer">First - It works but forces you to use a bunch of utility methods</a></p>
  
  <p><a href="https://simonbasle.github.io/2018/02/contextual-logging-with-reactor-context-and-mdc/" rel="noreferrer">Same thing</a></p>
  
  <p><a href="https://www.novatec-gmbh.de/en/blog/how-can-the-mdc-context-be-used-in-the-reactive-spring-applications/" rel="noreferrer">Second - It tries to copy the context during the onNext publisher event but seems to lose some features on the way of doing that. The signal context, for example, is lost.</a></p>
  
  <p>I am in need of a proper solution to deal with this:</p>
  
  <ul>
  <li>A library which would make the link between MDC and reactor?</li>
  <li>A way to tweak reactor/spring to achieve it transparently?</li>
  <li>Any advice?</li>
  </ul>