最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Spring Webflux + Micrometer: difference between .tap(Micrometer.observation(observationRegistry)) before and after the op

programmeradmin5浏览0评论

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?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论