-
Notifications
You must be signed in to change notification settings - Fork 47
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
suboptimal behavior of @Traced when applied to methods that don't finish synchronously #189
Comments
@Ladicek I am not sure if I fully understand you. Could you please provide a code snipped and mark where changes to span will be lost? I think a new scope should be created when the execution is dispatched to the new thread. I am not sure how exactly |
I don't know about servlet, that's not part of MicroProfile :-) But with JAX-RS, if the resource method returns For example: @ApplicationScoped
public class HelloService {
@Inject
ManagedExecutor executor; // MP Context Propagation
@Inject
Tracer tracer;
@Traced
public CompletionStage<String> get(String name) {
tracer.activeSpan().log("HelloService called");
return executor.supplyAsync(() -> {
tracer.activeSpan().log("HelloService async processing");
return "Hello, " + name + "!";
});
}
}
@Path("/hello")
public class HelloResource {
@Inject
HelloService hello;
@GET
public CompletionStage<String> hello() {
return hello.get("World");
}
} Here, the Again, I realize this is how it's supposed to work (as |
It doesn't have to be servlet it can be any underlying technology that is running JAX-RS. E.g. SmallRye-OpenTracing uses servlet filter by to finish spans bc jax-rs response filter is not invoked in case of exceptions... Thanks for the great explanation. The problem like this could be solved by using a reference counting on number of created OpenTracing The other solution might be to create a new span for the execution of the callback:
|
There's a couple of "context propagation" issues in this issue tracker already, but I think this deserves its own :-)
Say I have a CDI bean with a
@Traced
method, which returns aCompletionStage
. This can be for example:@Asynchronous
and therefore is executed on an extra threadManagedExecutor
to defer execution of some part of the methodSuch method can be called for example from a JAX-RS endpoint, where the method also returns
CompletionStage
(this is standard since JAX-RS 2.1).In such case, whatever is done to the span asynchronously (after the
@Traced
method returns) may be lost, and that is even if I hack together OpenTracing context propagation (which we've done in SmallRye Fault Tolerance). This is because the@Traced
interceptor closes the scope synchronously. That's of course a correct/specified behavior, but I think it's also rather suboptimal.We should find a way how to make these scenarios work. Integrating with Context Propagation is necessary, but not enough.
The text was updated successfully, but these errors were encountered: