Top Description Inners Fields Constructors Methods
io.micrometer.observation.aop

public Class ObservedAspect

extends Object
Class Inheritance
Annotations
@Aspect
@NonNullApi
Imports
io.micrometer.common.lang.NonNullApi, .Nullable, io.micrometer.observation.Observation, .ObservationRegistry, .ObservationConvention, io.micrometer.observation.annotation.Observed, org.aspectj.lang.ProceedingJoinPoint, org.aspectj.lang.annotation.Around, .Aspect, org.aspectj.lang.reflect.MethodSignature, java.lang.reflect.Method, java.util.concurrent.CompletionStage, java.util.function.Predicate

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 io.micrometer.common.KeyValues programmatically to the Observation.
In this case, the ObservationConvention can help. It receives an ObservedAspectContext that also contains the ProceedingJoinPoint and returns the io.micrometer.common.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);
}
Author
Jonatan Ivanov
Since
1.10.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final Predicate<ProceedingJoinPoint>
private final ObservationConvention<ObservedAspect.ObservedAspectContext>
private final ObservationRegistry
private final Predicate<ProceedingJoinPoint>

Constructor Summary

AccessConstructor and Description
public
public
public
public

Method Summary

Modifier and TypeMethod and Description
private Class<?>
private Method
private Object
observe(ProceedingJoinPoint pjp, Method method, Observed observed)

public Object
public Object
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DONT_SKIP_ANYTHINGback to summary
private static final Predicate<ProceedingJoinPoint> DONT_SKIP_ANYTHING
observationConventionback to summary
private final ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention
Annotations
@Nullable
registryback to summary
private final ObservationRegistry registry
shouldSkipback to summary
private final Predicate<ProceedingJoinPoint> shouldSkip

Constructor Detail

ObservedAspectback to summary
public ObservedAspect(ObservationRegistry registry)
ObservedAspectback to summary
public ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention)
ObservedAspectback to summary
public ObservedAspect(ObservationRegistry registry, Predicate<ProceedingJoinPoint> shouldSkip)
ObservedAspectback to summary
public ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.ObservedAspectContext> observationConvention, Predicate<ProceedingJoinPoint> shouldSkip)

Method Detail

getDeclaringClassback to summary
private Class<?> getDeclaringClass(ProceedingJoinPoint pjp)
getMethodback to summary
private Method getMethod(ProceedingJoinPoint pjp) throws NoSuchMethodException
observeback to summary
private Object observe(ProceedingJoinPoint pjp, Method method, Observed observed) throws Throwable
observeClassback to summary
public Object observeClass(ProceedingJoinPoint pjp) throws Throwable
Annotations
@Around:@within(io.micrometer.observation.annotation.Observed)
@Nullable
observeMethodback to summary
public Object observeMethod(ProceedingJoinPoint pjp) throws Throwable
Annotations
@Around:execution (@io.micrometer.observation.annotation.Observed * *.*(..))
@Nullable
stopObservationback to summary
private void stopObservation(Observation observation, Observation.Scope scope, Throwable error)
io.micrometer.observation.aop back to summary

public Class ObservedAspect.ObservedAspectContext

extends Context
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ProceedingJoinPoint

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ProceedingJoinPoint
Inherited from io.micrometer.observation.Observation.Context:
addHighCardinalityKeyValueaddHighCardinalityKeyValuesaddLowCardinalityKeyValueaddLowCardinalityKeyValuesclearcomputeIfAbsentcontainsKeygetgetAllKeyValuesgetContextualNamegetErrorgetHighCardinalityKeyValuegetHighCardinalityKeyValuesgetLowCardinalityKeyValuegetLowCardinalityKeyValuesgetNamegetOrDefaultgetParentObservationgetRequiredputremoveremoveHighCardinalityKeyValueremoveHighCardinalityKeyValuesremoveLowCardinalityKeyValueremoveLowCardinalityKeyValuessetContextualNamesetErrorsetNamesetParentObservationtoString

Field Detail

proceedingJoinPointback to summary
private final ProceedingJoinPoint proceedingJoinPoint

Constructor Detail

ObservedAspectContextback to summary
public ObservedAspectContext(ProceedingJoinPoint proceedingJoinPoint)

Method Detail

getProceedingJoinPointback to summary
public ProceedingJoinPoint getProceedingJoinPoint()