I have following aspect that tracks method execution time:
public Object addMetricsToReactiveMonoTimedMethod(ProceedingJoinPoint pjp, ReactiveTimed reactiveTimed) throws Throwable {
StopWatch stopWatch = new StopWatch();
Mono<?> mono = (Mono<?>) pjp.proceed();
return mono
.doOnSubscribe(subscription -> stopWatch.start())
.doFinally(signalType -> {
stopWatch.stop();
logTimer(pjp, stopWatch, reactiveTimed.name(), signalType);
});
}
Method itself looks like that:
public Mono<String> sayHi() {
return Mono.just("hi")
.subscriberContext(context -> context.put("requestId", "requestId"));
}
How can I get requestId variable from subscriber context in my aspect method? I want to use it in doFinally to know which request was profiled.