getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.95k stars 1.57k forks source link

Sentry Postgres Integration does not detect database events #9431

Closed RodoVJ closed 11 months ago

RodoVJ commented 11 months ago

Environment

SaaS (https://sentry.io/)

What are you trying to accomplish?

My team wants to use the Sentry Postgres integration to monitor the performance of our database. We are using Postgres as our database and use Typeorm as our ORM to make database operations.

How are you getting stuck?

Sentry does not seem to pick up any activity coming from Postgres and we don't see any metrics related to it. Is the reason Sentry can't pick up activity coming form Postgres because we are using Typeorm to interact with Postgres? If that's the case, is there a way to get around this issue? We introduced other automatic integrations (GraphQL and Express) and those are working fine.

Where in the product are you?

Performance

Link

No response

DSN

No response

Version

No response

getsantry[bot] commented 11 months ago

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] commented 11 months ago

Routing to @getsentry/product-owners-performance for triage ⏲️

mjq-sentry commented 11 months ago

Hi @RodoVJ, thanks for writing in! We don't have a direct integration with TypeORM, but it looks like it uses the pg library for its Postgres support, so I'd expect that to work. I'm going to transfer this issue to the SDK for that team to take a look.

AbhiPrasad commented 11 months ago

Hey @RodoVJ thanks for writing in! If you supply the debug: true attribute to your Sentry.init and use the sentry postgres integration, what gets logged out?

RodoVJ commented 11 months ago

Hi @AbhiPrasad, thank you for your response!

When our app first starts up, I get the following with debug: true:

Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: Undici
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: LocalVariables
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: Modules
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: Express
Sentry Logger [log]: Integration installed: Apollo
Sentry Logger [log]: Integration installed: GraphQL
Sentry Logger [log]: Integration installed: Postgres
Sentry Logger [log]: Integration installed: CaptureConsole

When I perform an action that triggers a GET call to our API that uses Postgres, I get several of the following console logs: (I couldn't spot any Postgres related events)

Sentry Logger [log]: [Tracing] starting http.server transaction - POST /graphql
Sentry Logger [log]: [Tracing] Starting 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Finishing 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Starting 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Starting 'http.client' span on transaction 'POST /graphql' ().
Sentry Logger [log]: [Tracing] Adding sentry-trace header <manually removed it for privacy> to outgoing request to <manually removed it for privacy>:
Sentry Logger [log]: [Tracing] Finishing 'http.client' span on transaction 'POST /graphql' (82edce63fe913792).
Sentry Logger [log]: [Tracing] Finishing 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Starting 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Finishing 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Starting 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Finishing 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Starting 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Finishing 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
Sentry Logger [log]: [Tracing] Starting 'middleware.express.use' span on transaction 'POST /graphql' (<manually removed it for privacy>).
--- AFTER 'Team' LOADED: <manually removed it for privacy>
Sentry Logger [log]: [Tracing] Starting 'graphql.execute' span on transaction 'POST /graphql' (<manually removed it for privacy>).
AbhiPrasad commented 11 months ago

I'm looking for logs like so: https://github.com/getsentry/sentry-javascript/blob/4babd02f0d38408880864dfc6d3fb858dba5c04f/packages/tracing-internal/src/node/integrations/postgres.ts#L86-L93

that tell us the pg module is unable to be required.

what version of the SDK are you on? Can you provide a copy of your Sentry.init config?

RodoVJ commented 11 months ago

I can't seem to find a similar message to "Postgres Integration was unable to access 'pg-native' bindings." in the logs that are printed. The version of our node SDK is 7.77.0

And for sure! This is our Sentry.init:

  Sentry.init({
    dsn: sentryDsn,
    debug: true,
    integrations: [
      new Sentry.Integrations.Http({ tracing: true }),
      new Sentry.Integrations.Express({ app }),
      new Sentry.Integrations.Apollo(),
      new Sentry.Integrations.GraphQL(),
      new Sentry.Integrations.Postgres(),
      new CaptureConsole({ levels: ['error'] }),
    ],

    tracesSampleRate: environment.production ? 0.2 : 1.0,
  });
RodoVJ commented 11 months ago

@AbhiPrasad I set the option usePgNative of the Postgres integration to true and it is now working. I didn't realize our TypeOrm connection is using pg-native. I will close the ticket but I very much appreciate your help!

mrZedov commented 9 months ago

I use MikroORM and I have the same problem. I don't see anything happening in Postgres. I use it like this:

   Sentry.init({
     dsn: process.env.SENTRY_DNS,
     integrations: [
       new ProfilingIntegration(),
       new Sentry.Integrations.Http({tracing: true}),
       new Sentry.Integrations.Postgres({   usePgNative: true  }),
       // ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
     ],
     tracesSampleRate: 1.0,
     profilesSampleRate: 1.0,
   });

Even using autoDiscoverNodePerformanceMonitoringIntegrations doesn't change anything I would really appreciate any help )

AbhiPrasad commented 9 months ago

Hey @mrZedov could you open a new GH issue and fill out the template? Would also be super helpful if you can add debug: true to your SDK config and paste the output. This will help us debug further. Thanks!

souterjk commented 4 months ago

@AbhiPrasad any chance there is documentation for what to use instead of usePgNative in sentry v8? Google and Github sent me here for typeorm/sentry problems, and this looks like a great fix, but its no longer available on the postgres integration in v8 as far as I can tell.

AbhiPrasad commented 4 months ago

For v8 the SDK uses OpenTelemetry, so the mechanisms for instrumentation are completely different. Let's see if we can figure it out in https://github.com/getsentry/sentry-javascript/issues/12265!