Skip to content

[WIP] fix(node): Capture Prisma v5 engine spans under the SentryTracerProvider#21867

Draft
andreiborza wants to merge 1 commit into
ab/sentry-trace-provider-nodefrom
ab/sentry-trace-provider-prisma-v5
Draft

[WIP] fix(node): Capture Prisma v5 engine spans under the SentryTracerProvider#21867
andreiborza wants to merge 1 commit into
ab/sentry-trace-provider-nodefrom
ab/sentry-trace-provider-prisma-v5

Conversation

@andreiborza

Copy link
Copy Markdown
Member

Prisma v5 engine spans (prisma:engine:*, which carry the SQL db.statement) were dropped under the SentryTracerProvider, leaving only the prisma:client:* spans in the transaction. This re-enables the Prisma v5 integration test and fixes the regression.

Root cause

The v5 compatibility shim minted engine spans by hijacking the OTel SDK tracer's private _idGenerator to stamp the engine's exact span/trace ids, then relied on the SDK exporter regrouping spans by parent_span_id at flush. The SentryTracerProvider's tracer has no _idGenerator (so the shim bailed out and dropped every engine span), and it assembles transactions from the live _children tree rather than regrouping a flat list.

Fix

A bounded spanId -> Span registry. Client spans register on spanStart; each v5 engine span is created under the parent it references by id via startInactiveSpan. Because v5 dispatches engine spans detached and out of order (a child can arrive before its parent), a span whose parent isn't registered yet waits in a pending buffer until a later batch registers it. This reproduces the exporter's flat parent_span_id regrouping for the provider path, and removes the fragile _idGenerator hack.


WIP / draft: stacked on #21680 to validate on CI. To be reworked into a standalone PR against develop (the fix is provider-agnostic; the OTel SDK / openTelemetryBasicTracerProvider path still needs validating there).

Prisma v5 engine spans (`prisma:engine:*`, which carry the SQL `db.statement`)
were minted by hijacking the OTel SDK tracer's private `_idGenerator`. The
SentryTracerProvider's tracer has no `_idGenerator`, so the shim bailed and
dropped every engine span, leaving only the `prisma:client:*` spans.

Replace the hack with a span registry: client spans register by their span id
on `spanStart`, and each v5 engine span is created under the parent it
references by id via `startInactiveSpan`. Engine spans whose parent hasn't been
seen yet wait in a pending buffer until a later batch registers it, reproducing
the flat `parent_span_id` regrouping the OTel SDK exporter used to do.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f67d8bd. Configure here.

createdSpan = true;
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LRU evicts parent before resolve

Medium Severity

The global prismaSpanRegistry caps at 1000 ids and evicts least-recent entries on new registrations, but pending v5 engine spans only resolve via prismaSpanRegistry.get(parent_span_id). Under concurrent Prisma load, a client parent can be evicted after spanStart yet before createEngineSpan, so engine spans stay pending or are dropped while the parent span still exists in the trace tree.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f67d8bd. Configure here.


const span = tracer.startSpan(engineSpan.name, {
kind,
links,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pending engine spans silently dropped

Medium Severity

When pendingEngineSpans exceeds 1000, the oldest entries are removed with splice before parent resolution. Unresolved engine spans waiting on a parent id that is not registered yet are discarded with no creation attempt, so prisma:engine:* spans (including SQL db.statement) can be lost under burst or out-of-order dispatch.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f67d8bd. Configure here.

kind: engineSpan.kind === 'client' ? SPAN_KIND.CLIENT : SPAN_KIND.INTERNAL,
startTime: engineSpan.start_time,
parentSpan,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

v5 engine span links omitted

Low Severity

The previous v5 compatibility path forwarded engineSpan.links onto created spans. The registry-based startInactiveSpan path does not map or attach links, so v5 engine spans that rely on link metadata lose cross-span references compared to the prior implementation and the v6 dispatchEngineSpan helper.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f67d8bd. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.62 kB added added
@sentry/browser - with treeshaking flags 26.05 kB added added
@sentry/browser (incl. Tracing) 46.32 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48.08 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.09 kB added added
@sentry/browser (incl. Tracing, Replay) 85.56 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.16 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 90.25 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 102.92 kB added added
@sentry/browser (incl. Feedback) 44.8 kB added added
@sentry/browser (incl. sendFeedback) 32.42 kB added added
@sentry/browser (incl. FeedbackAsync) 37.55 kB added added
@sentry/browser (incl. Metrics) 28.68 kB added added
@sentry/browser (incl. Logs) 28.93 kB added added
@sentry/browser (incl. Metrics & Logs) 29.61 kB added added
@sentry/react 29.41 kB added added
@sentry/react (incl. Tracing) 48.59 kB added added
@sentry/vue 33.1 kB added added
@sentry/vue (incl. Tracing) 48.2 kB added added
@sentry/svelte 27.64 kB added added
CDN Bundle 30.03 kB added added
CDN Bundle (incl. Tracing) 48.29 kB added added
CDN Bundle (incl. Logs, Metrics) 31.59 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 49.59 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 70.79 kB added added
CDN Bundle (incl. Tracing, Replay) 85.75 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.03 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 91.56 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.82 kB added added
CDN Bundle - uncompressed 89.42 kB added added
CDN Bundle (incl. Tracing) - uncompressed 146.09 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.12 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.06 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.66 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.1 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.06 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.8 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.75 kB added added
@sentry/nextjs (client) 51.02 kB added added
@sentry/sveltekit (client) 46.72 kB added added
@sentry/core/server 78.14 kB added added
@sentry/core/browser 64.46 kB added added
@sentry/node-core 61.8 kB added added
@sentry/node 123.97 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB added added
@sentry/node/light 50.72 kB added added
@sentry/node - without tracing 74.56 kB added added
@sentry/aws-serverless 85.34 kB added added
@sentry/cloudflare (withSentry) - minified 181.55 kB added added
@sentry/cloudflare (withSentry) 449.36 kB added added

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.

1 participant