Skip to content

OTel instrumentation package for the TracingChannel API (subscriber side of #4178) #4217

@Vunovati

Description

@Vunovati

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

What it does differently from @opentelemetry/instrumentation-mysql2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions