Skip to content

Commit b5355da

Browse files
author
Luca Forstner
committed
fix(node/v8): Add compatibility layer for Prisma v5
1 parent a6f7300 commit b5355da

File tree

23 files changed

+398
-16
lines changed

23 files changed

+398
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
"build:types": "tsc -p tsconfig.types.json",
1717
"clean": "rimraf -g **/node_modules && run-p clean:script",
1818
"clean:script": "node scripts/clean.js",
19-
"prisma:init": "(cd suites/tracing/prisma-orm && ts-node ./setup.ts)",
19+
"prisma-v5:init": "cd suites/tracing/prisma-orm-v5 && ts-node ./setup.ts",
20+
"prisma-v6:init": "cd suites/tracing/prisma-orm-v6 && ts-node ./setup.ts",
2021
"lint": "eslint . --format stylish",
2122
"fix": "eslint . --format stylish --fix",
2223
"type-check": "tsc",
23-
"pretest": "run-s --silent prisma:init",
24+
"pretest": "run-s --silent prisma-v5:init prisma-v6:init",
2425
"test": "jest --config ./jest.config.js",
2526
"test:watch": "yarn test --watch"
2627
},
@@ -30,7 +31,6 @@
3031
"@nestjs/common": "10.4.6",
3132
"@nestjs/core": "10.4.6",
3233
"@nestjs/platform-express": "10.4.6",
33-
"@prisma/client": "5.22.0",
3434
"@sentry/aws-serverless": "8.51.0",
3535
"@sentry/core": "8.51.0",
3636
"@sentry/node": "8.51.0",

dev-packages/node-integration-tests/suites/tracing/prisma-orm/docker-compose.yml renamed to dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
db:
55
image: postgres:13
66
restart: always
7-
container_name: integration-tests-prisma
7+
container_name: integration-tests-prisma-v5
88
ports:
99
- '5433:5432'
1010
environment:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "sentry-prisma-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"engines": {
7+
"node": ">=18"
8+
},
9+
"scripts": {
10+
"db-up": "docker compose up -d",
11+
"generate": "prisma generate",
12+
"migrate": "prisma migrate dev -n sentry-test",
13+
"setup": "run-s --silent db-up generate migrate"
14+
},
15+
"keywords": [],
16+
"author": "",
17+
"license": "ISC",
18+
"dependencies": {
19+
"@prisma/client": "5.22.0",
20+
"prisma": "5.22.0"
21+
}
22+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const Sentry = require('@sentry/node');
2+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
integrations: [Sentry.prismaIntegration()],
10+
});
11+
12+
const { randomBytes } = require('crypto');
13+
const { PrismaClient } = require('@prisma/client');
14+
15+
// Stop the process from exiting before the transaction is sent
16+
setInterval(() => {}, 1000);
17+
18+
async function run() {
19+
const client = new PrismaClient();
20+
21+
await Sentry.startSpanManual(
22+
{
23+
name: 'Test Transaction',
24+
op: 'transaction',
25+
},
26+
async span => {
27+
await client.user.create({
28+
data: {
29+
name: 'Tilda',
30+
email: `tilda_${randomBytes(4).toString('hex')}@sentry.io`,
31+
},
32+
});
33+
34+
await client.user.findMany();
35+
36+
await client.user.deleteMany({
37+
where: {
38+
email: {
39+
contains: 'sentry.io',
40+
},
41+
},
42+
});
43+
44+
setTimeout(async () => {
45+
span.end();
46+
await client.$disconnect();
47+
}, 500);
48+
},
49+
);
50+
}
51+
52+
run();
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { conditionalTest } from '../../../utils';
2+
import { createRunner } from '../../../utils/runner';
3+
4+
conditionalTest({ min: 16 })('Prisma ORM Tests', () => {
5+
test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => {
6+
createRunner(__dirname, 'scenario.js')
7+
.expect({
8+
transaction: transaction => {
9+
expect(transaction.transaction).toBe('Test Transaction');
10+
const spans = transaction.spans || [];
11+
expect(spans.length).toBeGreaterThanOrEqual(5);
12+
13+
expect(spans).toContainEqual(
14+
expect.objectContaining({
15+
data: {
16+
method: 'create',
17+
model: 'User',
18+
name: 'User.create',
19+
'sentry.origin': 'auto.db.otel.prisma',
20+
},
21+
description: 'prisma:client:operation',
22+
status: 'ok',
23+
}),
24+
);
25+
26+
expect(spans).toContainEqual(
27+
expect.objectContaining({
28+
data: {
29+
'sentry.origin': 'auto.db.otel.prisma',
30+
},
31+
description: 'prisma:client:serialize',
32+
status: 'ok',
33+
}),
34+
);
35+
36+
expect(spans).toContainEqual(
37+
expect.objectContaining({
38+
data: {
39+
'sentry.origin': 'auto.db.otel.prisma',
40+
},
41+
description: 'prisma:client:connect',
42+
status: 'ok',
43+
}),
44+
);
45+
expect(spans).toContainEqual(
46+
expect.objectContaining({
47+
data: {
48+
method: 'findMany',
49+
model: 'User',
50+
name: 'User.findMany',
51+
'sentry.origin': 'auto.db.otel.prisma',
52+
},
53+
description: 'prisma:client:operation',
54+
status: 'ok',
55+
}),
56+
);
57+
expect(spans).toContainEqual(
58+
expect.objectContaining({
59+
data: {
60+
'sentry.origin': 'auto.db.otel.prisma',
61+
},
62+
description: 'prisma:client:serialize',
63+
status: 'ok',
64+
}),
65+
);
66+
},
67+
})
68+
.start(done);
69+
});
70+
});

0 commit comments

Comments
 (0)