Hi @wellwelwel, @logaretm
PR #4178 added TracingChannel support to mysql2. I've built
the subscriber side: an OpenTelemetry instrumentation package that listens to
the mysql2:query, mysql2:execute, mysql2:connect, and mysql2:pool:connect
channels and produces proper OTel spans.
Here is the Package: mysql2-otel-instrumentation
and the Repo: mysql2-otel-instrumentation
The existing OTel instrumentation uses RITM (require-in-the-middle) to
monkey-patch Connection.prototype.query and Connection.prototype.execute.
This package does not monkey-patch. It is a simple diagnostics_channel subscriber.
|
@opentelemetry/instrumentation-mysql2 |
This package |
| Approach |
RITM monkey-patching |
TracingChannel subscriber |
| mysql2 version |
any |
≥3.20.0 |
| Node.js version |
≥14 |
≥20 |
| ESM safe |
fragile (IITM) |
yes |
| Initialization order |
must load before mysql2 |
no constraint |
| RITM/IITM dependency |
yes |
none |
Why this belongs close to mysql2
The OTel JS ecosystem is actively moving toward library-owned instrumentation.
The most recent precedent: @opentelemetry/instrumentation-fastify was deprecated
in January 2025 and removed in March 2026 in favor of @fastify/otel, maintained
by the Fastify team.
This package is the direct subscriber counterpart to the work done by @logaretm in #4178.
The ask
Would you be willing to add a link to this package in the mysql2 docs? Something minimal like:
## Tracing / Observability
For OpenTelemetry instrumentation based on the native TracingChannel API
(mysql2 ≥3.20.0, Node.js ≥20), see [mysql2-otel-instrumentation](https://www.npmjs.com/package/mysql2-otel-instrumentation).
Happy to open a PR for that if you're open to it.
Hi @wellwelwel, @logaretm
PR #4178 added
TracingChannelsupport to mysql2. I've builtthe subscriber side: an OpenTelemetry instrumentation package that listens to
the
mysql2:query,mysql2:execute,mysql2:connect, andmysql2:pool:connectchannels and produces proper OTel spans.
Here is the Package: mysql2-otel-instrumentation
and the Repo: mysql2-otel-instrumentation
What it does differently from @opentelemetry/instrumentation-mysql2
The existing OTel instrumentation uses RITM (require-in-the-middle) to
monkey-patch
Connection.prototype.queryandConnection.prototype.execute.This package does not monkey-patch. It is a simple
diagnostics_channelsubscriber.@opentelemetry/instrumentation-mysql2Why this belongs close to mysql2
The OTel JS ecosystem is actively moving toward library-owned instrumentation.
The most recent precedent:
@opentelemetry/instrumentation-fastifywas deprecatedin January 2025 and removed in March 2026 in favor of
@fastify/otel, maintainedby the Fastify team.
This package is the direct subscriber counterpart to the work done by @logaretm in #4178.
The ask
Would you be willing to add a link to this package in the mysql2 docs? Something minimal like:
Happy to open a PR for that if you're open to it.