-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add asynchronous tracing for Java 8 CompletableFuture in WithSpanAdvice #2530
Conversation
…nstrumentation into withspan-spring-async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely an interesting proposal :) But it needs some documentation. E.g. package-info.java
in io.opentelemetry.instrumentation.api.tracer.async
.
...ain/java/io/opentelemetry/instrumentation/api/tracer/async/MethodSpanStrategyContextKey.java
Outdated
Show resolved
Hide resolved
...t/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTest.java
Outdated
Show resolved
Hide resolved
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 |
...try/javaagent/instrumentation/otelannotations/async/CompletableFutureMethodSpanStrategy.java
Outdated
Show resolved
Hide resolved
...src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java
Outdated
Show resolved
Hide resolved
...a/io/opentelemetry/javaagent/instrumentation/otelannotations/async/MethodSpanStrategies.java
Outdated
Show resolved
Hide resolved
...src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java
Outdated
Show resolved
Hide resolved
...ava/io/opentelemetry/javaagent/instrumentation/otelannotations/async/Jdk8MethodStrategy.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Mateusz Rzeszutek <[email protected]>
…nstrumentation into withspan-spring-async
private boolean endSynchronously( | ||
CompletableFuture<?> future, BaseTracer tracer, Context context) { | ||
|
||
if (future.isDone()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you can return early instead:
if (!future.isDone()) {
return false;
}
LGTM 👍 |
…nstrumentation into withspan-spring-async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎
...ava/io/opentelemetry/javaagent/instrumentation/otelannotations/async/Jdk8MethodStrategy.java
Outdated
Show resolved
Hide resolved
...ava/io/opentelemetry/javaagent/instrumentation/otelannotations/async/Jdk8MethodStrategy.java
Outdated
Show resolved
Hide resolved
...ava/io/opentelemetry/javaagent/instrumentation/otelannotations/async/Jdk8MethodStrategy.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 theMethodSpanStrategy
interface should be able to support most/any promise-like return types.