Skip to content

ref(node): Streamline Prisma v5 instrumentation - #21980

Merged
andreiborza merged 4 commits into
developfrom
ab/streamline-prisma-v5
Jul 6, 2026
Merged

ref(node): Streamline Prisma v5 instrumentation#21980
andreiborza merged 4 commits into
developfrom
ab/streamline-prisma-v5

Conversation

@andreiborza

@andreiborzaandreiborza commented Jul 6, 2026

Copy link
Copy Markdown
Member

Reworks the Prisma v5 engine-span compatibility shim off the OTel SDK tracer's private _idGenerator and onto Sentry's provider-agnostic span APIs. This is the v5 counterpart of #21819 (which streamlined v6/v7).

Engine spans are now minted via startInactiveSpan, reparented by id through a bounded LRUMap registry plus a pendingEngineSpans buffer that resolves spans Prisma dispatches out of order across batches. The v5 integration test is re-enabled and a BasicTracerProvider variant is added, so v5 is verified under both the default SentryTracerProvider and the opt-in OTel BasicTracerProvider (openTelemetryBasicTracerProvider: true).

Root cause: The SentryTracerProvider became the default tracer provider. Its SentryTracer creates native Sentry spans and has no _idGenerator, so the v5 shim (which hijacked that private field to mint spans with the engine's exact ids) hit its guard, warned, and dropped every prisma:engine:* span, leaving only the prisma:client:* spans.

Closes: #21821

Reworks the Prisma v5 engine-span compatibility shim off the OTel SDK
tracer's private `_idGenerator` and onto Sentry's provider-agnostic span
APIs, the v5 counterpart of #21819 (v6/v7).
The `SentryTracerProvider` is now the default tracer provider. Its
`SentryTracer` creates native Sentry spans and has no `_idGenerator`, so
the v5 shim bailed and dropped every `prisma:engine:*` span, leaving only
the `prisma:client:*` spans. Engine spans are now minted via
`startInactiveSpan`, reparented by id through a bounded registry plus a
pending buffer that resolves spans Prisma dispatches out of order across
batches. This works under both the default `SentryTracerProvider` and the
opt-in OTel `BasicTracerProvider`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andreiborza
andreiborza requested a review from a team as a code ownerJuly 6, 2026 11:56
@andreiborza
andreiborza requested review from JPeer264 and mydea and removed request for a team, JPeer264 and mydeaJuly 6, 2026 11:56
Comment threadpackages/node/src/integrations/tracing/prisma/index.ts
@github-actions

github-actionsBot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser27.59 kB--
@sentry/browser - with treeshaking flags26.03 kB--
@sentry/browser (incl. Tracing)46.24 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.01 kB--
@sentry/browser (incl. Tracing, Profiling)51.01 kB--
@sentry/browser (incl. Tracing, Replay)85.49 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags75.1 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)90.19 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)102.84 kB--
@sentry/browser (incl. Feedback)44.76 kB--
@sentry/browser (incl. sendFeedback)32.38 kB--
@sentry/browser (incl. FeedbackAsync)37.51 kB--
@sentry/browser (incl. Metrics)28.67 kB--
@sentry/browser (incl. Logs)28.91 kB--
@sentry/browser (incl. Metrics & Logs)29.59 kB--
@sentry/react29.38 kB--
@sentry/react (incl. Tracing)48.51 kB--
@sentry/vue33.03 kB--
@sentry/vue (incl. Tracing)48.11 kB--
@sentry/svelte27.61 kB--
CDN Bundle30 kB--
CDN Bundle (incl. Tracing)48.24 kB--
CDN Bundle (incl. Logs, Metrics)31.57 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)49.54 kB--
CDN Bundle (incl. Replay, Logs, Metrics)70.77 kB--
CDN Bundle (incl. Tracing, Replay)85.7 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)87 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)91.49 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)92.78 kB--
CDN Bundle - uncompressed89.35 kB--
CDN Bundle (incl. Tracing) - uncompressed145.96 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed94.05 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed149.93 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed218.59 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed264.97 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed268.93 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed278.68 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed282.62 kB--
@sentry/nextjs (client)50.95 kB--
@sentry/sveltekit (client)46.65 kB--
@sentry/core/server78.38 kB--
@sentry/core/browser64.73 kB--
@sentry/node-core63.2 kB--
@sentry/node123.19 kB-0.02%-16 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection)69.95 kB--
@sentry/node/light50.72 kB--
@sentry/node - without tracing74.24 kB-0.01%-1 B 🔽
@sentry/aws-serverless85.02 kB-0.01%-1 B 🔽
@sentry/cloudflare (withSentry) - minified181.68 kB--
@sentry/cloudflare (withSentry)449.39 kB--

View base workflow run

@andreiborza

Copy link
Copy Markdown
MemberAuthor

bugbot run

Comment threadpackages/node/src/integrations/tracing/prisma/index.ts
Comment threadpackages/node/src/integrations/tracing/prisma/index.ts
Comment threadpackages/node/src/integrations/tracing/prisma/index.ts
Comment threadpackages/node/src/integrations/tracing/prisma/index.ts Outdated
Comment on lines -113 to -121
const links: Link[] | undefined = engineSpan.links?.map(link => {
return {
context: {
traceId: link.trace_id,
spanId: link.span_id,
traceFlags: TraceFlags.SAMPLED,
},
};
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's probably more complicated to still add the links - but they are dropped in the new version, am I seeing this correctly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

edit: I see they are already added

Comment on lines +88 to +91
const parentSpan = prismaSpanRegistry.get(engineSpan.parent_span_id);
if (!parentSpan) {
continue;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Q: Could it be a problem that spans without parent spans are kept in the prismaSpanRegistry?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Should not, at most we keep 1000 spans around in memory but that has already been the case before too. I think for the streamlining effort this fine and we could consider improving this if it's an actual problem. It's unlikely that we end up with spans without parent spans here, but if this will be an issue we can look at evicting this automatically or something like that.

Comment threadpackages/node/src/integrations/tracing/prisma/index.ts
@andreiborza

Copy link
Copy Markdown
MemberAuthor

bugbot run

@cursorcursorBot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 66be130. Configure here.

@andreiborza
andreiborza requested a review from s1gr1dJuly 6, 2026 14:20
@andreiborza
andreiborza merged commit 9cec6ed into developJul 6, 2026
242 checks passed
@andreiborza
andreiborza deleted the ab/streamline-prisma-v5 branch July 6, 2026 19:24
Sign up for freeto 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.

Streamline @prisma/instrumentation for v5

3 participants

@andreiborza@mydea@s1gr1d