spring-boot - 如何在SpringBoot 3中配置zipkin的baseUrl

标签 spring-boot spring-cloud-sleuth zipkin jaeger micrometer-tracing

我们设置了 Jaeger,主要用于跟踪 istio 代理之间的调用。我正在尝试在应用程序内部使用跟踪,在日志中包含任何traceId/spanId,并向 Jaeger 收集器报告应用程序中创建的任何跨度。

我们的大多数微服务仍然运行 Spring Boot 2。有些已经升级到 Spring Boot 3。

我已经让它在 Spring Boot2 中工作得令人满意。

我包含了以下依赖项:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
  <groupId>io.opentracing.brave</groupId>
  <artifactId>brave-opentracing</artifactId>
</dependency>

并在application.yaml中设置以下内容

spring:
  application:
    name: our-service
  sleuth:
    propagation:
      type: B3,W3C
    opentracing:
      enabled: true
  zipkin:
    base-url: <url to our jaeger collector>:9411

对于我们的 Spring Boot 3 应用程序,我添加了以下依赖项,而不是上面的依赖项:

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
  <groupId>io.zipkin.reporter2</groupId>
  <artifactId>zipkin-reporter-brave</artifactId>
</dependency>

并在 application.yaml 中添加了与上面相同的配置,但还添加了:

logging:
  pattern:
    level: "%5p [${spring.application.name},%X{traceId:-},%X{spanId:-}]"

当我在测试环境中运行两个应用程序时,我可以看到两个应用程序的日志中都显示了traceId,并且我也可以在 jaeger UI 中找到这些traceId,包括在 SpringBoot 2 应用程序中创建的跨度。除了应该来自 SpringBoot 3 应用程序的 spanId 之外。该应用程序在日志中具有匹配的traceId,但我也有以下错误:

2023-03-16T15:36:15.037Z WARN [our-service,,] 1 --- [ender@207ff82c}] z.r.AsyncReporter$BoundedAsyncReporter : Dropped 1 spans due to ResourceAccessException(I/O error on POST request for "http://localhost:9411/api/v2/spans": Connection refused

这让我得出结论,在 Spring Boot 3 中设置 Jaeger 收集器 url 的配置应该有所不同,因为它没有获取我配置的 url,而是使用 http://localhost。但我似乎无法在任何地方找到我应该如何配置它。

希望这里的任何人都可以帮助我并告诉我我做错了什么。

最佳答案

我最近遇到了同样的问题。在调查过程中,我通过查看 Spring Boot 执行器端点的输出来查找配置属性,找到了一个解决方案:http://localhost:8080/actuator/configprops

输出提到了一个名为 ZipkinProperties 的类,因此我在 Spring Boot API 文档中查找了它:https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinProperties.html

ZipkinConfiguration 类中有 3 个属性:

  • 连接超时
  • 端点
  • 读取超时

您正在寻找的是属性management.zipkin.tracing.endpoint

management:
  zipkin:
    tracing:
      endpoint: <url to collector>:9411/api/v2/spans

关于spring-boot - 如何在SpringBoot 3中配置zipkin的baseUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75758772/

相关文章:

java - Spring Cloud sleuth 没有与 Zipkin 一起运行

java - Spring转换器不转换自定义实体

spring - PCF 上的 128 位侦探跟踪 ID

spring-cloud - Spring Sleuth 卡住了向 Zipkin 发送 10% 的请求

spring - 在 Spring Cloud 中重命名 x-b3-traceid header

java - Zipkin - 是否有关于在 Java 中创建跨度和跟踪的更多信息

python - Zipkin 用于分析传统程序的内部结构

java - 由于缺少 EmbeddedServletContainerFactory bean,Spring 应用程序无法启动

spring-boot - 如何在Spring Boot中设置默认环境

postgresql - Atomikos JTA 事务管理器 'Purging orphaned entry from log' 登录输出