Spring for Apache Pulsar 包括一种通过 Micrometer 管理可观测性的方法。

可观测性尚未添加到反应式组件中
可观测性尚未添加到反应式组件中

千分尺观察

和 使用 Micrometer 观测 API 进行检测。 当提供千分尺 Bean 时,将跟踪发送和接收操作并计时。PulsarTemplatePulsarListenerObservationRegistry

自定义标签

默认实现为模板观察添加标记,为侦听器观察添加标记。 要将其他标记添加到计时器和跟踪,请分别配置自定义或模板或侦听器容器。bean.namelistener.idPulsarTemplateObservationConventionPulsarListenerObservationConvention

您可以对其中一个子类化,也可以提供全新的实现。DefaultPulsarTemplateObservationConventionDefaultPulsarListenerObservationConvention

可观测性 - 指标

您可以在下面找到此项目声明的所有指标的列表。

侦听器观察

Pulsar 监听器接收到消息时创建的观测值。

指标名称(由约定类定义)。键入spring.pulsar.listenerorg.springframework.pulsar.observation.DefaultPulsarListenerObservationConventiontimer

指标名称(由约定类定义)。键入spring.pulsar.listener.activeorg.springframework.pulsar.observation.DefaultPulsarListenerObservationConventionlong task timer

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds

封闭类 .org.springframework.pulsar.observation.PulsarListenerObservation

所有标签都必须以前缀为前缀!spring.pulsar.listener
表 1.低基数键

名字

描述

spring.pulsar.listener.id (必填)

接收消息的侦听器容器的 ID。

模板观察

Pulsar 模板发送消息时创建的观测值。

指标名称(由约定类定义)。键入spring.pulsar.templateorg.springframework.pulsar.observation.DefaultPulsarTemplateObservationConventiontimer

指标名称(由约定类定义)。键入spring.pulsar.template.activeorg.springframework.pulsar.observation.DefaultPulsarTemplateObservationConventionlong task timer

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds

封闭类 .org.springframework.pulsar.observation.PulsarTemplateObservation

所有标签都必须以前缀为前缀!spring.pulsar.template
表 2.低基数键

名字

描述

spring.pulsar.template.name (必填)

发送消息的模板的 Bean 名称。

可观测性 - 跨度

您可以在下面找到此项目声明的所有跨度的列表。

侦听器观察跨度

Pulsar 监听器接收到消息时创建的观测值。

Span 名称(由约定类定义)。spring.pulsar.listenerorg.springframework.pulsar.observation.DefaultPulsarListenerObservationConvention

封闭类 .org.springframework.pulsar.observation.PulsarListenerObservation

所有标签都必须以前缀为前缀!spring.pulsar.listener
表 3.标签键

名字

描述

spring.pulsar.listener.id (必填)

接收消息的侦听器容器的 ID。

模板观察跨度

Pulsar 模板发送消息时创建的观测值。

Span 名称(由约定类定义)。spring.pulsar.templateorg.springframework.pulsar.observation.DefaultPulsarTemplateObservationConvention

封闭类 .org.springframework.pulsar.observation.PulsarTemplateObservation

所有标签都必须以前缀为前缀!spring.pulsar.template
表 4.标签键

名字

描述

spring.pulsar.template.name (必填)

发送消息的模板的 Bean 名称。

有关详细信息,请参阅千分尺跟踪

没有Spring Boot的手动配置

如果不使用 Spring Boot,则需要配置并提供 以及 Micrometer Tracing。有关详细信息,请参阅千分尺跟踪ObservationRegistry

使用 Spring Boot 自动配置

如果您使用 Spring Boot,则 Spring Boot Actuator 会自动为您配置一个实例。 如果在类路径上,则每个停止的观察都会导致一个计时器。ObservationRegistrymicrometer-core

Spring Boot 还会自动为您配置千分尺跟踪。这包括对 Brave OpenTelemetry、Zipkin 和 Wavefront 的支持。使用千分尺观测 API 时,完成观测会导致向 Zipkin 或 Wavefront 报告跨度。可以通过在 下设置属性来控制跟踪。您可以将 Zipkin 与 一起使用,而 Wavefront 使用 .management.tracingmanagement.zipkin.tracingmanagement.wavefront

配置示例

以下示例显示了将 Spring Boot 应用程序配置为将 Zipkin 与 Brave 一起使用的步骤。

  1. 将所需的依赖项添加到应用程序(分别在 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>
    Gradle
    dependencies {
        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 时,才需要依赖项。'io.zipkin.reporter2:zipkin-sender-urlconnection'

  2. 将所需的属性添加到应用程序:

    management:
      tracing.enabled: true
      zipkin:
        tracing.endpoint: "http://localhost:9411/api/v2/spans"

    上述要求 Zipkin 在本地运行,如此所述。tracing.endpoint

此时,您的应用程序应该在您发送和接收 Pulsar 消息时记录跟踪。您应该能够在 Zipkin UI 中查看它们(在本地运行时位于 localhost:9411)。

您还可以在 Spring for Apache Pulsar 示例应用程序上查看上述配置。

这些步骤与配置任何其他受支持的跟踪环境非常相似。

您可以对其中一个子类化,也可以提供全新的实现。DefaultPulsarTemplateObservationConventionDefaultPulsarListenerObservationConvention
*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds
所有标签都必须以前缀为前缀!spring.pulsar.listener
表 1.低基数键

名字

描述

spring.pulsar.listener.id (必填)

接收消息的侦听器容器的 ID。

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds
所有标签都必须以前缀为前缀!spring.pulsar.template
表 2.低基数键

名字

描述

spring.pulsar.template.name (必填)

发送消息的模板的 Bean 名称。

所有标签都必须以前缀为前缀!spring.pulsar.listener
表 3.标签键

名字

描述

spring.pulsar.listener.id (必填)

接收消息的侦听器容器的 ID。

所有标签都必须以前缀为前缀!spring.pulsar.template
表 4.标签键

名字

描述

spring.pulsar.template.name (必填)

发送消息的模板的 Bean 名称。

您还可以在 Spring for Apache Pulsar 示例应用程序上查看上述配置。