首页 > 解决方案 > 为 ForkJoinPool.commonPool() 打开跟踪工具

问题描述

我的应用程序广泛使用CompletableFuture.supplyAsync(() -> someService(context, args));& 我们依靠 supplyAsync 使用ForkJoinPool.commonPool()线程池来让服务在自己的线程中运行。

有没有办法在开放跟踪中检测 someService 调用而不将自定义Executor作为参数传递给 supplyAsync() ?我正在使用 spring 和 jaeger 并具有以下依赖项

        <dependency>
            <groupId>io.opentracing.contrib</groupId>
            <artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
            <version>3.2.2</version>
        </dependency>       

标签: spring-bootjaegeropentracing

解决方案


据我所知, 的设计ForkJoinPool.commonPool()使得不可能以编程方式用检测版本实际替换该池。所以唯一的解决方法是通过字节码操作来做到这一点。

OpenTelemetry Java Automatic Instrumentation库执行了很多魔法,能够通过异步/并发原语正确地传播上下文,您可能想尝试一下。


推荐阅读