feat(server-utils): Add tracingChannel-to-span binding#21641
Draft
logaretm wants to merge 3 commits into
Draft
Conversation
Add `bindTracingChannelToSpan` to generalize Node `diagnostics_channel` TracingChannel instrumentation onto Sentry spans. It binds the active span into async context on `start` and, in the default `auto` lifecycle, ends the span on the canonical terminal event: `end` for synchronous calls (detected via presence of `result`/`error` on the context object) and `asyncEnd` for async calls, recording exceptions on `error`. Backed by a new `getTracingChannelBinding` async context strategy hook wired through core, node-core, opentelemetry, cloudflare, and deno.
8c4ca47 to
61a560f
Compare
Contributor
size-limit report 📦
|
…oSpan
`bindTracingChannelToSpan` now returns a `TracingChannelBindingHandle`
`{ channel, unbind }` instead of the channel directly. `unbind()`
unsubscribes the auto lifecycle handlers and unbinds the start store
(idempotent; a no-op when no async context binding is available), so
callers can detach a binding — useful for teardown and test isolation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This abstracts away our tracing channels consumption into a utility that:
This util can be consumed uniformly across all of our server-side runtimes, I will create a stacked PR that refactors our code to use it, showcasing Nitro, Redis, and Deno adoption of that util.
Lifecycle Management
After testing across several node releases (20 -> 26), I locked down the strategy that we can rely on to make this reliable and predictable.
startlifecycle event, this is emitted always and is reliable.errorFor capturing exceptions and setting error span status, always reliable.endis emitted:erroris present on the context object, end the span immediatly, there won’t be any async events coming up, the function threw in the sync part, so there is no async part to execute.resultis present on the context object, end the span immediately, there won’t be any async events coming up. The function returned in the sync part or is sync trace itself. UseinorhasOwnProperty, Do not useundefinedchecks as the function can return nothing.asyncStartis emitted: Do nothing, this event has no value for us.asyncEndis emitted: Just end the span.