Class JmsInstrumentation

java.lang.Object
io.micrometer.jakarta9.instrument.jms.JmsInstrumentation

public abstract class JmsInstrumentation extends Object
Instrument Jakarta JMS sessions for observability.

This instrumentation proxies JMS sessions to intercept various calls and create 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 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));
 
Since:
1.12.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static jakarta.jms.Session
    instrumentSession(jakarta.jms.Session session, io.micrometer.observation.ObservationRegistry registry)
    Instrument the Session given as argument for observability and record observations using the provided Observation registry.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • instrumentSession

      public static jakarta.jms.Session instrumentSession(jakarta.jms.Session session, io.micrometer.observation.ObservationRegistry registry)
      Instrument the Session given as argument for observability and record observations using the provided Observation registry.
      Parameters:
      session - the target session to proxy for instrumentation
      registry - the Observation registry to use
      Returns:
      the instrumented session that should be used to record observations