I would like to generate metrics (time) and traces for a reactive operation.
Here is the reactive operation, very straightforward:
@GetMapping("/question")
Flux<String> question() {
return Flux.interval(Duration.ofSeconds(1))
.map(oneLong -> measureMe(oneLong));
}
To observe such, the doc suggests to use the tap operator.
However, it seems there are many versions of it. Some using it before, some using it after the operation to observe, like this:
@GetMapping("/tapBefore")
Flux<String> tapBefore() {
return Flux.interval(Duration.ofSeconds(1))
.name("tapBefore")
.tap(Micrometer.observation(observationRegistry))
.map(oneLong -> measureMe(oneLong));
}
vs
@GetMapping("/tapAfter")
Flux<String> tapAfter() {
return Flux.interval(Duration.ofSeconds(1))
.map(oneLong -> measureMe(oneLong))
.name("tapAfter")
.tap(Micrometer.observation(observationRegistry));
}
It seems both are "generating something" I do see some traces and metrics.
But it seems the values are not correct depending on whether it is placed before or after.
Questions:
What are the differences between placing the tap operator before or after the operation to be measured?
If my goal is to measure the operation
measureMe
, should I use tap before or after?