Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Bump opentelemetry/instrumentation-pg to 0.51.0 #15206

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
7 changes: 5 additions & 2 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"clean:script": "node scripts/clean.js",
"prisma-v5:init": "cd suites/tracing/prisma-orm-v5 && yarn && yarn setup",
"prisma-v6:init": "cd suites/tracing/prisma-orm-v6 && yarn && yarn setup",
"pg-native:rebuild": "yarn add --force pg-native --frozen-lockfile",
"lint": "eslint . --format stylish",
"fix": "eslint . --format stylish --fix",
"type-check": "tsc",
"pretest": "run-s --silent prisma-v5:init prisma-v6:init",
"pretest": "run-s --silent pg-native:rebuild prisma-v5:init prisma-v6:init",
"test": "jest --config ./jest.config.js",
"test:watch": "yarn test --watch"
},
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 All @@ -74,6 +76,7 @@
"@types/amqplib": "^0.10.5",
"@types/node-cron": "^3.0.11",
"@types/node-schedule": "^2.1.7",
"@types/send": "0.17.1",
"globby": "11"
},
"config": {
Expand Down
1 change: 1 addition & 0 deletions dev-packages/node-integration-tests/scripts/use-ts-3_8.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
if (!packageJson.resolutions) packageJson.resolutions = {};
packageJson.resolutions['@types/express'] = '4.17.13';
packageJson.resolutions['@types/express-serve-static-core'] = '4.17.30';
packageJson.resolutions['@types/send'] = '#ts3.8';

writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

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);
});
});
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@opentelemetry/instrumentation-mongoose": "0.46.0",
"@opentelemetry/instrumentation-mysql": "0.45.0",
"@opentelemetry/instrumentation-mysql2": "0.45.0",
"@opentelemetry/instrumentation-pg": "0.50.0",
"@opentelemetry/instrumentation-pg": "0.51.0",
"@opentelemetry/instrumentation-redis-4": "0.46.0",
"@opentelemetry/instrumentation-tedious": "0.18.0",
"@opentelemetry/instrumentation-undici": "0.10.0",
Expand Down
Loading
Loading