Skip to content

ref(node): Streamline Prisma instrumentation (v6 and v7)#21819

Open
s1gr1d wants to merge 3 commits into
developfrom
sig/streamline-prisma
Open

ref(node): Streamline Prisma instrumentation (v6 and v7)#21819
s1gr1d wants to merge 3 commits into
developfrom
sig/streamline-prisma

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Jun 26, 2026

Copy link
Copy Markdown
Member

Streamlines the vendored Prisma instrumentation onto Sentry's span APIs (v6/v7):

  • Folds attributes previously set via the spanStart hook (origin, the db_query → SQL span rename, the db.system backfill) into span creation.
  • Uses startSpanManual/startInactiveSpan from @sentry/core instead of the OTel tracer in the vendored tracing helper.
  • Removes unused code: the setTracerProvider/tracerProvider plumbing, the deprecated no-op prismaInstrumentation option, and unused contract types (EngineTrace, EngineTraceEvent, LogLevel).
  • Removes the /* eslint-disable */ banners from the vendored files so they pass the linter.
  • Tightens the v6/v7 integration assertions to lock down the rename (the raw prisma:*:db_query span name never leaks through).

Keeps a minimal residual spanStart hook and the Prisma v5 _idGenerator compatibility path untouched. v5 support will be done in a follow-up PR.

Part of #20744

Closes #21820
Closes Linear: https://linear.app/getsentry/issue/JS-2877/streamline-prismainstrumentation-for-v6v7

@s1gr1d s1gr1d requested a review from a team as a code owner June 26, 2026 13:45
@s1gr1d s1gr1d requested review from JPeer264, andreiborza, mydea and nicohrubec and removed request for a team June 26, 2026 13:45
}

return tracer.startActiveSpan(name, options, span => endSpan(span, callback(span, context)));
return _context.with(context, () => startSpanManual(spanOptions, span => endSpan(span, callback(span, context))));

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: A synchronous error in the callback for runInChildSpan will cause a span leak because endSpan is never called.
Severity: LOW

Suggested Fix

Wrap the callback(span, context) call in a try/catch block within the endSpan function or restructure the code to ensure span.end() is always called in a finally block, regardless of whether the callback succeeds or throws an error.

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/node/src/integrations/tracing/prisma/vendored/active-tracing-helper.ts#L139

Potential issue: In `runInChildSpan`, the `startSpanManual` function is used in a way
that can lead to a resource leak. If the `callback` function passed into it throws a
synchronous error, the `endSpan` function is never called. Because `startSpanManual` is
configured with `autoEnd = false`, its internal error handling will correctly mark the
span with an error status but will not end it. This results in an unclosed span, which
can lead to increased memory and resource consumption over time.

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

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.48 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.97 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.76 kB - -
@sentry/browser (incl. Tracing, Replay) 85.22 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB - -
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.63 kB - -
@sentry/vue (incl. Tracing) 47.84 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.89 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.4 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB - -
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.69 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 77.54 kB - -
@sentry/core/browser 63.88 kB - -
@sentry/node-core 61.51 kB - -
@sentry/node 123.53 kB +0.04% +49 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.4 kB -0.01% -1 B 🔽
@sentry/node - without tracing 73.61 kB +0.01% +1 B 🔺
@sentry/aws-serverless 84.4 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 180.31 kB - -
@sentry/cloudflare (withSentry) 446.24 kB - -

View base workflow run

};

function engineSpanKindToOtelSpanKind(engineSpanKind: EngineSpanKind): SpanKind {
function engineSpanKindToSentrySpanKind(engineSpanKind: EngineSpanKind): SpanKindValue {

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.

m: we have a SPAN_KIND type in core now that we can use here

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.

Streamline @prisma/instrumentation for v6/v7

2 participants