Skip to content

Commit 81407c4

Browse files
onurtemizkanLuca Forstner
authored and
Luca Forstner
committed
test(node): Add integration test for MySQL auto-instrumentation (#4806)
1 parent cba5059 commit 81407c4

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

packages/node-integration-tests/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"test:watch": "yarn test --watch"
1616
},
1717
"dependencies": {
18+
"@types/mysql": "^2.15.21",
1819
"@types/pg": "^8.6.5",
1920
"express": "^4.17.3",
21+
"mysql": "^2.18.1",
2022
"nock": "^13.1.0",
2123
"pg": "^8.7.3",
2224
"portfinder": "^1.0.28"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import '@sentry/tracing';
2+
3+
import * as Sentry from '@sentry/node';
4+
import mysql from 'mysql';
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
release: '1.0',
9+
tracesSampleRate: 1.0,
10+
});
11+
12+
const connection = mysql.createConnection({
13+
user: 'root',
14+
password: 'docker',
15+
});
16+
17+
connection.connect(function (err: unknown) {
18+
if (err) {
19+
return;
20+
}
21+
});
22+
23+
const transaction = Sentry.startTransaction({
24+
op: 'transaction',
25+
name: 'Test Transaction',
26+
});
27+
28+
Sentry.configureScope(scope => {
29+
scope.setSpan(transaction);
30+
});
31+
32+
connection.query('SELECT 1 + 1 AS solution', function () {
33+
connection.query('SELECT NOW()', ['1', '2'], () => {
34+
if (transaction) transaction.finish();
35+
connection.end();
36+
});
37+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';
2+
3+
test('should auto-instrument `mysql` package.', async () => {
4+
const url = await runServer(__dirname);
5+
const envelope = await getEnvelopeRequest(url);
6+
7+
expect(envelope).toHaveLength(3);
8+
9+
assertSentryTransaction(envelope[2], {
10+
transaction: 'Test Transaction',
11+
spans: [
12+
{
13+
description: 'SELECT 1 + 1 AS solution',
14+
op: 'db',
15+
},
16+
17+
{
18+
description: 'SELECT NOW()',
19+
op: 'db',
20+
},
21+
],
22+
});
23+
});

yarn.lock

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3812,6 +3812,13 @@
38123812
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
38133813
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
38143814

3815+
"@types/mysql@^2.15.21":
3816+
version "2.15.21"
3817+
resolved "https://registry.yarnpkg.com/@types/mysql/-/mysql-2.15.21.tgz#7516cba7f9d077f980100c85fd500c8210bd5e45"
3818+
integrity sha512-NPotx5CVful7yB+qZbWtXL2fA4e7aEHkihHLjklc6ID8aq7bhguHgeIoC1EmSNTAuCgI6ZXrjt2ZSaXnYX0EUg==
3819+
dependencies:
3820+
"@types/node" "*"
3821+
38153822
"@types/node@*", "@types/node@>= 8", "@types/node@>=12.12.47", "@types/node@^14.6.4":
38163823
version "14.14.37"
38173824
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.37.tgz#a3dd8da4eb84a996c36e331df98d82abd76b516e"
@@ -5959,6 +5966,11 @@ big.js@^6.0.0:
59595966
resolved "https://registry.yarnpkg.com/big.js/-/big.js-6.0.3.tgz#8b4d99ac7023668e0e465d3f78c23b8ac29ad381"
59605967
integrity sha512-n6yn1FyVL1EW2DBAr4jlU/kObhRzmr+NNRESl65VIOT8WBJj/Kezpx2zFdhJUqYI6qrtTW7moCStYL5VxeVdPA==
59615968

5969+
5970+
version "9.0.0"
5971+
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.0.tgz#805880f84a329b5eac6e7cb6f8274b6d82bdf075"
5972+
integrity sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==
5973+
59625974
bignumber.js@^9.0.0:
59635975
version "9.0.1"
59645976
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5"
@@ -15758,6 +15770,16 @@ [email protected], mute-stream@~0.0.4:
1575815770
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
1575915771
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
1576015772

15773+
mysql@^2.18.1:
15774+
version "2.18.1"
15775+
resolved "https://registry.yarnpkg.com/mysql/-/mysql-2.18.1.tgz#2254143855c5a8c73825e4522baf2ea021766717"
15776+
integrity sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==
15777+
dependencies:
15778+
bignumber.js "9.0.0"
15779+
readable-stream "2.3.7"
15780+
safe-buffer "5.1.2"
15781+
sqlstring "2.3.1"
15782+
1576115783
nan@^2.12.1:
1576215784
version "2.14.2"
1576315785
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
@@ -18444,7 +18466,7 @@ read@1, read@~1.0.1:
1844418466
dependencies:
1844518467
mute-stream "~0.0.4"
1844618468

18447-
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6:
18469+
"readable-stream@1 || 2", readable-stream@2.3.7, readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6:
1844818470
version "2.3.7"
1844918471
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
1845018472
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
@@ -20041,6 +20063,11 @@ sprintf-js@~1.0.2:
2004120063
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
2004220064
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
2004320065

20066+
20067+
version "2.3.1"
20068+
resolved "https://registry.yarnpkg.com/sqlstring/-/sqlstring-2.3.1.tgz#475393ff9e91479aea62dcaf0ca3d14983a7fb40"
20069+
integrity sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=
20070+
2004420071
sri-toolbox@^0.2.0:
2004520072
version "0.2.0"
2004620073
resolved "https://registry.yarnpkg.com/sri-toolbox/-/sri-toolbox-0.2.0.tgz#a7fea5c3fde55e675cf1c8c06f3ebb5c2935835e"

0 commit comments

Comments
 (0)