Skip to content

Commit a182658

Browse files
author
Luca Forstner
committed
Add v5 tests
1 parent 6571e0c commit a182658

File tree

18 files changed

+523
-13
lines changed

18 files changed

+523
-13
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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/instrumentation": "5.22.0",
21+
"prisma": "5.22.0"
22+
}
23+
}

dev-packages/node-integration-tests/suites/tracing/prisma-orm/prisma/migrations/migration_lock.toml renamed to dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/prisma/migrations/migration_lock.toml

File renamed without changes.

dev-packages/node-integration-tests/suites/tracing/prisma-orm/prisma/migrations/sentry_test/migration.sql renamed to dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/prisma/migrations/sentry_test/migration.sql

File renamed without changes.

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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const Sentry = require('@sentry/node');
2+
const { PrismaInstrumentation } = require('@prisma/instrumentation');
3+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
release: '1.0',
8+
tracesSampleRate: 1.0,
9+
transport: loggingTransport,
10+
integrations: [
11+
Sentry.prismaIntegration({
12+
prismaInstrumentation: new PrismaInstrumentation(),
13+
}),
14+
],
15+
});
16+
17+
const { randomBytes } = require('crypto');
18+
const { PrismaClient } = require('@prisma/client');
19+
20+
// Stop the process from exiting before the transaction is sent
21+
setInterval(() => {}, 1000);
22+
23+
async function run() {
24+
const client = new PrismaClient();
25+
26+
await Sentry.startSpan(
27+
{
28+
name: 'Test Transaction',
29+
op: 'transaction',
30+
},
31+
async span => {
32+
await client.user.create({
33+
data: {
34+
name: 'Tilda',
35+
email: `tilda_${randomBytes(4).toString('hex')}@sentry.io`,
36+
},
37+
});
38+
39+
await client.user.findMany();
40+
41+
await client.user.deleteMany({
42+
where: {
43+
email: {
44+
contains: 'sentry.io',
45+
},
46+
},
47+
});
48+
49+
setTimeout(async () => {
50+
span.end();
51+
await client.$disconnect();
52+
}, 500);
53+
},
54+
);
55+
}
56+
57+
run();
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
45+
expect(spans).toContainEqual(
46+
expect.objectContaining({
47+
data: {
48+
'sentry.origin': 'auto.db.otel.prisma',
49+
},
50+
description: 'prisma:engine',
51+
status: 'ok',
52+
}),
53+
);
54+
expect(spans).toContainEqual(
55+
expect.objectContaining({
56+
data: {
57+
'sentry.origin': 'auto.db.otel.prisma',
58+
'sentry.op': 'db',
59+
'db.system': 'postgresql',
60+
},
61+
description: 'prisma:engine:connection',
62+
status: 'ok',
63+
op: 'db',
64+
}),
65+
);
66+
67+
expect(spans).toContainEqual(
68+
expect.objectContaining({
69+
data: {
70+
'db.statement': expect.stringContaining(
71+
'INSERT INTO "public"."User" ("createdAt","email","name") VALUES ($1,$2,$3) RETURNING "public"."User"."id", "public"."User"."createdAt", "public"."User"."email", "public"."User"."name" /* traceparent',
72+
),
73+
'sentry.origin': 'auto.db.otel.prisma',
74+
'sentry.op': 'db',
75+
'db.system': 'postgresql',
76+
'otel.kind': 'CLIENT',
77+
},
78+
description: expect.stringContaining(
79+
'INSERT INTO "public"."User" ("createdAt","email","name") VALUES ($1,$2,$3) RETURNING "public"."User"."id", "public"."User"."createdAt", "public"."User"."email", "public"."User"."name" /* traceparent',
80+
),
81+
status: 'ok',
82+
op: 'db',
83+
}),
84+
);
85+
expect(spans).toContainEqual(
86+
expect.objectContaining({
87+
data: {
88+
'sentry.origin': 'auto.db.otel.prisma',
89+
},
90+
description: 'prisma:engine:serialize',
91+
status: 'ok',
92+
}),
93+
);
94+
expect(spans).toContainEqual(
95+
expect.objectContaining({
96+
data: {
97+
'sentry.origin': 'auto.db.otel.prisma',
98+
},
99+
description: 'prisma:engine:response_json_serialization',
100+
status: 'ok',
101+
}),
102+
);
103+
expect(spans).toContainEqual(
104+
expect.objectContaining({
105+
data: {
106+
method: 'findMany',
107+
model: 'User',
108+
name: 'User.findMany',
109+
'sentry.origin': 'auto.db.otel.prisma',
110+
},
111+
description: 'prisma:client:operation',
112+
status: 'ok',
113+
}),
114+
);
115+
expect(spans).toContainEqual(
116+
expect.objectContaining({
117+
data: {
118+
'sentry.origin': 'auto.db.otel.prisma',
119+
},
120+
description: 'prisma:client:serialize',
121+
status: 'ok',
122+
}),
123+
);
124+
expect(spans).toContainEqual(
125+
expect.objectContaining({
126+
data: {
127+
'sentry.origin': 'auto.db.otel.prisma',
128+
},
129+
description: 'prisma:engine',
130+
status: 'ok',
131+
}),
132+
);
133+
},
134+
})
135+
.start(done);
136+
});
137+
});

0 commit comments

Comments
 (0)