sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

`Sentry.postgresJsIntegration()` not creating any DB spans

Open aldy505 opened this issue 3 months ago • 5 comments

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/node

SDK Version

10.18.0

Framework Version

Node 22.16.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

Init script:

import { parseConfiguration } from "@internal-company/config";
import * as Sentry from "@sentry/node";
const environment = process.env.NODE_ENV ?? "development";
const sentryDebug: boolean | undefined =
    process.env.SENTRY_DEBUG != null ? process.env.SENTRY_DEBUG === "true" : undefined;
const configuration = await parseConfiguration();
Sentry.init({
    dsn: configuration.sentry.sentry_worker_dsn,
    sampleRate: configuration.sentry.sentry_sample_rate,
    environment,
    tracesSampleRate: configuration.sentry.sentry_traces_sample_rate,
    debug: sentryDebug ?? environment === "local",
    release: "{{SENTRY_VERSION}}+{{GIT_COMMIT_SHA}}",
    sendDefaultPii: true,
    enableLogs: true,
    integrations: [
        ...Sentry.getDefaultIntegrations({}),
        Sentry.zodErrorsIntegration(),
        Sentry.tediousIntegration(),
        Sentry.postgresJsIntegration(),
        Sentry.httpIntegration(),
        Sentry.requestDataIntegration(),
        Sentry.featureFlagsIntegration(),
    ],
});

Steps to Reproduce

  1. Enabled Sentry.postgresJsIntegration() based on this PR: https://github.com/getsentry/sentry-javascript/pull/16665
  2. Create some traffic, hit some SQL queries

Expected Result

At least, I see that the postgres library was patched by the otel instrumentation hook. The queries coming from Tedious (SQL Server) was successfully captured, but any other query for PostgreJs was not captured.

Here's the trace waterfall:

Image

Actual Result

Oct 09 08:10:23 vm npm[970308]: > node --import ./dist/instrument.js ./dist/entry.js
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Initializing Sentry: process: 970321, thread: main.
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: InboundFilters
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: FunctionToString
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: LinkedErrors
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: RequestData
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: NodeSystemError
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Console
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: OnUncaughtException
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: OnUnhandledRejection
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: ContextLines
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: LocalVariablesAsync
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Context
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: ChildProcess
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: ProcessSession
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Modules
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Http
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: NodeFetch
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Express
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Fastify
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Graphql
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Hono
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Mongo
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Mongoose
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Mysql
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Mysql2
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Redis
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Postgres
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Prisma
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Hapi
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Koa
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Connect
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Tedious
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: GenericPool
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Kafka
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Amqplib
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: LruMemoizer
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: VercelAI
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: OpenAI
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: PostgresJs
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Firebase
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Anthropic_AI
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: Google_GenAI
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: ZodErrors
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: Integration installed: FeatureFlags
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: SDK initialized from ESM
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for diag v1.9.0.
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for trace v1.9.0.
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Oct 09 08:10:24 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for context v1.9.0.
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https' }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https'>
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https' }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https'>
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry/instrumentation-redis Applying instrumentation patch for nodejs module file on require hook {
Oct 09 08:10:27 vm npm[970321]:   module: '@redis/client',
Oct 09 08:10:27 vm npm[970321]:   version: '5.8.2',
Oct 09 08:10:27 vm npm[970321]:   fileName: '@redis/client/dist/lib/client/multi-command.js',
Oct 09 08:10:27 vm npm[970321]:   baseDir: '/home/user/user/node_modules/@redis/client'
Oct 09 08:10:27 vm npm[970321]: }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry/instrumentation-redis Applying instrumentation patch for nodejs module file on require hook {
Oct 09 08:10:27 vm npm[970321]:   module: '@redis/client',
Oct 09 08:10:27 vm npm[970321]:   version: '5.8.2',
Oct 09 08:10:27 vm npm[970321]:   fileName: '@redis/client/dist/lib/client/index.js',
Oct 09 08:10:27 vm npm[970321]:   baseDir: '/home/user/user/node_modules/@redis/client'
Oct 09 08:10:27 vm npm[970321]: }
Oct 09 08:10:27 vm npm[970321]: Sentry Logger [log]: @opentelemetry/instrumentation-redis Applying instrumentation patch for module on require hook {
Oct 09 08:10:27 vm npm[970321]:   module: '@redis/client',
Oct 09 08:10:27 vm npm[970321]:   version: '5.8.2',
Oct 09 08:10:27 vm npm[970321]:   baseDir: '/home/user/user/node_modules/@redis/client'
Oct 09 08:10:27 vm npm[970321]: }
Oct 09 08:10:28 vm npm[970321]: Sentry Logger [log]: @opentelemetry/instrumentation-tedious Applying instrumentation patch for module on require hook {
Oct 09 08:10:28 vm npm[970321]:   module: 'tedious',
Oct 09 08:10:28 vm npm[970321]:   version: '18.6.1',
Oct 09 08:10:28 vm npm[970321]:   baseDir: '/home/user/user/node_modules/tedious'
Oct 09 08:10:28 vm npm[970321]: }
Oct 09 08:10:28 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-hono Applying instrumentation patch for module on require hook {
Oct 09 08:10:28 vm npm[970321]:   module: 'hono',
Oct 09 08:10:28 vm npm[970321]:   version: '4.9.8',
Oct 09 08:10:28 vm npm[970321]:   baseDir: '/home/user/user/node_modules/hono'
Oct 09 08:10:28 vm npm[970321]: }
Oct 09 08:10:28 vm npm[970321]: Sentry Logger [log]: Recording is off, propagating context in a non-recording span
Oct 09 08:10:28 vm npm[970321]: Sentry Logger [log]: Recording is off, propagating context in a non-recording span
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: [Tracing] Starting sampled root span
Oct 09 08:10:29 vm npm[970321]:   op: < unknown op >
Oct 09 08:10:29 vm npm[970321]:   name: redis-connect
Oct 09 08:10:29 vm npm[970321]:   ID: 9baeb2bae56a385f
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: [Tracing] Finishing "< unknown op >" root span "redis-connect" with ID 9baeb2bae56a385f
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Recording is off, propagating context in a non-recording span
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: SpanExporter exported 1 spans, 0 spans are waiting for their parent spans to finish
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Recording is off, propagating context in a non-recording span
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-http Handling finished outgoing request
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Initializing Sentry: process: 970321, thread: worker-2.
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: InboundFilters
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: FunctionToString
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: LinkedErrors
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: RequestData
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: NodeSystemError
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Console
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: OnUncaughtException
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: OnUnhandledRejection
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: ContextLines
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: LocalVariablesAsync
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Context
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: ChildProcess
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: ProcessSession
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Modules
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Http
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: NodeFetch
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Express
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Fastify
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Graphql
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Hono
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Mongo
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Mongoose
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Mysql
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Mysql2
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Redis
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Postgres
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Prisma
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Hapi
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Koa
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Connect
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Tedious
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: GenericPool
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Kafka
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Amqplib
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: LruMemoizer
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: VercelAI
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: OpenAI
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: PostgresJs
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Firebase
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Anthropic_AI
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: Google_GenAI
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: ZodErrors
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: Integration installed: FeatureFlags
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: SDK initialized from ESM
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for diag v1.9.0.
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for trace v1.9.0.
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Oct 09 08:10:29 vm npm[970321]: Sentry Logger [log]: @opentelemetry/api: Registered a global for context v1.9.0.
Oct 09 08:10:29 vm npm[970321]: {"level":30,"time":1759972229153,"pid":970321,"hostname":"vm","msg":"Server starting on http://0.0.0.0:5000"}
Oct 09 08:10:34 vm npm[970321]: Sentry Logger [log]: @sentry/instrumentation-http Handling finished outgoing request
Oct 09 08:10:34 vm npm[970321]: Sentry Logger [log]: Recording is off, propagating context in a non-recording span
Oct 09 08:11:24 vm npm[970321]: Sentry Logger [log]: Flushing client reports based on interval.
Oct 09 08:11:24 vm npm[970321]: Sentry Logger [log]: Flushing outcomes...
Oct 09 08:11:24 vm npm[970321]: Sentry Logger [log]: No outcomes to send
Oct 09 08:11:29 vm npm[970321]: Sentry Logger [log]: Flushing client reports based on interval.
Oct 09 08:11:29 vm npm[970321]: Sentry Logger [log]: Flushing outcomes...
Oct 09 08:11:29 vm npm[970321]: Sentry Logger [log]: No outcomes to send

Additional Context

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

aldy505 avatar Oct 09 '25 01:10 aldy505

Looks like there are no logs about our instrumentation patching postgres exports but only tedious. Are you running your application in ESM or CJS? Just to confirm, you're preloading the init script via --import or --require?

Lms24 avatar Oct 09 '25 17:10 Lms24

Looks like there are no logs about our instrumentation patching postgres exports but only tedious. Are you running your application in ESM or CJS? Just to confirm, you're preloading the init script via --import or --require?

ESM and --import. You can notice that on the uppermost logs:

Oct 09 08:10:23 vm npm[970308]: > node --import ./dist/instrument.js ./dist/entry.js

aldy505 avatar Oct 10 '25 02:10 aldy505

I can reproduce this. Still looking into what's going on at the moment. I'll leave an update once I know more. Thanks for reporting!

Lms24 avatar Oct 13 '25 11:10 Lms24

FE-621

linear[bot] avatar Oct 13 '25 11:10 linear[bot]

So I investigated this a bit and it seems like our current method of patching certain files within the package doesn't work in ESM. I don't have full context around this part of the SDK so I'm gonna defer to @onurtemizkan for now who created the initial integration. Onur, could you take a look at this and see if there's a way to also get this integration to work in ESM setups?

Here's a reproduction demonstrating that the integration works for CJS but not for ESM:

https://github.com/Lms24/gh-sentry-javascript-17889-postgresjsintegration

Lms24 avatar Oct 13 '25 15:10 Lms24

A PR closing this issue has just been released 🚀

This issue was referenced by PR #17961, which was included in the 10.31.0 release.

github-actions[bot] avatar Dec 16 '25 15:12 github-actions[bot]