Skip to content

Commit a427638

Browse files
committed
Generate documentation with Micrometer observation
1 parent 99aa250 commit a427638

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

ci/publish-documentation-to-github-pages.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
. $(pwd)/release-versions.txt
44

5+
./mvnw clean test-compile exec:java \
6+
-Dexec.mainClass=io.micrometer.docs.DocsGeneratorCommand \
7+
-Dexec.classpathScope="test" \
8+
-Dexec.args='src/main/java/com/rabbitmq/model/observation/micrometer .* target/micrometer-observation-docs'
9+
510
MESSAGE=$(git log -1 --pretty=%B)
611
./mvnw buildnumber:create pre-site --no-transfer-progress
712

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<mockito.version>5.12.0</mockito.version>
5252
<amqp-client.version>5.20.0</amqp-client.version>
5353
<micrometer-tracing-test.version>1.3.0</micrometer-tracing-test.version>
54+
<micrometer-docs-generator.version>1.0.2</micrometer-docs-generator.version>
5455
<maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>
5556
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
5657
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
@@ -175,6 +176,13 @@
175176
<optional>true</optional>
176177
</dependency>
177178

179+
<dependency>
180+
<groupId>io.micrometer</groupId>
181+
<artifactId>micrometer-docs-generator</artifactId>
182+
<version>${micrometer-docs-generator.version}</version>
183+
<scope>test</scope>
184+
</dependency>
185+
178186
<dependency>
179187
<groupId>com.github.spotbugs</groupId>
180188
<artifactId>spotbugs-annotations</artifactId>

src/docs/asciidoc/appendixes.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ifndef::build-directory[:build-directory: ../../../target]
2+
:test-examples: ../../test/java/com/rabbitmq/model/docs
3+
4+
[appendix]
5+
== Micrometer Observation
6+
7+
It is possible to use https://micrometer.io/docs/observation[Micrometer Observation] to instrument publishing and consuming in the AMQP Java client.
8+
Micrometer Observation provides https://spring.io/blog/2022/10/12/observability-with-spring-boot-3[metrics, tracing, and log correlation with one single API].
9+
10+
The AMQP Java client provides an `ObservationCollector` abstraction and an implementation for Micrometer Observation.
11+
The following snippet shows how to create and set up the Micrometer `ObservationCollector` implementation with an existing `ObservationRegistry`:
12+
13+
.Configuring Micrometer Observation
14+
[source,java,indent=0]
15+
--------
16+
include::{test-examples}/Api.java[tag=micrometer-observation]
17+
--------
18+
<1> Configure Micrometer `ObservationCollector` with builder
19+
<2> Set Micrometer `ObservationRegistry`
20+
21+
The next sections document the conventions, spans, and metrics made available by the instrumentation.
22+
They are automatically generated from the source code with the https://github.com/micrometer-metrics/micrometer-docs-generator[Micrometer documentation generator].
23+
24+
include::{build-directory}/micrometer-observation-docs/_conventions.adoc[]
25+
include::{build-directory}/micrometer-observation-docs/_spans.adoc[]
26+
include::{build-directory}/micrometer-observation-docs/_metrics.adoc[]

src/docs/asciidoc/index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ ifndef::sourcedir[:sourcedir: ../../main/java]
1212
The library is open source, developed https://github.com/rabbitmq-pro/rabbitmq-java-model/[on GitHub], and is licensed under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache Public License 2.0]
1313

1414
include::usage.adoc[]
15+
16+
include::appendixes.adoc[]

src/main/java/com/rabbitmq/model/observation/micrometer/AmqpObservationDocumentation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.micrometer.observation.docs.ObservationDocumentation;
2424

2525
public enum AmqpObservationDocumentation implements ObservationDocumentation {
26+
/** Observation for publishing a message. */
2627
PUBLISH_OBSERVATION {
2728

2829
@Override
@@ -36,6 +37,8 @@ public KeyName[] getLowCardinalityKeyNames() {
3637
return LowCardinalityTags.values();
3738
}
3839
},
40+
41+
/** Observation for processing a message. */
3942
PROCESS_OBSERVATION {
4043

4144
@Override

src/test/java/com/rabbitmq/model/docs/Api.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import com.rabbitmq.model.amqp.AmqpEnvironmentBuilder;
2222
import com.rabbitmq.model.metrics.MetricsCollector;
2323
import com.rabbitmq.model.metrics.MicrometerMetricsCollector;
24+
import com.rabbitmq.model.observation.micrometer.MicrometerObservationCollectorBuilder;
25+
import io.micrometer.observation.ObservationRegistry;
2426
import io.micrometer.prometheusmetrics.PrometheusConfig;
2527
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
2628

@@ -321,5 +323,14 @@ void metricsCollectorMicrometerPrometheus() {
321323
// end::metrics-micrometer-prometheus[]
322324
}
323325

326+
void micrometerObservation() {
327+
ObservationRegistry observationRegistry = ObservationRegistry.NOOP;
328+
// tag::micrometer-observation[]
329+
Environment environment = new AmqpEnvironmentBuilder()
330+
.observationCollector(new MicrometerObservationCollectorBuilder() // <1>
331+
.registry(observationRegistry).build()) // <2>
332+
.build();
333+
// end::micrometer-observation[]
334+
}
324335

325336
}

0 commit comments

Comments
 (0)