Skip to content

Commit 90a39b8

Browse files
authored
Add Micrometer Tracing to sample apps (#160)
Also documents how to configure Micrometer Observations. See #147
1 parent 1a94d40 commit 90a39b8

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

spring-pulsar-docs/src/main/asciidoc/pulsar.adoc

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,9 @@ Headers can also be extracted in the same manner when receiving payload as `List
13381338
=== Observability
13391339

13401340
[[observation]]
1341-
==== Micrometer Observation
1341+
==== Micrometer Observations
13421342
The `PulsarTemplate` and `PulsarListener` are instrumented with the Micrometer observations API.
1343-
When enabled, send and receive operations are traced and timed.
1344-
1345-
To enable, set `observationEnabled` on each component.
1343+
When a Micrometer `ObservationRegistry` bean is provided, send and receive operations are traced and timed.
13461344

13471345
===== Custom tags
13481346
The default implementation adds the `bean.name` tag for template observations and `listener.id` tag for listener observations.
@@ -1356,7 +1354,73 @@ include::observation/_spans.adoc[leveloffset=+2]
13561354

13571355
Refer to https://micrometer.io/docs/tracing[Micrometer Tracing] for more information.
13581356

1359-
==== Appendix
1357+
===== Manual Configuration Without Spring Boot
1358+
If you are not using Spring Boot then you will need to configure and provide an `ObservationRegistry` as well as Micrometer Tracing. Refer to https://micrometer.io/docs/tracing[Micrometer Tracing] for more information.
1359+
1360+
===== Auto-Configuration With Spring Boot
1361+
If you are using Spring Boot, the Spring Boot Actuator auto-configures an instance of `ObservationRegistry` for you.
1362+
If `micrometer-core` is on the classpath every stopped Observation leads to a timer.
1363+
1364+
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 will lead to spans reported to Zipkin or Wavefront. Tracing can be controlled with properties under `management.tracing`. Zipkin can be configured with `management.zipkin.tracing` while Wavefront uses `management.wavefront`.
1365+
1366+
====== Example Configuration
1367+
The following illustrates the steps to configure your Spring Boot app to use Zipkin with Brave.
1368+
1369+
**Step 1:** Add the required dependencies to your application [small]#(Maven or Gradle, respectively)#:
1370+
1371+
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
1372+
.Maven
1373+
----
1374+
<dependencies>
1375+
<dependency>
1376+
<groupId>org.springframework.boot</groupId>
1377+
<artifactId>spring-boot-starter-actuator</artifactId>
1378+
</dependency>
1379+
<dependency>
1380+
<groupId>io.micrometer</groupId>
1381+
<artifactId>micrometer-tracing-bridge-brave</artifactId>
1382+
</dependency>
1383+
<dependency>
1384+
<groupId>io.zipkin.reporter2</groupId>
1385+
<artifactId>zipkin-reporter-brave</artifactId>
1386+
</dependency>
1387+
<dependency>
1388+
<groupId>io.zipkin.reporter2</groupId>
1389+
<artifactId>zipkin-sender-urlconnection</artifactId>
1390+
</dependency>
1391+
</dependencies>
1392+
----
1393+
1394+
[source,groovy,indent=0,subs="verbatim,attributes",role="secondary"]
1395+
.Gradle
1396+
----
1397+
dependencies {
1398+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
1399+
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
1400+
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'
1401+
implementation 'io.zipkin.reporter2:zipkin-sender-urlconnection'
1402+
}
1403+
----
1404+
NOTE: The `'io.zipkin.reporter2:zipkin-sender-urlconnection'` dependency is only needed if your application does not have a configured WebClient or RestTemplate.
1405+
1406+
**Step 2:** Add the required properties to your application:
1407+
1408+
[source,yaml,indent=0,subs="verbatim"]
1409+
----
1410+
management:
1411+
tracing.enabled: true
1412+
zipkin:
1413+
tracing.endpoint: "http://localhost:9411/api/v2/spans"
1414+
----
1415+
The `tracing.endpoint` above expects Zipkin is running locally as described https://zipkin.io/pages/quickstart.html[here].
1416+
1417+
At this point, your application should be recording traces when you send and receive Pulsar messages. You should be able to view them in the Zipkin UI [small]#(when running locally http://localhost:9411)#.
1418+
1419+
TIP: The above configuration can also be seen on the link:{github}/blob/main/spring-pulsar-sample-apps/README.adoc[Spring Pulsar Sample Apps].
1420+
1421+
The steps would be very similar to configure in any of the other supporting Tracing environments.
1422+
1423+
=== Appendix
13601424
The reference documentation has the following appendices:
13611425

13621426
[horizontal]

spring-pulsar-sample-apps/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ description = 'Spring Pulsar Sample Applications'
88
dependencies {
99
api project(':spring-pulsar-spring-boot-starter')
1010
implementation 'com.google.code.findbugs:jsr305'
11+
12+
// observability
13+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
14+
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
15+
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'
16+
implementation 'io.zipkin.reporter2:zipkin-sender-urlconnection'
1117
}
1218

1319
springBoot {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
logging:
22
level:
33
org.apache.pulsar: error
4+
5+
management:
6+
tracing:
7+
enabled: false
8+
zipkin:
9+
tracing:
10+
endpoint: "http://localhost:9411/api/v2/spans"

0 commit comments

Comments
 (0)