Class MicrometerMetricsRecorder
java.lang.Object
com.fayupable.logged.spring.metrics.MicrometerMetricsRecorder
- All Implemented Interfaces:
MetricsRecorder
MetricsRecorder implementation backed by Micrometer.
Every invocation is recorded against three meters:
method.invocations: a counter tagged withclass,method, andoutcome(successorerror), tracking how many times a method was called.method.duration: a timer tagged withclassandmethod, tracking how long calls took, with a percentile histogram published for latency dashboards.method.errors: a counter tagged withclass,method, andexception, registered only when an invocation fails, tracking which exceptions occur and how often.
All tags are bounded to a small, fixed set of low-cardinality values derived from the invoked method itself. Method arguments and return values are never used as tags, since they could otherwise produce an unbounded number of time series and degrade the metrics backend.
Meters are looked up once per distinct tag combination and cached
afterward. MeterRegistry's own register call is not
prohibitively expensive, but it still allocates a Meter.Id and
performs a map lookup on every call; caching avoids repeating that work
on every single invocation of a hot @Logged method.
-
Constructor Summary
ConstructorsConstructorDescriptionMicrometerMetricsRecorder(io.micrometer.core.instrument.MeterRegistry meterRegistry) -
Method Summary
-
Constructor Details
-
MicrometerMetricsRecorder
public MicrometerMetricsRecorder(io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
-
Method Details
-
record
public void record(String className, String methodName, long durationNanos, boolean success, String exceptionType) Records the given invocation against the invocation counter, the duration timer, and, if the call failed, the error counter.- 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
-