java-spring-cloud
java-spring-cloud copied to clipboard
Trace context does not propagate to the callback of ThreadPoolTaskExecutor/Scheduler
TracedThreadPoolTaskExecutor tracedExecutor = new TracedThreadPoolTaskExecutor(myExecutor, GlobalTracer.get());
try (Scope scope = GlobalTracer.activateSpan(span)) {
ListenableFuture<?> future = tracedExecutor.submitListenable(() -> {
Thread.sleep(1000); // Let callback run in other thread
System.out.println(GlobalTracer.get().activeSpan()); // It's OK
});
future.addCallback(
r -> System.out.println(GlobalTracer.get().activeSpan()), // Context loss!
e -> {}
);
}
This is confusing me, the context (activeSpan) is missed in the callback while the main task can get it correctly.
@JasonMing would you like to submit a fix for https://github.com/opentracing-contrib/java-spring-cloud/blob/master/instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/async/instrument/TracedThreadPoolTaskExecutor.java#L30?
@pavolloffay I open a PR #287 , could you please review it?