Prisma opt-in with Nest.js doesn't work
Environment
SaaS (https://sentry.io/)
Version
Everything latest
Steps to Reproduce
I'm trying to configure performance monitoring with Nest.js and Prisma ORM. Followed the steps here but I only get the http span in the event, I don't see any DB related spans.
I also tried to use the @prisma/instrumentation package instead of the @prisma/client which is used in the docs, but nothing seems to work.
schema.prisma:
generator client {
provider = "prisma-client-js"
previewFeatures = ["tracing"]
}
This is my basic main.ts file:
import { PrismaClient } from '@prisma/client';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import 'cross-fetch/polyfill'; // required for @microsoft/microsoft-graph-client
import dotenv from 'dotenv';
import AppModule from './app.module';
async function bootstrap() {
dotenv.config();
const app = await NestFactory.create(AppModule);
const httpAdapter = app.getHttpAdapter();
Sentry.init({
dsn: 'https://xxxxxx',
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({
app: httpAdapter.getInstance(),
}),
new Tracing.Integrations.Prisma({ client: new PrismaClient() }),
],
tracesSampleRate: 1.0,
});
app
.use(Sentry.Handlers.requestHandler())
.use(Sentry.Handlers.tracingHandler())
.use(Sentry.Handlers.errorHandler());
await app.listen(app.get(ConfigService).get('PORT') || 3000);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
bootstrap();
Expected Result
I should see DB spans in the transactions
Actual Result
Example event from sentry, without any DB span, only HTTP:

Routing to @getsentry/team-web-sdk-backend for triage. ⏲️
Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️
Hey thanks for writing in!
new Tracing.Integrations.Prisma({ client: new PrismaClient() }),
Looking at this line, the issue might be that you're constructing a brand new prisma client, instead of passing down a reference to the existing prisma client you use for your database queries. This means we are not monitoring the prisma client actually beign used to make the query. It seems like from the docs that the prisma client is dependency injected into your app, not sure if there's an easy way to access it outside of that. I would ask the NestJS folks on advice from that.
Hey thanks for writing in!
new Tracing.Integrations.Prisma({ client: new PrismaClient() }),
Looking at this line, the issue might be that you're constructing a brand new prisma client, instead of passing down a reference to the existing prisma client you use for your database queries. This means we are not monitoring the prisma client actually beign used to make the query. It seems like from the docs that the prisma client is dependency injected into your app, not sure if there's an easy way to access it outside of that. I would ask the NestJS folks on advice from that.
@AbhiPrasad yea I also tried to access the PrismaService and not the client, but same results.
I guess someone in Sentry tested it with NestJs and Prisma and knows the best way to make it work, I would add it to the docs since it just doesn't work the current way.
What I did for now is adding to the $use Prisma middleware a span with op: 'db.prisma' after getting the transaction.
It seems to work, but sounds like it should be better instrumented.
We haven't invested in a first class NestJS SDK - if you want to see that happen please let us know here: https://github.com/getsentry/sentry-javascript/discussions/5578. Backlogging this for now - but PRs welcome!
I just want to chime in here -
I am instrumenting a NestJS app correctly, using the actual PrismaService resolved from Nest, like so:
Sentry.init({
dsn: '<redacted>',
tracesSampleRate: 1.0,
integrations: [
new Tracing.Integrations.Express({ app: app.getHttpAdapter().getInstance() }),
new Tracing.Integrations.Apollo(),
new Tracing.Integrations.Prisma({ client: app.get(PrismaService) }),
],
});
And I can verify that no traces are being sent whatsoever. None from Express, none from Apollo, and none from Prisma.
In the above, app is the NestJS application.
Hello, I tried 2 ways to do it with NestJS and no Prisma trace appears. Is there somewhere a working example except the very short explanation in the doc ?
Hey! We now have a Nest.js integration as part of our Node.js SDK (that also works with Prisma out of the box) as part of Sentry 8.x
https://docs.sentry.io/platforms/javascript/guides/nestjs/
Upgrade to 8.x: https://docs.sentry.io/platforms/javascript/guides/nestjs/migration/v7-to-v8/