-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(vertx): inject context to downstream #15285
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
base: main
Are you sure you want to change the base?
Conversation
|
|
d25f1f8 to
98a5de1
Compare
|
|
||
| private static void injectContextToDownstream( | ||
| Context otelContext, HttpServerRequest serverRequest) { | ||
| TextMapSetter<HttpServerRequest> setter = |
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.
the typical pattern is injecting context using TextMapSetters is something that happens in a client as opposed to server instrumentation
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.
Not an expert on Otel, but this is what I've seen as a way to propagate context [1]. It's also the way we're doing internally in our framework. If there is a better alternative to achieve the same goal, we can certainly go for it.
[1] https://opentelemetry.io/docs/languages/java/api/#contextpropagators
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.
Usually you'd just call Context.current(). Serializing the context to context propagation headers is used for propagating context to external systems.
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.
The problem with Context.current() is the thread consistency. We have a multithreading environment and we cannot be certain that the thread that was executing the Vertx process is the same later used in the downstream process. That is the reason why we do prefer to use the context propagation via header instead.
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 you are using threads in a way where context isn't automatically propagated you could capture the value of Context.current() at a point where it is still available and pass it along manually.
Could you elaborate why you wish to add the header based propagation here instead of doing it inside your own application?
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.
Apache Camel is not a simple application. It's a large framework with the integration of many components. We don't know beforehand how the user configure their applications or if even the user is going to include telemetry or not. We found several problem due to the context propagation in async situations, reason why we are adopting the header propagation [1] which seems to fit perfectly into our design. You can consider Camel as a black box, so, we are expecting upstream traces to carry on a traceparent header when this is somehow instrumented or enabled. Camel expects any upstream to carry on that header. And same for the downstream, Camel will add always a traceparent header for any downstream process to be able to relate the trace. I understood that was the correct way to handle distributed tracing.
[1] https://github.com/apache/camel/blob/main/proposals/tracing.adoc#context-propagation
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.
@laurit FYI, I've created a reproducer in the issue linked for this PR [1] if you want to have a look.
[1] #15284 (comment)
With this PR we are propagating the
traceparentto downstream applications according to the W3C Trace Context specification. I am not sure if there is any best way to achieve that, in case, just guide me through and I'll change the code accordingly.Closes #15284