Skip to content

Support for observing suspending functions with @Observed annotation #4827

@ilya40umov

Description

@ilya40umov

Problem Statement

@Observed annotation, which is powered by ObservedAspect, does not seem to be able to correctly handle suspending methods. The aspect is able to invoke the suspending call, but the newly created observation does not become "current" within the suspending method.

Rationale
The issue #4754 is covering additions to the Observation API, so that it can be used to observe a suspending block of code, however, a lot of Spring users may prefer to use the annotation @Observed instead.

Additional context

Seems like Spring Framework does support AOP on suspending code since some time ago: spring-projects/spring-framework#22462. E.g. AopUtils has additional logic for dealing with invoking a suspending function.

Also, looking at this comment has made me think that ObservedAspect could actually get a mono/flux from calling ProceedingJoinPoint.proceed() and then put the newly created observation into the Reactor context via ObservationThreadLocalAccessor.KEY.

Raised initially in issues/4754#issuecomment-1977193040 by @ArvindEnvoy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions