WO-1582 Add tracing getActiveSpan - #7111
Conversation
| } | ||
|
|
||
| auto& ioContext = IoContext::current(); | ||
| auto context = ioContext.getInvocationSpanContext(); |
There was a problem hiding this comment.
[P1] Preserve the request that owns a cached invocation span
An async frame from Durable Object request A can resume after request B has been delivered, making B incomingRequests.front() (see IoContext::IncomingRequest::delivered()). The frame still contains A’s user SpanParent, but these values are read from the current IoContext, so the cached wrapper combines A’s parent with B’s tracer and trace/invocation IDs. setAttribute() then emits A’s attribute into B’s tail trace. Store the originating tracer and InvocationSpanContext with the user-trace async-context holder when it is created, and construct the cached InvocationSpanState from that captured origin rather than IoContext::getCurrent*(); add an overlapping-DO-request regression test.
|
I'm Bonk, and I've done a quick review of your PR. Adds
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## jmorrell/refactor-spans #7111 +/- ##
===========================================================
- Coverage 67.95% 67.90% -0.05%
===========================================================
Files 465 465
Lines 130753 130877 +124
Branches 21389 21411 +22
===========================================================
+ Hits 88847 88871 +24
- Misses 28934 29033 +99
- Partials 12972 12973 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ca17ac6 to
a2aa06b
Compare
165a055 to
73eb9f4
Compare
Add an internal WorkerTracer entry point that accepts an explicit timestamp. This allows process-sandbox tracing to preserve the timestamp from the sandbox, where the request's IoContext is available.
Builds on top of #7093
Adds
tracing.getActiveSpan()getActiveSpan()returns the active user-created span when one exists.undefinedoutside an invocation or in an async context detached from the invocation.end()on an invocation span is a no-op because the platform owns its lifecycle.When you create your own spans, you get a reference to a
spanthat you can add attributes to, but there is currently no way of getting a reference to this span if you are never passed it. This is important for middlewares, instrumentation, etc.Additionally, we've had no way to get a reference to the root invocation span. This is where all of the interesting data lives! Extending the attributes of this invocation span is an o11y best practice (IMO)..
Things like:
/user/:idWe currently have no internal
spanobject that represents this invocation span. This addsInvocationSpanStateto fill that role.This should work exactly as a normal span except that it should treat
span.end()as a no-op, since that lifecycle is owned by the platform. There is some precedent for this in theNonRecordingSpanin the otel-sdk.There were some tricky bits for overlapping Durable Object requests. They share an
IoContext: a continuation from request A must not emit attributes through request B’s tracer after B becomes the current request.