sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

prismaInstrumentation.PrismaInstrumentation is not a constructor

Open gajus opened this issue 1 year ago • 7 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.0.0-alpha.4

Framework Version

No response

Link to Sentry event

No response

SDK Setup

N/A

Steps to Reproduce

Load script with node --loader=import-in-the-middle/hook.mjs ./dist/bin/server.js

Gives error:

030292a3 > This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
030292a3 > TypeError: prismaInstrumentation.PrismaInstrumentation is not a constructor
030292a3 >     at Object.setupOnce (file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/node/esm/index.js:2075:11)
030292a3 >     at setupIntegration (file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/core/esm/index.js:4927:17)
030292a3 >     at file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/core/esm/index.js:4897:7
030292a3 >     at Array.forEach (<anonymous>)
030292a3 >     at setupIntegrations (file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/core/esm/index.js:4894:16)
030292a3 >     at NodeClient._setupIntegrations (file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/core/esm/index.js:5396:26)
030292a3 >     at NodeClient.init (file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/core/esm/index.js:5249:12)
030292a3 >     at init (file:///Users/x/Developer/contra/gaia/node_modules/.pnpm/@[email protected]/node_modules/@sentry/node/esm/index.js:3104:12)
030292a3 >     at createSentry (file:///Users/x/Developer/contra/gaia/packages/sentry/dist/node.js:69:5)
030292a3 >     at file:///Users/x/Developer/contra/gaia/apps/contra-api/src/bin/server.ts:1:205

What worked was a dumb patch:

diff --git a/esm/index.js b/esm/index.js
index d9f5c81971e65b60e49a9ae7502c710bb4d2bd9d..bd28c7836c5b9e9075e611a117d80c1d66e7a82a 100644
--- a/esm/index.js
+++ b/esm/index.js
@@ -2072,7 +2072,7 @@ const _prismaIntegration = (() => {
       registerInstrumentations({
         instrumentations: [
           // does not have a hook to adjust spans & add origin
-          new prismaInstrumentation.PrismaInstrumentation({}),
+          // new prismaInstrumentation.PrismaInstrumentation({}),
         ],
       });
     },

All other modules load fine.

gajus avatar Mar 20 '24 20:03 gajus

This is https://github.com/prisma/prisma/issues/23410 - tracked by https://github.com/getsentry/sentry-javascript/issues/11070.

Known issue that we will resolve before v8 comes out, maybe for now just have to disable prisma instrumentation in ESM builds (basically strip it out).

AbhiPrasad avatar Mar 20 '24 20:03 AbhiPrasad

Closing as duplicate. Thanks for the update.

gajus avatar Mar 20 '24 21:03 gajus

@jnicklas Re your comment https://github.com/getsentry/sentry-javascript/issues/11070#issuecomment-2110492318. Are you manually using the prismaIntegration() with ESM?

lforst avatar May 14 '24 17:05 lforst

@lforst yes, that's what I'm doing, maybe this is no longer necessary in the new version? This was not mentioned in the upgrade guide, so I'm not sure. I know there are some default integrations, but it's not quite clear which ones those are, and what I actually need to do.

jnicklas avatar May 15 '24 08:05 jnicklas

Generally, for now you do need to still add it manually in v8 (see: https://docs.sentry.io/platforms/javascript/guides/node/performance/database/#supported-platforms).

Can you show your Sentry.init(), as well as the relevant parts from your package.json?

mydea avatar May 15 '24 11:05 mydea

Could not get it to work with Remix ESM.

lilouartz avatar May 16 '24 03:05 lilouartz

We'll need to investigate ESM support for this some more. I think there are some fundamental incpompatibilies there, but not 100% sure, cc @timfish and @AbhiPrasad you've looked into this more in the past!

mydea avatar May 17 '24 09:05 mydea

I had the same issue in an ESM build using --import ./instrument.js.

Versions:

  • Node v20.13.1
  • @sentry/node 8.3.0
  • @prisma/instrumentation 5.14.0

I fixed this with the following patch (applied with with patch-package)

# patches/@sentry+node+8.3.0.patch
diff --git a/node_modules/@sentry/node/esm/integrations/tracing/prisma.js b/node_modules/@sentry/node/esm/integrations/tracing/prisma.js
index abe7880..0b2a7a6 100644
--- a/node_modules/@sentry/node/esm/integrations/tracing/prisma.js
+++ b/node_modules/@sentry/node/esm/integrations/tracing/prisma.js
@@ -1,5 +1,5 @@
 import { _optionalChain } from '@sentry/utils';
-import * as prismaInstrumentation from '@prisma/instrumentation';
+import prismaInstrumentation from '@prisma/instrumentation';
 import { defineIntegration, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
 import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';

danthareja avatar May 22 '24 19:05 danthareja