From cb45771f2cfd4f3f10082e8d2af37fe7db981ea0 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 21 Jul 2026 10:43:03 -0700 Subject: [PATCH] feat(deno): add tedious integration --- .../suites/orchestrion-tedious/test.ts | 109 ++++++++++++++++++ packages/deno/src/index.ts | 1 + packages/deno/src/sdk.ts | 2 + .../deno/test/__snapshots__/mod.test.ts.snap | 4 + 4 files changed, 116 insertions(+) create mode 100644 dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts new file mode 100644 index 000000000000..a5c22dff256b --- /dev/null +++ b/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts @@ -0,0 +1,109 @@ +// + +import { EventEmitter } from 'node:events'; +import { tracingChannel } from 'node:diagnostics_channel'; +import type { TransactionEvent } from '@sentry/core'; +import type { DenoClient } from '@sentry/deno'; +import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; +import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; +import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; + +function resetGlobals(): void { + getCurrentScope().clear(); + getCurrentScope().setClient(undefined); + getIsolationScope().clear(); + getGlobalScope().clear(); +} + +/** See deno-redis.test.ts — same sink shape, deduped for clarity. */ +function transactionSink(): { + beforeSendTransaction: (event: TransactionEvent) => null; + waitFor: (predicate: (event: TransactionEvent) => boolean) => Promise; +} { + const transactions: TransactionEvent[] = []; + const waiters: { predicate: (e: TransactionEvent) => boolean; resolve: (e: TransactionEvent) => void }[] = []; + return { + beforeSendTransaction(event) { + transactions.push(event); + for (let i = waiters.length - 1; i >= 0; i--) { + const w = waiters[i]!; + if (w.predicate(event)) { + waiters.splice(i, 1); + w.resolve(event); + } + } + return null; + }, + waitFor(predicate) { + const already = transactions.find(predicate); + if (already) return Promise.resolve(already); + return new Promise(resolve => { + waiters.push({ predicate, resolve }); + }); + }, + }; +} + +function withTimeout(p: Promise, ms: number, what: string): Promise { + let timer: ReturnType | undefined; + const timeout = new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error(`Timed out waiting for ${what} after ${ms}ms`)), ms); + }); + return Promise.race([p, timeout]).finally(() => { + if (timer !== undefined) clearTimeout(timer); + }); +} + +Deno.test('tedious instrumentation: included in default integrations (Deno 2.8.0+)', () => { + resetGlobals(); + const client = init({ dsn: 'https://username@domain/123' }) as DenoClient; + const names = client.getOptions().integrations.map(i => i.name); + assert(names.includes('Tedious'), `Tedious should be in defaults, got ${names.join(', ')}`); +}); + +Deno.test('tedious instrumentation: orchestrion:tedious:execSql channel produces a nested db span', async () => { + resetGlobals(); + const sink = transactionSink(); + init({ + dsn: 'https://username@domain/123', + tracesSampleRate: 1, + beforeSendTransaction: sink.beforeSendTransaction, + }); + + // The connection and request are `EventEmitter`s; the subscriber only traces + // when `arguments[0]` is one, and ends the span from the request's callback. + const connection = Object.assign(new EventEmitter(), { + config: { server: '127.0.0.1', userName: 'sa', options: { database: 'mydb', port: 1433 } }, + }); + const request = Object.assign(new EventEmitter(), { + sqlTextOrProcedure: 'SELECT 1', + callback: (..._args: unknown[]) => undefined, + }); + + // `connect` seeds the connection's current database, read into `db.name`. + tracingChannel('orchestrion:tedious:connect').start.publish({ self: connection, arguments: [] }); + + startSpan({ name: 'parent', op: 'test' }, () => { + tracingChannel('orchestrion:tedious:execSql').start.publish({ self: connection, arguments: [request] }); + // tedious signals completion via the request callback; the wrapper ends the span. + request.callback(); + }); + + const parent = await withTimeout( + sink.waitFor(t => t.transaction === 'parent'), + 5000, + "'parent' transaction", + ); + + const tediousSpan = parent.spans?.find(s => s.op === 'db'); + assertExists(tediousSpan, `expected a db child span, got ops: ${parent.spans?.map(s => s.op).join(', ')}`); + assertEquals(tediousSpan!.description, 'execSql mydb'); + assertEquals(tediousSpan!.data?.['db.system'], 'mssql'); + assertEquals(tediousSpan!.data?.['db.name'], 'mydb'); + assertEquals(tediousSpan!.data?.['db.user'], 'sa'); + assertEquals(tediousSpan!.data?.['db.statement'], 'SELECT 1'); + assertEquals(tediousSpan!.data?.['net.peer.name'], '127.0.0.1'); + assertEquals(tediousSpan!.data?.['net.peer.port'], 1433); + assertEquals(tediousSpan!.data?.['sentry.origin'], 'auto.db.orchestrion.tedious'); +}); diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 3d3ef7fa10f9..294e96c85de6 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -126,6 +126,7 @@ export { mysql2ChannelIntegration, postgresChannelIntegration, postgresJsChannelIntegration, + tediousChannelIntegration, } from '@sentry/server-utils/orchestrion'; // Deprecated aliases kept for back-compat. Each forwards to the shared // integration above, so its name is the shared name (e.g. `Mysql`), not the old diff --git a/packages/deno/src/sdk.ts b/packages/deno/src/sdk.ts index e3ec76137b43..b173bca91229 100644 --- a/packages/deno/src/sdk.ts +++ b/packages/deno/src/sdk.ts @@ -20,6 +20,7 @@ import { mysql2ChannelIntegration, postgresChannelIntegration, postgresJsChannelIntegration, + tediousChannelIntegration, } from '@sentry/server-utils/orchestrion'; import { DenoClient } from './client'; import { breadcrumbsIntegration } from './integrations/breadcrumbs'; @@ -81,6 +82,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] { mysql2ChannelIntegration(), postgresChannelIntegration(), postgresJsChannelIntegration(), + tediousChannelIntegration(), ] : []), contextLinesIntegration(), diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index e110dcb09e6c..99e1139a5c5c 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -123,6 +123,7 @@ snapshot[`captureException 1`] = ` "Mysql2", "Postgres", "PostgresJs", + "Tedious", "ContextLines", "NormalizePaths", "GlobalHandlers", @@ -206,6 +207,7 @@ snapshot[`captureMessage 1`] = ` "Mysql2", "Postgres", "PostgresJs", + "Tedious", "ContextLines", "NormalizePaths", "GlobalHandlers", @@ -296,6 +298,7 @@ snapshot[`captureMessage twice 1`] = ` "Mysql2", "Postgres", "PostgresJs", + "Tedious", "ContextLines", "NormalizePaths", "GlobalHandlers", @@ -393,6 +396,7 @@ snapshot[`captureMessage twice 2`] = ` "Mysql2", "Postgres", "PostgresJs", + "Tedious", "ContextLines", "NormalizePaths", "GlobalHandlers",