-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
105 lines (92 loc) · 3.65 KB
/
test.ts
File metadata and controls
105 lines (92 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { SpanJSON } from '@sentry/core';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
afterAll(() => {
cleanupChildProcesses();
});
describe('Prisma ORM v6 Tests', () => {
createEsmAndCjsTests(
__dirname,
'scenario.mjs',
'instrument.mjs',
(createRunner, test, _mode, cwd) => {
test('should instrument PostgreSQL queries from Prisma ORM', { timeout: 75_000 }, async () => {
await createRunner()
.withDockerCompose({
workingDirectory: [cwd],
setupCommand: `yarn prisma generate --schema ${cwd}/prisma/schema.prisma && yarn prisma migrate dev -n sentry-test --schema ${cwd}/prisma/schema.prisma`,
})
.expect({
transaction: transaction => {
expect(transaction.transaction).toBe('Test Transaction');
const spans = transaction.spans || [];
expect(spans.length).toBeGreaterThanOrEqual(5);
function expectPrismaSpanToIncludeSpanWith(span: Partial<SpanJSON>) {
expect(spans).toContainEqual(
expect.objectContaining({
...span,
data: {
...span.data,
'sentry.origin': 'auto.db.otel.prisma',
},
status: 'ok',
}),
);
}
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:client:detect_platform',
});
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:client:load_engine',
});
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:client:operation',
data: {
method: 'create',
model: 'User',
name: 'User.create',
},
});
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:client:serialize',
});
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:client:connect',
});
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:engine:connect',
});
expectPrismaSpanToIncludeSpanWith({
description: 'prisma:engine:query',
});
expectPrismaSpanToIncludeSpanWith({
data: {
'sentry.op': 'db',
'db.query.text':
'SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."email", "public"."User"."name" FROM "public"."User" WHERE 1=1 OFFSET $1',
'db.system': 'postgresql',
'otel.kind': 'CLIENT',
},
description:
'SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."email", "public"."User"."name" FROM "public"."User" WHERE 1=1 OFFSET $1',
});
expectPrismaSpanToIncludeSpanWith({
data: {
'sentry.op': 'db',
'db.query.text': 'DELETE FROM "public"."User" WHERE "public"."User"."email"::text LIKE $1',
'db.system': 'postgresql',
'otel.kind': 'CLIENT',
},
description: 'DELETE FROM "public"."User" WHERE "public"."User"."email"::text LIKE $1',
});
},
})
.start()
.completed();
});
},
{
copyPaths: ['prisma', 'docker-compose.yml'],
},
);
});