npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unhandled/instrumentation-kysely

v0.1.14

Published

Kysely query tracing and pg pool metrics for Unhandled

Readme

@unhandled/instrumentation-kysely

Traces Kysely queries, streams and transactions, and exports pg pool gauges. Supports Kysely ^0.28.16 and ^0.29.6 with PostgresDialect (pg) and PostgresJSDialect (kysely-postgres-js).

This package is manual only. It has no /integration entry, so the AdonisJS agent never enables it for you.

Install

npm i @unhandled/instrumentation-kysely

Use

Create the dialect after OpenTelemetry is initialised and pass the wrapped dialect to Kysely:

import { Kysely, PostgresDialect } from 'kysely'
import pg from 'pg'
import { observeDialect } from '@unhandled/instrumentation-kysely'

const pool = new pg.Pool({ host, port, database, user, password, max: 10 })

export const db = new Kysely<Database>({
  dialect: observeDialect({
    dialect: new PostgresDialect({ pool }),
    dbSystem: 'postgresql',
    connection: { host, port, database },
  }),
})

Options

| Option | Default | Effect | | ------------------- | -------- | --------------------------------------------------------------------------------------------- | | dialect | required | The dialect to wrap. | | dbSystem | required | Value of db.system.name, for example postgresql. | | recordQueryText | true | false leaves db.query.text off every span. | | recordErrors | true | false keeps ERROR status but drops the status message and the exception event. | | requireParentSpan | false | Only create spans when a span is already active. | | connection | none | { host, port, database }, reported as server.address, server.port and db.namespace. |

SQL text and error messages can contain sensitive data. Query parameters are never recorded, but literals inlined in SQL are. Turn off recordQueryText and recordErrors if that matters.

Spans

Every span is CLIENT kind. The name is <OPERATION> <table> (SELECT users), or just the operation when no table can be parsed, with the operation and table read from the SQL text. A transaction produces BEGIN, one span per query, then COMMIT or ROLLBACK. A stream is one span that lasts until the stream is drained, closed or fails.

| Attribute | Value | | -------------------- | ----------------------------------------------------------------------- | | db.system.name | dbSystem | | db.query.text | SQL with placeholders, when recordQueryText is on | | db.operation.name | Upper-cased first keyword, for example SELECT | | db.collection.name | Target table when it can be parsed | | db.namespace | connection.database | | server.address | connection.host | | server.port | connection.port | | db.transaction | true on BEGIN, COMMIT, ROLLBACK and queries inside a transaction | | error.type | Error class name on failures |

Pool metrics

import { registerPgPoolMetrics } from '@unhandled/instrumentation-kysely'

const stop = registerPgPoolMetrics({ pool, max: 10, poolName: 'primary' })
// later, before pool.end()
stop()

Call it after the metrics provider is set up. Only pg.Pool is supported; anything else throws a TypeError. postgres.js exposes no pool counters.

| Gauge | Meaning | | ---------------------------------------- | ---------------------------------------- | | db.client.connection.used | Connections checked out | | db.client.connection.idle | Open connections sitting idle | | db.client.connection.pending_requests | Callers waiting for a connection | | db.client.connection.max | The max you passed |

Each point carries db.client.connection.pool.name set to poolName.

Duplicate spans

If you also enable OpenTelemetry's pg instrumentation, every query is traced twice, once here and once at the driver. Keep one of them. postgres.js has no OpenTelemetry coverage, so wrapping its dialect here causes no duplicates.

For AI agents

A coding agent can install this package, check that its data arrives and fix the errors it reports through the Unhandled MCP server at https://unhandled.net/mcp. In Claude Code, the Unhandled plugin adds that server plus skills for instrumenting a service, fixing a production error with a failing test first and verifying a deploy:

claude plugin marketplace add treboryx/unhandled
claude plugin install unhandled@unhandled

Codex, Cursor, Gemini CLI and other agents connect to the same URL. Coding agents has the setup for each one and an AGENTS.md section to add to your repository.