Skip to content

Commit 90cb4d1

Browse files
authored
test(node): Add pg-native tests (#15465)
Moved the `pg` and `pg-native` dependencies inside the test suite. This keeps `libpq` out of the root `yarn.lock`.
1 parent 7cdc88d commit 90cb4d1

File tree

8 files changed

+289
-48
lines changed

8 files changed

+289
-48
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"nock": "^13.5.5",
6161
"node-cron": "^3.0.3",
6262
"node-schedule": "^2.1.1",
63-
"pg": "^8.7.3",
63+
"pg": "8.16.0",
6464
"proxy": "^2.1.1",
6565
"redis-4": "npm:redis@^4.6.14",
6666
"reflect-metadata": "0.2.1",

dev-packages/node-integration-tests/suites/tracing/postgres/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
restart: always
77
container_name: integration-tests-postgres
88
ports:
9-
- '5444:5432'
9+
- '5494:5432'
1010
environment:
1111
POSTGRES_USER: test
1212
POSTGRES_PASSWORD: test
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "sentry-postgres-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"engines": {
7+
"node": ">=18"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"pg": "8.16.0",
14+
"pg-native": "3.5.0"
15+
}
16+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 { native } = require('pg');
15+
16+
const { Client } = native;
17+
18+
const client = new Client({ port: 5494, user: 'test', password: 'test', database: 'tests' });
19+
20+
async function run() {
21+
await Sentry.startSpan(
22+
{
23+
name: 'Test Transaction',
24+
op: 'transaction',
25+
},
26+
async () => {
27+
try {
28+
await client.connect();
29+
30+
await client
31+
.query(
32+
'CREATE TABLE "NativeUser" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));',
33+
)
34+
.catch(() => {
35+
// if this is not a fresh database, the table might already exist
36+
});
37+
38+
await client.query('INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)', ['tim', '[email protected]']);
39+
await client.query('SELECT * FROM "NativeUser"');
40+
} finally {
41+
await client.end();
42+
}
43+
},
44+
);
45+
}
46+
47+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
48+
run();

dev-packages/node-integration-tests/suites/tracing/postgres/scenario.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ setInterval(() => {}, 1000);
1313

1414
const { Client } = require('pg');
1515

16-
const client = new Client({ port: 5444, user: 'test', password: 'test', database: 'tests' });
16+
const client = new Client({ port: 5494, user: 'test', password: 'test', database: 'tests' });
1717

1818
async function run() {
1919
await Sentry.startSpan(

dev-packages/node-integration-tests/suites/tracing/postgres/test.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';
22
import { createRunner } from '../../../utils/runner';
33

44
describe('postgres auto instrumentation', () => {
5-
test('should auto-instrument `pg` package', { timeout: 60_000 }, async () => {
5+
test('should auto-instrument `pg` package', { timeout: 90_000 }, async () => {
66
const EXPECTED_TRANSACTION = {
77
transaction: 'Test Transaction',
88
spans: expect.arrayContaining([
@@ -47,7 +47,66 @@ describe('postgres auto instrumentation', () => {
4747
};
4848

4949
await createRunner(__dirname, 'scenario.js')
50-
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] })
50+
.withDockerCompose({
51+
workingDirectory: [__dirname],
52+
readyMatches: ['port 5432'],
53+
setupCommand: 'yarn',
54+
})
55+
.expect({ transaction: EXPECTED_TRANSACTION })
56+
.start()
57+
.completed();
58+
});
59+
60+
test('should auto-instrument `pg-native` package', { timeout: 90_000 }, async () => {
61+
const EXPECTED_TRANSACTION = {
62+
transaction: 'Test Transaction',
63+
spans: expect.arrayContaining([
64+
expect.objectContaining({
65+
data: expect.objectContaining({
66+
'db.system': 'postgresql',
67+
'db.name': 'tests',
68+
'sentry.origin': 'manual',
69+
'sentry.op': 'db',
70+
}),
71+
description: 'pg.connect',
72+
op: 'db',
73+
status: 'ok',
74+
}),
75+
expect.objectContaining({
76+
data: expect.objectContaining({
77+
'db.system': 'postgresql',
78+
'db.name': 'tests',
79+
'db.statement': 'INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)',
80+
'sentry.origin': 'auto.db.otel.postgres',
81+
'sentry.op': 'db',
82+
}),
83+
description: 'INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)',
84+
op: 'db',
85+
status: 'ok',
86+
origin: 'auto.db.otel.postgres',
87+
}),
88+
expect.objectContaining({
89+
data: expect.objectContaining({
90+
'db.system': 'postgresql',
91+
'db.name': 'tests',
92+
'db.statement': 'SELECT * FROM "NativeUser"',
93+
'sentry.origin': 'auto.db.otel.postgres',
94+
'sentry.op': 'db',
95+
}),
96+
description: 'SELECT * FROM "NativeUser"',
97+
op: 'db',
98+
status: 'ok',
99+
origin: 'auto.db.otel.postgres',
100+
}),
101+
]),
102+
};
103+
104+
await createRunner(__dirname, 'scenario-native.js')
105+
.withDockerCompose({
106+
workingDirectory: [__dirname],
107+
readyMatches: ['port 5432'],
108+
setupCommand: 'yarn',
109+
})
51110
.expect({ transaction: EXPECTED_TRANSACTION })
52111
.start()
53112
.completed();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
6+
version "1.5.0"
7+
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
8+
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
9+
dependencies:
10+
file-uri-to-path "1.0.0"
11+
12+
13+
version "1.0.0"
14+
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
15+
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
16+
17+
libpq@^1.8.15:
18+
version "1.8.15"
19+
resolved "https://registry.yarnpkg.com/libpq/-/libpq-1.8.15.tgz#bf9cea8e59e1a4a911d06df01d408213a09925ad"
20+
integrity sha512-4lSWmly2Nsj3LaTxxtFmJWuP3Kx+0hYHEd+aNrcXEWT0nKWaPd9/QZPiMkkC680zeALFGHQdQWjBvnilL+vgWA==
21+
dependencies:
22+
bindings "1.5.0"
23+
nan "~2.22.2"
24+
25+
nan@~2.22.2:
26+
version "2.22.2"
27+
resolved "https://registry.yarnpkg.com/nan/-/nan-2.22.2.tgz#6b504fd029fb8f38c0990e52ad5c26772fdacfbb"
28+
integrity sha512-DANghxFkS1plDdRsX0X9pm0Z6SJNN6gBdtXfanwoZ8hooC5gosGFSBGRYHUVPz1asKA/kMRqDRdHrluZ61SpBQ==
29+
30+
pg-cloudflare@^1.2.5:
31+
version "1.2.5"
32+
resolved "https://registry.yarnpkg.com/pg-cloudflare/-/pg-cloudflare-1.2.5.tgz#2e3649c38a7a9c74a7e5327c8098a2fd9af595bd"
33+
integrity sha512-OOX22Vt0vOSRrdoUPKJ8Wi2OpE/o/h9T8X1s4qSkCedbNah9ei2W2765be8iMVxQUsvgT7zIAT2eIa9fs5+vtg==
34+
35+
pg-connection-string@^2.9.0:
36+
version "2.9.0"
37+
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.9.0.tgz#f75e06591fdd42ec7636fe2c6a03febeedbec9bf"
38+
integrity sha512-P2DEBKuvh5RClafLngkAuGe9OUlFV7ebu8w1kmaaOgPcpJd1RIFh7otETfI6hAR8YupOLFTY7nuvvIn7PLciUQ==
39+
40+
41+
version "1.0.1"
42+
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
43+
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==
44+
45+
46+
version "3.5.0"
47+
resolved "https://registry.yarnpkg.com/pg-native/-/pg-native-3.5.0.tgz#1a43c0d5f5744e40df3bf737c43178ce98984255"
48+
integrity sha512-rj4LYouevTdKxvRLnvtOLEPOerkiPAqUdZE1K48IfQluEH/x7GrldEDdSaEOmJ6z7s6LQwDTpAPhm2s00iG8xw==
49+
dependencies:
50+
libpq "^1.8.15"
51+
pg-types "2.2.0"
52+
53+
pg-pool@^3.10.0:
54+
version "3.10.0"
55+
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.10.0.tgz#134b0213755c5e7135152976488aa7cd7ee1268d"
56+
integrity sha512-DzZ26On4sQ0KmqnO34muPcmKbhrjmyiO4lCCR0VwEd7MjmiKf5NTg/6+apUEu0NF7ESa37CGzFxH513CoUmWnA==
57+
58+
pg-protocol@^1.10.0:
59+
version "1.10.0"
60+
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.10.0.tgz#a473afcbb1c6e5dc3ac24869ba3dd563f8a1ae1b"
61+
integrity sha512-IpdytjudNuLv8nhlHs/UrVBhU0e78J0oIS/0AVdTbWxSOkFUVdsHC/NrorO6nXsQNDTT1kzDSOMJubBQviX18Q==
62+
63+
64+
version "2.2.0"
65+
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.2.0.tgz#2d0250d636454f7cfa3b6ae0382fdfa8063254a3"
66+
integrity sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==
67+
dependencies:
68+
pg-int8 "1.0.1"
69+
postgres-array "~2.0.0"
70+
postgres-bytea "~1.0.0"
71+
postgres-date "~1.0.4"
72+
postgres-interval "^1.1.0"
73+
74+
75+
version "8.16.0"
76+
resolved "https://registry.yarnpkg.com/pg/-/pg-8.16.0.tgz#40b08eedb5eb1834252cf3e3629503e32e6c6c04"
77+
integrity sha512-7SKfdvP8CTNXjMUzfcVTaI+TDzBEeaUnVwiVGZQD1Hh33Kpev7liQba9uLd4CfN8r9mCVsD0JIpq03+Unpz+kg==
78+
dependencies:
79+
pg-connection-string "^2.9.0"
80+
pg-pool "^3.10.0"
81+
pg-protocol "^1.10.0"
82+
pg-types "2.2.0"
83+
pgpass "1.0.5"
84+
optionalDependencies:
85+
pg-cloudflare "^1.2.5"
86+
87+
88+
version "1.0.5"
89+
resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.5.tgz#9b873e4a564bb10fa7a7dbd55312728d422a223d"
90+
integrity sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==
91+
dependencies:
92+
split2 "^4.1.0"
93+
94+
postgres-array@~2.0.0:
95+
version "2.0.0"
96+
resolved "https://registry.yarnpkg.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
97+
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==
98+
99+
postgres-bytea@~1.0.0:
100+
version "1.0.0"
101+
resolved "https://registry.yarnpkg.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35"
102+
integrity sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==
103+
104+
postgres-date@~1.0.4:
105+
version "1.0.7"
106+
resolved "https://registry.yarnpkg.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8"
107+
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==
108+
109+
postgres-interval@^1.1.0:
110+
version "1.2.0"
111+
resolved "https://registry.yarnpkg.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695"
112+
integrity sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==
113+
dependencies:
114+
xtend "^4.0.0"
115+
116+
split2@^4.1.0:
117+
version "4.2.0"
118+
resolved "https://registry.yarnpkg.com/split2/-/split2-4.2.0.tgz#c9c5920904d148bab0b9f67145f245a86aadbfa4"
119+
integrity sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==
120+
121+
xtend@^4.0.0:
122+
version "4.0.2"
123+
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
124+
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==

0 commit comments

Comments
 (0)