8000 test(node): Add integration test for Postgres auto-instrumentation. (… · michax/sentry-javascript@4260f12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4260f12

Browse files
authored
test(node): Add integration test for Postgres auto-instrumentation. (getsentry#4804)
1 parent 918af34 commit 4260f12

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
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/pg": "^8.6.5",
1819
"express": "^4.17.3",
1920
"nock": "^13.1.0",
21+
"pg": "^8.7.3",
2022
"portfinder": "^1.0.28"
2123
}
2224
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import '@sentry/tracing';
2+
3+
import * as Sentry from '@sentry/node';
4+
import pg from 'pg';
5+
6+
Sentry.init({
7+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
8+
release: '1.0',
9+
tracesSampleRate: 1.0,
10+
});
11+
12+
const transaction = Sentry.startTransaction({
13+
op: 'transaction',
14+
name: 'Test Transaction',
15+
});
16+
17+
Sentry.configureScope(scope => {
18+
scope.setSpan(transaction);
19+
});
20+
21+
const client = new pg.Client();
22+
client.query('SELECT * FROM foo where bar ilike "baz%"', ['a', 'b'], () =>
23+
client.query('SELECT * FROM bazz', () => {
24+
client.query('SELECT NOW()', () => transaction.finish());
25+
}),
26+
);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';
2+
3+
class PgClient {
4+
// https://node-postgres.com/api/client#clientquery
5+
public query(_text: unknown, values: unknown, callback?: () => void) {
6+
if (typeof callback === 'function') {
7+
callback();
8+
return;
9+
}
10+
11+
if (typeof values === 'function') {
12+
values();
13+
return;
14+
}
15+
16+
return Promise.resolve();
17+
}
18+
}
19+
20+
beforeAll(() => {
21+
jest.mock('pg', () => {
22+
return {
23+
Client: PgClient,
24+
native: {
25+
Client: PgClient,
26+
},
27+
};
28+
});
29+
});
30+
31+
test('should auto-instrument `pg` package.', async () => {
32+
const url = await runServer(__dirname);
33+
const envelope = await getEnvelopeRequest(url);
34+
35+
expect(envelope).toHaveLength(3);
36+
37+
assertSentryTransaction(envelope[2], {
38+
transaction: 'Test Transaction',
39+
spans: [
40+
{
41+
description: 'SELECT * FROM foo where bar ilike "baz%"',
42+
o 6D4E p: 'db',
43+
},
44+
{
45+
description: 'SELECT * FROM bazz',
46+
op: 'db',
47+
},
48+
{
49+
description: 'SELECT NOW()',
50+
op: 'db',
51+
},
52+
],
53+
});
54+
});

yarn.lock

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,6 +3842,15 @@
38423842
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.0.tgz#38590dc2c3cf5717154064e3ee9b6947ee21b299"
38433843
integrity sha512-oPwPSj4a1wu9rsXTEGIJz91ISU725t0BmSnUhb57sI+M8XEmvUop84lzuiYdq0Y5M6xLY8DBPg0C2xEQKLyvBA==
38443844

3845+
"@types/pg@^8.6.5":
3846+
version "8.6.5"
3847+
resolved "https://registry.yarnpkg.com/@types/pg/-/pg-8.6.5.tgz#2dce9cb468a6a5e0f1296a59aea3ac75dd27b702"
3848+
integrity sha512-tOkGtAqRVkHa/PVZicq67zuujI4Oorfglsr2IbKofDwBSysnaqSx7W1mDqFqdkGE6Fbgh+PZAl0r/BWON/mozw==
3849+
dependencies:
3850+
"@types/node" "*"
3851+
pg-protocol "*"
3852+
pg-types "^2.2.0"
3853+
38453854
"@types/prop-types@*":
38463855
version "15.7.3"
38473856
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
@@ -6841,6 +6850,11 @@ buffer-from@1.x, buffer-from@^1.0.0:
68416850
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
68426851
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
68436852

6853+
buffer-writer@2.0.0:
6854+
version "2.0.0"
6855+
resolved "https://registry.yarnpkg.com/buffer-writer/-/buffer-writer-2.0.0.tgz#ce7eb81a38f7829db09c873f2fbb792c0c98ec04"
6856+
integrity sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==
6857+
68446858
buffer-xor@^1.0.3:
68456859
version "1.0.3"
68466860
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9"
@@ -16727,6 +16741,11 @@ package-name-regex@2.0.5:
1672716741
resolved "https://registry.yarnpkg.com/package-name-regex/-/package-name-regex-2.0.5.tgz#5e3548ffe3dba340b9779d28a024bdb4a19f055b"
1672816742
integrity sha512-F0lX+FBs/Bo7KWY6EuUXj+oarXU0Og1R2Zdg3F/fVcNw3pPQAKFKxUrugno0Ds5NUztlx/gRLnQW9MF+7VTqAw==
1672916743

16744+
packet-reader@1.0.0:
16745+
version "1.0.0"
16746+
resolved "https://registry.yarnpkg.com/packet-reader/-/packet-reader-1.0.0.tgz#9238e5480dedabacfe1fe3f2771063f164157d74"
16747+
integrity sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==
16748+
1673016749
pacote@^9.5.0:
1673116750
version "9.5.12"
1673216751
resolved "https://registry.yarnpkg.com/pacote/-/pacote-9.5.12.tgz#1e11dd7a8d736bcc36b375a9804d41bb0377bf66"
@@ -17074,6 +17093,57 @@ performance-now@^2.1.0:
1707417093
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
1707517094
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
1707617095

17096+
pg-connection-string@^2.5.0:
17097+
version "2.5.0"
17098+
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34"
17099+
integrity sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==
17100+
17101+
pg-int8@1.0.1:
17102+
version "1.0.1"
17103+
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
17104+
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==
17105+
17106+
pg-pool@^3.5.1:
17107+
version "3.5.1"
17108+
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.5.1.tgz#f499ce76f9bf5097488b3b83b19861f28e4ed905"
17109+
integrity sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==
17110+
17111+
pg-protocol@*, pg-protocol@^1.5.0:
17112+
version "1.5.0"
17113+
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.5.0.tgz#b5dd452257314565e2d54ab3c132adc46565a6a0"
17114+
integrity sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ==
17115+
17116+
pg-types@^2.1.0, pg-types@^2.2.0:
17117+
version "2.2.0"
17118+
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.2.0.tgz#2d0250d636454f7cfa3b6ae0382fdfa8063254a3"
17119+
integrity sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==
17120+
dependencies:
17121+
pg-int8 "1.0.1"
17122+
postgres-array "~2.0.0"
17123+
postgres-bytea "~1.0.0"
17124+
postgres-date "~1.0.4"
17125+
postgres-interval "^1.1.0"
17126+
17127+
pg@^8.7.3:
17128+
version "8.7.3"
17129+
resolved "https://registry.yarnpkg.com/pg/-/pg-8.7.3.tgz#8a5bdd664ca4fda4db7997ec634c6e5455b27c44"
17130+
integrity sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==
17131+
dependencies:
17132+
buffer-writer "2.0.0"
17133+
packet-reader "1.0.0"
17134+
pg-connection-string "^2.5.0"
17135+
pg-pool "^3.5.1"
17136+
pg-protocol "^1.5.0"
17137+
pg-types "^2.1.0"
17138+
pgpass "1.x"
17139+
17140+
pgpass@1.x:
17141+
version "1.0.5"
17142+
resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.5.tgz#9b873e4a564bb10fa7a7dbd55312728d422a223d"
17143+
integrity sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==
17144+
dependencies:
17145+
split2 "^4.1.0"
17146+
1707717147
picocolors@^1.0.0:
1707817148
version "1.0.0"
1707917149
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
@@ -17617,6 +17687,28 @@ postcss@^8.2.15:
1761717687
picocolors "^1.0.0"
1761817688
source-map-js "^1.0.1"
1761917689

17690+
postgres-array@~2.0.0:
17691+
version "2.0.0"
17692+
resolved "https://registry.yarnpkg.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
17693+
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==
17694+
17695+
postgres-bytea@~1.0.0:
17696+
version "1.0.0"
17697+
resolved "https://registry.yarnpkg.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35"
17698+
integrity sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=
17699+
17700+
postgres-date@~1.0.4:
17701+
version "1.0.7"
17702+
resolved "https://registry.yarnpkg.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8"
17703+
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==
17704+
17705+
postgres-interval@^1.1.0:
17706+
version "1.2.0"
17707+
resolved "https://registry.yarnpkg.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695"
17708+
integrity sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==
17709+
dependencies:
17710+
xtend "^4.0.0"
17711+
1762017712
precinct@^7.0.0:
1762117713
version "7.1.0"
1762217714
resolved "https://registry.yarnpkg.com/precinct/-/precinct-7.1.0.tgz#a0311e0b59029647eaf57c2d30b8efa9c85d129a"
@@ -19920,6 +20012,11 @@ split2@^3.0.0:
1992020012
dependencies:
1992120013
readable-stream "^3.0.0"
1992220014

20015+
split2@^4.1.0:
20016+
version "4.1.0"
20017+
resolved "https://registry.yarnpkg.com/split2/-/split2-4.1.0.tgz#101907a24370f85bb782f08adaabe4e281ecf809"
20018+
integrity sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==
20019+
1992320020
split@0.3:
1992420021
version "0.3.3"
1992520022
resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f"

0 commit comments

Comments
 (0)
0