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).

Comment thread packages/node/src/integrations/tracing/prisma/index.ts
Comment thread packages/node/src/integrations/tracing/prisma/index.ts
Comment thread packages/node/src/integrations/tracing/prisma/index.ts
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.59 kB added added
@sentry/browser - with treeshaking flags 26.03 kB added added
@sentry/browser (incl. Tracing) 46.26 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.02 kB added added
@sentry/browser (incl. Tracing, Replay) 85.5 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.1 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 90.19 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 102.85 kB added added
@sentry/browser (incl. Feedback) 44.77 kB added added
@sentry/browser (incl. sendFeedback) 32.39 kB added added
@sentry/browser (incl. FeedbackAsync) 37.52 kB added added
@sentry/browser (incl. Metrics) 28.67 kB added added
@sentry/browser (incl. Logs) 28.91 kB added added
@sentry/browser (incl. Metrics & Logs) 29.6 kB added added
@sentry/react 29.38 kB added added
@sentry/react (incl. Tracing) 48.53 kB added added
@sentry/vue 33.03 kB added added
@sentry/vue (incl. Tracing) 48.12 kB added added
@sentry/svelte 27.61 kB added added
CDN Bundle 30 kB added added
CDN Bundle (incl. Tracing) 48.22 kB added added
CDN Bundle (incl. Logs, Metrics) 31.57 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 49.52 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 70.77 kB added added
CDN Bundle (incl. Tracing, Replay) 85.7 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.97 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 91.5 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.74 kB added added
CDN Bundle - uncompressed 89.35 kB added added
CDN Bundle (incl. Tracing) - uncompressed 145.93 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.05 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.9 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.59 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.94 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.9 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.64 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.59 kB added added
@sentry/nextjs (client) 50.96 kB added added
@sentry/sveltekit (client) 46.66 kB added added
@sentry/core/server 78.28 kB added added
@sentry/core/browser 64.61 kB added added
@sentry/node-core 63.15 kB added added
@sentry/node 122.68 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB added added
@sentry/node/light 50.69 kB added added
@sentry/node - without tracing 74.19 kB added added
@sentry/aws-serverless 84.97 kB added added
@sentry/cloudflare (withSentry) - minified 181.52 kB added added
@sentry/cloudflare (withSentry) 449.22 kB added added

@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from ab6fac9 to db893dc Compare July 1, 2026 11:46
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from f67d8bd to ddfd706 Compare July 1, 2026 11:46
Comment thread packages/node/src/integrations/tracing/prisma/index.ts
Comment thread packages/node/src/integrations/tracing/prisma/index.ts
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from db893dc to e7deffe Compare July 1, 2026 12:05
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from ddfd706 to 6f37f91 Compare July 1, 2026 12:05
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from e7deffe to c2ffa6d Compare July 1, 2026 12:43
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch 2 times, most recently from 34472ac to 00bddb6 Compare July 1, 2026 13:51
Comment thread packages/node/src/integrations/tracing/prisma/index.ts
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from aab7745 to d506cee Compare July 1, 2026 14:02
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch 2 times, most recently from c635e74 to bbac34a Compare July 1, 2026 18:07
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch 2 times, most recently from f553a31 to 83debe2 Compare July 1, 2026 18:41
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from bbac34a to 78daa6e Compare July 1, 2026 18:45
Comment thread packages/core/src/tracing/deferSegmentSpanCapture.ts
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from 78daa6e to 55b71c3 Compare July 1, 2026 20:40
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from 83debe2 to be9048a Compare July 1, 2026 20:40

@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 1 potential issue.

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 55b71c3. Configure here.

Comment thread packages/node/src/integrations/tracing/prisma/index.ts
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from 55b71c3 to 053dbdf Compare July 1, 2026 22:05
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from be9048a to 134ffbc Compare July 1, 2026 22:05
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from 053dbdf to 1818744 Compare July 1, 2026 22:32
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch 2 times, most recently from a9b926a to cdede48 Compare July 1, 2026 23:09
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from 1818744 to 4ac0a46 Compare July 1, 2026 23:09
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>
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-prisma-v5 branch from 4ac0a46 to 9e9591e Compare July 2, 2026 08:00
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