springboot 3.1.6 webflux 跟踪丢失

问题描述 投票:0回答:2

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

 @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) 的形式完成,例如。没有办法连接整个轨迹。

请问我该如何解决这个问题?

spring-boot spring-webflux open-telemetry micrometer micrometer-tracing
2个回答
1
投票

看看这个问题的第一条评论是否对您有帮助。它解决了我的问题。

Micrometer 跟踪上下文传播在 Web 客户端 flatMap 函数中丢失

当我升级到 Project Reactor 3.6.0 时,跟踪从一个

WebClient
调用传播到下一个。

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

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


0
投票

根据 自动上下文传播,自 Reactor-Core 版本 3.5.3 起,应将以下行添加到应用程序内的一处:

    Hooks.enableAutomaticContextPropagation();
© www.soinside.com 2019 - 2024. All rights reserved.