Class MicrometerObservationCollectorBuilder

java.lang.Object
com.rabbitmq.client.observation.micrometer.MicrometerObservationCollectorBuilder

public class MicrometerObservationCollectorBuilder extends Object
Builder to configure and create Micrometer Observation implementation of ObservationCollector.
Since:
5.19.0
  • Constructor Details

    • MicrometerObservationCollectorBuilder

      public MicrometerObservationCollectorBuilder()
  • Method Details

    • registry

      public MicrometerObservationCollectorBuilder registry(io.micrometer.observation.ObservationRegistry registry)
      Set the ObservationRegistry to use.

      Default is ObservationRegistry.NOOP.

      Parameters:
      registry - the registry
      Returns:
      this builder instance
    • customPublishObservationConvention

      public MicrometerObservationCollectorBuilder customPublishObservationConvention(PublishObservationConvention customPublishObservationConvention)
      Custom convention for basic.publish.

      If not null, it will override any pre-configured conventions.

      Default is null.

      Parameters:
      customPublishObservationConvention - the convention
      Returns:
      this builder instance
      See Also:
      • ObservationDocumentation.observation(ObservationConvention, ObservationConvention, Supplier, ObservationRegistry)
    • defaultPublishObservationConvention

      public MicrometerObservationCollectorBuilder defaultPublishObservationConvention(PublishObservationConvention defaultPublishObservationConvention)
      Default convention for basic.publish.

      It will be picked if there was neither custom convention nor a pre-configured one via ObservationRegistry.

      Default is DefaultPublishObservationConvention.

      Parameters:
      defaultPublishObservationConvention - the convention
      Returns:
      this builder instance
      See Also:
      • ObservationDocumentation.observation(ObservationConvention, ObservationConvention, Supplier, ObservationRegistry)
    • customProcessObservationConvention

      public MicrometerObservationCollectorBuilder customProcessObservationConvention(DeliverObservationConvention customProcessObservationConvention)
      Custom convention for basic.deliver.

      If not null, it will override any pre-configured conventions.

      Default is null.

      Parameters:
      customProcessObservationConvention - the convention
      Returns:
      this builder instance
      See Also:
      • ObservationDocumentation.observation(ObservationConvention, ObservationConvention, Supplier, ObservationRegistry)
    • defaultProcessObservationConvention

      public MicrometerObservationCollectorBuilder defaultProcessObservationConvention(DeliverObservationConvention defaultProcessObservationConvention)
      Default convention for basic.delivery.

      It will be picked if there was neither custom convention nor a pre-configured one via ObservationRegistry.

      Default is DefaultProcessObservationConvention("process").

      Parameters:
      defaultProcessObservationConvention - the convention
      Returns:
      this builder instance
      See Also:
      • ObservationDocumentation.observation(ObservationConvention, ObservationConvention, Supplier, ObservationRegistry)
    • customReceiveObservationConvention

      public MicrometerObservationCollectorBuilder customReceiveObservationConvention(DeliverObservationConvention customReceiveObservationConvention)
      Custom convention for basic.get.

      If not null, it will override any pre-configured conventions.

      Default is null.

      Parameters:
      customReceiveObservationConvention - the convention
      Returns:
      this builder instance
      See Also:
      • ObservationDocumentation.observation(ObservationConvention, ObservationConvention, Supplier, ObservationRegistry)
    • defaultReceiveObservationConvention

      public MicrometerObservationCollectorBuilder defaultReceiveObservationConvention(DeliverObservationConvention defaultReceiveObservationConvention)
      Default convention for basic.get.

      It will be picked if there was neither custom convention nor a pre-configured one via ObservationRegistry.

      Default is DefaultReceiveObservationConvention("receive").

      Parameters:
      defaultReceiveObservationConvention - the convention
      Returns:
      this builder instance
      See Also:
      • ObservationDocumentation.observation(ObservationConvention, ObservationConvention, Supplier, ObservationRegistry)
    • keepObservationStartedOnBasicGet

      public MicrometerObservationCollectorBuilder keepObservationStartedOnBasicGet(boolean keepObservationStartedOnBasicGet)
      Whether to keep the basic.get observation started or not.

      The MicrometerObservationCollector starts and stops the observation immediately after the message reception. This way the observation can have all the context from the received message but has a very short duration. This is the default behavior.

      By setting this flag to true the collector does not stop the observation and opens a scope. The processing of the message can then be included in the observation.

      This is then the responsibility of the developer to retrieve the observation and stop it to avoid memory leaks. Here is an example:

       GetResponse response = channel.basicGet(queue, true);
       // process the message...
       // stop the observation
       Observation.Scope scope = observationRegistry.getCurrentObservationScope();
       scope.close();
       scope.getCurrentObservation().stop();
      Default is false, that is stopping the observation immediately.
      Parameters:
      keepObservationStartedOnBasicGet - whether to keep the observation started or not
      Returns:
      this builder instance
    • build

      public ObservationCollector build()
      Create the Micrometer ObservationCollector.
      Returns:
      the Micrometer observation collector