Skip to content

ref(server-utils): Move prisma instrumentation to server-utils - #22222

Merged
mydea merged 2 commits into
developfrom
fn/prisma-no-otel
Jul 13, 2026
Merged

ref(server-utils): Move prisma instrumentation to server-utils#22222
mydea merged 2 commits into
developfrom
fn/prisma-no-otel

Conversation

@mydea

Copy link
Copy Markdown
Member

This moves the prisma instrumentation code out of node into server-utils package, and reexports this as-is.
This can likely also be used in all other runtimes.

It also removes any otel dependencies, which were not even needed anymore - this does not do any monkey patching, but simply sets up a global tracing helper which prisma internally uses if found. This also allowed us to streamline the code a bit to properly handle v5-v7 compatibility in a single place.

Closes#20768

@mydeamydea self-assigned this Jul 13, 2026
@github-actions

github-actionsBot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser27.6 kB--
@sentry/browser - with treeshaking flags26.04 kB--
@sentry/browser (incl. Tracing)46.35 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.14 kB--
@sentry/browser (incl. Tracing, Profiling)51.13 kB--
@sentry/browser (incl. Tracing, Replay)85.62 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags75.26 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)90.33 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)102.99 kB--
@sentry/browser (incl. Feedback)44.78 kB--
@sentry/browser (incl. sendFeedback)32.4 kB--
@sentry/browser (incl. FeedbackAsync)37.53 kB--
@sentry/browser (incl. Metrics)28.68 kB--
@sentry/browser (incl. Logs)28.93 kB--
@sentry/browser (incl. Metrics & Logs)29.61 kB--
@sentry/react29.39 kB--
@sentry/react (incl. Tracing)48.62 kB--
@sentry/vue33.03 kB--
@sentry/vue (incl. Tracing)48.33 kB--
@sentry/svelte27.63 kB--
CDN Bundle30 kB--
CDN Bundle (incl. Tracing)48.33 kB--
CDN Bundle (incl. Logs, Metrics)31.58 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)49.65 kB--
CDN Bundle (incl. Replay, Logs, Metrics)70.82 kB--
CDN Bundle (incl. Tracing, Replay)85.84 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)87.16 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)91.64 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)92.92 kB--
CDN Bundle - uncompressed89.33 kB--
CDN Bundle (incl. Tracing) - uncompressed146.07 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed94.03 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed150.05 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed218.76 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed265.28 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed269.24 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed278.98 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed282.93 kB--
@sentry/nextjs (client)51.17 kB--
@sentry/sveltekit (client)46.8 kB--
@sentry/core/server78.42 kB--
@sentry/core/browser64.77 kB--
@sentry/node-core62.73 kB--
@sentry/node125.03 kB-0.26%-317 B 🔽
@sentry/node (incl. diagnostics channel injection)139.33 kB-0.23%-309 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection)69.96 kB--
@sentry/node/light50.73 kB+0.01%+1 B 🔺
@sentry/node - without tracing74.04 kB+0.01%+3 B 🔺
@sentry/aws-serverless83.26 kB+0.01%+1 B 🔺
@sentry/cloudflare (withSentry) - minified181.58 kB--
@sentry/cloudflare (withSentry)449.49 kB--

View base workflow run

@mydea
mydeaforce-pushed the fn/prisma-no-otel branch from a297a2b to 48bb0c8CompareJuly 13, 2026 12:43
const errString = td.decode(output.stderr);
assertEquals(outString, 'App has started\n');
assertEquals(errString, '');
assertEquals(outString, 'App has started\n');

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.

this test caught a problem I almost introduced (accessing process.env in server-utils), great! I re-ordered the assertions here to get more details when this fails, as it would otherwise fail on "true !== false" which is not super helpful, instead of failing on the error string assertion which actually told me the problem.

@mydea
mydea marked this pull request as ready for review July 13, 2026 12:44
@mydea
mydea requested review from a team as code ownersJuly 13, 2026 12:44
@mydea
mydea requested review from JPeer264, andreiborza and isaacs and removed request for a teamJuly 13, 2026 12:44
Comment on lines +189 to +195
const roots = spans.filter(span => span.parentId === null);

for (const root of roots) {
dispatchEngineSpan(root, spans, linkIds, this.ignoreSpanTypes);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: In dispatchEngineSpan, if a parent span is ignored via ignoreSpanTypes, its entire child span subtree is also dropped, leading to incomplete traces.
Severity: MEDIUM

Suggested Fix

Modify dispatchEngineSpan to handle ignored spans differently. Instead of returning early when shouldIgnoreSpan is true, the function should skip processing the current span but still iterate over its children and recursively call dispatchEngineSpan for each one. This ensures child spans are preserved even if their parent is filtered out.

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/server-utils/src/prisma/tracing-helper.ts#L189-L195
Potential issue: In the `dispatchEngineSpan` function, if a span's name matches a
pattern in the `ignoreSpanTypes` configuration, the function returns early. This
prevents the recursive processing of that span's children. As a result, if a root or
parent span is ignored, its entire subtree of child spans is also dropped, leading to
incomplete trace data. For example, ignoring a high-level `prisma:client:operation` span
would unintentionally cause its nested `prisma:engine:db_query` spans to be lost.

Did we get this right? 👍 / 👎 to inform future reviews.

@JPeer264JPeer264 left a comment

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.

LGTM. 🤞 for the CI

@andreiborzaandreiborza left a comment

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.

Nice

@mydea
mydea merged commit 7edbb8b into developJul 13, 2026
416 of 426 checks passed
@mydea
mydea deleted the fn/prisma-no-otel branch July 13, 2026 14:37
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.

Rewrite @prisma/instrumentation to orchestrion

3 participants

@mydea@JPeer264@andreiborza