可观察性
Spring for Apache Pulsar 包括一种通过 Micrometer 管理可观测性的方法。
可观测性尚未添加到响应式组件中 |
千分尺观测
这PulsarTemplate
和PulsarListener
使用 Micrometer observations API 进行检测。
当千分尺ObservationRegistry
提供 bean,跟踪发送和接收作并定时。
自定义标签
默认实现将bean.name
标签用于模板观察,以及listener.id
标签。
要向计时器和跟踪添加其他标记,请配置自定义PulsarTemplateObservationConvention
或PulsarListenerObservationConvention
分别添加到模板或侦听器容器。
您可以对其中任一进行子类化DefaultPulsarTemplateObservationConvention 或DefaultPulsarListenerObservationConvention 或提供全新的实现。 |
可观测性 - 指标
您可以在下面找到此项目声明的所有指标的列表。
听众观察
当 Pulsar 侦听器收到消息时创建的观察。
指标名称 spring.pulsar.listener
(由约定类定义org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention
).类型 timer
.
指标名称 spring.pulsar.listener.active
(由约定类定义org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention
).类型 long task timer
.
启动观察后添加的 KeyValues 可能在 *.active 指标中缺失。 |
千分尺内部使用nanoseconds 用于基站。但是,每个后端都确定了实际的基数单元。(即普罗米修斯使用秒) |
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarListenerObservation
.
所有标签必须以spring.pulsar.listener 前缀! |
名称 |
描述 |
|
接收消息的侦听器容器的 ID。 |
模板观察
Pulsar 模板发送消息时创建的观察。
指标名称 spring.pulsar.template
(由约定类定义org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention
).类型 timer
.
指标名称 spring.pulsar.template.active
(由约定类定义org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention
).类型 long task timer
.
启动观察后添加的 KeyValues 可能在 *.active 指标中缺失。 |
千分尺内部使用nanoseconds 用于基站。但是,每个后端都确定了实际的基数单元。(即普罗米修斯使用秒) |
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarTemplateObservation
.
所有标签必须以spring.pulsar.template 前缀! |
名称 |
描述 |
|
发送消息的模板的 Bean 名称。 |
可观测性 - 跨度
您可以在下面找到此项目声明的所有跨度的列表。
侦听器观察跨度
当 Pulsar 侦听器收到消息时创建的观察。
跨度名称 spring.pulsar.listener
(由约定类定义org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention
).
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarListenerObservation
.
所有标签必须以spring.pulsar.listener 前缀! |
名称 |
描述 |
|
接收消息的侦听器容器的 ID。 |
模板观察范围
Pulsar 模板发送消息时创建的观察。
跨度名称 spring.pulsar.template
(由约定类定义org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention
).
封闭类的完全限定名称org.springframework.pulsar.observation.PulsarTemplateObservation
.
所有标签必须以spring.pulsar.template 前缀! |
名称 |
描述 |
|
发送消息的模板的 Bean 名称。 |
有关更多信息,请参阅千分尺追踪。
无需 Spring Boot 的手动配置
如果您不使用 Spring Boot,则需要配置并提供ObservationRegistry
以及千分尺追踪。有关更多信息,请参阅千分尺追踪。
使用 Spring Boot 自动配置
如果您使用 Spring Boot,Spring Boot Actuator 会自动配置ObservationRegistry
给你的。
如果micrometer-core
在类路径上,则每个停止的观察都会导致一个计时器。
Spring Boot 还会自动为您配置千分尺追踪。这包括对 Brave OpenTelemetry、Zipkin 和 Wavefront 的支持。使用千分尺观测 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 示例应用程序上查看上述配置。 |
这些步骤与配置任何其他受支持的跟踪环境非常相似。