@NonNullApi public class CountedAspect extends java.lang.Object
Counted
annotation and record a few counter metrics about their execution status.Counted
Modifier and Type | Field and Description |
---|---|
java.lang.String |
DEFAULT_EXCEPTION_TAG_VALUE |
java.lang.String |
RESULT_TAG_FAILURE_VALUE |
java.lang.String |
RESULT_TAG_SUCCESS_VALUE |
Constructor and Description |
---|
CountedAspect(MeterRegistry meterRegistry)
Construct a new aspect with the given
meterRegistry along 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 given
meterRegistry and tags provider function. |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
interceptAndRecord(org.aspectj.lang.ProceedingJoinPoint pjp,
Counted counted)
Intercept methods annotated with the
Counted annotation and expose a few counters about
their execution status. |
public final java.lang.String DEFAULT_EXCEPTION_TAG_VALUE
public final java.lang.String RESULT_TAG_FAILURE_VALUE
public final java.lang.String RESULT_TAG_SUCCESS_VALUE
public CountedAspect(MeterRegistry meterRegistry)
meterRegistry
along with a default
tags provider.meterRegistry
- Where we're going register metrics.public CountedAspect(MeterRegistry meterRegistry, java.util.function.Function<org.aspectj.lang.ProceedingJoinPoint,java.lang.Iterable<Tag>> tagsBasedOnJoinPoint)
meterRegistry
and tags provider function.meterRegistry
- Where we're going register metrics.tagsBasedOnJoinPoint
- A function to generate tags given a join point.public java.lang.Object interceptAndRecord(org.aspectj.lang.ProceedingJoinPoint pjp, Counted counted) throws java.lang.Throwable
Counted
annotation and expose a few counters about
their execution status. By default, this aspect records both failed and successful attempts. If the
Counted.recordFailuresOnly()
is set to true
, 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 CompletionStage
or any of its subclasses, the counters will be incremented
only when the CompletionStage
is completed. If completed exceptionally a failure is recorded, otherwise if
Counted.recordFailuresOnly()
is set to false
, a success is recorded.
pjp
- Encapsulates some information about the intercepted area.counted
- The annotation.java.lang.Throwable
- When the intercepted method throws one.