Class LazyMetricsRecorder
- All Implemented Interfaces:
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 in the common case: by the time any @Logged method is
actually invoked, the application context has usually fully started, and
any MeterRegistry bean that is ever going to exist already does.
That said, a @Logged method can still be invoked earlier than
that — for example from another bean's @PostConstruct — before a
MeterRegistry bean has been created. Only the found
outcome is cached in delegate: if no MeterRegistry is
available yet, this class deliberately does not pin itself to
NoOpMetricsRecorder forever, and instead checks again on every
subsequent call until one is found. Caching a negative result here would
silently and permanently disable metrics for the rest of the
application's lifetime the moment this class lost that one-time race,
which is a far worse failure mode than re-checking an already-cheap
ObjectProvider.getIfAvailable() call a few extra times early in
the application's startup.
-
Constructor Summary
ConstructorsConstructorDescriptionLazyMetricsRecorder(org.springframework.beans.factory.ObjectProvider<io.micrometer.core.instrument.MeterRegistry> meterRegistryProvider) -
Method Summary
-
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:MetricsRecorderRecords the outcome and duration of a single method invocation.- Specified by:
recordin interfaceMetricsRecorder- Parameters:
className- the simple or fully qualified name of the class declaring the invoked methodmethodName- the name of the invoked methoddurationNanos- the wall-clock duration of the invocation, in nanosecondssuccess-trueif the method returned normally,falseif it threw an exceptionexceptionType- the simple class name of the exception thrown by the method, ornullif the call succeeded
-