[improvement] Add AsyncTracer that tracks enqueued-time and run-time of a deferred action - #117
Conversation
|
Why is it important that we can start a span, then complete it on multiple threads? tracing-java makes assumptions about threads that become foot-guns when applied to asynchronous usage. It might be time for a v2 API. |
|
Yeah, we're explicitly interested in tracing async things (eg: how long tasks spend in queues or waiting for their client side limiters) |
|
Can we produce a new function for this case with fewer sharp edges? I'm worried about queueing multiple operations, and having them all complete copies of the same span. We need some way to enforce the concept of span ownership. |
|
Yes, that was a bug and a foot-gun. Perhaps this behavior should live in a separate |
| private final Trace deferredTrace; | ||
| private final String operation; | ||
| @Nullable | ||
| private final String parentSpanId; |
There was a problem hiding this comment.
If we go with this approach it will require a serialVersionUID bump
| this.parentSpanId = null; | ||
| this.operation = null; | ||
| } | ||
| this.operation = operation.orElse(DEFAULT_OPERATION); |
There was a problem hiding this comment.
Forwarding @dfox's comment about the default operation name: #110 (comment)
|
Rough notes on the detached span idea so I remember later: /* Does not modify thread state, the current span is used as detached spans parent
* if it exists, otherwise a detached span is created with a new trace that has no
* thread state. */
DetachedSpan detached = Tracer.startDetachedSpan("operation")interface DetachedSpan {
/* Executes the Runnable with tracing state applied. */
void run(String operation, Runnable runnable)
/* Executes the Callable with tracing state applied. */
<T> T call(String operation, Callable<T> callable)
/* Complete this span */
void close();
} |
442b77b to
81b71d7
Compare
|
Thanks @robert3005 👍 |
| private final Trace deferredTrace; | ||
| private final String operation; | ||
|
|
||
| public AsyncTracer() { |
There was a problem hiding this comment.
Given that this is a new class, we should have made the operation required.
Before this PR
DeferredTracer only preserves traceid and last span id
After this PR
Add AsyncTracer that preserves full span stack of parent trace
cc @ellisjoe