title: Logging in reactive streams
body: <p>I'm working on a reactive streams application using spring webflux. I have 1 single chain/pipeline of code that goes from Controller methods to Services to DAOs and returns back the response. During this pipeline I have a lot of Publishers. I would like to add logging support for the operators that are there in the pipeline. Say I have the following code,</p>
  <pre><code>public class Example {
  
   @Autowired
   private GreetingService gs;
  
   public Mono&lt;String&gt; getGreetingMessage(String name) {
    return Mono.just(name)
               .map(name -&gt; {
                    log.info(&quot;Name is being converted to Uppercase&quot;);
                    return name.toUpperCase();})
               .map(name -&gt; {
                    log.info(&quot;Name is being converted to Lowercase&quot;);
                    return name.toUpperCase();})
               .onErrorResume(ex -&gt; {
                    log.error(&quot;Exception occured, relying on fallback value = guest&quot;);
                    return Mono.just(&quot;guest&quot;);})
               .flatMap(name -&gt; {
                log.info(&quot;Getting greeting from greetingService&quot;);
                return gs.getGreeting(name);
                }); 
   }
  
  }
  
  @Service
  public class GreetingService {
   public Mono&lt;String&gt; getGreeting(String name) {
    return Mono.just(&quot;Welcome, &quot; + name+&quot;.&quot;);
   }
  }
  </code></pre>
  <p>I know this a contrived example but the actual code is a lot lengthier than this with a lot of calls to different classes within the pipeline. How exactly do we perform the logging in this scenario? What is an elegant way to do logging?</p>
  <p>Note: Since there are multiple publishers like in <code>flatMap</code>, <code>onErrorResume</code> I dont think we can use a simple <code>log()</code> because <code>log()</code> would only be applied to that particular publisher for which we use it.</p>
  <p>PS: I have like 8 operators in each method of the services and DAO layers and I want to know when I get there is an exception, at what operator the issue came from. How can I do this? I thought I should use <code>log.info(&quot;Some message about what each operator is doing&quot;)</code> for each operator in the method which would around 8 log statements. or alternatively using multiple doOn* operators to do the same. What would a better way to log here?</p>