Fix double accounting of JMS process observations

Prior to this commit, the instrumentation of the processing of JMS
messages would happen a different levels of the hierarchy, accounting
for alli known implementations, `SimpleMessageListenerContainer` and
`DefaultMessageListenerContainer` as well as various use cases and
`MessageListener` variants.

Unfortunately, this instrumentation could lead to observing JMS
processing twice in some cases, and would not be consistent about the
scope of what's observed.

This commit moves the instrumentation basics into the
`AbstractMessageListenerContainer` but leaves the actual observation
calls to the public implementations.

Fixes gh-33758
This commit is contained in:
Brian Clozel
2024-10-21 16:09:58 +02:00
parent e90a2da05d
commit 84e762b470
3 changed files with 17 additions and 17 deletions

View File

@@ -75,7 +75,8 @@ class MessageListenerContainerObservationTests {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.convertAndSend("spring.test.observation", "message content");
latch.await(2, TimeUnit.SECONDS);
assertThat(registry).hasObservationWithNameEqualTo("jms.message.process")
assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.process", 1)
.hasObservationWithNameEqualTo("jms.message.process")
.that()
.hasHighCardinalityKeyValue("messaging.destination.name", "spring.test.observation");
assertThat(registry).hasNumberOfObservationsEqualTo(1);
@@ -86,7 +87,6 @@ class MessageListenerContainerObservationTests {
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("listenerContainers")
void shouldRecordJmsPublishObservations(AbstractMessageListenerContainer listenerContainer) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
listenerContainer.setConnectionFactory(connectionFactory);
listenerContainer.setObservationRegistry(registry);
listenerContainer.setDestinationName("spring.test.observation");
@@ -100,8 +100,7 @@ class MessageListenerContainerObservationTests {
TextMessage response = (TextMessage) jmsTemplate.sendAndReceive("spring.test.observation",
session -> session.createTextMessage("test request"));
// request received by listener and response received by template
assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.process", 2);
assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.process", 1);
// response sent to the template
assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.publish", 1);