Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ jobs:
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Build `libpq`
run: yarn libpq:build
working-directory: dev-packages/node-integration-tests

- name: Overwrite typescript version
if: matrix.typescript == '3.8'
run: node ./scripts/use-ts-3_8.js
Expand Down
4 changes: 3 additions & 1 deletion dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:types": "tsc -p tsconfig.types.json",
"clean": "rimraf -g **/node_modules && run-p clean:script",
"clean:script": "node scripts/clean.js",
"libpq:build": "npm rebuild libpq",
"express-v5-install": "cd suites/express-v5 && yarn --no-lockfile",
"lint": "eslint . --format stylish",
"fix": "eslint . --format stylish --fix",
Expand Down Expand Up @@ -62,7 +63,8 @@
"nock": "^13.5.5",
"node-cron": "^3.0.3",
"node-schedule": "^2.1.1",
"pg": "^8.7.3",
"pg": "^8.13.1",
"pg-native": "3.2.0",
"proxy": "^2.1.1",
"redis-4": "npm:redis@^4.6.14",
"reflect-metadata": "0.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

const { native } = require('pg');
const { Client } = native;

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

async function run() {
await Sentry.startSpan(
{
name: 'Test Transaction',
op: 'transaction',
},
async () => {
try {
await client.connect();

await client
.query(
'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"));',
)
.catch(() => {
// if this is not a fresh database, the table might already exist
});

await client.query('INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)', ['tim', '[email protected]']);
await client.query('SELECT * FROM "NativeUser"');
} finally {
await client.end();
}
},
);
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,54 @@ describe('postgres auto instrumentation', () => {
.expect({ transaction: EXPECTED_TRANSACTION })
.start(done);
});

test('should auto-instrument `pg-native` package', done => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
expect.objectContaining({
data: expect.objectContaining({
'db.system': 'postgresql',
'db.name': 'tests',
'sentry.origin': 'manual',
'sentry.op': 'db',
}),
description: 'pg.connect',
op: 'db',
status: 'ok',
}),
expect.objectContaining({
data: expect.objectContaining({
'db.system': 'postgresql',
'db.name': 'tests',
'db.statement': 'INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)',
'sentry.origin': 'auto.db.otel.postgres',
'sentry.op': 'db',
}),
description: 'INSERT INTO "NativeUser" ("email", "name") VALUES ($1, $2)',
op: 'db',
status: 'ok',
origin: 'auto.db.otel.postgres',
}),
expect.objectContaining({
data: expect.objectContaining({
'db.system': 'postgresql',
'db.name': 'tests',
'db.statement': 'SELECT * FROM "NativeUser"',
'sentry.origin': 'auto.db.otel.postgres',
'sentry.op': 'db',
}),
description: 'SELECT * FROM "NativeUser"',
op: 'db',
status: 'ok',
origin: 'auto.db.otel.postgres',
}),
]),
};

createRunner(__dirname, 'scenario-native.js')
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] })
.expect({ transaction: EXPECTED_TRANSACTION })
.start(done);
});
});
Loading
Loading