ref(node): Streamline Prisma instrumentation (v6 and v7)#21819
Open
s1gr1d wants to merge 3 commits into
Open
Conversation
| } | ||
|
|
||
| return tracer.startActiveSpan(name, options, span => endSpan(span, callback(span, context))); | ||
| return _context.with(context, () => startSpanManual(spanOptions, span => endSpan(span, callback(span, context)))); |
Contributor
There was a problem hiding this comment.
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.
Contributor
size-limit report 📦
|
nicohrubec
reviewed
Jun 26, 2026
| }; | ||
|
|
||
| function engineSpanKindToOtelSpanKind(engineSpanKind: EngineSpanKind): SpanKind { | ||
| function engineSpanKindToSentrySpanKind(engineSpanKind: EngineSpanKind): SpanKindValue { |
Member
There was a problem hiding this comment.
m: we have a SPAN_KIND type in core now that we can use here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Streamlines the vendored Prisma instrumentation onto Sentry's span APIs (v6/v7):
spanStarthook (origin, thedb_query→ SQL span rename, thedb.systembackfill) into span creation.startSpanManual/startInactiveSpanfrom@sentry/coreinstead of the OTel tracer in the vendored tracing helper.setTracerProvider/tracerProviderplumbing, the deprecated no-opprismaInstrumentationoption, and unused contract types (EngineTrace,EngineTraceEvent,LogLevel)./* eslint-disable */banners from the vendored files so they pass the linter.prisma:*:db_queryspan name never leaks through).Keeps a minimal residual
spanStarthook and the Prisma v5_idGeneratorcompatibility 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