Skip to content

feat(mysql2): Instrument mysql2 >= 3.20.0 via native tracing channels#21824

Draft
logaretm wants to merge 2 commits into
developfrom
awad/instrument-mysql2-via-tc
Draft

feat(mysql2): Instrument mysql2 >= 3.20.0 via native tracing channels#21824
logaretm wants to merge 2 commits into
developfrom
awad/instrument-mysql2-via-tc

Conversation

@logaretm

@logaretm logaretm commented Jun 26, 2026

Copy link
Copy Markdown
Member

Instruments mysql2 >= 3.20.0 through its native diagnostics_channel tracing channels instead of monkey-patching, the same way we did for redis/ioredis and mongoose. mysql2 publishes on mysql2:query, mysql2:execute, mysql2:connect and mysql2:pool:connect.

The channel path emits the stable DB semconv (db.system.name, db.query.text, db.operation.name, db.namespace, server.address, server.port), so there's an attribute drift here. We could match the legacy attributes and drop them at v11 instead if that's what we want.

One mysql2-specific thing: the mysql2:query channel publishes the already-formatted SQL with values inlined, so I run it through the OTel db.query.text sanitizer.

mysql2 >= 3.20.0 publishes its operations over node:diagnostics_channel
(mysql2:query / :execute / :connect / :pool:connect), so the SDK can
subscribe to those channels instead of monkey-patching, the same way we
did for redis/ioredis and mongoose.

The subscription lives in server-utils as mysql2Integration, and the node
mysql2Integration extends it (via extendIntegration) while keeping the
vendored OTel patcher for mysql2 < 3.20.0, which is now gated to that range
so the two paths never double-instrument.

The channel path emits the stable DB semconv (db.system.name,
db.query.text, db.operation.name, db.namespace, server.address,
server.port), so there's the same attribute drift we accepted for
redis/mongoose. mysql2 publishes already-formatted SQL, so db.query.text
is run through the OTel sanitizer and raw values are never attached.
Comment thread packages/server-utils/src/index.ts
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.48 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.97 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.76 kB - -
@sentry/browser (incl. Tracing, Replay) 85.22 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB - -
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.63 kB - -
@sentry/vue (incl. Tracing) 47.84 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.89 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.4 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB - -
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.69 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 77.54 kB - -
@sentry/core/browser 63.88 kB - -
@sentry/node-core 61.51 kB -0.01% -1 B 🔽
@sentry/node 123.77 kB +0.24% +285 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.4 kB -0.01% -1 B 🔽
@sentry/node - without tracing 73.61 kB - -
@sentry/aws-serverless 84.4 kB - -
@sentry/cloudflare (withSentry) - minified 180.31 kB - -
@sentry/cloudflare (withSentry) 446.24 kB - -

View base workflow run

The mysql2-tracing-channel docker-compose bound host port 3307, which
collides with the knex/mysql2 suite. When both run in parallel the second
container fails with 'port is already allocated'. Switch to 3308.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant