Skip to content

Commit 0963af0

Browse files
author
Luca Forstner
authored
fix(node): Add compatibility layer for Prisma v5 (getsentry#15169)
1 parent ec02f84 commit 0963af0

File tree

21 files changed

+380
-16
lines changed

21 files changed

+380
-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 && yarn && yarn setup",
19+
"prisma-v5:init": "cd suites/tracing/prisma-orm-v5 && yarn && yarn setup",
20+
"prisma-v6:init": "cd suites/tracing/prisma-orm-v6 && yarn && yarn setup",
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": "6.2.1",
3434
"@sentry/aws-serverless": "9.0.0-alpha.0",
3535
"@sentry/core": "9.0.0-alpha.0",
3636
"@sentry/node": "9.0.0-alpha.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+
}

dev-packages/node-integration-tests/suites/tracing/prisma-orm/prisma/schema.prisma renamed to dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ datasource db {
55

66
generator client {
77
provider = "prisma-client-js"
8+
previewFeatures = ["tracing"]
89
}
910

1011
model User {
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://public@dsn.ingest.sentry.io/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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { createRunner } from '../../../utils/runner';
2+
3+
describe('Prisma ORM Tests', () => {
4+
test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => {
5+
createRunner(__dirname, 'scenario.js')
6+
.expect({
7+
transaction: transaction => {
8+
expect(transaction.transaction).toBe('Test Transaction');
9+
const spans = transaction.spans || [];
10+
expect(spans.length).toBeGreaterThanOrEqual(5);
11+
12+
expect(spans).toContainEqual(
13+
expect.objectContaining({
14+
data: {
15+
method: 'create',
16+
model: 'User',
17+
name: 'User.create',
18+
'sentry.origin': 'auto.db.otel.prisma',
19+
},
20+
description: 'prisma:client:operation',
21+
status: 'ok',
22+
}),
23+
);
24+
25+
expect(spans).toContainEqual(
26+
expect.objectContaining({
27+
data: {
28+
'sentry.origin': 'auto.db.otel.prisma',
29+
},
30+
description: 'prisma:client:serialize',
31+
status: 'ok',
32+
}),
33+
);
34+
35+
expect(spans).toContainEqual(
36+
expect.objectContaining({
37+
data: {
38+
'sentry.origin': 'auto.db.otel.prisma',
39+
},
40+
description: 'prisma:client:connect',
41+
status: 'ok',
42+
}),
43+
);
44+
expect(spans).toContainEqual(
45+
expect.objectContaining({
46+
data: {
47+
method: 'findMany',
48+
model: 'User',
49+
name: 'User.findMany',
50+
'sentry.origin': 'auto.db.otel.prisma',
51+
},
52+
description: 'prisma:client:operation',
53+
status: 'ok',
54+
}),
55+
);
56+
expect(spans).toContainEqual(
57+
expect.objectContaining({
58+
data: {
59+
'sentry.origin': 'auto.db.otel.prisma',
60+
},
61+
description: 'prisma:client:serialize',
62+
status: 'ok',
63+
}),
64+
);
65+
},
66+
})
67+
.start(done);
68+
});
69+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@prisma/client@5.22.0":
6+
version "5.22.0"
7+
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.22.0.tgz#da1ca9c133fbefe89e0da781c75e1c59da5f8802"
8+
integrity sha512-M0SVXfyHnQREBKxCgyo7sffrKttwE6R8PMq330MIUF0pTwjUhLbW84pFDlf06B27XyCR++VtjugEnIHdr07SVA==
9+
10+
"@prisma/debug@5.22.0":
11+
version "5.22.0"
12+
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.22.0.tgz#58af56ed7f6f313df9fb1042b6224d3174bbf412"
13+
integrity sha512-AUt44v3YJeggO2ZU5BkXI7M4hu9BF2zzH2iF2V5pyXT/lRTyWiElZ7It+bRH1EshoMRxHgpYg4VB6rCM+mG5jQ==
14+
15+
"@prisma/engines-version@5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2":
16+
version "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2"
17+
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2.tgz#d534dd7235c1ba5a23bacd5b92cc0ca3894c28f4"
18+
integrity sha512-2PTmxFR2yHW/eB3uqWtcgRcgAbG1rwG9ZriSvQw+nnb7c4uCr3RAcGMb6/zfE88SKlC1Nj2ziUvc96Z379mHgQ==
19+
20+
"@prisma/engines@5.22.0":
21+
version "5.22.0"
22+
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.22.0.tgz#28f3f52a2812c990a8b66eb93a0987816a5b6d84"
23+
integrity sha512-UNjfslWhAt06kVL3CjkuYpHAWSO6L4kDCVPegV6itt7nD1kSJavd3vhgAEhjglLJJKEdJ7oIqDJ+yHk6qO8gPA==
24+
dependencies:
25+
"@prisma/debug" "5.22.0"
26+
"@prisma/engines-version" "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2"
27+
"@prisma/fetch-engine" "5.22.0"
28+
"@prisma/get-platform" "5.22.0"
29+
30+
"@prisma/fetch-engine@5.22.0":
31+
version "5.22.0"
32+
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.22.0.tgz#4fb691b483a450c5548aac2f837b267dd50ef52e"
33+
integrity sha512-bkrD/Mc2fSvkQBV5EpoFcZ87AvOgDxbG99488a5cexp5Ccny+UM6MAe/UFkUC0wLYD9+9befNOqGiIJhhq+HbA==
34+
dependencies:
35+
"@prisma/debug" "5.22.0"
36+
"@prisma/engines-version" "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2"
37+
"@prisma/get-platform" "5.22.0"
38+
39+
"@prisma/get-platform@5.22.0":
40+
version "5.22.0"
41+
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.22.0.tgz#fc675bc9d12614ca2dade0506c9c4a77e7dddacd"
42+
integrity sha512-pHhpQdr1UPFpt+zFfnPazhulaZYCUqeIcPpJViYoq9R+D/yw4fjE+CtnsnKzPYm0ddUbeXUzjGVGIRVgPDCk4Q==
43+
dependencies:
44+
"@prisma/debug" "5.22.0"
45+
46+
fsevents@2.3.3:
47+
version "2.3.3"
48+
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
49+
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
50+
51+
prisma@5.22.0:
52+
version "5.22.0"
53+
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.22.0.tgz#1f6717ff487cdef5f5799cc1010459920e2e6197"
54+
integrity sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==
55+
dependencies:
56+
"@prisma/engines" "5.22.0"
57+
optionalDependencies:
58+
fsevents "2.3.3"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.9'
2+
3+
services:
4+
db:
5+
image: postgres:13
6+
restart: always
7+
container_name: integration-tests-prisma-v6
8+
ports:
9+
- '5434:5432'
10+
environment:
11+
POSTGRES_USER: prisma
12+
POSTGRES_PASSWORD: prisma
13+
POSTGRES_DB: tests

0 commit comments

Comments
 (0)