Skip to content

Conversation

@lforst
Copy link
Contributor

@lforst lforst commented Jan 24, 2025

Background and Problem

Hi :) We maintain the official Sentry SDK and would love to have first class support for Prisma instrumentation. We are currently depending on a specific v5 version of the @prisma/instrumentation package as a dependency of our Node.js SDK (@sentry/node).

With the release of Prisma v6 we examined applications crash that used Prisma v6 in combination with our SDK with our Prisma instrumentation enabled. The reason for that was that the TracingHelper's interface was changed with Prisma v6, renaming a method (createEngineSpan -> dispatchEngineSpans) and the Sentry SDK registered the version 5 TracingHelper, which caused Prisma to call a method on it that doesn't exist.

We would love for our SDK to be compatible with multiple Prisma versions, and we assume other telemetry vendors would do so too! This PR doesn't necessarily fix the crashing, but it introduces a non-breaking mechanism to facilitate registering tracing helpers for specific versions of Prisma in a forwards compatible way.

Changes

Currently, Prisma picks up whatever tracing helper is on globalThis.PRISMA_INSTRUMENTATION when an instrumentation library like @prisma/instrumentation put a helper there. There are no checks whether the helper is compatible with the current prisma version or not.

Because doing checks for compatibility is annoying, this PR updates Prisma to pick up the tracing helpers from a versioned field instead. The field is named V${prismaMajorVersion}_PRISMA_INSTRUMENTATION. This allows instrumentation libraries to register tracing helpers for specific versions of Prisma, without introducing any sort of incompatibilities.

To make this change actually non-breaking, we still need to read from globalThis.PRISMA_INSTRUMENTATION, for example when people would upgrade @prisma/client (where the reading happens) but not @prisma/instrumentation (where the writing happens). In the next major, I would recommend dropping the fallback to reduce the risk of Prisma crashing when libraries put incompatible helpers on the fallback global.

### Background and Problem

Hi :) We maintain the official Sentry SDK and would love to have first class support for Prisma instrumentation. We are currently depending on a specific v5 version of the `@prisma/instrumentation` package as a dependency of our Node.js SDK (`@sentry/node`).

With the release of Prisma v6 we examined applications crash that used Prisma v6 in combination with our SDK with our Prisma instrumentation enabled. The reason for that was that the `TracingHelper`'s interface was changed with Prisma v6, renaming a method (`createEngineSpan` -> `dispatchEngineSpans`) and the Sentry SDK registered the version 5 `TracingHelper`, which caused Prisma to call a method on it that doesn't exist.

We would love for our SDK to be compatible with multiple Prisma versions, and we assume other telemetry vendors would do so too! This PR doesn't necessarily fix the crashing, but it introduces a non-breaking mechanism to facilitate registering tracing helpers for specific versions of Prisma in a forwards compatible way.

### Changes

Currently, Prisma picks up whatever tracing helper is on `globalThis.PRISMA_INSTRUMENTATION` when an instrumentation library like `@prisma/instrumentation` put a helper there. There are no checks whether the helper is compatible with the current prisma version or not.

Because doing checks for compatibility is annoying, this PR updates Prisma to pick up the tracing helpers from a versioned field instead. The field is named `V${prismaMajorVersion}_PRISMA_INSTRUMENTATION`. This allows instrumentation libraries to register tracing helpers for specific versions of Prisma, without introducing any sort of incompatibilities.

To make this change actually non-breaking, we still need to read from `globalThis.PRISMA_INSTRUMENTATION`, for example when people would upgrade `@prisma/client` (where the reading happens) but not `@prisma/instrumentation` (where the writing happens).
Copy link
Member

@aqrln aqrln left a comment

Choose a reason for hiding this comment

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

This looks great to me, thank you!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 30, 2025
@aqrln aqrln added this to the 6.4.0 milestone Jan 30, 2025
@aqrln aqrln merged commit e4aca67 into prisma:main Jan 30, 2025
233 checks passed
@aqrln
Copy link
Member

aqrln commented Jan 31, 2025

Hey @lforst, do you want us to make a patch release with this change so you could make use of it right away?

@lforst
Copy link
Contributor Author

lforst commented Feb 3, 2025

@aqrln all good. Thank you! This was more like a thing to ensure that things don't blow up in the future. We ended up adding something to our SDK that patches the helper to ensure that it doesn't crash on older versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants