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.s programmatically to the
Observation.
In this case, the ObservationConvention can help. It receives an
ObservedAspectContext that also contains the ProceedingJoinPoint and
returns the io.s 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);
}
| Modifier and Type | Class and Description |
|---|---|
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final Predicate | |
| private final ObservationConvention | |
| private final ObservationRegistry | |
| private final Predicate |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.
|
| public | |
| public | ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect.
|
| Modifier and Type | Method and Description |
|---|---|
| private Class | |
| private Method | |
| private Object | |
| public Object | |
| public Object | |
| private void |
| DONT_SKIP_ANYTHING | back to summary |
|---|---|
| private static final Predicate<ProceedingJoinPoint> DONT_SKIP_ANYTHING | |
| observationConvention | back to summary |
|---|---|
| private final ObservationConvention<ObservedAspect. | |
| registry | back to summary |
|---|---|
| private final ObservationRegistry registry | |
| shouldSkip | back to summary |
|---|---|
| private final Predicate<ProceedingJoinPoint> shouldSkip | |
| ObservedAspect | back to summary |
|---|---|
| public ObservedAspect(ObservationRegistry registry) | |
| ObservedAspect | back to summary |
|---|---|
| public ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect. | |
| ObservedAspect | back to summary |
|---|---|
| public ObservedAspect(ObservationRegistry registry, Predicate<ProceedingJoinPoint> shouldSkip) | |
| ObservedAspect | back to summary |
|---|---|
| public ObservedAspect(ObservationRegistry registry, ObservationConvention<ObservedAspect. | |
| getDeclaringClass | back to summary |
|---|---|
| private Class | |
| getMethod | back to summary |
|---|---|
| private Method getMethod(ProceedingJoinPoint pjp) throws NoSuchMethodException | |
| observe | back to summary |
|---|---|
| private Object observe(ProceedingJoinPoint pjp, Method method, Observed observed) throws Throwable | |
| observeClass | back to summary |
|---|---|
| public Object observeClass(ProceedingJoinPoint pjp) throws Throwable | |
| observeMethod | back to summary |
|---|---|
| public Object observeMethod(ProceedingJoinPoint pjp) throws Throwable | |
| stopObservation | back to summary |
|---|---|
| private void stopObservation(Observation observation, Observation. | |
| Modifier and Type | Field and Description |
|---|---|
| private final ProceedingJoinPoint |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public ProceedingJoinPoint |
| proceedingJoinPoint | back to summary |
|---|---|
| private final ProceedingJoinPoint proceedingJoinPoint | |
| ObservedAspectContext | back to summary |
|---|---|
| public ObservedAspectContext(ProceedingJoinPoint proceedingJoinPoint) | |
| getProceedingJoinPoint | back to summary |
|---|---|
| public ProceedingJoinPoint getProceedingJoinPoint() | |