Skip to content

Commit

Permalink
GH-637 - Enable TraceContext propagation across asynchronous threads.
Browse files Browse the repository at this point in the history
We're now registering a customizers for both the SimpleAsyncTaskExecutor (used for virtual threads) and the ThreadPoolTaskExecutor to register a ContextPropagatingTaskDecorator.
  • Loading branch information
odrotbohm committed May 24, 2024
1 parent 324e824 commit e1f8be0
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading;
import org.springframework.boot.autoconfigure.thread.Threading;
import org.springframework.boot.task.SimpleAsyncTaskExecutorCustomizer;
import org.springframework.boot.task.ThreadPoolTaskExecutorCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.support.ContextPropagatingTaskDecorator;
import org.springframework.modulith.observability.ModuleEventListener;
import org.springframework.modulith.observability.ModuleTracingBeanPostProcessor;
import org.springframework.modulith.runtime.ApplicationModulesRuntime;
Expand All @@ -53,6 +58,18 @@ static ModuleEventListener tracingModuleEventListener(ApplicationModulesRuntime
return new ModuleEventListener(runtime, () -> tracer.getObject());
}

@Bean
@ConditionalOnThreading(Threading.VIRTUAL)
SimpleAsyncTaskExecutorCustomizer simpleAsyncTaskExecutorCustomizer() {
return executor -> executor.setTaskDecorator(new ContextPropagatingTaskDecorator());
}

@Bean
@ConditionalOnThreading(Threading.PLATFORM)
ThreadPoolTaskExecutorCustomizer threadPoolTaskExecutorCustomizer() {
return executor -> executor.setTaskDecorator(new ContextPropagatingTaskDecorator());
}

/**
* Brave-specific auto configuration.
*
Expand Down

0 comments on commit e1f8be0

Please sign in to comment.