Skip to content

Commit 4d7ddbf

Browse files
committed
test(node): Add tests for genericPoolIntegration
Signed-off-by: Kaung Zin Hein <[email protected]>
1 parent aaae010 commit 4d7ddbf

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

dev-packages/node-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"cors": "^2.8.5",
4545
"cron": "^3.1.6",
4646
"express": "^4.17.3",
47+
"generic-pool": "3.9.0",
4748
"graphql": "^16.3.0",
4849
"http-terminator": "^3.2.0",
4950
"ioredis": "^5.4.1",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2+
const Sentry = require('@sentry/node');
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
});
10+
11+
// Stop the process from exiting before the transaction is sent
12+
setInterval(() => {}, 1000);
13+
14+
const mysql = require('mysql');
15+
const genericPool = require('generic-pool');
16+
17+
const factory = {
18+
create: function () {
19+
return mysql.createConnection({
20+
user: 'root',
21+
password: 'docker',
22+
});
23+
},
24+
destroy: function (client) {
25+
client.end(err => {
26+
if (err) {
27+
// eslint-disable-next-line no-console
28+
console.error('Error while disconnecting MySQL:', err);
29+
}
30+
});
31+
},
32+
};
33+
34+
const opts = {
35+
max: 10,
36+
min: 2,
37+
};
38+
39+
const myPool = genericPool.createPool(factory, opts);
40+
41+
async function run() {
42+
await Sentry.startSpan(
43+
{
44+
op: 'transaction',
45+
name: 'Test Transaction',
46+
},
47+
async () => {
48+
try {
49+
const client1 = await myPool.acquire();
50+
const client2 = await myPool.acquire();
51+
52+
client1.query('SELECT NOW()', function () {
53+
myPool.release(client1);
54+
});
55+
56+
client2.query('SELECT 1 + 1 AS solution', function () {
57+
myPool.release(client2);
58+
});
59+
} catch (err) {
60+
// eslint-disable-next-line no-console
61+
console.error('Error while pooling MySQL:', err);
62+
} finally {
63+
await myPool.drain();
64+
await myPool.clear();
65+
}
66+
},
67+
);
68+
}
69+
70+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
71+
run();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
2+
3+
describe('genericPool auto instrumentation', () => {
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
test('should auto-instrument `genericPool` package when calling pool.require()', done => {
9+
const EXPECTED_TRANSACTION = {
10+
transaction: 'Test Transaction',
11+
spans: expect.arrayContaining([
12+
expect.objectContaining({
13+
description: 'generic-pool.aquire',
14+
origin: 'auto.db.otel.generic-pool',
15+
data: {
16+
'sentry.origin': 'auto.db.otel.generic-pool',
17+
},
18+
status: 'ok',
19+
}),
20+
21+
expect.objectContaining({
22+
description: 'generic-pool.aquire',
23+
origin: 'auto.db.otel.generic-pool',
24+
data: {
25+
'sentry.origin': 'auto.db.otel.generic-pool',
26+
},
27+
status: 'ok',
28+
}),
29+
]),
30+
};
31+
32+
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
33+
});
34+
});

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@opentelemetry/instrumentation-express": "0.41.1",
7474
"@opentelemetry/instrumentation-fastify": "0.38.0",
7575
"@opentelemetry/instrumentation-fs": "0.14.0",
76+
"@opentelemetry/instrumentation-generic-pool": "0.38.0",
7677
"@opentelemetry/instrumentation-graphql": "0.42.0",
7778
"@opentelemetry/instrumentation-hapi": "0.40.0",
7879
"@opentelemetry/instrumentation-http": "0.52.1",
@@ -85,7 +86,6 @@
8586
"@opentelemetry/instrumentation-nestjs-core": "0.39.0",
8687
"@opentelemetry/instrumentation-pg": "0.43.0",
8788
"@opentelemetry/instrumentation-redis-4": "0.41.0",
88-
"@@opentelemetry/instrumentation-generic-pool": "0.38.0",
8989
"@opentelemetry/resources": "^1.25.1",
9090
"@opentelemetry/sdk-trace-base": "^1.25.1",
9191
"@opentelemetry/semantic-conventions": "^1.25.1",

0 commit comments

Comments
 (0)