Add asynchronous tracing for Java 8 CompletableFuture in WithSpanAdvice - #2530
Conversation
…nstrumentation into withspan-spring-async
iNikem
left a comment
There was a problem hiding this comment.
This is definitely an interesting proposal :) But it needs some documentation. E.g. package-info.java in io.opentelemetry.instrumentation.api.tracer.async.
|
Thanks for the feedback! I hope "interesting" is a good thing. 😁 |
|
I will park this for feedback again. I've moved some more of the machinery to I changed the Names and other conventions are certainly up for discussion. Thank you! |
|
Thanks @HaloFour! To be honest, I was only expecting a change in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations because I forgot about the spring aspect :) It does seem like we'd want to make something generic to apply to both, but does it make sense to first create something non-generic in just |
…nstrumentation into withspan-spring-async
|
Done and done, shifted all of the potentially sharable bits over to the otelannotations instrumentation module. I targeted the Spring version as the projects I've been working on are Spring WebFlux. I also see a |
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
…nstrumentation into withspan-spring-async
| private boolean endSynchronously( | ||
| CompletableFuture<?> future, BaseTracer tracer, Context context) { | ||
|
|
||
| if (future.isDone()) { |
There was a problem hiding this comment.
Nit: you can return early instead:
if (!future.isDone()) {
return false;
}|
LGTM 👍 |
…nstrumentation into withspan-spring-async
anuraaga
left a comment
There was a problem hiding this comment.
Sorry for delay, just a small comment but this mostly looks ready
| */ | ||
| private CompletionStage<?> endWhenComplete( | ||
| CompletionStage<?> stage, BaseTracer tracer, Context context) { | ||
| return stage.whenComplete( |
There was a problem hiding this comment.
If the stage is already complete I think this is guaranteed to be synchronous - I guess we can remove endSynchronously?
There was a problem hiding this comment.
I double checked to be sure and yes, whenComplete should always be synchronous, at least given how it's implemented in CompletableFuture<T>. Checking and completing synchronously was more about optimizing away the need for the callback and the extra allocations that requires. It's not observable, but it is cheaper/faster. But if that's not worth the complexity I can remove it.
|
I sent a PR to your PR with a couple of suggestions HaloFour#1 |
|
thanks for the new feature @HaloFour 🎉 |
|
Excellent news! Glad I could contribute. From here what might the plan be to extend this to other aspect-based instrumentation, especially Then there is expanding the list of strategies to other asynchronous types, like Reactor, RxJava, Guava, etc. I'd love to be involved with both but I can understand wanting to let this "soak in" first. |
Adds basic support for asynchronous tracing with the OTel annotation WithSpanAdvice. Only supports Java 8
CompletionStage<T>andCompletableFuture<T>but theMethodSpanStrategyinterface should be able to support most/any promise-like return types.