Search code examples
spring-bootjaegeropentracing

Open tracing instrumentation for ForkJoinPool.commonPool()


My application extensively uses CompletableFuture.supplyAsync(() -> someService(context, args)); & we rely on supplyAsync to use ForkJoinPool.commonPool() thread pool to get the service run in its own thread.

Is there a way to instrument someService call in open tracing without passing in a custom Executor as argument to supplyAsync() ? I'm using spring and jaeger and have the below dependency

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

Solution

  • To my knowledge, the design of ForkJoinPool.commonPool() makes it impossible to actually replace that pool programmatically with an instrumented version. So the only workaround is to do it via bytecode manipulation.

    The OpenTelemetry Java Automatic Instrumentation libraries perform a lot of magic to be able to take care of correctly propagating context through async/concurrency primitives, you may want to give them a try.