Package io.micrometer.core.aop
Class CountedAspect
java.lang.Object
io.micrometer.core.aop.CountedAspect
@NonNullApi public class CountedAspect extends java.lang.Object
Aspect responsible for intercepting all methods annotated with the
Counted
annotation and record a few counter metrics about their execution status.- Since:
- 1.2.0
- See Also:
Counted
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringDEFAULT_EXCEPTION_TAG_VALUEjava.lang.StringRESULT_TAG_FAILURE_VALUEjava.lang.StringRESULT_TAG_SUCCESS_VALUE -
Constructor Summary
Constructors Constructor Description CountedAspect(MeterRegistry meterRegistry)Construct a new aspect with the givenmeterRegistryalong with a default tags provider.CountedAspect(MeterRegistry meterRegistry, java.util.function.Function<org.aspectj.lang.ProceedingJoinPoint,java.lang.Iterable<Tag>> tagsBasedOnJoinPoint)Constructs a new aspect with the givenmeterRegistryand tags provider function. -
Method Summary
Modifier and Type Method Description java.lang.ObjectinterceptAndRecord(org.aspectj.lang.ProceedingJoinPoint pjp, Counted counted)Intercept methods annotated with theCountedannotation and expose a few counters about their execution status.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DEFAULT_EXCEPTION_TAG_VALUE
public final java.lang.String DEFAULT_EXCEPTION_TAG_VALUE- See Also:
- Constant Field Values
-
RESULT_TAG_FAILURE_VALUE
public final java.lang.String RESULT_TAG_FAILURE_VALUE- See Also:
- Constant Field Values
-
RESULT_TAG_SUCCESS_VALUE
public final java.lang.String RESULT_TAG_SUCCESS_VALUE- See Also:
- Constant Field Values
-
-
Constructor Details
-
CountedAspect
Construct a new aspect with the givenmeterRegistryalong with a default tags provider.- Parameters:
meterRegistry- Where we're going register metrics.
-
CountedAspect
public CountedAspect(MeterRegistry meterRegistry, java.util.function.Function<org.aspectj.lang.ProceedingJoinPoint,java.lang.Iterable<Tag>> tagsBasedOnJoinPoint)Constructs a new aspect with the givenmeterRegistryand tags provider function.- Parameters:
meterRegistry- Where we're going register metrics.tagsBasedOnJoinPoint- A function to generate tags given a join point.
-
-
Method Details
-
interceptAndRecord
public java.lang.Object interceptAndRecord(org.aspectj.lang.ProceedingJoinPoint pjp, Counted counted) throws java.lang.ThrowableIntercept methods annotated with theCountedannotation and expose a few counters about their execution status. By default, this aspect records both failed and successful attempts. If theCounted.recordFailuresOnly()is set totrue, then the aspect would record only failed attempts. In case of a failure, the aspect tags the counter with the simple name of the thrown exception.When the annotated method returns a
CompletionStageor any of its subclasses, the counters will be incremented only when theCompletionStageis completed. If completed exceptionally a failure is recorded, otherwise ifCounted.recordFailuresOnly()is set tofalse, a success is recorded.- Parameters:
pjp- Encapsulates some information about the intercepted area.counted- The annotation.- Returns:
- Whatever the intercepted method returns.
- Throws:
java.lang.Throwable- When the intercepted method throws one.
-