Skip to content

Commit 1fd8be1

Browse files
committed
Use postgres suite instead of running another server.
1 parent ef09ce6 commit 1fd8be1

File tree

4 files changed

+54
-73
lines changed

4 files changed

+54
-73
lines changed

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ setInterval(() => {}, 1000);
1414
const { native } = require('pg');
1515
const { Client } = native;
1616

17-
const client = new Client({ port: 5434, user: 'test', password: 'test', database: 'tests' });
17+
const client = new Client({ port: 5444, user: 'test', password: 'test', database: 'tests' });
1818

1919
async function run() {
2020
await Sentry.startSpan(
@@ -28,14 +28,14 @@ async function run() {
2828

2929
await client
3030
.query(
31-
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));',
31+
'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"));',
3232
)
3333
.catch(() => {
3434
// if this is not a fresh database, the table might already exist
3535
});
3636

37-
await client.query('INSERT INTO "User" ("email", "name") VALUES ($1, $2)', ['tim', 'tim@domain.com']);
38-
await client.query('SELECT * FROM "User"');
37+
await client.query('INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)', ['tim', 'tim@domain.com']);
38+
await client.query('SELECT * FROM "NativeUser"');
3939
} finally {
4040
await client.end();
4141
}

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,54 @@ describe('postgres auto instrumentation', () => {
5353
.expect({ transaction: EXPECTED_TRANSACTION })
5454
.start(done);
5555
});
56+
57+
test('should auto-instrument `pg-native` package', done => {
58+
const EXPECTED_TRANSACTION = {
59+
transaction: 'Test Transaction',
60+
spans: expect.arrayContaining([
61+
expect.objectContaining({
62+
data: expect.objectContaining({
63+
'db.system': 'postgresql',
64+
'db.name': 'tests',
65+
'sentry.origin': 'manual',
66+
'sentry.op': 'db',
67+
}),
68+
description: 'pg.connect',
69+
op: 'db',
70+
status: 'ok',
71+
}),
72+
expect.objectContaining({
73+
data: expect.objectContaining({
74+
'db.system': 'postgresql',
75+
'db.name': 'tests',
76+
'db.statement': 'INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)',
77+
'sentry.origin': 'auto.db.otel.postgres',
78+
'sentry.op': 'db',
79+
}),
80+
description: 'INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)',
81+
op: 'db',
82+
status: 'ok',
83+
origin: 'auto.db.otel.postgres',
84+
}),
85+
expect.objectContaining({
86+
data: expect.objectContaining({
87+
'db.system': 'postgresql',
88+
'db.name': 'tests',
89+
'db.statement': 'SELECT * FROM "NativeUser"',
90+
'sentry.origin': 'auto.db.otel.postgres',
91+
'sentry.op': 'db',
92+
}),
93+
description: 'SELECT * FROM "NativeUser"',
94+
op: 'db',
95+
status: 'ok',
96+
origin: 'auto.db.otel.postgres',
97+
}),
98+
]),
99+
};
100+
101+
createRunner(__dirname, 'scenario-native.js')
102+
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] })
103+
.expect({ transaction: EXPECTED_TRANSACTION })
104+
.start(done);
105+
});
56106
});

0 commit comments

Comments
 (0)