Observability
面向 Apache Pulsar 的 Spring 包括一种通过 Micrometer 管理可观察性的方式。
Spring for Apache Pulsar includes a way to manage observability through Micrometer.
可观测性尚未添加到 Reactive 组件中 |
Observability has not been added to the Reactive components yet |
Micrometer Observations
PulsarTemplate
和 PulsarListener
使用 Micrometer 可观察性 API 进行检测。当提供 Micrometer ObservationRegistry
bean 时,发送和接收操作将被追踪和计时。
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.
Custom tags
默认实现为模板可观察性添加 bean.name
标签,并为侦听器可观察性添加 listener.id
标签。要向计时器和追踪添加其他标签,请分别将自定义 PulsarTemplateObservationConvention
或 PulsarListenerObservationConvention
配置到模板或侦听器容器。
The default implementation adds the bean.name
tag for template observations and listener.id
tag for listener observations.
To add other tags to timers and traces, configure a custom PulsarTemplateObservationConvention
or PulsarListenerObservationConvention
to the template or listener container, respectively.
您可以将 |
You can subclass either |
Unresolved include directive in modules/ROOT/pages/reference/observability.adoc - include::partial$_metrics.adoc[]
Unresolved include directive in modules/ROOT/pages/reference/observability.adoc - include::partial$_spans.adoc[]
有关更多信息,请参见 Micrometer Tracing。
See Micrometer Tracing for more information.
Manual Configuration without Spring Boot
如果不使用 Spring Boot,则需要配置和提供 ObservationRegistry
以及微米追踪。有关更多信息,请参见 Micrometer Tracing。
If you do not use Spring Boot, you need to configure and provide an ObservationRegistry
as well as Micrometer Tracing. See Micrometer Tracing for more information.
Auto-Configuration with Spring Boot
如果你使用 Spring Boot,Spring Boot Actuator 将为你自动配置一个 ObservationRegistry
实例。如果类路径上有 micrometer-core
,则每个停止的可观察性都会导致一个计时器。
If you use Spring Boot, the Spring Boot Actuator auto-configures an instance of ObservationRegistry
for you.
If micrometer-core
is on the classpath, every stopped observation leads to a timer.
Spring Boot 也为你自动配置了 Micrometer Tracing。其中包括对 Brave OpenTelemetry、Zipkin 和 Wavefront 的支持。在使用 Micrometer Observation API 时,完成观察会导致将 span 报告给 Zipkin 或 Wavefront。你可以通过设置 management.tracing
下的属性来控制跟踪。你可以使用 management.zipkin.tracing
和 Zipkin,而 Wavefront 使用 `management.wavefront。
Spring Boot also auto-configures Micrometer Tracing for you. This includes support for Brave OpenTelemetry, Zipkin, and Wavefront. When using the Micrometer Observation API, finishing observations leads to spans reported to Zipkin or Wavefront. You can control tracing by setting properties under management.tracing
. You can use Zipkin with management.zipkin.tracing
, while Wavefront uses management.wavefront
.
Example Configuration
下面的示例演示了将 Spring Boot 应用程序配置为使用具有 Brave 的 Zipkin 的步骤。
The following example shows the steps to configure your Spring Boot application to use Zipkin with Brave.
-
Add the required dependencies to your application (in Maven or Gradle, respectively):
- 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>
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'` 依赖项。
NOTE You need the ’io.zipkin.reporter2:zipkin-sender-urlconnection'` dependency only if your application does not have a configured WebClient or RestTemplate. . Add the required properties to your application:[source, yaml]
management: tracing.enabled: true zipkin: tracing.endpoint: "http://localhost:9411/api/v2/spans"
如 tracing.endpoint
所述,Zipkin 在本地运行,如 here 中所述。
The tracing.endpoint
above expects Zipkin is running locally as described here.
此时,您的应用程序在发送和接收 Pulsar 消息时应该会记录追踪。在 Zipkin UI(在 [role="bare"][role="bare"]http://localhost:9411,本地运行中)中,您应该可以查看追踪。
At this point, your application should record traces when you send and receive Pulsar messages. You should be able to view them in the Zipkin UI (at [role="bare"]http://localhost:9411, when running locally).
您还可以在 Spring for Apache Pulsar Sample Apps 上看到前面的配置。 |
You can also see the preceding configuration on the Spring for Apache Pulsar Sample Apps. |
这些步骤与配置任何所支持的其它跟踪环境非常相似。
The steps are very similar to configuring any of the other supported Tracing environments.