Class ObservedAspect
AspectJ aspect for intercepting types or methods annotated with
@Observed.
The aspect supports programmatic customizations through constructor-injectable custom
logic.
You might want to add KeyValues programmatically to the
Observation.
In this case, the ObservationConvention can help. It receives an
ObservedAspect.ObservedAspectContext that also contains the ProceedingJoinPoint and
returns the KeyValues that will be attached to the
Observation.
You might also want to skip the Observation creation programmatically.
One use-case can be having another component in your application that already processes
the @Observed annotation in some cases so that ObservedAspect
should not intercept these methods. E.g.: Spring Boot does this for its controllers. By
using the skip predicate (Predicate<ProceedingJoinPoint>) you can
tell the ObservedAspect when not to create an Observation.
Here's an example to disable Observation creation for Spring controllers:
@Bean
public ObservedAspect observedAspect(ObservationRegistry observationRegistry) {
return new ObservedAspect(observationRegistry, this::skipControllers);
}
private boolean skipControllers(ProceedingJoinPoint pjp) {
Class<?> targetClass = pjp.getTarget().getClass();
return targetClass.isAnnotationPresent(RestController.class) || targetClass.isAnnotationPresent(Controller.class);
}
- Since:
- 1.10.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionObservedAspect(ObservationRegistry registry) ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention) ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention, Predicate<org.aspectj.lang.ProceedingJoinPoint> shouldSkip) ObservedAspect(ObservationRegistry registry, Predicate<org.aspectj.lang.ProceedingJoinPoint> shouldSkip) -
Method Summary
Modifier and TypeMethodDescriptionobserveClass(org.aspectj.lang.ProceedingJoinPoint pjp) observeMethod(org.aspectj.lang.ProceedingJoinPoint pjp)
-
Constructor Details
-
ObservedAspect
-
ObservedAspect
public ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention) -
ObservedAspect
public ObservedAspect(ObservationRegistry registry, Predicate<org.aspectj.lang.ProceedingJoinPoint> shouldSkip) -
ObservedAspect
public ObservedAspect(ObservationRegistry registry, @Nullable ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention, Predicate<org.aspectj.lang.ProceedingJoinPoint> shouldSkip)
-
-
Method Details