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 Sentry Tracing

See original GitHub issue

Problem

Sentry.io has a new feature called “Tracing” which is essentially an APM. They have a postgres integration, however this does not work with Prisma

Suggested solution

Either make a PR to fix the postgres integration to support prisma or create a separate prisma integration

Alternatives

N/A

Additional context

See: https://github.com/getsentry/sentry-javascript/issues/3143

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:13
  • Comments:6

github_iconTop GitHub Comments

3reactions
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;
  });

Maybe a good starting point?

1reaction
stnwkcommented, Nov 30, 2021

Thanks for sharing the awesome script. On a side node, it was smart of you to post the script on the related Github issue for Sentry’s javascript package.

You’re welcome & thanks 😃

Have you seen any performance issues when tracking every query via middleware?

So far, the impact has been nothing to worry about for us

Read more comments on GitHub >

github_iconTop Results From Across the Web

@sentry/tracing - npm
Start using @sentry/tracing in your project by running `npm i ... Future support for @sentry/apm is limited to bug fixes only.
Read more >
Distributed Tracing - Sentry Documentation
With tracing, Sentry tracks your software performance, measures metrics like throughput and latency, and displays the impact of errors across multiple ...
Read more >
Error Tracing | Sentry Documentation
With error tracing, you can correlate errors from multiple services and uncover a significant story surrounding a break. Using a unique identifier allows ......
Read more >
@sentry/tracing | Yarn - Package Manager
Please explicitly install and import @sentry/tracing if you want to use performance monitoring capabilities. For more details, see our docs on setting up...
Read more >
sentry-tracing - crates.io: Rust Package Registry
Adds support for automatic Breadcrumb, Event and Transaction capturing from tracing events, similar to the sentry-log crate.
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