Skip to main content
@monocle.sh/instrumentation-kysely traces queries, streams, and transactions. Configure it manually after initializing OpenTelemetry; the Monocle agent does not enable it automatically.

Installation

Supports Kysely ^0.28.16 and ^0.29.6. This example uses pg:
Terminal

Configure query tracing

Wrap your dialect with observeDialect() and set dbSystem to your database type.
app/services/database.ts
If your driver is also instrumented, queries can produce duplicate spans. Disable one instrumentation to keep a single span per query.

Use postgres.js

For postgres.js, use PostgresJSDialect from kysely-postgres-js:
Terminal
app/services/database.ts
Pass this dialect to your Kysely instance. OpenTelemetry’s pg instrumentation does not cover postgres.js, so it adds no duplicate spans here.

Control captured data

SQL and errors are recorded by default and may contain sensitive data. Options for observeDialect():
  • recordQueryText: false: omit SQL text.
  • recordErrors: false: omit error details while still marking failures.
  • requireParentSpan: true: trace only within an active span.
  • connection: add host, port, and database details.

Pool metrics with pg

After initializing your metrics provider, call registerPgPoolMetrics() to track used and idle connections, pending requests, and the configured limit. Stop collection before closing the pool:
app/services/database.ts
Pool metrics require pg.Pool. postgres.js does not expose the pool statistics this helper needs. Query tracing still works with postgres.js and other Kysely drivers.