Here is what we have in a spring application, in case of it can help someone.
It uses an around
aspect to intercept the suspendable method call, wrapping it inside a Mono.using
to start and then stop the span accordingly.
For sure it's not the best regarding performances (coroutine -> mono -> coroutine), but we accept it as the tracing is really important on our side.
@EnableAspectJAutoProxy
on you main class !
Note that
joinPoint.proceed()
returns aMono
thanks to spring aop that wraps automatically coroutines to aMono
Usage example:
@CoTrace
suspend fun aTracedMethod() {
// ...
}
@CoTrace(resourceName = "here a custom resource name")
suspend fun anotherTracedMethod() {
// ...
}