Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Observability instrumentation for Jakarta JMS #4007

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

bclozel
Copy link
Contributor

@bclozel bclozel commented Aug 2, 2023

This commit adds a new JmsInstrumentation class that instruments
an instances of a jakarta.jms.Session with the Observation API.
This proxies the MessageProducer and MessageConsumer instances
created by the session and creates dedicated observations:

  • send* method calls on MessageProducer will create "jms.message.publish"
    observations.
  • when configuring a MessageListener on MessageConsumer instances returned
    by the session, "jms.message.process" observations are created when messages
    are received and processed by the callback.

Here is how an existing JMS Session instance can be instrumented for observability:

Session original = ...
ObservationRegistry registry = ...
Session session = JmsInstrumentation.instrumentSession(original, registry);

Topic topic = session.createTopic("micrometer.test.topic");
MessageProducer producer = session.createProducer(topic);
// this operation will create a "jms.message.publish" observation
producer.send(session.createMessage("test message content"));

MessageConsumer consumer = session.createConsumer(topic);
// when a message is processed by the listener,
// a "jms.message.process" observation is created
consumer.setMessageListener(message -> consumeMessage(message));

This change does not instrument receive methods on the
MessageConsumer as there is little value here. The resulting metric
would only measure the time it takes to receive the message (i.e. not
process it) and there would be no actionable trace, as those methods
return the received Message and its processing will not happen in
scope.

@bclozel bclozel added enhancement A general enhancement module: micrometer-core An issue that is related to our core module instrumentation An issue that is related to instrumenting a component labels Aug 2, 2023
@bclozel bclozel added this to the 1.12.0-M2 milestone Aug 2, 2023
This commit adds a new `JmsInstrumentation` class that instruments
an instances of a `jakarta.jms.Session` with the Observation API.
This proxies the `MessageProducer` and `MessageConsumer` instances
created by the session and creates dedicated observations:

* `send*` method calls on `MessageProducer` will create `"jms.message.publish"`
  observations.
* when configuring a `MessageListener` on `MessageConsumer` instances returned
by the session, `"jms.message.process"` observations are created when messages
are received and processed by the callback.

Here is how an existing JMS Session instance can be instrumented for observability:

```
Session original = ...
ObservationRegistry registry = ...
Session session = JmsInstrumentation.instrumentSession(original, registry);

Topic topic = session.createTopic("micrometer.test.topic");
MessageProducer producer = session.createProducer(topic);
// this operation will create a "jms.message.publish" observation
producer.send(session.createMessage("test message content"));

MessageConsumer consumer = session.createConsumer(topic);
// when a message is processed by the listener,
// a "jms.message.process" observation is created
consumer.setMessageListener(message -> consumeMessage(message));
```

This change does not instrument `receive` methods on the
`MessageConsumer` as there is little value here. The resulting metric
would only measure the time it takes to receive the message (i.e. not
process it) and there would be no actionable trace, as those methods
return the received `Message` and its processing will not happen in
tracing scope.

Closes micrometer-metricsgh-4007
@marcingrzejszczak marcingrzejszczak merged commit eeddb72 into micrometer-metrics:main Aug 10, 2023
1 check passed
@bclozel bclozel self-assigned this Aug 13, 2023
izeye added a commit to izeye/micrometer that referenced this pull request Sep 17, 2023
@izeye izeye mentioned this pull request Sep 17, 2023
shakuzen pushed a commit that referenced this pull request Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement instrumentation An issue that is related to instrumenting a component module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants