- Wrap your Kysely dialect to create query spans
- Control which query and error details are recorded
- Optionally collect PostgreSQL pool metrics
Overview
@monocle.sh/instrumentation-kysely wraps a Kysely dialect and creates OpenTelemetry spans for database operations. It uses your active OpenTelemetry provider and must be configured in your application. The AdonisJS agent does not install or enable this package automatically.
Installation
Install the instrumentation, Kysely, and the database driver used by your dialect. This package supports Kysely^0.28.16.
Terminal
pg.
Configure query tracing
Initialize OpenTelemetry before importing your database module. Wrap your existing dialect withobserveDialect() and set dbSystem to identify the database.
app/services/database.ts
Control captured data
Query text and database errors are recorded by default. Query text contains placeholders for bound parameters, but literal values in raw SQL remain in the statement. Error messages can also contain submitted values.- Set
recordQueryText: falseto omit SQL statements. The default maximum length is 1,022 characters; usemaxQueryLengthto change it. - Set
recordErrors: falseto omit exception details while keeping the span error status and type. - Set
requireParentSpan: trueto trace database operations only when a parent span is active. - Pass
connectionwithhost,port, anddatabaseto add database connection details to spans.
PostgreSQL pool metrics
CallregisterPgPoolMetrics() after initializing your metrics provider. It records used and idle connections and pending requests. Call the returned function during shutdown, before closing the pool.
app/services/database.ts