Documentation / Connect
Node databases
Monitor slow and repeated queries with pg, mysql2, Drizzle and Prisma PostgreSQL.
The JavaScript SDK 0.13.0 /database entry observes application-owned pg and mysql2 instances. It emits native slow_query measurements and repeated-query verdicts; it does not create OpenTelemetry traces. It is disabled by default.
PostgreSQL
Install @bussolabs/closeyourit-js@^0.13.0 and the pg driver compatible with your application. Supply connection settings and credentials only at runtime, on the server. This example runs a real query and closes resources afterward; in a server, install once at startup and close on shutdown.
import pg from 'pg'
import { Client } from '@bussolabs/closeyourit-js'
import { DatabaseMonitoring } from '@bussolabs/closeyourit-js/database'
const client = new Client({
endpointUrl: process.env.CLOSEYOURIT_ENDPOINT_URL!,
projectId: process.env.CLOSEYOURIT_PROJECT_ID!,
token: process.env.CLOSEYOURIT_TOKEN,
environment: process.env.NODE_ENV,
release: process.env.APP_VERSION,
})
const pool = new pg.Pool()
const monitoring = new DatabaseMonitoring(client, {
enabled: true,
slowQueryThresholdMs: 100,
repeatedQueryThreshold: 5,
})
monitoring.instrumentPostgres(pool)
await client.runWithScope(() =>
monitoring.profile(async () => {
await pool.query('SELECT $1::integer AS value', [1])
}),
)
monitoring.uninstall()
await client.close()
await pool.end()
The default thresholds are 100 ms and five repetitions. The example query may not emit a measurement: it must exceed the threshold. For a controlled check, use slowQueryThresholdMs: 0, then verify the stored record in the correct project.
profile() bounds one request; concurrent requests do not share counts. Queries outside a profile can emit slow measurements but no repetition verdict. For callback or streaming HTTP requests, use monitoring.request(end => …) and call end at response completion. Streaming database queries remain excluded.
MySQL and ORMs
For a mysql2/promise pool, call monitoring.instrumentMysql(pool, 'promise'); use 'callback' for callback APIs. With Drizzle, instrument the same pg/mysql2 pool passed to the ORM. With Prisma 7, instrument the explicit PostgreSQL pool passed to PrismaPg.
Prisma MySQL, internal engines, cursors and custom query objects are not covered. Physical queries are counted once at the driver boundary. Repetition is evidence to investigate, not proof of a semantic ORM N+1 defect.
Privacy, limits and removal
Bindings and results are never sent. SQL identifiers are pseudonymous; that is not an anonymity guarantee against guessed names. Unrecognized syntax is omitted without changing the application's query.
Limits are 256 instances, 64 concurrent profiles, 64 groups and 1,000 operations per profile. Incomplete profiles do not produce aggregate verdicts. monitoring.getStats() exposes local omissions. Transport adds no durable offline queue or automatic retries.
uninstall() restores only methods still owned by the adapter. Pools, transactions and SDK clients remain application-owned. Check disabled and removed behavior too; consult observed combinations before extending support to other runtimes.