Skip to content

Commit 884975e

Browse files
izeyebclozel
authored andcommitted
Polish JMS observation instrumentation
See gh-30335 Closes gh-31172
1 parent adb7338 commit 884975e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

framework-docs/modules/ROOT/pages/integration/observability.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ but note that `@JmsListener` annotations can refer to specific container factory
176176
In all cases, Observations are only recorded if the observation registry is configured on the container factory.
177177

178178
Similar observations are recorded with `JmsTemplate` when messages are processed by a `MessageListener`.
179-
Such listeners are set on a `MessageConsumer` within a session callback (see `JmsTemplate.execute(SessionCallback<T>)`).
179+
Such listeners are set on a `MessageConsumer` within a session callback (see `JmsTemplate.execute(SessionCallback<T>)`).
180180

181181
This observation uses the `io.micrometer.core.instrument.binder.jms.DefaultJmsProcessObservationConvention` by default, backed by the `io.micrometer.core.instrument.binder.jms.JmsProcessObservationContext`.
182182

spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ public void setAutoStartup(boolean autoStartup) {
198198
}
199199

200200
/**
201+
* Set the {@link ObservationRegistry} to be used for recording
202+
* {@link io.micrometer.core.instrument.binder.jms.JmsObservationDocumentation#JMS_MESSAGE_PROCESS JMS message processing observations}.
203+
* Defaults to no-op observations if the registry is not set.
204+
* @since 6.1
201205
* @see AbstractMessageListenerContainer#setObservationRegistry(ObservationRegistry)
202206
*/
203207
public void setObservationRegistry(ObservationRegistry observationRegistry) {

spring-jms/src/main/java/org/springframework/jms/listener/AbstractMessageListenerContainer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public ErrorHandler getErrorHandler() {
577577

578578
/**
579579
* Return the {@link ObservationRegistry} used for recording
580-
* {@link JmsObservationDocumentation#JMS_MESSAGE_PUBLISH JMS message processing observations}.
580+
* {@link JmsObservationDocumentation#JMS_MESSAGE_PROCESS JMS message processing observations}.
581581
* @since 6.1
582582
*/
583583
@Nullable
@@ -587,7 +587,7 @@ public ObservationRegistry getObservationRegistry() {
587587

588588
/**
589589
* Set the {@link ObservationRegistry} to be used for recording
590-
* {@link JmsObservationDocumentation#JMS_MESSAGE_PUBLISH JMS message processing observations}.
590+
* {@link JmsObservationDocumentation#JMS_MESSAGE_PROCESS JMS message processing observations}.
591591
* Defaults to no-op observations if the registry is not set.
592592
* @since 6.1
593593
*/
@@ -716,7 +716,7 @@ protected void doExecuteListener(Session session, Message message) throws JMSExc
716716
}
717717

718718
private Observation createObservation(Message message) {
719-
if (micrometerCorePresent) {
719+
if (micrometerCorePresent && this.observationRegistry != null) {
720720
return ObservationFactory.create(this.observationRegistry, message);
721721
}
722722
else {
@@ -995,7 +995,7 @@ private static abstract class ObservationFactory {
995995

996996
private static final JmsProcessObservationConvention DEFAULT_CONVENTION = new DefaultJmsProcessObservationConvention();
997997

998-
static Observation create(@Nullable ObservationRegistry registry, Message message) {
998+
static Observation create(ObservationRegistry registry, Message message) {
999999
return JmsObservationDocumentation.JMS_MESSAGE_PROCESS
10001000
.observation(null, DEFAULT_CONVENTION, () -> new JmsProcessObservationContext(message), registry);
10011001
}

0 commit comments

Comments
 (0)