feat: Adopt bindTracingChannelToSpan across runtimes#21642
Conversation
8c4ca47 to
61a560f
Compare
e189fda to
3f71785
Compare
size-limit report 📦
|
8ec64f0 to
7a09a2e
Compare
| expect.objectContaining({ | ||
| handled: false, | ||
| type: 'auto.http.nitro.onTraceError', | ||
| type: 'auto.diagnostic_channels.bind_span', |
There was a problem hiding this comment.
this is no good, this should be somewhat similar to what it was before 😬
There was a problem hiding this comment.
okay I can add an option for error mechanism to preserve this
2fbdda3 to
3cb7959
Compare
7a09a2e to
a11202f
Compare
3cb7959 to
e34e28a
Compare
d452bdb to
2d8060e
Compare
766b254 to
05cfa5b
Compare
08b9cbb to
c02e8e1
Compare
05cfa5b to
5208656
Compare
c02e8e1 to
738418f
Compare
68ab8c1 to
b9a3ae4
Compare
0e7b31f to
3e93527
Compare
b9a3ae4 to
757e9d1
Compare
3e93527 to
4a4adb2
Compare
757e9d1 to
103ebc0
Compare
Migrate the Nitro HTTP/storage channels and the node/deno redis diagnostics_channel subscribers off the `@sentry/opentelemetry` `tracingChannel` helper onto `bindTracingChannelToSpan` from `@sentry/server-utils`, using the `auto` lifecycle. - Add `beforeSpanEnd(span, data)` to enrich the span on the canonical terminal event (sync `end` / async `asyncEnd`) right before it ends. - Add `captureError` (default `true`) to gate exception capture; the span error status is always set. Redis opts out (`captureError: false`) since command failures are captured at the boundary that owns them. - Unify the error mechanism to `auto.diagnostic_channels.bind_span`. - Create channel spans with `startInactiveSpan`; the binding activates the span as the async context, so parenting is preserved. - node and deno redis now pass the native `node:diagnostics_channel` `tracingChannel` directly; deno's bespoke factory is removed. BREAKING: remove the `@sentry/opentelemetry/tracing-channel` subpath export (shipped in 10.58.0); use `bindTracingChannelToSpan` instead.
Addresses review nit: tighten the bare toHaveBeenCalledWith assertions to also verify the hook isn't invoked more than once. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follows the base-branch collapse of the binding API to a single bindTracingChannelToSpan. Updates the redis and Nitro consumers to the new name. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| 'db.collection.name': mountBase(data), | ||
| 'db.system.name': data.driver?.name ?? 'unknown', | ||
| }, | ||
| }, | ||
| span => span, | ||
| ); | ||
| }); | ||
|
|
||
| channel.subscribe({ | ||
| asyncEnd(data: TracingChannelContextWithSpan<TraceContext & { result?: unknown }>) { | ||
| if (data._sentrySpan && CACHE_HIT_OPERATIONS.has(operation)) { | ||
| const hit = operation === 'hasItem' ? Boolean(data.result) : isCacheHit(data.keys?.[0], data.result); | ||
| data._sentrySpan.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, hit); | ||
| } | ||
|
|
||
| data._sentrySpan?.setStatus({ code: SPAN_STATUS_OK }); | ||
| data._sentrySpan?.end(); | ||
|
|
||
| void flushIfServerless(); | ||
| }, | ||
| error(data: TracingChannelContextWithSpan<TraceContext & { error?: unknown }>) { | ||
| captureException(data.error, { | ||
| mechanism: { handled: false, type: ORIGIN }, | ||
| }); | ||
|
|
||
| data._sentrySpan?.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' }); | ||
| data._sentrySpan?.end(); | ||
|
|
||
| void flushIfServerless(); | ||
| }, | ||
| }); | ||
| { | ||
| beforeSpanEnd(span, data) { | ||
| // Auto-capture + error status is handled by the binding; only enrich the success path. | ||
| if (!('error' in data)) { | ||
| const result = (data as { result?: unknown }).result; |
There was a problem hiding this comment.
Bug: The refactoring to bindTracingChannelToSpan for storage events unintentionally changes the error mechanism type, losing the specific 'auto.cache.nitro' context.
Severity: LOW
Suggested Fix
Preserve the original error mechanism type for storage events by providing a custom captureError function when calling bindTracingChannelToSpan, similar to how HTTP events are handled. This function should return a mechanism object with the type set to 'auto.cache.nitro'. For example: captureError: () => ({ mechanism: { handled: false, type: 'auto.cache.nitro' } }).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/nitro/src/runtime/hooks/captureStorageEvents.ts#L71-L80
Potential issue: During the migration to `bindTracingChannelToSpan`, the error capturing
for storage events was changed to use the default mechanism. This results in errors
being reported with a generic mechanism type of `'auto.diagnostic_channels.bind_span'`
instead of the previous, more specific `'auto.cache.nitro'`. This is inconsistent with
the handling of HTTP events in the same file, which explicitly preserve their custom
mechanism type. This change can negatively affect error grouping and filtering in
Sentry, making it harder to track and analyze storage-related failures.
Did we get this right? 👍 / 👎 to inform future reviews.
An unset span status already serializes to 'ok' for streamed spans, so setting it explicitly on the cache success path was redundant. Also correct the stale comment: with captureError defaulting to false, the binding only sets error status; the error is captured at the request boundary, not on cache ops.
103ebc0 to
bee3c83
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bee3c83. Configure here.
| error: onTraceError, | ||
| }); | ||
| }, | ||
| ); |
There was a problem hiding this comment.
Srvx trace errors not captured
Medium Severity
The srvx.request and srvx.middleware bindings no longer pass captureError to bindTracingChannelToSpan, so tracing-channel failures only update span status. Previously both channels used onTraceError, which called captureException with mechanism auto.http.nitro.onTraceError. The h3 channel still uses that pattern after review feedback; srvx does not, so srvx trace failures may no longer produce Sentry error events with the same mechanism as before.
Reviewed by Cursor Bugbot for commit bee3c83. Configure here.


This PR adopts
bindTracingChannelToSpanutility across our packages, and drops thetracingChannelhelper we had.The
tracingChanneldrop isn't a breaking change imo, its an internal export used by us exclusively.