-
Notifications
You must be signed in to change notification settings - Fork 34
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
Can't get OpenTelemetry Context in different thread #76
Comments
Can you paste here a snippet with your solution? |
just put Context in httpContext and get it in SEND_REQUEST phase c.makeCurrent() will save context into VertxContextStorage @Override
public void handle(HttpContext<T> httpContext) {
try {
if (httpContext.phase() == ClientPhase.PREPARE_REQUEST) {
httpContext.set(OPEN_TELEMETRY_CONTEXT, Context.current());
}
// send phase need to use PREPARE_REQUEST phase's context
if (httpContext.phase() == ClientPhase.SEND_REQUEST
&& httpContext.get(OPEN_TELEMETRY_CONTEXT) instanceof Context c && c != Context.current()) {
httpContext.set(OPEN_TELEMETRY_SCOPE, c.makeCurrent());
}
if ((httpContext.phase() == ClientPhase.RECEIVE_RESPONSE || httpContext.phase() == ClientPhase.FAILURE)
&& httpContext.get(OPEN_TELEMETRY_SCOPE) instanceof Scope s) {
s.close();
}
httpContext.next();
} catch (Exception e) {
log.warn("switch OpenTelemetry Context fail", e);
}
} |
@semistone I can't think of anything much better than to be honest. I wonder if you have tried OTel instrumentations like this one: https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client |
I will try it later, but I guess those instrument will still rely on those Context to pass successfully. |
I tested and it work |
Thanks for sharing this information with us @semistone ! I'm closing this since we have a good workaround (thanks to you) documented here and we know using the otel instrumentation solves the problem. |
Questions
I am using vertx webclient in different thread with attach Context
when PREPARE_REQUEST and CREATE_REQUEST phase, it's still in original thread and still could get Context by
at this phase, Vertx Context still doesn't exist, so it get context current from OpenTelemetry Context
but in SEND_REQUEST phase, it switch to different thread after create connection.
and in this phase will create Vertx Context by vertx.getOrCreateContext() then call
it will try to get OpenTelemetry Context by
and at this moment, Vertx Context is empty , so it can't get OpenTelemetry Context
currently, I wrote a Handler to propagator OpenTelemetry Context to SEND_REQUEST phase, but not sure is there any other better solution?
Version
4.5.7
Context
Do you have a reproducer?
I changed unit test in vertx-opentelemetry/src/test/java/io/vertx/tracing/opentelemetry/OpenTelemetryIntegrationTest.java
Steps to reproduce
Extra
The text was updated successfully, but these errors were encountered: