Skip to content

Attribute non-span tail events to the current user span#6656

Merged
danlapid merged 1 commit intomainfrom
dlapid/EW-10672_spanContext
Apr 24, 2026
Merged

Attribute non-span tail events to the current user span#6656
danlapid merged 1 commit intomainfrom
dlapid/EW-10672_spanContext

Conversation

@danlapid
Copy link
Copy Markdown
Collaborator

IoContext::getInvocationSpanContext() now substitutes in the currently-active user span's spanId (from the AsyncContextFrame pushed by Tracing::enterSpan), falling back to the invocation root when none is active. Previously Log/Exception/DiagnosticChannelEvent/JsRpc Attribute tail events always reported the root spanId, even when emitted inside a ctx.tracing.enterSpan() callback.

@danlapid danlapid requested review from a team as code owners April 24, 2026 00:23
@danlapid danlapid requested review from fhanau and mar-cf April 24, 2026 00:25
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 24, 2026

UnknownError: ProviderInitError

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 24, 2026

@danlapid Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

IoContext::getInvocationSpanContext() now substitutes in the
currently-active user span's spanId (from the AsyncContextFrame pushed
by Tracing::enterSpan), falling back to the invocation root when none
is active. Previously Log/Exception/DiagnosticChannelEvent/JsRpc
Attribute tail events always reported the root spanId, even when
emitted inside a ctx.tracing.enterSpan() callback.
@danlapid danlapid force-pushed the dlapid/EW-10672_spanContext branch from dfe92a5 to a0fb590 Compare April 24, 2026 00:38
@danlapid
Copy link
Copy Markdown
Collaborator Author

/bonk review this PR

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • getInvocationSpanContext() return-type change from & to value is safe: all call-sites pass to const InvocationSpanContext& parameters. The constructed context lacks an entropy source (so newChild() would assert), but no call-site invokes newChild() on it.
  • The getCurrentUserTraceSpan() refactor correctly short-circuits when user tracing is unobserved, avoiding the AsyncContextFrame probe on the hot path when there is no tail worker.
  • SpanObserver::getSpanId() + SpanParent::getSpanId() are clean additions. Adding override to UserSpanObserver::getSpanId() is a correctness fix.
  • Test coverage is good (sync, async/await, nested, outside-span, diagnostics channel). One gap noted in an inline comment.

This review was generated by an AI code review assistant and may contain inaccuracies.

Comment thread src/workerd/io/io-context.h
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 24, 2026

Review posted on PR #6656. Summary of findings:

C++ changes (correct, safe):

  • The return-type change of getInvocationSpanContext() from & to by-value is safe — all callers pass the result by const-ref to addLog/addException/addDiagnosticChannelEvent/setJsRpcInfo.
  • The getCurrentUserTraceSpan() refactor correctly early-exits when the root user span is unobserved, avoiding unnecessary AsyncContextFrame probes when no tail worker is attached.
  • SpanObserver::getSpanId() virtual + SpanParent::getSpanId() are clean additions. The override fix on UserSpanObserver::getSpanId() is correct.

Two inline comments posted:

  1. On io-context.h:919 — suggesting a comment noting the 3-arg InvocationSpanContext constructor drops the entropy source, so newChild() must not be called on the result.
  2. On tracing-log-attribution-test.js:83 — noting that Exception tail event attribution is not tested despite being covered by the fix. Suggested adding a test case that throws inside enterSpan.

github run

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 24, 2026

Merging this PR will not alter performance

✅ 72 untouched benchmarks
⏩ 129 skipped benchmarks1


Comparing dlapid/EW-10672_spanContext (a0fb590) with main (73c75fa)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread src/workerd/io/io-context.c++
@fhanau
Copy link
Copy Markdown
Contributor

fhanau commented Apr 24, 2026

Implementation changes LGTM. The tests feel too verbose, but that's non-blocking/can be hard to avoid with LLM output

@danlapid danlapid merged commit 16ecbe5 into main Apr 24, 2026
28 of 29 checks passed
@danlapid danlapid deleted the dlapid/EW-10672_spanContext branch April 24, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants