1.问题
spring cloud seluth 完成日志追踪的能力,但是seluth不支持线程之间的传递。
@PostMapping("/test/test")
public void test() {
log.info("日志追踪测试-主线程打印");
ThreadPoolUtil.mmsExecutor(()->{
log.info("子线程打印");
});
}
private static final ThreadPoolExecutor THREAD_POOL_MMS_EXECUTOR = new ThreadPoolExecutor(CPU_NUM, CPU_NUM << 1,
2, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("mms-message", false));
public static void mmsExecutor(Runnable runnable) {
THREAD_POOL_MMS_EXECUTOR.execute(runnable);
}
0 We’re providing
LazyTraceExecutor
,TraceableExecutorService
andTraceableScheduledExecutorService
. Those implementations are creating Spans each time a new task is submitted, invoked or scheduled.Here you can see an example of how to pass tracing information with
TraceableExecutorService
when working withCompletableFuture
:CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> { // perform some logic return 1_000_000L; }, new TraceableExecutorService(executorService, // 'calculateTax' explicitly names the span - this param is optional tracer, traceKeys, spanNamer, "calculateTax"))
官网给出了可以传递的方案。
2.方法
1.使用Filter进行处理