Skip to content

Commit 9930d87

Browse files
committed
Add observation Javadoc
1 parent 46f074d commit 9930d87

11 files changed

+186
-26
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@
401401
<groupId>org.apache.maven.plugins</groupId>
402402
<artifactId>maven-resources-plugin</artifactId>
403403
<version>${maven-resources-plugin.version}</version>
404+
<configuration>
405+
<propertiesEncoding>${project.build.sourceEncoding}</propertiesEncoding>
406+
</configuration>
404407
</plugin>
405408

406409
<plugin>

src/main/java/com/rabbitmq/stream/ObservationCollector.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
1414
package com.rabbitmq.stream;
1515

16+
/**
17+
* API to instrument operations in the stream client. The supported operations are publishing, and
18+
* asynchronous delivery.
19+
*
20+
* <p>Implementations can gather information and send it to tracing backends. This allows e.g.
21+
* following the processing steps of a given message through different systems.
22+
*
23+
* <p>This is considered an SPI and is susceptible to change at any time.
24+
*
25+
* @since 0.12.0
26+
* @see EnvironmentBuilder#observationCollector(ObservationCollector)
27+
* @see com.rabbitmq.stream.observation.micrometer.MicrometerObservationCollectorBuilder
28+
*/
1629
public interface ObservationCollector<T> {
1730

1831
ObservationCollector<Void> NO_OP =
@@ -31,12 +44,39 @@ public MessageHandler subscribe(MessageHandler handler) {
3144
}
3245
};
3346

34-
void published(T context, Message message);
35-
47+
/**
48+
* Start observation.
49+
*
50+
* <p>Implementations are expecting to return an observation context that will be passed in to the
51+
* {@link #published(Object, Message)} callback.
52+
*
53+
* @param stream the stream to publish to
54+
* @param message the message to publish
55+
* @return observation context
56+
*/
3657
T prePublish(String stream, Message message);
3758

59+
/**
60+
* Callback when the message is about to be published.
61+
*
62+
* @param context the observation context
63+
* @param message the message to publish
64+
*/
65+
void published(T context, Message message);
66+
67+
/**
68+
* Decorate consumer registration.
69+
*
70+
* @param handler the original handler
71+
* @return a decorated handler
72+
*/
3873
MessageHandler subscribe(MessageHandler handler);
3974

75+
/**
76+
* Says whether the implementation does nothing or not.
77+
*
78+
* @return true if the implementation is a no-op
79+
*/
4080
default boolean isNoop() {
4181
return this == NO_OP;
4282
}

src/main/java/com/rabbitmq/stream/observation/micrometer/DefaultProcessObservationConvention.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import com.rabbitmq.stream.observation.micrometer.StreamObservationDocumentation.LowCardinalityTags;
1919
import io.micrometer.common.KeyValues;
2020

21+
/**
22+
* Default {@link ProcessObservationConvention}.
23+
*
24+
* @since 0.12.0
25+
*/
2126
public class DefaultProcessObservationConvention implements ProcessObservationConvention {
2227

2328
private static final String OPERATION = "process";

src/main/java/com/rabbitmq/stream/observation/micrometer/DefaultPublishObservationConvention.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import com.rabbitmq.stream.observation.micrometer.StreamObservationDocumentation.LowCardinalityTags;
1919
import io.micrometer.common.KeyValues;
2020

21+
/**
22+
* Default {@link PublishObservationConvention}.
23+
*
24+
* @since 0.12.0
25+
*/
2126
public class DefaultPublishObservationConvention implements PublishObservationConvention {
2227

2328
private static final String OPERATION = "publish";

src/main/java/com/rabbitmq/stream/observation/micrometer/MicrometerObservationCollector.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@
1616
import com.rabbitmq.stream.*;
1717
import io.micrometer.observation.Observation;
1818
import io.micrometer.observation.ObservationRegistry;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
1921

22+
/**
23+
* Micrometer's {@link ObservationCollector}.
24+
*
25+
* @since 0.12.0
26+
*/
2027
class MicrometerObservationCollector implements ObservationCollector<Observation> {
2128

29+
private static final Logger LOGGER =
30+
LoggerFactory.getLogger(MicrometerObservationCollector.class);
31+
2232
private final ObservationRegistry registry;
2333
private final PublishObservationConvention customPublishConvention, defaultPublishConvention;
2434
private final ProcessObservationConvention customProcessConvention, defaultProcessConvention;
2535

26-
public MicrometerObservationCollector(
36+
MicrometerObservationCollector(
2737
ObservationRegistry registry,
2838
PublishObservationConvention customPublishConvention,
2939
PublishObservationConvention defaultPublishConvention,
@@ -41,7 +51,7 @@ public void published(Observation observation, Message message) {
4151
try {
4252
observation.stop();
4353
} catch (Exception e) {
44-
// TODO log error
54+
LOGGER.warn("Error while stopping Micrometer observation: {}", e.getMessage());
4555
}
4656
}
4757

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

Lines changed: 94 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,126 @@
1414
package com.rabbitmq.stream.observation.micrometer;
1515

1616
import com.rabbitmq.stream.ObservationCollector;
17+
import io.micrometer.observation.Observation;
18+
import io.micrometer.observation.ObservationConvention;
1719
import io.micrometer.observation.ObservationRegistry;
20+
import java.util.function.Supplier;
1821

22+
/**
23+
* Builder to configure and create <a href="https://micrometer.io/docs/observation">Micrometer
24+
* Observation</a> implementation of {@link ObservationCollector}.
25+
*
26+
* @since 0.12.0
27+
*/
1928
public class MicrometerObservationCollectorBuilder {
2029

2130
private ObservationRegistry registry = ObservationRegistry.NOOP;
22-
private PublishObservationConvention customPublishConvention;
23-
private PublishObservationConvention defaultPublishConvention =
31+
private PublishObservationConvention customPublishObservationConvention;
32+
private PublishObservationConvention defaultPublishObservationConvention =
2433
new DefaultPublishObservationConvention();
25-
private ProcessObservationConvention customProcessConvention;
26-
private ProcessObservationConvention defaultProcessConvention =
34+
private ProcessObservationConvention customProcessObservationConvention;
35+
private ProcessObservationConvention defaultProcessObservationConvention =
2736
new DefaultProcessObservationConvention();
2837

38+
/**
39+
* Set the {@link ObservationRegistry} to use.
40+
*
41+
* <p>Default is {@link ObservationRegistry#NOOP}.
42+
*
43+
* @param registry the registry
44+
* @return this builder instance
45+
*/
2946
public MicrometerObservationCollectorBuilder registry(ObservationRegistry registry) {
3047
this.registry = registry;
3148
return this;
3249
}
3350

34-
public MicrometerObservationCollectorBuilder customPublishConvention(
35-
PublishObservationConvention customPublishConvention) {
36-
this.customPublishConvention = customPublishConvention;
51+
/**
52+
* Custom convention for publishing.
53+
*
54+
* <p>If not null, it will override any pre-configured conventions.
55+
*
56+
* <p>Default is <code>null</code>.
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+
*/
63+
public MicrometerObservationCollectorBuilder customPublishObservationConvention(
64+
PublishObservationConvention customPublishObservationConvention) {
65+
this.customPublishObservationConvention = customPublishObservationConvention;
3766
return this;
3867
}
3968

40-
public MicrometerObservationCollectorBuilder defaultPublishConvention(
41-
PublishObservationConvention defaultPublishConvention) {
42-
this.defaultPublishConvention = defaultPublishConvention;
69+
/**
70+
* Default convention for publishing.
71+
*
72+
* <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link
73+
* ObservationRegistry}.
74+
*
75+
* <p>Default is {@link DefaultPublishObservationConvention}.
76+
*
77+
* @param defaultPublishObservationConvention the convention
78+
* @return this builder instance
79+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
80+
* ObservationConvention, Supplier, ObservationRegistry)
81+
*/
82+
public MicrometerObservationCollectorBuilder defaultPublishObservationConvention(
83+
PublishObservationConvention defaultPublishObservationConvention) {
84+
this.defaultPublishObservationConvention = defaultPublishObservationConvention;
4385
return this;
4486
}
4587

46-
public MicrometerObservationCollectorBuilder customProcessConvention(
47-
ProcessObservationConvention customProcessConvention) {
48-
this.customProcessConvention = customProcessConvention;
88+
/**
89+
* Custom convention for consuming.
90+
*
91+
* <p>If not null, it will override any pre-configured conventions.
92+
*
93+
* <p>Default is <code>null</code>.
94+
*
95+
* @param customProcessObservationConvention the convention
96+
* @return this builder instance
97+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
98+
* ObservationConvention, Supplier, ObservationRegistry)
99+
*/
100+
public MicrometerObservationCollectorBuilder customProcessObservationConvention(
101+
ProcessObservationConvention customProcessObservationConvention) {
102+
this.customProcessObservationConvention = customProcessObservationConvention;
49103
return this;
50104
}
51105

52-
public MicrometerObservationCollectorBuilder defaultProcessConvention(
53-
ProcessObservationConvention defaultProcessConvention) {
54-
this.defaultProcessConvention = defaultProcessConvention;
106+
/**
107+
* Default convention for consuming.
108+
*
109+
* <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link
110+
* ObservationRegistry}.
111+
*
112+
* <p>Default is {@link DefaultProcessObservationConvention}.
113+
*
114+
* @param defaultProcessObservationConvention the convention
115+
* @return this builder instance
116+
* @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention,
117+
* ObservationConvention, Supplier, ObservationRegistry)
118+
* @since 0.12.0
119+
*/
120+
public MicrometerObservationCollectorBuilder defaultProcessObservationConvention(
121+
ProcessObservationConvention defaultProcessObservationConvention) {
122+
this.defaultProcessObservationConvention = defaultProcessObservationConvention;
55123
return this;
56124
}
57125

58-
public ObservationCollector build() {
126+
/**
127+
* Create the Micrometer {@link ObservationCollector}.
128+
*
129+
* @return the Micrometer observation collector
130+
*/
131+
public ObservationCollector<Observation> build() {
59132
return new MicrometerObservationCollector(
60133
this.registry,
61-
this.customPublishConvention,
62-
this.defaultPublishConvention,
63-
this.customProcessConvention,
64-
this.defaultProcessConvention);
134+
this.customPublishObservationConvention,
135+
this.defaultPublishObservationConvention,
136+
this.customProcessObservationConvention,
137+
this.defaultProcessObservationConvention);
65138
}
66139
}

src/main/java/com/rabbitmq/stream/observation/micrometer/ProcessContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
import io.micrometer.observation.transport.ReceiverContext;
1818
import java.util.Map;
1919

20+
/**
21+
* {@link io.micrometer.observation.Observation.Context} for RabbitMQ Stream consuming.
22+
*
23+
* @since 0.12.0
24+
*/
2025
public class ProcessContext extends ReceiverContext<Message> {
2126

2227
private final String stream;

src/main/java/com/rabbitmq/stream/observation/micrometer/ProcessObservationConvention.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import io.micrometer.observation.Observation;
1717
import io.micrometer.observation.ObservationConvention;
1818

19+
/**
20+
* {@link ObservationConvention} for RabbitMQ Stream consuming.
21+
*
22+
* @since 0.12.0
23+
*/
1924
public interface ProcessObservationConvention extends ObservationConvention<ProcessContext> {
2025

2126
@Override

src/main/java/com/rabbitmq/stream/observation/micrometer/PublishContext.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
import com.rabbitmq.stream.Message;
1717
import io.micrometer.observation.transport.SenderContext;
1818

19+
/**
20+
* {@link io.micrometer.observation.Observation.Context} for RabbitMQ Stream publishing.
21+
*
22+
* @since 0.12.0
23+
*/
1924
public class PublishContext extends SenderContext<Message> {
2025

21-
// TODO need payload size
2226
private final String stream;
2327
private final int payloadSizeBytes;
2428

src/main/java/com/rabbitmq/stream/observation/micrometer/PublishObservationConvention.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import io.micrometer.observation.Observation;
1717
import io.micrometer.observation.ObservationConvention;
1818

19+
/**
20+
* {@link ObservationConvention} for RabbitMQ Stream consuming.
21+
*
22+
* @since 0.12.0
23+
*/
1924
public interface PublishObservationConvention extends ObservationConvention<PublishContext> {
2025

2126
@Override

src/main/java/com/rabbitmq/stream/observation/micrometer/StreamObservationDocumentation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import io.micrometer.observation.ObservationConvention;
1919
import io.micrometer.observation.docs.ObservationDocumentation;
2020

21+
/**
22+
* {@link ObservationDocumentation} for RabbitMQ Stream.
23+
*
24+
* @since 0.12.0
25+
*/
2126
public enum StreamObservationDocumentation implements ObservationDocumentation {
2227

2328
/** Observation for publishing a message. */

0 commit comments

Comments
 (0)