@@ -3,103 +3,137 @@ import { createRunner } from '../../../utils/runner';
3
3
4
4
conditionalTest ( { min : 16 } ) ( 'Prisma ORM Tests' , ( ) => {
5
5
test ( 'CJS - should instrument PostgreSQL queries from Prisma ORM' , done => {
6
- const EXPECTED_TRANSACTION = {
7
- transaction : 'Test Transaction' ,
8
- spans : expect . arrayContaining ( [
9
- expect . objectContaining ( {
10
- data : {
11
- method : 'create' ,
12
- model : 'User' ,
13
- name : 'User.create' ,
14
- 'sentry.origin' : 'auto.db.otel.prisma' ,
15
- } ,
16
- description : 'prisma:client:operation' ,
17
- status : 'ok' ,
18
- } ) ,
19
- expect . objectContaining ( {
20
- data : {
21
- 'sentry.origin' : 'auto.db.otel.prisma' ,
22
- } ,
23
- description : 'prisma:client:serialize' ,
24
- status : 'ok' ,
25
- } ) ,
26
- expect . objectContaining ( {
27
- data : {
28
- 'sentry.origin' : 'auto.db.otel.prisma' ,
29
- } ,
30
- description : 'prisma:client:connect' ,
31
- status : 'ok' ,
32
- } ) ,
33
- expect . objectContaining ( {
34
- data : {
35
- 'sentry.origin' : 'auto.db.otel.prisma' ,
36
- } ,
37
- description : 'prisma:engine' ,
38
- status : 'ok' ,
39
- } ) ,
40
- expect . objectContaining ( {
41
- data : {
42
- 'db.type' : 'postgres' ,
43
- 'sentry.origin' : 'auto.db.otel.prisma' ,
44
- } ,
45
- description : 'prisma:engine:connection' ,
46
- status : 'ok' ,
47
- } ) ,
48
- expect . objectContaining ( {
49
- data : {
50
- 'db.statement' : expect . stringContaining (
51
- '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' ,
52
- ) ,
53
- 'sentry.origin' : 'auto.db.otel.prisma' ,
54
- 'db.system' : 'prisma' ,
55
- 'sentry.op' : 'db' ,
56
- } ,
57
- description : expect . stringContaining (
58
- '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' ,
59
- ) ,
60
- status : 'ok' ,
61
- } ) ,
62
- expect . objectContaining ( {
63
- data : {
64
- 'sentry.origin' : 'auto.db.otel.prisma' ,
65
- } ,
66
- description : 'prisma:engine:serialize' ,
67
- status : 'ok' ,
68
- } ) ,
69
- expect . objectContaining ( {
70
- data : {
71
- 'sentry.origin' : 'auto.db.otel.prisma' ,
72
- } ,
73
- description : 'prisma:engine:response_json_serialization' ,
74
- status : 'ok' ,
75
- } ) ,
76
- expect . objectContaining ( {
77
- data : {
78
- method : 'findMany' ,
79
- model : 'User' ,
80
- name : 'User.findMany' ,
81
- 'sentry.origin' : 'auto.db.otel.prisma' ,
82
- } ,
83
- description : 'prisma:client:operation' ,
84
- status : 'ok' ,
85
- } ) ,
86
- expect . objectContaining ( {
87
- data : {
88
- 'sentry.origin' : 'auto.db.otel.prisma' ,
89
- } ,
90
- description : 'prisma:client:serialize' ,
91
- status : 'ok' ,
92
- } ) ,
93
- expect . objectContaining ( {
94
- data : {
95
- 'sentry.origin' : 'auto.db.otel.prisma' ,
96
- } ,
97
- description : 'prisma:engine' ,
98
- status : 'ok' ,
99
- } ) ,
100
- ] ) ,
101
- } ;
6
+ createRunner ( __dirname , 'scenario.js' )
7
+ . expect ( {
8
+ transaction : transaction => {
9
+ expect ( transaction . transaction ) . toBe ( 'Test Transaction' ) ;
102
10
103
- createRunner ( __dirname , 'scenario.js' ) . expect ( { transaction : EXPECTED_TRANSACTION } ) . start ( done ) ;
11
+ const spans = transaction . spans || [ ] ;
12
+ expect ( spans . length ) . toBeGreaterThanOrEqual ( 5 ) ;
13
+
14
+ expect ( spans ) . toContainEqual (
15
+ expect . objectContaining ( {
16
+ data : {
17
+ method : 'create' ,
18
+ model : 'User' ,
19
+ name : 'User.create' ,
20
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
21
+ } ,
22
+ description : 'prisma:client:operation' ,
23
+ status : 'ok' ,
24
+ } ) ,
25
+ ) ;
26
+
27
+ expect ( spans ) . toContainEqual (
28
+ expect . objectContaining ( {
29
+ data : {
30
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
31
+ } ,
32
+ description : 'prisma:client:serialize' ,
33
+ status : 'ok' ,
34
+ } ) ,
35
+ ) ;
36
+
37
+ expect ( spans ) . toContainEqual (
38
+ expect . objectContaining ( {
39
+ data : {
40
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
41
+ } ,
42
+ description : 'prisma:client:connect' ,
43
+ status : 'ok' ,
44
+ } ) ,
45
+ ) ;
46
+
47
+ expect ( spans ) . toContainEqual (
48
+ expect . objectContaining ( {
49
+ data : {
50
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
51
+ } ,
52
+ description : 'prisma:engine' ,
53
+ status : 'ok' ,
54
+ } ) ,
55
+ ) ;
56
+ expect ( spans ) . toContainEqual (
57
+ expect . objectContaining ( {
58
+ data : {
59
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
60
+ 'sentry.op' : 'db' ,
61
+ 'db.system' : 'postgresql' ,
62
+ } ,
63
+ description : 'prisma:engine:connection' ,
64
+ status : 'ok' ,
65
+ op : 'db' ,
66
+ } ) ,
67
+ ) ;
68
+
69
+ expect ( spans ) . toContainEqual (
70
+ expect . objectContaining ( {
71
+ data : {
72
+ 'db.statement' : expect . stringContaining (
73
+ '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' ,
74
+ ) ,
75
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
76
+ 'sentry.op' : 'db' ,
77
+ 'db.system' : 'postgresql' ,
78
+ 'otel.kind' : 'CLIENT' ,
79
+ } ,
80
+ description : expect . stringContaining (
81
+ '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' ,
82
+ ) ,
83
+ status : 'ok' ,
84
+ op : 'db' ,
85
+ } ) ,
86
+ ) ;
87
+ expect ( spans ) . toContainEqual (
88
+ expect . objectContaining ( {
89
+ data : {
90
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
91
+ } ,
92
+ description : 'prisma:engine:serialize' ,
93
+ status : 'ok' ,
94
+ } ) ,
95
+ ) ;
96
+ expect ( spans ) . toContainEqual (
97
+ expect . objectContaining ( {
98
+ data : {
99
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
100
+ } ,
101
+ description : 'prisma:engine:response_json_serialization' ,
102
+ status : 'ok' ,
103
+ } ) ,
104
+ ) ;
105
+ expect ( spans ) . toContainEqual (
106
+ expect . objectContaining ( {
107
+ data : {
108
+ method : 'findMany' ,
109
+ model : 'User' ,
110
+ name : 'User.findMany' ,
111
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
112
+ } ,
113
+ description : 'prisma:client:operation' ,
114
+ status : 'ok' ,
115
+ } ) ,
116
+ ) ;
117
+ expect ( spans ) . toContainEqual (
118
+ expect . objectContaining ( {
119
+ data : {
120
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
121
+ } ,
122
+ description : 'prisma:client:serialize' ,
123
+ status : 'ok' ,
124
+ } ) ,
125
+ ) ;
126
+ expect ( spans ) . toContainEqual (
127
+ expect . objectContaining ( {
128
+ data : {
129
+ 'sentry.origin' : 'auto.db.otel.prisma' ,
130
+ } ,
131
+ description : 'prisma:engine' ,
132
+ status : 'ok' ,
133
+ } ) ,
134
+ ) ;
135
+ } ,
136
+ } )
137
+ . start ( done ) ;
104
138
} ) ;
105
139
} ) ;
0 commit comments