可观察性
Spring for Apache Pulsar 包括一种通过 Micrometer 管理可观测性的方法。
可观察性尚未添加到 Reactive 组件中 |
千分尺观测
这PulsarTemplate
和PulsarListener
使用 Micrometer observations API 进行检测。
当 MicrometerObservationRegistry
bean,则跟踪和计时发送和接收作。
自定义标签
默认实现会添加bean.name
标签,以及listener.id
标签中。
要向计时器和跟踪添加其他标签,请配置自定义PulsarTemplateObservationConvention
或PulsarListenerObservationConvention
分别添加到模板或侦听器容器中。
您可以子类化DefaultPulsarTemplateObservationConvention 或DefaultPulsarListenerObservationConvention 或提供全新的实现。 |
可观测性 - 指标
您可以在下面找到此项目声明的所有指标的列表。
侦听器观察
当 Pulsar 侦听器收到消息时创建的 Observation。
指标名称 spring.pulsar.listener
(由 convention 类定义org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention
).类型 timer
.
指标名称 spring.pulsar.listener.active
(由 convention 类定义org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention
).类型 long task timer
.
*.active 指标中可能缺少在开始观察后添加的 KeyValue。 |
千分尺内部使用nanoseconds 对于 baseUnit。但是,每个后端都决定了实际的 baseunit。(即 Prometheus 使用秒) |
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarListenerObservation
.
所有标签都必须以spring.pulsar.listener 前缀! |
名字 |
描述 |
|
接收消息的侦听器容器的 ID。 |
模板观察
当 Pulsar 模板发送消息时创建的 Observation。
指标名称 spring.pulsar.template
(由 convention 类定义org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention
).类型 timer
.
指标名称 spring.pulsar.template.active
(由 convention 类定义org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention
).类型 long task timer
.
*.active 指标中可能缺少在开始观察后添加的 KeyValue。 |
千分尺内部使用nanoseconds 对于 baseUnit。但是,每个后端都决定了实际的 baseunit。(即 Prometheus 使用秒) |
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarTemplateObservation
.
所有标签都必须以spring.pulsar.template 前缀! |
名字 |
描述 |
|
发送消息的模板的 Bean 名称。 |
可观测性 - Span
您可以在下面找到此项目声明的所有 span 的列表。
侦听器观察跨度
当 Pulsar 侦听器收到消息时创建的 Observation。
Span 名称 spring.pulsar.listener
(由 convention 类定义org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention
).
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarListenerObservation
.
所有标签都必须以spring.pulsar.listener 前缀! |
名字 |
描述 |
|
接收消息的侦听器容器的 ID。 |
模板观察跨度
当 Pulsar 模板发送消息时创建的 Observation。
Span 名称 spring.pulsar.template
(由 convention 类定义org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention
).
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarTemplateObservation
.
所有标签都必须以spring.pulsar.template 前缀! |
名字 |
描述 |
|
发送消息的模板的 Bean 名称。 |
有关更多信息,请参阅 Micrometer Tracing 。
不使用 Spring Boot 的手动配置
如果不使用 Spring Boot,则需要配置并提供ObservationRegistry
以及千分尺跟踪。有关更多信息,请参阅 Micrometer Tracing 。
使用 Spring Boot 进行自动配置
如果使用 Spring Boot,则 Spring Boot Actuator 会自动配置一个ObservationRegistry
给你的。
如果micrometer-core
在 Classpath 上,则每个停止的观察都会导致一个计时器。
Spring Boot 还为您自动配置了 Micrometer Tracing。这包括对 Brave OpenTelemetry、Zipkin 和 Wavefront 的支持。使用 Micrometer Observation API 时,完成观测会导致向 Zipkin 或 Wavefront 报告跨度。您可以通过在management.tracing
.您可以将 Zipkin 与management.zipkin.tracing
,而 Wavefront 使用management.wavefront
.
示例配置
以下示例显示了将 Spring Boot 应用程序配置为将 Zipkin 与 Brave 一起使用的步骤。
-
将所需的依赖项添加到您的应用程序(分别在 Maven 或 Gradle 中):
-
Maven
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-tracing-bridge-brave</artifactId> </dependency> <dependency> <groupId>io.zipkin.reporter2</groupId> <artifactId>zipkin-reporter-brave</artifactId> </dependency> <dependency> <groupId>io.zipkin.reporter2</groupId> <artifactId>zipkin-sender-urlconnection</artifactId> </dependency> </dependencies>
Gradledependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-tracing-bridge-brave' implementation 'io.zipkin.reporter2:zipkin-reporter-brave' implementation 'io.zipkin.reporter2:zipkin-sender-urlconnection' }
注意 您需要
'io.zipkin.reporter2:zipkin-sender-urlconnection'
依赖项,仅当您的应用程序没有配置的 WebClient 或 RestTemplate 时。 -
-
将所需的属性添加到您的应用程序:
management: tracing.enabled: true zipkin: tracing.endpoint: "http://localhost:9411/api/v2/spans"
这
tracing.endpoint
上面期望 Zipkin 在本地运行,如此处所述。
此时,你的应用程序应该在发送和接收 Pulsar 消息时记录跟踪。您应该能够在 Zipkin UI 中查看它们(在本地运行时,位于 localhost:9411)。
您还可以在 Spring for Apache Pulsar Sample Apps 上查看上述配置。 |
这些步骤与配置任何其他受支持的跟踪环境非常相似。