Skip to content

Commit 92b3346

Browse files
committed
feat(deno): add genericPool integration
1 parent f1886be commit 92b3346

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// <reference lib="deno.ns" />
2+
3+
import { tracingChannel } from 'node:diagnostics_channel';
4+
import type { TransactionEvent } from '@sentry/core';
5+
import type { DenoClient } from '@sentry/deno';
6+
import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno';
7+
import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts';
8+
import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts';
9+
import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts';
10+
11+
function resetGlobals(): void {
12+
getCurrentScope().clear();
13+
getCurrentScope().setClient(undefined);
14+
getIsolationScope().clear();
15+
getGlobalScope().clear();
16+
}
17+
18+
/** See deno-redis.test.ts — same sink shape, deduped for clarity. */
19+
function transactionSink(): {
20+
beforeSendTransaction: (event: TransactionEvent) => null;
21+
waitFor: (predicate: (event: TransactionEvent) => boolean) => Promise<TransactionEvent>;
22+
} {
23+
const transactions: TransactionEvent[] = [];
24+
const waiters: { predicate: (e: TransactionEvent) => boolean; resolve: (e: TransactionEvent) => void }[] = [];
25+
return {
26+
beforeSendTransaction(event) {
27+
transactions.push(event);
28+
for (let i = waiters.length - 1; i >= 0; i--) {
29+
const w = waiters[i]!;
30+
if (w.predicate(event)) {
31+
waiters.splice(i, 1);
32+
w.resolve(event);
33+
}
34+
}
35+
return null;
36+
},
37+
waitFor(predicate) {
38+
const already = transactions.find(predicate);
39+
if (already) return Promise.resolve(already);
40+
return new Promise<TransactionEvent>(resolve => {
41+
waiters.push({ predicate, resolve });
42+
});
43+
},
44+
};
45+
}
46+
47+
function withTimeout<T>(p: Promise<T>, ms: number, what: string): Promise<T> {
48+
let timer: ReturnType<typeof setTimeout> | undefined;
49+
const timeout = new Promise<T>((_, reject) => {
50+
timer = setTimeout(() => reject(new Error(`Timed out waiting for ${what} after ${ms}ms`)), ms);
51+
});
52+
return Promise.race([p, timeout]).finally(() => {
53+
if (timer !== undefined) clearTimeout(timer);
54+
});
55+
}
56+
57+
Deno.test('generic-pool instrumentation: included in default integrations (Deno 2.8.0+)', () => {
58+
resetGlobals();
59+
const client = init({ dsn: 'https://username@domain/123' }) as DenoClient;
60+
const names = client.getOptions().integrations.map(i => i.name);
61+
assert(names.includes('GenericPool'), `GenericPool should be in defaults, got ${names.join(', ')}`);
62+
});
63+
64+
Deno.test('generic-pool instrumentation: orchestrion:generic-pool:acquire channel produces a nested span', async () => {
65+
resetGlobals();
66+
const sink = transactionSink();
67+
init({
68+
dsn: 'https://username@domain/123',
69+
tracesSampleRate: 1,
70+
beforeSendTransaction: sink.beforeSendTransaction,
71+
});
72+
73+
const channel = tracingChannel('orchestrion:generic-pool:acquire');
74+
75+
// The subscriber ignores the payload; the span is a fixed `generic-pool.acquire`.
76+
const ctx = { arguments: [] };
77+
78+
startSpan({ name: 'parent', op: 'test' }, () => {
79+
channel.start.runStores(ctx, () => {
80+
channel.end.publish(ctx);
81+
});
82+
channel.asyncStart.runStores(ctx, () => {
83+
channel.asyncEnd.publish(ctx);
84+
});
85+
});
86+
87+
const parent = await withTimeout(
88+
sink.waitFor(t => t.transaction === 'parent'),
89+
5000,
90+
"'parent' transaction",
91+
);
92+
93+
// generic-pool sets a name + origin but no `op`, so match on description.
94+
const poolSpan = parent.spans?.find(s => s.description === 'generic-pool.acquire');
95+
assertExists(
96+
poolSpan,
97+
`expected a generic-pool.acquire span, got descriptions: ${parent.spans?.map(s => s.description).join(', ')}`,
98+
);
99+
assertEquals(poolSpan!.data?.['sentry.origin'], 'auto.db.orchestrion.generic_pool');
100+
});

packages/deno/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export type { DenoRedisIntegrationOptions } from './integrations/redis';
118118
export {
119119
amqplibChannelIntegration,
120120
dataloaderChannelIntegration,
121+
genericPoolChannelIntegration,
121122
knexChannelIntegration,
122123
koaChannelIntegration,
123124
mongodbChannelIntegration,

packages/deno/src/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@sentry/core';
1414
import {
1515
amqplibChannelIntegration,
16+
genericPoolChannelIntegration,
1617
koaChannelIntegration,
1718
mongodbChannelIntegration,
1819
mongooseChannelIntegration,
@@ -75,6 +76,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
7576
...(MODULE_REGISTER_HOOKS_SUPPORTED
7677
? [
7778
amqplibChannelIntegration(),
79+
genericPoolChannelIntegration(),
7880
koaChannelIntegration(),
7981
mongodbChannelIntegration(),
8082
mongooseChannelIntegration(),

packages/deno/test/__snapshots__/mod.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ snapshot[`captureException 1`] = `
116116
"DenoHttp",
117117
"DenoRedis",
118118
"Amqplib",
119+
"GenericPool",
119120
"Koa",
120121
"Mongo",
121122
"Mongoose",
@@ -200,6 +201,7 @@ snapshot[`captureMessage 1`] = `
200201
"DenoHttp",
201202
"DenoRedis",
202203
"Amqplib",
204+
"GenericPool",
203205
"Koa",
204206
"Mongo",
205207
"Mongoose",
@@ -291,6 +293,7 @@ snapshot[`captureMessage twice 1`] = `
291293
"DenoHttp",
292294
"DenoRedis",
293295
"Amqplib",
296+
"GenericPool",
294297
"Koa",
295298
"Mongo",
296299
"Mongoose",
@@ -389,6 +392,7 @@ snapshot[`captureMessage twice 2`] = `
389392
"DenoHttp",
390393
"DenoRedis",
391394
"Amqplib",
395+
"GenericPool",
392396
"Koa",
393397
"Mongo",
394398
"Mongoose",

0 commit comments

Comments
 (0)