From 87cf01d7a0770d1dea75d15b8661a6bc735f91d4 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 21 Jul 2026 11:13:31 -0700 Subject: [PATCH] feat(deno): add genericPool integration --- .../suites/orchestrion-generic-pool/test.ts | 100 ++++++++++++++++++ packages/deno/src/index.ts | 1 + packages/deno/src/sdk.ts | 2 + .../deno/test/__snapshots__/mod.test.ts.snap | 4 + 4 files changed, 107 insertions(+) create mode 100644 dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts new file mode 100644 index 000000000000..f3b67fd84bd7 --- /dev/null +++ b/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts @@ -0,0 +1,100 @@ +// + +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('generic-pool 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('GenericPool'), `GenericPool should be in defaults, got ${names.join(', ')}`); +}); + +Deno.test('generic-pool instrumentation: orchestrion:generic-pool:acquire channel produces a nested span', async () => { + resetGlobals(); + const sink = transactionSink(); + init({ + dsn: 'https://username@domain/123', + tracesSampleRate: 1, + beforeSendTransaction: sink.beforeSendTransaction, + }); + + const channel = tracingChannel('orchestrion:generic-pool:acquire'); + + // The subscriber ignores the payload; the span is a fixed `generic-pool.acquire`. + const ctx = { arguments: [] }; + + startSpan({ name: 'parent', op: 'test' }, () => { + channel.start.runStores(ctx, () => { + channel.end.publish(ctx); + }); + channel.asyncStart.runStores(ctx, () => { + channel.asyncEnd.publish(ctx); + }); + }); + + const parent = await withTimeout( + sink.waitFor(t => t.transaction === 'parent'), + 5000, + "'parent' transaction", + ); + + // generic-pool sets a name + origin but no `op`, so match on description. + const poolSpan = parent.spans?.find(s => s.description === 'generic-pool.acquire'); + assertExists( + poolSpan, + `expected a generic-pool.acquire span, got descriptions: ${parent.spans?.map(s => s.description).join(', ')}`, + ); + assertEquals(poolSpan!.data?.['sentry.origin'], 'auto.db.orchestrion.generic_pool'); +}); diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 294e96c85de6..95310d319a1e 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -118,6 +118,7 @@ export type { DenoRedisIntegrationOptions } from './integrations/redis'; export { amqplibChannelIntegration, dataloaderChannelIntegration, + genericPoolChannelIntegration, knexChannelIntegration, koaChannelIntegration, mongodbChannelIntegration, diff --git a/packages/deno/src/sdk.ts b/packages/deno/src/sdk.ts index b173bca91229..5c0c237207f1 100644 --- a/packages/deno/src/sdk.ts +++ b/packages/deno/src/sdk.ts @@ -13,6 +13,7 @@ import { } from '@sentry/core'; import { amqplibChannelIntegration, + genericPoolChannelIntegration, koaChannelIntegration, mongodbChannelIntegration, mongooseChannelIntegration, @@ -75,6 +76,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] { ...(MODULE_REGISTER_HOOKS_SUPPORTED ? [ amqplibChannelIntegration(), + genericPoolChannelIntegration(), koaChannelIntegration(), mongodbChannelIntegration(), mongooseChannelIntegration(), diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index 99e1139a5c5c..2c8a22a7782d 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -116,6 +116,7 @@ snapshot[`captureException 1`] = ` "DenoHttp", "DenoRedis", "Amqplib", + "GenericPool", "Koa", "Mongo", "Mongoose", @@ -200,6 +201,7 @@ snapshot[`captureMessage 1`] = ` "DenoHttp", "DenoRedis", "Amqplib", + "GenericPool", "Koa", "Mongo", "Mongoose", @@ -291,6 +293,7 @@ snapshot[`captureMessage twice 1`] = ` "DenoHttp", "DenoRedis", "Amqplib", + "GenericPool", "Koa", "Mongo", "Mongoose", @@ -389,6 +392,7 @@ snapshot[`captureMessage twice 2`] = ` "DenoHttp", "DenoRedis", "Amqplib", + "GenericPool", "Koa", "Mongo", "Mongoose",