From d5255472271c1901ecbc5addce956fd5cf93f5e4 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 12 Aug 2026 11:33:06 +0200 Subject: [PATCH] ref(server-utils): Streamline mysql2 integration --- packages/server-utils/src/index.ts | 1 - .../{mysql2.ts => mysql2/index.ts} | 12 ++++---- .../mysql2/mysql2-dc-subscriber.ts | 2 +- packages/server-utils/src/mysql2/index.ts | 30 ------------------- .../test/mysql2/mysql2-dc-subscriber.test.ts | 2 +- 5 files changed, 8 insertions(+), 39 deletions(-) rename packages/server-utils/src/integrations/{mysql2.ts => mysql2/index.ts} (93%) rename packages/server-utils/src/{ => integrations}/mysql2/mysql2-dc-subscriber.ts (98%) delete mode 100644 packages/server-utils/src/mysql2/index.ts diff --git a/packages/server-utils/src/index.ts b/packages/server-utils/src/index.ts index 043896b5cabe..a6eb08e78e71 100644 --- a/packages/server-utils/src/index.ts +++ b/packages/server-utils/src/index.ts @@ -1,7 +1,6 @@ export * from './exports'; // Exports using diagnostics channels -export { mysql2Integration } from './mysql2'; export { instrumentPrisma, prismaIntegration } from './prisma'; export type { PrismaInstrumentationConfig, PrismaOptions } from './prisma'; export { bindTracingChannelToSpan } from './tracing-channel'; diff --git a/packages/server-utils/src/integrations/mysql2.ts b/packages/server-utils/src/integrations/mysql2/index.ts similarity index 93% rename from packages/server-utils/src/integrations/mysql2.ts rename to packages/server-utils/src/integrations/mysql2/index.ts index 2622dcbf7f9e..199ae878b664 100644 --- a/packages/server-utils/src/integrations/mysql2.ts +++ b/packages/server-utils/src/integrations/mysql2/index.ts @@ -8,12 +8,12 @@ import { startInactiveSpan, waitForTracingChannelBinding, } from '@sentry/core'; -import { subscribeMysql2DiagnosticChannels } from '../mysql2/mysql2-dc-subscriber'; -import type { ChannelName } from '../orchestrion/channels'; -import { CHANNELS } from '../orchestrion/channels'; -import { bindTracingChannelToSpan } from '../tracing-channel'; -import { mysql2ModuleNames } from '../orchestrion/config/mysql2'; -import { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation'; +import { subscribeMysql2DiagnosticChannels } from './mysql2-dc-subscriber'; +import type { ChannelName } from '../../orchestrion/channels'; +import { CHANNELS } from '../../orchestrion/channels'; +import { bindTracingChannelToSpan } from '../../tracing-channel'; +import { mysql2ModuleNames } from '../../orchestrion/config/mysql2'; +import { invokeOrchestrionInstrumentation } from '../../orchestrion/instrumentation'; import { DB_NAME, DB_STATEMENT, diff --git a/packages/server-utils/src/mysql2/mysql2-dc-subscriber.ts b/packages/server-utils/src/integrations/mysql2/mysql2-dc-subscriber.ts similarity index 98% rename from packages/server-utils/src/mysql2/mysql2-dc-subscriber.ts rename to packages/server-utils/src/integrations/mysql2/mysql2-dc-subscriber.ts index bf3c1fb462a3..2dcf1849ed89 100644 --- a/packages/server-utils/src/mysql2/mysql2-dc-subscriber.ts +++ b/packages/server-utils/src/integrations/mysql2/mysql2-dc-subscriber.ts @@ -13,7 +13,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startInactiveSpan, } from '@sentry/core'; -import { bindTracingChannelToSpan } from '../tracing-channel'; +import { bindTracingChannelToSpan } from '../../tracing-channel'; // Channel names published by mysql2 >= 3.20.0 (see mysql2 `lib/tracing.js`). // Hardcoded so the subscriber does not have to import mysql2 — the channels diff --git a/packages/server-utils/src/mysql2/index.ts b/packages/server-utils/src/mysql2/index.ts deleted file mode 100644 index d04758fbc96d..000000000000 --- a/packages/server-utils/src/mysql2/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { defineIntegration, type IntegrationFn, waitForTracingChannelBinding } from '@sentry/core'; -import * as dc from 'node:diagnostics_channel'; -import { subscribeMysql2DiagnosticChannels } from './mysql2-dc-subscriber'; - -const _mysql2Integration = (() => { - return { - name: 'Mysql2', - setupOnce() { - // Bail on Node <= 18.18.0, where `tracingChannel` does not exist. - if (!dc.tracingChannel) { - return; - } - - // Subscribe to mysql2's native tracing channels (mysql2 >= 3.20.0). - // This is a no-op on versions that don't publish to the channels, so it is always safe to call. - waitForTracingChannelBinding(() => { - subscribeMysql2DiagnosticChannels(dc.tracingChannel); - }); - }, - }; -}) satisfies IntegrationFn; - -/** - * Auto-instrument the [mysql2](https://www.npmjs.com/package/mysql2) library via its native - * `node:diagnostics_channel` tracing channels (mysql2 >= 3.20.0). - * - * On older mysql2 versions the channels are never published to, so this integration is inert and - * the vendored OTel instrumentation (gated to `< 3.20.0`) handles instrumentation instead. - */ -export const mysql2Integration = defineIntegration(_mysql2Integration); diff --git a/packages/server-utils/test/mysql2/mysql2-dc-subscriber.test.ts b/packages/server-utils/test/mysql2/mysql2-dc-subscriber.test.ts index e8f0bcb05554..79f2ece2ae53 100644 --- a/packages/server-utils/test/mysql2/mysql2-dc-subscriber.test.ts +++ b/packages/server-utils/test/mysql2/mysql2-dc-subscriber.test.ts @@ -25,7 +25,7 @@ import { MYSQL2_DC_CHANNEL_QUERY, type MySQL2TracingChannelFactory, subscribeMysql2DiagnosticChannels, -} from '../../src/mysql2/mysql2-dc-subscriber'; +} from '../../src/integrations/mysql2/mysql2-dc-subscriber'; interface TestStore { scope: Scope;