springboot 3.1.6 webflux跟踪丢失

gk7wooem  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(185)

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

  1. @Bean
  2. public XXXApiService xxxApiClient(HttpClient httpClient, WebClient.Builder builder) {
  3. WebClient webClient = builder
  4. .baseUrl("XX")
  5. .clientConnector(new ReactorClientHttpConnector(httpClient))
  6. .defaultStatusHandler(
  7. httpStatusCode -> HttpStatus.NOT_FOUND == httpStatusCode,
  8. response -> Mono.empty())
  9. .defaultStatusHandler(
  10. HttpStatusCode::is5xxServerError,
  11. response -> Mono.error(new RuntimeException(response.statusCode().toString())))
  12. .build();
  13. return HttpServiceProxyFactory
  14. .builder(WebClientAdapter.forClient(webClient))
  15. .build()
  16. .createClient(XXXApiService.class);
  17. }

字符串
我发现当从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调用传播到下一个。

  1. <dependency>
  2. <groupId>io.projectreactor</groupId>
  3. <artifactId>reactor-core</artifactId>
  4. <version>3.6.0</version>
  5. </dependency>

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

相关问题