-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Observability of @Async annotated methods does not work #29977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A small example to to reproduce the problem: https://github.com/jmecsei/micrometer-threadpool |
@bclozel this will be related to instrumenting |
This probably doesn't solve everything but this should get you a long way: ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler() {
@Nullable
ScheduledExecutorService contextScheduler;
@Override
public ScheduledExecutorService getScheduledExecutor() throws IllegalStateException {
Assert.state(this.contextScheduler != null, "ThreadPoolTaskScheduler not initialized");
return this.contextScheduler;
}
@Override
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
ExecutorService executorService = super.initializeExecutor(threadFactory, rejectedExecutionHandler);
if (executorService instanceof ScheduledExecutorService scheduledExecutorService) {
//the wrapped executor to be used in getScheduledExecutor(), which is used for actual task submission
this.contextScheduler = ContextScheduledExecutorService.wrap(scheduledExecutorService, ContextSnapshot::captureAll);
//returning the original, which will be affected to private scheduledExecutor field.
//maintains the concrete type (notably, is it a configurable pool).
return executorService;
}
throw new IllegalStateException("initializeExecutor didn't return a ScheduledExecutorService");
}
}; |
I don't think we should create dedicated observations for After chatting with @marcingrzejszczak, we agreed that context propagation should be taken care of in #29883. We'll reopen this issue if it turns out this is not enough. I'm declining this issue as a result. |
Could this be reconsidered? I recently opened #30832 that was marked as a duplicate of this one.
The way I see it, annotating some method with If some codepath is being instrumented, and somewhere along the lines it call a method that's |
So I guess this is not about creating observations but rather context propagation? We could consider this, although
I don't think this happened in the end with the implementation for the reasons listed above. Let me think about this more. |
This sounds correct as far as my expectations are concerned (ones that prompted me to open #30089). ATM I can't think of a scenario where I wouldn't want Also I should familiarize myself with the correct terminology in the whole observability area. 🙂 |
Wouldn't there be currently an option to just ask the user to wrap an executor service with Context Propagation API? |
Superseded by #31130 |
Here is an example how we can configure Spring if we want to observ the async methods:
I think this approach can not be work because, the Spring store the executor in local variable: https://github.com/spring-projects/spring-framework/blob/main/spring-context/src/m[…]ringframework/scheduling/concurrent/ThreadPoolTaskExecutor.java
Thus when we wrap the result : ContextExecutorService.wrap(executorService), the Spring uses this wrapped Executor only in shutdown() process. https://github.com/spring-projects/spring-framework/blob/main/spring-context/src/m[…]amework/scheduling/concurrent/ExecutorConfigurationSupport.java
I cc: @marcingrzejszczak according to our slack conversation
The text was updated successfully, but these errors were encountered: