java.util.concurrent.Executor instrumentation? #1988
-
I'm using 0.13.0 beta locally with my Dropwizard 2.x service, which has asynchronous JAX-RS resources (my REST endpoints return import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/greetings/{name}")
@Produces(MediaType.TEXT_PLAIN)
public class GreetingsResource {
private final Executor threadPool;
public GreetingsResource(Executor threadPool) {
this.threadPool = threadPool;
}
@GET
public CompletableFuture<String> getGreeting(@PathParam("name") String name) {
return CompletableFuture.supplyAsync(() -> String.format("Hello, %s!", name), threadPool);
}
} The execution of the Supplier doesn't seem to be resulting in a separate Span. I see (via Honeycomb through the contrib collector) the Jetty instrumented incoming request and the JAX-RS instrumented call to GreetingsResource.getGreeting() but nothing for the Supplier run via the Executor: I didn't see any mention of instrumenting threads, Executors, ExecutorServices, etc in the project README. So I suppose it's not been implemented. It's not mentioned in the GA requirements document, either. Is this an oversight or was there an intentional decision to leave off instrumenting asynchronous activity like this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @rkennedy-mode! The javaagent should propagate the tracing context across executors / async activities, so if you make an external http/database/etc call from inside of your callback, that should get tracked correlated with the request. The problem with capturing a span on every executor execution is that can be very noisy / produce a lot of spans. If you want to capture an additional span that you think is noteworthy, I recommend using the |
Beta Was this translation helpful? Give feedback.
Hi @rkennedy-mode!
The javaagent should propagate the tracing context across executors / async activities, so if you make an external http/database/etc call from inside of your callback, that should get tracked correlated with the request.
The problem with capturing a span on every executor execution is that can be very noisy / produce a lot of spans.
If you want to capture an additional span that you think is noteworthy, I recommend using the
@WithSpan
annotation: https://github.com/open-telemetry/opentelemetry-java-instrumentation#configure-a-withspan-annotation (and also worth checking out #1945)