title: Spring webflux filter: How to get the reactor context after the query execution?
body: <p>Spring boot 2.1.5 
  Project Reactor 3.2.9</p>
  
  <p>In my webflux project I extensively use the reactor contexts in order to pass around some values.</p>
  
  <p>I set up a filter and am trying to log things which are in the context and to log different things in case of error/success.</p>
  
  <p>I have checked this documentation: <a href="https://projectreactor.io/docs/core/release/reference/#context" rel="noreferrer">https://projectreactor.io/docs/core/release/reference/#context</a></p>
  
  <p>I still struggle (especially on the error side) to get it.</p>
  
  <p>Basically, I have this filter:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class MdcWebFilter implements WebFilter {
  
      @NotNull
      @Override
      public Mono&lt;Void&gt; filter(@NotNull ServerWebExchange serverWebExchange,
                               WebFilterChain webFilterChain) {
  
          Mono&lt;Void&gt; filter = webFilterChain.filter(serverWebExchange);
  
          return filter
              .doAfterSuccessOrError(new BiConsumer&lt;Void, Throwable&gt;() {
                  @Override
                  public void accept(Void aVoid, Throwable throwable) {
                      //Here i would like to be able to access to the request's context
                      System.out.println("doAfterSuccessOrError:" + (throwable==null ? "OK" : throwable.getMessage())+"log the context");
                  }
              })
              .doOnEach(new Consumer&lt;Signal&lt;Void&gt;&gt;() {
                  @Override
                  public void accept(Signal&lt;Void&gt; voidSignal) {
                      //Here i have the context but i don't really know if i am in success or error
                      System.out.println("doOnEach:"+"Log OK/KO and the exception" + voidSignal.getContext());
                  }
              })
              .subscriberContext(context -&gt; context.put("somevar", "whatever"));
      }
  
  }
  </code></pre>
  
  <p>I also tried with a flatMap() and a Mono.subscriberContext() but i am not sure how to plug correctly with the filter (especially in error).</p>
  
  <p>What would be the best way to achieve this ?</p>