springboot 3.1.6 webflux跟踪丢失

gk7wooem  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(60)

我使用以下方法构建了Web客户端。

@Bean
    public XXXApiService xxxApiClient(HttpClient httpClient, WebClient.Builder builder) {
        WebClient webClient = builder
                .baseUrl("XX")
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .defaultStatusHandler(
                        httpStatusCode -> HttpStatus.NOT_FOUND == httpStatusCode,
                        response -> Mono.empty())
                .defaultStatusHandler(
                        HttpStatusCode::is5xxServerError,
                        response -> Mono.error(new RuntimeException(response.statusCode().toString())))
                .build();
        return HttpServiceProxyFactory
                .builder(WebClientAdapter.forClient(webClient))
                .build()
                .createClient(XXXApiService.class);
    }

字符串
我发现当从webflux进入并直接调用webclient时,trace可以成功连接。
然而,如果它首先以Flux.fromIterable(xx).flatMap(xx -> webClient.xxx)的形式完成,例如。没有办法连接整个跟踪。
那么,请问我应该如何着手解决这个问题呢?

0h4hbjxa

0h4hbjxa1#

看看这个问题的第一个评论是否对你有帮助。它为我解决了这个问题。
Micrometer tracing context propagration is lost in webclient flatMap function
当我升级到Project Reactor 3.6.0时,跟踪从一个WebClient调用传播到下一个。

<dependency>
    <groupId>io.projectreactor</groupId>
    <artifactId>reactor-core</artifactId>
    <version>3.6.0</version>
</dependency>

字符串
感谢用户@Trind提供解决方案。

相关问题