Class DefaultMeterObservationHandler

java.lang.Object
io.micrometer.core.instrument.observation.DefaultMeterObservationHandler
All Implemented Interfaces:
MeterObservationHandler<io.micrometer.observation.Observation.Context>, io.micrometer.observation.ObservationHandler<io.micrometer.observation.Observation.Context>

public class DefaultMeterObservationHandler extends Object implements MeterObservationHandler<io.micrometer.observation.Observation.Context>
Handler for Timer.Sample and Counter.

Use builder(MeterRegistry) to create an instance. The builder does not create the active observation LongTaskTimer (named <observation-name>.active); opt in to it with DefaultMeterObservationHandler.Builder.includeActiveObservationLongTaskTimer(boolean). The deprecated constructors always create it.

This class is not designed for extension. To customize behavior, implement MeterObservationHandler and delegate to an instance created by builder(MeterRegistry); every ObservationHandler lifecycle method has a no-op default, so only the methods you care about need to be delegated.

WARNING: When the active observation LongTaskTimer is included: since it needs to be created in the onStart method, it can only contain tags that are available by that time. This means that if you add a lowCardinalityKeyValue after calling start on the Observation, that KeyValue will not be translated as a Tag on the LongTaskTimer. Likewise, since the KeyValuesProvider is evaluated in the stop method of the Observation (after start), those KeyValue instances will not be used for the LongTaskTimer.

Since:
1.10.0
  • Constructor Details

    • DefaultMeterObservationHandler

      @Deprecated public DefaultMeterObservationHandler(MeterRegistry meterRegistry)
      Deprecated.
      since 1.18.0, use builder(MeterRegistry) instead. Beware that this constructor creates a LongTaskTimer named <observation-name>.active in addition to the Timer, but builder(meterRegistry).build() does not. Use builder(meterRegistry).includeActiveObservationLongTaskTimer(true).build() to keep the behavior of this constructor.
      Creates the handler with the default configuration.
      Parameters:
      meterRegistry - the MeterRegistry to use
    • DefaultMeterObservationHandler

      @Deprecated public DefaultMeterObservationHandler(MeterRegistry meterRegistry, DefaultMeterObservationHandler.IgnoredMeters... metersToIgnore)
      Deprecated.
      since 1.18.0, use builder(MeterRegistry) and DefaultMeterObservationHandler.Builder.includeActiveObservationLongTaskTimer(boolean) instead. Opting out by meter type does not scale as meters are added and cannot express a different default. new DefaultMeterObservationHandler(registry) maps to builder(registry).includeActiveObservationLongTaskTimer(true).build(), and new DefaultMeterObservationHandler(registry, IgnoredMeters.LONG_TASK_TIMER) maps to builder(registry).build().
      Creates the handler with the defined IgnoredMeters to use when the handler processes the Observations.
      Parameters:
      meterRegistry - the MeterRegistry to use
      metersToIgnore - the Meters that should not be created when Observations are handled
      Since:
      1.13.0
  • Method Details

    • builder

      public static DefaultMeterObservationHandler.Builder builder(MeterRegistry meterRegistry)
      Returns a DefaultMeterObservationHandler.Builder for a DefaultMeterObservationHandler. The returned builder does not create the active observation LongTaskTimer (named <observation-name>.active) unless DefaultMeterObservationHandler.Builder.includeActiveObservationLongTaskTimer(boolean) is set to true. This differs from the deprecated constructors, which create it unless DefaultMeterObservationHandler.IgnoredMeters.LONG_TASK_TIMER is passed.
      Parameters:
      meterRegistry - the MeterRegistry in which to register meters
      Returns:
      a new builder
      Since:
      1.18.0
    • onStart

      public void onStart(io.micrometer.observation.Observation.Context context)
      Specified by:
      onStart in interface io.micrometer.observation.ObservationHandler<io.micrometer.observation.Observation.Context>
    • onStop

      public void onStop(io.micrometer.observation.Observation.Context context)
      Specified by:
      onStop in interface io.micrometer.observation.ObservationHandler<io.micrometer.observation.Observation.Context>
    • onEvent

      public void onEvent(io.micrometer.observation.Observation.Event event, io.micrometer.observation.Observation.Context context)
      Specified by:
      onEvent in interface io.micrometer.observation.ObservationHandler<io.micrometer.observation.Observation.Context>