-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Support for Prisma ORM #3143
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
That function is only used in test scripts internally. Regular Prisma users have the Prisma engines connect to the database. The Node.js app never connects directly to the database. |
@pizzafox is correct here. |
Thanks for the info. I allowed myself to change the title of this issue then. |
Hope this gets more attention. How are people working around this? Has anyone managed to configure it for better stack traces? |
I took a look at how this is implemented for the pg integration: https://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/integrations/postgres.ts and applied prisma's middleware concept to it: https://www.prisma.io/docs/concepts/components/prisma-client/middleware Here's what worked for me: import { PrismaClient } from "@prisma/client";
import { getCurrentHub, Severity } from "@sentry/nextjs"; // whatever package you're using
prisma.$use(async (params, next) => {
const { model, action, runInTransaction, args } = params;
const description = [model, action].filter(Boolean).join(".");
const data = {
model,
action,
runInTransaction,
args,
};
const scope = getCurrentHub().getScope();
const parentSpan = scope?.getSpan();
const span = parentSpan?.startChild({
op: "db",
description,
data,
});
// optional but nice
scope?.addBreadcrumb({
category: "db",
message: description,
data,
});
const result = await next(params);
span?.finish();
return result;
}); |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Leave it |
this is shipped in betas for V7! 🚀 we will close this request and would love to get any feedback on the usage! |
So I read that Prisma is not auto-instrumented, but I can't figure out how to run setupOnce or whatever. Is this documented somewhere? I can't figure out how to import Sentry Prisma stuff :( Edit: I'm getting closer, I found the import:
However I'm not sure what to pass to the setupOnce:
Apparently setupOnce needs some args which I don't understand. |
@Noitidart it is confusing, but I believe that you don't need to call setup yourself, but instead pass into your sentry init like this: |
Oh thanks @MaxBittker I'll try that out. I noticed we don't have params.args or params.runInTransaction in the data of the span. Is it possible to add this? Also I noticed that in some errors, if it happens after the span starts, and prevents the span from finishing, then we don't see that data fire up for that request. One such error is permission to db user is denied. So maybe we should also add a type "query" category "started" breadcrumb with this data? |
If this runs in node js, but the queries are actually ran by prisma's query engine in rust under the hood, are these spans accurate? I measured time that
Then time measured on the nodejs side is longer than the query actually took. Just wanted to note this. |
Package + Version
@sentry/integrations - ^5.27.3
@sentry/node - ^5.27.3
@sentry/tracing - ^5.29.2
Description
I want to use the Postgres Tracing Integrations mentioned in these docs: https://docs.sentry.io/platforms/node/performance/database/
But for some reason, it does not work.
I'm using Prisma to do my Postgres queries: https://github.com/prisma/prisma
Underlying, Prisma is using the pg client package: https://github.com/prisma/prisma/blob/master/src/packages/client/src/utils/setupPostgres.ts
My code looks like this:
The text was updated successfully, but these errors were encountered: