Measure elapsed time on Spring reactor
17:47 29 Oct 2025

I am using spring-webflux version 3.2.x

I want to log the total elapsed time of an whole pipeline execution.

I have found a method elapsed() but I want the total time, but I want the total time, not for items (doOnNext).

I saw a lot of options but I am not sure what is the correct to use.

My code:

private Mono getData(String slug) {

var stopWatch = StopWatch.createStarted();

return getProducts(
    Mono.zip(
        proxy.getExternalData(slug),
        getProductPersonalization(slug)))
    .doOnSuccess(it -> log.info("Finish with success:"))
    .doOnTerminate(() -> {
      stopWatch.stop();
      log.info("getData execution time: {} ms",
          stopWatch.getTime(TimeUnit.MILLISECONDS));
    });

}

  private Mono getProducts(Mono> tuple);

Note: I read that using stopWatch outside the pipeline is wrong, that is the reason I am looking for another solution.

This method is returned to a Controller

java spring-webflux project-reactor