Hi, I'm not sure if this is a problem with Spring Cloud Sleuth or I'm doing something wrong.
I found that when I use Spring ThreadPoolTaskExecutor the trace id of the parent process is not been used with the asynchronous task.
I have a small example with the problem here:
https://github.com/andcuevas/spring-cloud-sleuth-thread-pool-problem
Regards,
Andres
Since ThreadPoolTaskExecutor creates a separate thread it drops the MDC variables added by Sleuth and thus you see Trace Id and Span IDs being dropped.
Try to add a Decorator Pattern on top of ThreadPoolTaskExecutor class and override the execute method.
Also the Bean where you are configuring your TaskExecutor, initialize it to the new wrapper class.
Here is a sample implementation :
I was hoping that Spring Cloud Sleuth and ThreadPoolTaskExecutor were compatible out the box since these are two tools from Spring.
It would be nice to know if a full compatibility will come in the future.
Well I hoped so too, may be that can be a question to @marcingrzejszczak However I dont see that as an issue in Sleuth but if ThreadPoolTaskExecutor can incorporate that in its library.
It should be working - currently I'm on holidays so will try to take a look at this once I'm back
Thanks. This is applicable for any multi-threaded method/class overridden. Best applicable for java 8 lambda functionality.