-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Prisma not tracking spans with Sentry Node.js integration #10680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We are currently working on v8 of the SDK which has a completely new prisma integration based on OpenTelemetry, which should support this much better out of the box. What version of Prisma are you using? Maybe we have some incompatibility with a new Prisma version... 🤔 |
Sorry, should have included that in my original message. I am using Prisma |
Hi, for my side project I am using the prisma integration on the latest version and everything seems to work. Would you mind turning on |
Here's the output I get after loading Sentry and when I load a page which has a Prisma query:
This is using Sentry 7.101 and Prisma 5.9.1. Do I need to do anything else other than the setup below? Sentry.init({
debug: !!process.env.SENTRY_DEBUG,
dsn: SENTRY_DSN,
environment: IS_AZURE_PRODUCTION ? "production" : "staging",
ignoreErrors: [
],
integrations: [
new ProfilingIntegration(),
extraErrorDataIntegration({
depth: 4
}),
// Sentry.anrIntegration({ captureStackTrace: true }),
Sentry.consoleIntegration(),
new Sentry.Integrations.GraphQL(),
new Sentry.Integrations.Prisma({ client: prisma })
],
profilesSampleRate: 1.0,
tracesSampleRate: 1.0
}); |
The only thing that could be happening is that you are passing a different instance of the prisma client to sentry than you end up using. To avoid this, I am doing the following in my app: import { PrismaClient } from '@prisma/client';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const globalThis: Record<string, any>;
const registerService = <T>(name: string, initFn: () => T): T => {
if (!(name in global)) {
globalThis[name] = initFn();
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return globalThis[name];
};
const basePrismaClient = registerService(
'base-prisma-client',
() =>
new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_CONNECTION_STRING || 'DID_NOT_SET_CONNECTION_STRING',
},
},
})
);
export { basePrismaClient }; It is a bit overly complex because it caters to my use-case but maybe it helps solve your case? |
Are you using a serverless setup or a regular server? I'm on a regular server setup, and I'm just following the Prisma documentation for instantiating a Prisma client once and reusing it. I think you bring up a point though that perhaps Sentry is being initialized before Prisma is. I updated my Sentry setup file to be a function that is passed the Prisma client, and now I can see the Prisma span. Is this kind of pattern OK? Should I expect any issues with Sentry if I do export function initializeSentry(prisma: PrismaClient) {
Sentry.init({
debug: !!process.env.SENTRY_DEBUG,
dsn: SENTRY_DSN,
environment: IS_AZURE_PRODUCTION ? "production" : "staging",
ignoreErrors: [
],
integrations: [
new ProfilingIntegration(),
new Sentry.Integrations.Prisma({ client: prisma }),
extraErrorDataIntegration({
depth: 4
}),
Sentry.consoleIntegration(),
new Sentry.Integrations.GraphQL()
],
profilesSampleRate: 1.0,
tracesSampleRate: 0.5
});
console.log(`🔦 Sentry initialized`);
} |
Interesting. Generally, it shouldn't matter from where you call Sentry.init() but you should call it as early as possible in your code because it can only collect errors that happen after it was called. I am using Next.js deployed to vercel, so kinda serverless. |
I'll keep playing with it, but my immediate issue is solved. Going to close this now. Thanks for your help! |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
7.101.0
Framework Version
Node 18.18.2
Prisma 5.9.1
Link to Sentry event
https://mentra-ec.sentry.io/discover/leto:f128265a11dc4a19aa16092121985b6d/?field=title&field=event.type&field=project&field=user.display&field=timestamp&field=replayId&name=All+Events&project=6509483&query=&sort=-timestamp&statsPeriod=7d&yAxis=count%28%29
SDK Setup
Steps to Reproduce
Expected Result
I should see information about the Prisma operation in the recorded Sentry span
Actual Result
I do not see anything about Prisma in the recorded Sentry span. In this case, Prisma executes before the
http.client
call in the below picture.The text was updated successfully, but these errors were encountered: