All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rabbitmq.client.observation.micrometer.MicrometerObservationCollectorBuilder Maven / Gradle / Ivy

Go to download

The RabbitMQ Java client library allows Java applications to interface with RabbitMQ.

There is a newer version: 5.22.0
Show newest version
// Copyright (c) 2023 Broadcom. All Rights Reserved.
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2.  For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// [email protected].
package com.rabbitmq.client.observation.micrometer;

import com.rabbitmq.client.observation.ObservationCollector;
import io.micrometer.observation.ObservationConvention;
import io.micrometer.observation.ObservationRegistry;
import java.util.function.Supplier;

/**
 * Builder to configure and create Micrometer
 * Observation implementation of {@link ObservationCollector}.
 *
 * @since 5.19.0
 */
public class MicrometerObservationCollectorBuilder {

  private ObservationRegistry registry = ObservationRegistry.NOOP;
  private PublishObservationConvention customPublishObservationConvention;
  private PublishObservationConvention defaultPublishObservationConvention =
      new DefaultPublishObservationConvention();
  private DeliverObservationConvention customProcessObservationConvention;
  private DeliverObservationConvention defaultProcessObservationConvention =
      new DefaultProcessObservationConvention("process");
  private DeliverObservationConvention customReceiveObservationConvention;
  private DeliverObservationConvention defaultReceiveObservationConvention =
      new DefaultReceiveObservationConvention("receive");
  private boolean keepObservationStartedOnBasicGet = false;

  /**
   * Set the {@link ObservationRegistry} to use.
   *
   * 

Default is {@link ObservationRegistry#NOOP}. * * @param registry the registry * @return this builder instance */ public MicrometerObservationCollectorBuilder registry(ObservationRegistry registry) { this.registry = registry; return this; } /** * Custom convention for basic.publish. * *

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

Default is null. * * @param customPublishObservationConvention the convention * @return this builder instance * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, * ObservationConvention, Supplier, ObservationRegistry) */ public MicrometerObservationCollectorBuilder customPublishObservationConvention( PublishObservationConvention customPublishObservationConvention) { this.customPublishObservationConvention = customPublishObservationConvention; return this; } /** * Default convention for basic.publish. * *

It will be picked if there was neither custom convention nor a pre-configured one via {@link * ObservationRegistry}. * *

Default is {@link DefaultPublishObservationConvention}. * * @param defaultPublishObservationConvention the convention * @return this builder instance * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, * ObservationConvention, Supplier, ObservationRegistry) */ public MicrometerObservationCollectorBuilder defaultPublishObservationConvention( PublishObservationConvention defaultPublishObservationConvention) { this.defaultPublishObservationConvention = defaultPublishObservationConvention; return this; } /** * Custom convention for basic.deliver. * *

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

Default is null. * * @param customProcessObservationConvention the convention * @return this builder instance * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, * ObservationConvention, Supplier, ObservationRegistry) */ public MicrometerObservationCollectorBuilder customProcessObservationConvention( DeliverObservationConvention customProcessObservationConvention) { this.customProcessObservationConvention = customProcessObservationConvention; return this; } /** * Default convention for basic.delivery. * *

It will be picked if there was neither custom convention nor a pre-configured one via {@link * ObservationRegistry}. * *

Default is DefaultProcessObservationConvention("process"). * * @param defaultProcessObservationConvention the convention * @return this builder instance * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, * ObservationConvention, Supplier, ObservationRegistry) */ public MicrometerObservationCollectorBuilder defaultProcessObservationConvention( DeliverObservationConvention defaultProcessObservationConvention) { this.defaultProcessObservationConvention = defaultProcessObservationConvention; return this; } /** * Custom convention for basic.get. * *

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

Default is null. * * @param customReceiveObservationConvention the convention * @return this builder instance * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, * ObservationConvention, Supplier, ObservationRegistry) */ public MicrometerObservationCollectorBuilder customReceiveObservationConvention( DeliverObservationConvention customReceiveObservationConvention) { this.customReceiveObservationConvention = customReceiveObservationConvention; return this; } /** * Default convention for basic.get. * *

It will be picked if there was neither custom convention nor a pre-configured one via {@link * ObservationRegistry}. * *

Default is DefaultReceiveObservationConvention("receive"). * * @param defaultReceiveObservationConvention the convention * @return this builder instance * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, * ObservationConvention, Supplier, ObservationRegistry) */ public MicrometerObservationCollectorBuilder defaultReceiveObservationConvention( DeliverObservationConvention defaultReceiveObservationConvention) { this.defaultReceiveObservationConvention = defaultReceiveObservationConvention; return this; } /** * Whether to keep the basic.get observation started or not. * *

The {@link 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. * * @param keepObservationStartedOnBasicGet whether to keep the observation started or not * @return this builder instance */ public MicrometerObservationCollectorBuilder keepObservationStartedOnBasicGet( boolean keepObservationStartedOnBasicGet) { this.keepObservationStartedOnBasicGet = keepObservationStartedOnBasicGet; return this; } /** * Create the Micrometer {@link ObservationCollector}. * * @return the Micrometer observation collector */ public ObservationCollector build() { return new MicrometerObservationCollector( this.registry, this.customPublishObservationConvention, this.defaultPublishObservationConvention, this.customProcessObservationConvention, this.defaultProcessObservationConvention, this.customReceiveObservationConvention, this.defaultReceiveObservationConvention, keepObservationStartedOnBasicGet); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy