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
TraceAsyncCustomAutoConfiguration configures a BeanPostProcessor that changes the type of AsyncConfigurer beans and breaks dependency resolution #2100
Comments
Here is a workaround if you do not want to disable Sleuth for async ( spring:
autoconfigure:
exclude:
- org.springframework.cloud.sleuth.autoconfig.instrument.async.TraceAsyncCustomAutoConfiguration @EnableAsync
@Configuration
public class AsyncConfig implements AsyncConfigurer {
private final BeanFactory beanFactory;
public AsyncConfig(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
public Executor getAsyncExecutor() {
Executor executor = new ThreadPoolTaskExecutor(); // create or configure your executor
return new LazyTraceExecutor(beanFactory, executor);
}
} |
This is blocked by spring-projects/spring-framework#27953 |
Another workaround you can do without modifying any other settings is this. before @Configuration
@EnableAsync
class AsyncConfiguration : AsyncConfigurer {
override fun getAsyncExecutor(): Executor {
val executor = ThreadPoolTaskExecutor()
executor.initialize()
return executor
}
override fun getAsyncUncaughtExceptionHandler(): AsyncUncaughtExceptionHandler {
return YourCustomAsyncUncaughtExceptionHandler()
}
} after @Configuration
@EnableAsync
class AsyncConfiguration {
@Bean
fun asyncConfigurer(): AsyncConfigurer {
return object : AsyncConfigurer {
override fun getAsyncExecutor(): Executor {
val executor = ThreadPoolTaskExecutor()
executor.initialize()
return executor
}
override fun getAsyncUncaughtExceptionHandler(): AsyncUncaughtExceptionHandler {
return YourCustomAsyncUncaughtExceptionHandler()
}
}
}
} |
Do we have an fix for this issue. We are still seeing the error with Spring boot 2.6.8 and 3.1.0 version of sleuth. |
May I ask for any progresses or any better solutions? |
Adding the following configuration into the application.properties and keeping the @bean annotation above the override method getAsyncExecutor() can be a solution. My spring version is spring-boot:2.6.7 and spirng-cloud:3.1.x |
this is not working for me |
@Saljack @lette1394 The following solutions mentioned are not working for me. Here is the sample reproducible code https://github.com/maradanasai/otel-async-exper.git . Using spring boot 2.7.14 and spring cloud 2021.0.8 version with jdk 17. It is blocking migrating to latest versions. |
There's a PR open in Framework that should be fixing this (spring-projects/spring-framework#27953) you can write a comment there that you're being blocked because of this |
Since Spring Framework won't merge this PR. The only thing we can do is to document that in cases of exceptions you must
example: spring.sleuth.async.enabled=false and configuration example @Configuration
@EnableAsync
public class AsyncConfiguration implements AsyncConfigurer {
private final BeanFactory beanFactory;
public AsyncConfiguration(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
@Bean("AsyncTaskExecutor")
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.initialize();
return new LazyTraceThreadPoolTaskExecutor(beanFactory, executor);
}
} I will update the documentation |
Describe the bug
Please see spring-projects/spring-boot#29151 for details.
Sample
This zipped Maven project will reproduce the problem using Sleuth 3.0.5 without really involving Boot. Running the main method will fail:
The failure does not occur without the
TraceAsyncCustomAutoConfiguration
bean post-processor.The text was updated successfully, but these errors were encountered: