question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Support for Prisma ORM

See original GitHub issue

Package + Version

  • [ x ] @sentry/integrations - ^5.27.3
  • [ x ] @sentry/node - ^5.27.3
  • [ x ] @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:

 Sentry.init({
      dsn: '***',
      environment: env,
      integrations: [
        new ExtraErrorData({ depth: 20 }),
        app && new Sentry.Integrations.Http({ tracing: true }),
        app && new Tracing.Integrations.Express({ app }),
        // Only works with pg client. Wait on support for Prisma
        app && new Tracing.Integrations.Postgres(),
      ].filter(Boolean),
      tracesSampleRate: 1.0,
      normalizeDepth: 21,
    });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:26
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
smeubankcommented, May 19, 2022

this is shipped in betas for V7! 🚀

we will close this request and would love to get any feedback on the usage!

8reactions
stnwkcommented, Jul 24, 2021

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;
  });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma | Next-generation ORM for Node.js & TypeScript
Prisma is a next-generation Node.js and TypeScript ORM for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB, and CockroachDB. It provides type-safety, ...
Read more >
Relational databases - Add to existing project - Prisma
Learn how to add Prisma to an existing Node.js or TypeScript project by connecting it to your database and generating a Prisma Client...
Read more >
Express & Prisma | Next-Generation ORM for SQL DBs
Prisma is a next-generation ORM for Node.js & TypeScript. It's the easiest way to build Express apps with MySQL, PostgreSQL & SQL Server...
Read more >
CRUD (Reference) - Prisma
This page describes how to perform CRUD operations with your generated Prisma Client API. CRUD is an acronym that stands for: Create; Read;...
Read more >
Prisma Client
Prisma Client is an auto-generated, type-safe query builder generated based on the models and attributes of your Prisma schema.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found