Most production Node services talk to Postgres through more than one door: an ORM for app models, raw SQL for hot paths, maybe a thin helper around pg or postgres.js. That fragmentation makes “one true APM wrapper” awkward.
queryd (npm i @olegkoval/queryd) is a small library that focuses on one job: detect queries that exceed a latency threshold and emit structured events you can route anywhere (console logger included; everything else is your ILogger—Sentry, OpenTelemetry exporter, internal pipeline, etc.).
What you get
-
Driver-agnostic hooks such as
wrapQueryFnandwrapTaggedTemplate, plusSlowQueryDetector.executeQuerywhen you want to wrap a callback manually. -
Optional Prisma behind a separate import:
@olegkoval/queryd/prisma(wrapPrismaClient, etc.) so the default surface stays Prisma-free. -
Sampling, optional
EXPLAIN ANALYZE, and enough context hooks (for examplerunWithDbContext) to correlate slow queries with a request or user id—without taking over your whole observability stack.
Minimal tagged-template example
The README’s postgres.js-style example is the quickest mental model: create a detector with warnThresholdMs, attach createConsoleLogger() (or your adapter), then wrap the client’s tagged template function so every query flows through the detector.
(Install: npm install @olegkoval/queryd.)
Prisma users
Install @prisma/client only if you use the Prisma entry. Wrap your PrismaClient, keep thresholds consistent, and use runWithDbContext when you want request-scoped metadata on events.
What this is / isn’t
- Is: a focused library boundary around latency and optional explain, with pluggable logging.
- Isn’t: a hosted dashboard, query store, or full APM replacement—bring your own sink and retention model.
Links
- Repo: https://github.com/oleg-koval/slow-query-detector
- Docs (GitHub Pages): https://oleg-koval.github.io/slow-query-detector/
- npm: https://www.npmjs.com/package/@olegkoval/queryd
License
MIT (see the repo LICENSE).
Disclaimer: this post summarizes the project’s documented API and goals; it does not claim adoption metrics or benchmarks not stated upstream.

Top comments (0)