This repository was archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
StartSpan & EndSpan from within different Threads #85
Copy link
Copy link
Open
Description
Hi,
my plan is to integrate tracing into our existing backend. All the request handling is currently accomplished by a chain of CompletionStages. My intention now was to simply hook in the tracing by wrapping the existing chains like shown below (exemplary!):
CompletableFuture.runAsync(() -> {
// tracer.startSpan("abc");
}, tracerPool)
.thenCompose(x -> {
return completionStage; // <-- stuff to measure
})
.thenApplyAsync(result -> {
// tracer.endSpan(traceContextChild);
return result;
}, tracerPool)
What might happen over here is that startSpan and endSpan get executed in different threads. But since the information about the last context is stored within a thread local variable, stopping the span will fail with the following error:
Context was not attached when detaching
java.lang.Throwable
at io.grpc.Context.detach(Context.java:353)
at com.google.cloud.trace.GrpcSpanContextHandler$GrpcSpanContextHandle.detach(GrpcSpanContextHandler.java:64)
at com.google.cloud.trace.SpanContextHandlerTracer.endSpan(SpanContextHandlerTracer.java:92)
Do I miss something?
danielcompton, FabianIB, jstjohn, jodersky, amohabir and 5 more
Metadata
Metadata
Assignees
Labels
No labels