-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Context propagation with OpenTelemetry and Smallrye context propagation #30362
Comments
/cc @FroMage (context-propagation), @Ladicek (smallrye), @brunobat (opentelemetry), @jmartisk (smallrye), @manovotn (context-propagation), @phillip-kruger (smallrye), @radcortez (opentelemetry,smallrye) |
After some debugging, it would seem that it's the VertxContext that is not correctly propagated. |
I'll have a look. |
The workaround proposed here #26353 (comment) seems to do the trick, but it doesn't cover the case where there is no vertx context (using MDCEnabledContextStorage). |
A working workaround for both VertxContext and MDCEnabledContextStorage:
I hope there is a way to do it better 😄 |
From what you describe, context propagation is working correctly, no? Context propagation only works when using Or did I perhaps misunderstand the issue? |
I am in fact using the I'm just providing a custom ExecutorService to execute the tasks. |
I don't think that is a workaround. That is probably what we need to implement between OTel and CP. We have something similar for OpenTracing: |
Nice catch, then if you agree I can open a PR with the change I proposed. |
Well, OK. So what you're doing is creating your own executor and using Your threads will not have a Vert.x context because they're not Vert.x/Quarkus threads. So if OTel stores its context in a Vert.x context then yes, this will fail. Otherwise, the shown |
I'm using a custom executor to be able to use a ForkJoinPool as threadpool, it's something we can't (or I didn't find how) customize in the ManagedExecutor. I indeed tried to only use the part dealing with the QuarkusContextStorage, but as is it only works with the MDCEnabledStorage mode, not with the vertx one. |
I think this should be enough for the OTel integration: Context current = QuarkusContextStorage.INSTANCE.current();
if (current != null) {
return () -> {
QuarkusContextStorage.INSTANCE.attach(current);
return () -> {};
};
}
return () -> () -> {}; Is there a case that this does not cover (considering your proposal)? |
Well, normally you'd also restore the previous context in the returned lambda ;) |
Yes indeed it seems to do the trick, I don't know why I didn't stick to that version earlier 🤔 |
Not sure if that is required because we just want to propagate the OTel Context to the new thread. When the context is restored, we are in the Vert.x Context, which already contains the OTel Context. Am I missing something? |
I guess it's just to stick with the ThreadContextProvider contract.
|
Looks reasonable. We want this in the OTel Extension with a build step that checks if CP propagation is available and only registers the service in that case. |
Ok I'm on it |
Great. Thanks! |
Describe the bug
Hello,
When using asynchronous code (based on CompletionStages) and context propagation, it seems that the opentelemetry context is not correctly propagated.
It's visible when using a custom ExecutorService and the ThreadContext.withContextPropagation.
When injecting the ManagedExecutor, it's working correctly.
Expected behavior
The tracing should be correctly propagated from one thread to the other.
Actual behavior
The opentelemetry information is lost when jumping to a new thread.
How to Reproduce?
I've created here a reproducer:
https://github.com/OpenGuidou/opentelemetry-propagation-reproducer
It contains one implementation with opentracing for which the context is correctly propagated, and one with opentelemetry for which it isn't.
Output of
java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Microsoft-6841604 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Microsoft-6841604 (build 17.0.5+8-LTS, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
See reproducer
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
The text was updated successfully, but these errors were encountered: