Class ObservedAspect

java.lang.Object
io.micrometer.observation.aop.ObservedAspect

@NonNullApi public class ObservedAspect extends Object

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