Class LazyMetricsRecorder

java.lang.Object
com.fayupable.logged.spring.metrics.LazyMetricsRecorder
All Implemented Interfaces:
MetricsRecorder

public class LazyMetricsRecorder extends Object implements MetricsRecorder
MetricsRecorder that defers the choice between a real Micrometer-backed recorder and a no-op fallback to the first actual invocation, instead of to Spring Boot auto-configuration ordering.

Whether a MeterRegistry bean exists at a given point during context refresh depends on the order in which Spring Boot processes auto-configurations, an order this module cannot reliably pin itself against across Spring Boot versions. Resolving lazily through ObjectProvider, on the other hand, is unaffected by that ordering: by the time any @Logged method is actually invoked, the application context has fully started, and any MeterRegistry bean that is ever going to exist already does.

  • Constructor Summary

    Constructors
    Constructor
    Description
    LazyMetricsRecorder(org.springframework.beans.factory.ObjectProvider<io.micrometer.core.instrument.MeterRegistry> meterRegistryProvider)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    record(String className, String methodName, long durationNanos, boolean success, String exceptionType)
    Records the outcome and duration of a single method invocation.

    Methods inherited from class java.lang.Object

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

    • LazyMetricsRecorder

      public LazyMetricsRecorder(org.springframework.beans.factory.ObjectProvider<io.micrometer.core.instrument.MeterRegistry> meterRegistryProvider)
  • Method Details

    • record

      public void record(String className, String methodName, long durationNanos, boolean success, String exceptionType)
      Description copied from interface: MetricsRecorder
      Records the outcome and duration of a single method invocation.
      Specified by:
      record in interface MetricsRecorder
      Parameters:
      className - the simple or fully qualified name of the class declaring the invoked method
      methodName - the name of the invoked method
      durationNanos - the wall-clock duration of the invocation, in nanoseconds
      success - true if the method returned normally, false if it threw an exception
      exceptionType - the simple class name of the exception thrown by the method, or null if the call succeeded