Spring Boot 3 Upgrade Executor context propagation sleuth to micrometer tracing

290 Views Asked by At

I am migrating my project from Spring boot version 2.7.4 to version 3.2.2. i need to use micrometer instead of sleuth how should I edit the "Executor" BEAN I mentioned below for asynchronous?
What should I use instead of LazyTraceExecutor class?

@Bean("asyncExecutor")
    public Executor getAsyncExecutor(BeanFactory beanFactory) {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setThreadNamePrefix("Async-");
        executor.setTaskDecorator(new ContextDecorator());
        executor.initialize();

        return new LazyTraceExecutor(beanFactory, executor);
    }
1

There are 1 best solutions below

2
gtiwari333 On

You don't need a substitution for LazyTraceExecutor.

The following should work fine:

@Bean
public TaskDecorator decorator() {
      return new ContextPropagatingTaskDecorator();
}

@Bean
ThreadPoolTaskExecutor executor(ThreadPoolTaskExecutorBuilder builder, TaskDecorator td) {
      return builder.threadNamePrefix("GTX-")
             .taskDecorator(td)
             .build();
}