可观测性
Spring for Apache Pulsar 包含通过 Micrometer 来管理可观测性的功能。
| 可观性尚未添加到响应式组件中 |
Micrometer 监控观测
The PulsarTemplate and PulsarListener are instrumented with the Micrometer observations API.
When a Micrometer ObservationRegistry bean is provided, send and receive operations are traced and timed.
自定义标签
The 默认实现 为 模板 观察 添加 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。
| 在启动 Observation 后添加的 KeyValues 可能会缺失于 *.active 指标中。 |
Micrometer 内部使用 nanoseconds 作为基本单位。然而,每个后端决定实际的基本单位。(即 Prometheus 使用秒) |
封闭类 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。
| 在启动 Observation 后添加的 KeyValues 可能会缺失于 *.active 指标中。 |
Micrometer 内部使用 nanoseconds 作为基本单位。然而,每个后端决定实际的基本单位。(即 Prometheus 使用秒) |
封闭类 org.springframework.pulsar.observation.PulsarTemplateObservation 的全限定名。
所有标签都必须以 spring.pulsar.template 前缀开头! |
姓名 |
描述 |
|
发送消息的模板的Bean名称。 |
可观测性 - 跨度
以下列出了本项目声明的所有 span。
监听器观测范围
创建当Pulsar监听器接收到消息时的观察记录。
Span 名称 spring.pulsar.listener(由约定类 org.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention 定义)。
封闭类 org.springframework.pulsar.observation.PulsarListenerObservation 的全限定名。
所有标签都必须以 spring.pulsar.listener 前缀开头! |
姓名 |
描述 |
|
接收消息的监听器容器的ID。 |
模板观察跨度
当Pulsar模板发送消息时创建的观察记录。
Span 名称 spring.pulsar.template(由约定类 org.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention 定义)。
封闭类 org.springframework.pulsar.observation.PulsarTemplateObservation 的全限定名。
所有标签都必须以 spring.pulsar.template 前缀开头! |
姓名 |
描述 |
|
发送消息的模板的Bean名称。 |
见 Micrometer Tracing 了解更多信息。
手动配置不使用 Spring Boot
如果未使用 Spring Boot,还需要配置并提供一个 ObservationRegistry 以及 Micrometer Tracing。请参阅 Micrometer Tracing 以获取更多信息。
自动配置与Spring Boot
如果使用 Spring Boot,Spring Boot Actuator 会自动配置一个 ObservationRegistry 实例。
如果 micrometer-core 在类路径上,每次停止的观察都会导致定时器。
Spring Boot 也为您自动配置了 Micrometer 跟踪。这包括对 Brave OpenTelemetry、Zipkin 和 Wavefront 的支持。当使用 Micrometer 观察 API 时,完成观察会将跨度报告到 Zipkin 或 Wavefront。您可以通过在 management.tracing 下的属性控制跟踪。您可以在 management.zipkin.tracing 中使用 Zipkin,而 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' }注意 仅当您的应用程序没有配置 WebClient 或 RestTemplate 时,才需要 0 依赖项。
-
-
添加到您的应用程序所需的属性:
management: tracing.enabled: true zipkin: tracing.endpoint: "http://localhost:9411/api/v2/spans"The
tracing.endpoint以上期望 Zipkin 本地运行,如在 此处 所描述。
此时,您的应用程序在发送和接收Pulsar消息时应该记录trace。当在本地运行时,您应该能够在localhost:9411访问的Zipkin UI中查看它们。
| 您也可以在Spring for Apache Pulsar Sample Apps上查看前面的配置。 |
步骤与配置其他受支持的追踪环境非常相似。