-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Prisma Tracer not working on production builds #7216
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
Hey @jporsay, thanks for writing in! What version of prisma are you using? |
What is the difference between running the application in production/development mode? Do you bundle differently? Do you change prisma config in any way? |
We're using 4.8.0 |
We do not change the prisma config. As for the bundling, there are no changes that we know of. Bundling is that provided by NX (15.3.0) and the NextJS version provided above. |
I recently noticed something similar going on in a test app of mine. I investigated a bit but couldn't get to the root cause yet. What I found though is that manually instrumenting prisma in import * as Sentry from '@sentry/nextjs';
import { getCurrentHub } from '@sentry/nextjs';
import { prismaClient } from './prisma/client';
prismaClient.$use(async (params, next) => {
const scope = getCurrentHub().getScope();
const parentSpan = scope?.getSpan();
const action = params.action;
const model = params.model;
const span = parentSpan?.startChild({
description: model ? `${model} ${action}` : action,
op: 'db.sql.prisma',
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const rv: unknown = await next(params);
span?.finish();
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return rv;
});
Sentry.init({
dsn: 'dsn',
tracesSampleRate: 1.0,
environment: process.env.VERCEL_ENV || 'development',
includeLocalVariables: true,
}); |
We've thought about adding manual instrumentation to prisma, but given that it was working without any issues before, we'd rather help surface this than going the "manual route". |
Seeing the same problem with sentry |
Ok documenting my process to figure out why it is not working:
Brainstorming a fix: Solution 1Instead of an integration, or rather in addition to our integration, we export a Prisma middleware that can be passed to Solution 2Instead of adding the Prisma middleware inside of |
@lforst this still doesn't seem to work for us even on the latest version of sentry and prisma and itt may be because we are using clientExtensions. We extend the client on each request to facilitate RLS and then put that into our TRPC context for use in our routers, so the extended client is not just available to pass a normal reference to the Prisma integration constructor because it is created using a function on each HTTP request. This is the expected way to implement this according to the prisma docs:
and then in our server config file
I think the only way this integration can really work is if the tracing happens within a client extension. |
@joe-giunti-kiefa I think you are right. I am not really happy with our Prisma integration right now and I am planning to do a better version that is able to also capture queries and such. As far as I can remember client extensions are quite new so we just didn't get around to build support for them yet. |
@lforst any update on this? |
@ThallesP Yes I looked into it and it is currently not possible to have a proper tracer that uses the client extension as it breaks out of async context. Luckily we will soon have full OTEL support so this is gonna be solved by that. |
@lforst Is there another issue I should follow for when this integration works again? Should I simply remove the |
@SheaBelsky The prisma integration should work, however it won't capture the content of your queries. It should create spans though. Can you please open an issue and provide reproduction steps for your problem. Thanks! |
Yes I will open a separate issue! Thanks! |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g.
bundle.tracing.min.js
) in your SDK setup.@sentry/nextjs
SDK Version
7.37.2
Framework Version
13.1.1
Link to Sentry event
https://pulposapp.sentry.io/performance/pulpos-app-dev:d8283cfa1e9f4cd893e0e8cc26e59988/?project=4504339811074048&query=http.method%3AGET&referrer=performance-transaction-summary&statsPeriod=7d&transaction=GET+%2Fapi%2Ftrpc%2F%5Btrpc%5D&unselectedSeries=p100%28%29
SDK Setup
Steps to Reproduce
For context, this is being run within an NX monorepo.
Steps:
nx build app
(application is called app)nx run app:serve:production
Expected Result
Profiling contains prisma database spans.
Actual Result
No database spans are present. However the interesting thing is that if I were to execute the application in development mode, the spans are reported correctly. This issue started happening when we upgraded the following packages:
The text was updated successfully, but these errors were encountered: