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,TraceableExecutorServiceandTraceableScheduledExecutorService. 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
TraceableExecutorServicewhen 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进行处理
本文探讨了Spring Cloud Sleuth的日志追踪能力及其在线程间传递的限制。通过使用LazyTraceExecutor等工具,实现任务提交时创建追踪上下文,确保了日志信息的完整性和一致性。

1470

被折叠的 条评论
为什么被折叠?



