Skip to content

Commit 0f57d51

Browse files
committed
Add Javadoc for Micrometer observability
1 parent bc2a996 commit 0f57d51

File tree

2 files changed

+108
-11
lines changed

2 files changed

+108
-11
lines changed

src/main/java/com/rabbitmq/client/observation/micrometer/MicrometerObservationCollectorBuilder.java

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
package com.rabbitmq.client.observation.micrometer;
1616

1717
import com.rabbitmq.client.observation.ObservationCollector;
18+
import io.micrometer.observation.ObservationConvention;
1819
import io.micrometer.observation.ObservationRegistry;
20+
import java.util.function.Supplier;
1921

2022
/**
2123
* Builder to configure and create <a href="https://micrometer.io/docs/observation">Micrometer
@@ -35,52 +37,147 @@ public class MicrometerObservationCollectorBuilder {
3537
private DeliverObservationConvention customReceiveObservationConvention;
3638
private DeliverObservationConvention defaultReceiveObservationConvention =
3739
new DefaultReceiveObservationConvention("receive");
38-
private boolean keepObservationOpenOnBasicGet = false;
40+
private boolean keepObservationStartedOnBasicGet = false;
3941

42+
/**
43+
* Set the {@link ObservationRegistry} to use.
44+
*
45+
* @param registry the registry
46+
* @return this builder instance
47+
*/
4048
public MicrometerObservationCollectorBuilder registry(ObservationRegistry registry) {
4149
this.registry = registry;
4250
return this;
4351
}
4452

53+
/**
54+
* Custom convention for <code>basic.publish</code>.
55+
*
56+
* <p>If not null, it will override any pre-configured conventions.
57+
*
58+
* @param customPublishObservationConvention the convention
59+
* @return this builder instance
60+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
61+
* ObservationConvention, Supplier, ObservationRegistry)
62+
*/
4563
public MicrometerObservationCollectorBuilder customPublishObservationConvention(
4664
PublishObservationConvention customPublishObservationConvention) {
4765
this.customPublishObservationConvention = customPublishObservationConvention;
4866
return this;
4967
}
5068

69+
/**
70+
* Default convention for <code>basic.publish</code>.
71+
*
72+
* <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link
73+
* ObservationRegistry}.
74+
*
75+
* @param defaultPublishObservationConvention the convention
76+
* @return this builder instance
77+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
78+
* ObservationConvention, Supplier, ObservationRegistry)
79+
*/
5180
public MicrometerObservationCollectorBuilder defaultPublishObservationConvention(
5281
PublishObservationConvention defaultPublishObservationConvention) {
5382
this.defaultPublishObservationConvention = defaultPublishObservationConvention;
5483
return this;
5584
}
5685

86+
/**
87+
* Custom convention for <code>basic.deliver</code>.
88+
*
89+
* <p>If not null, it will override any pre-configured conventions.
90+
*
91+
* @param customProcessObservationConvention the convention
92+
* @return this builder instance
93+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
94+
* ObservationConvention, Supplier, ObservationRegistry)
95+
*/
5796
public MicrometerObservationCollectorBuilder customProcessObservationConvention(
58-
DeliverObservationConvention customConsumeObservationConvention) {
59-
this.customProcessObservationConvention = customConsumeObservationConvention;
97+
DeliverObservationConvention customProcessObservationConvention) {
98+
this.customProcessObservationConvention = customProcessObservationConvention;
6099
return this;
61100
}
62101

102+
/**
103+
* Default convention for <code>basic.delivery</code>.
104+
*
105+
* <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link
106+
* ObservationRegistry}.
107+
*
108+
* @param defaultProcessObservationConvention the convention
109+
* @return this builder instance
110+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
111+
* ObservationConvention, Supplier, ObservationRegistry)
112+
*/
63113
public MicrometerObservationCollectorBuilder defaultProcessObservationConvention(
64-
DeliverObservationConvention defaultConsumeObservationConvention) {
65-
this.defaultProcessObservationConvention = defaultConsumeObservationConvention;
114+
DeliverObservationConvention defaultProcessObservationConvention) {
115+
this.defaultProcessObservationConvention = defaultProcessObservationConvention;
66116
return this;
67117
}
68118

119+
/**
120+
* Custom convention for <code>basic.get</code>.
121+
*
122+
* <p>If not null, it will override any pre-configured conventions.
123+
*
124+
* @param customReceiveObservationConvention the convention
125+
* @return this builder instance
126+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
127+
* ObservationConvention, Supplier, ObservationRegistry)
128+
*/
69129
public MicrometerObservationCollectorBuilder customReceiveObservationConvention(
70130
DeliverObservationConvention customReceiveObservationConvention) {
71131
this.customReceiveObservationConvention = customReceiveObservationConvention;
72132
return this;
73133
}
74134

135+
/**
136+
* Default convention for <code>basic.get</code>.
137+
*
138+
* <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link
139+
* ObservationRegistry}.
140+
*
141+
* @param defaultReceiveObservationConvention the convention
142+
* @return this builder instance
143+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
144+
* ObservationConvention, Supplier, ObservationRegistry)
145+
*/
75146
public MicrometerObservationCollectorBuilder defaultReceiveObservationConvention(
76147
DeliverObservationConvention defaultReceiveObservationConvention) {
77148
this.defaultReceiveObservationConvention = defaultReceiveObservationConvention;
78149
return this;
79150
}
80151

81-
public MicrometerObservationCollectorBuilder keepObservationOpenOnBasicGet(
82-
boolean keepObservationOpenOnBasicGet) {
83-
this.keepObservationOpenOnBasicGet = keepObservationOpenOnBasicGet;
152+
/**
153+
* Whether to keep the <code>basic.get</code> observation started or not.
154+
*
155+
* <p>The {@link MicrometerObservationCollector} starts and stops the observation immediately
156+
* after the message reception. This way the observation can have all the context from the
157+
* received message but has a very short duration. This is the default behavior.
158+
*
159+
* <p>By setting this flag to <code>true</code> the collector does not stop the observation and
160+
* opens a scope. The processing of the message can then be included in the observation.
161+
*
162+
* <p>This is then the responsibility of the developer to retrieve the observation and stop it to
163+
* avoid memory leaks. Here is an example:
164+
*
165+
* <pre>
166+
* GetResponse response = channel.basicGet(queue, true);
167+
* // process the message...
168+
* // stop the observation
169+
* Observation.Scope scope = observationRegistry.getCurrentObservationScope();
170+
* scope.close();
171+
* scope.getCurrentObservation().stop();</pre>
172+
*
173+
* Default is false, that is stopping the observation immediately.
174+
*
175+
* @param keepObservationStartedOnBasicGet whether to keep the observation started or not
176+
* @return this builder instance
177+
*/
178+
public MicrometerObservationCollectorBuilder keepObservationStartedOnBasicGet(
179+
boolean keepObservationStartedOnBasicGet) {
180+
this.keepObservationStartedOnBasicGet = keepObservationStartedOnBasicGet;
84181
return this;
85182
}
86183

@@ -93,6 +190,6 @@ public ObservationCollector build() {
93190
this.defaultProcessObservationConvention,
94191
this.customReceiveObservationConvention,
95192
this.defaultReceiveObservationConvention,
96-
keepObservationOpenOnBasicGet);
193+
keepObservationStartedOnBasicGet);
97194
}
98195
}

src/test/java/com/rabbitmq/client/test/functional/MicrometerObservationCollectorMetrics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ private static ConnectionFactory createConnectionFactory(
5656
}
5757

5858
private static ConnectionFactory createConnectionFactory(
59-
boolean keepObservationOpenOnBasicGet, ObservationRegistry observationRegistry) {
59+
boolean keepObservationStartedOnBasicGet, ObservationRegistry observationRegistry) {
6060
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
6161
connectionFactory.setAutomaticRecoveryEnabled(true);
6262
if (observationRegistry != null) {
6363
ObservationCollector collector =
6464
new MicrometerObservationCollectorBuilder()
65-
.keepObservationOpenOnBasicGet(keepObservationOpenOnBasicGet)
65+
.keepObservationStartedOnBasicGet(keepObservationStartedOnBasicGet)
6666
.registry(observationRegistry)
6767
.build();
6868
connectionFactory.setObservationCollector(collector);

0 commit comments

Comments
 (0)