-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathperformance.test.ts
More file actions
197 lines (173 loc) · 6.84 KB
/
performance.test.ts
File metadata and controls
197 lines (173 loc) · 6.84 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
// This test should be run in serial mode to ensure that the test user is created before the other tests
test.describe.configure({ mode: 'serial' });
// This should be the first test as it will be needed for the other tests
test('Sends server-side Supabase auth admin `createUser` span', async ({ page, baseURL }) => {
const httpTransactionPromise = waitForTransaction('supabase-nextjs', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /api/create-test-user'
);
});
await fetch(`${baseURL}/api/create-test-user`);
const transactionEvent = await httpTransactionPromise;
expect(transactionEvent.spans).toContainEqual({
data: expect.objectContaining({
'db.operation': 'auth.admin.createUser',
'db.system': 'postgresql',
'sentry.op': 'db',
'sentry.origin': 'auto.db.supabase',
}),
description: 'auth (admin) createUser',
op: 'db',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
origin: 'auto.db.supabase',
});
});
test('Sends client-side Supabase db-operation spans and breadcrumbs to Sentry', async ({ page, baseURL }) => {
const pageloadTransactionPromise = waitForTransaction('supabase-nextjs', transactionEvent => {
return transactionEvent?.contexts?.trace?.op === 'pageload' && transactionEvent?.transaction === '/';
});
await page.goto('/');
// Fill in login credentials
// The email and password should be the same as the ones used in the `create-test-user` endpoint
await page.locator('input[name=email]').fill('test@sentry.test');
await page.locator('input[name=password]').fill('sentry.test');
await page.locator('button[type=submit]').click();
// Wait for login to complete
await page.waitForSelector('button:has-text("Add")');
// Add a new todo entry
await page.locator('input[id=new-task-text]').fill('test');
await page.locator('button[id=add-task]').click();
const transactionEvent = await pageloadTransactionPromise;
// Client uses default sendDefaultPii: false — URL filters and bodies are not attached to spans/breadcrumbs.
const redactedSelectSpan = expect.objectContaining({
description: '[redacted] from(todos)',
op: 'db',
data: expect.objectContaining({
'db.operation': 'select',
'db.system': 'postgresql',
'sentry.op': 'db',
'sentry.origin': 'auto.db.supabase',
}),
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
origin: 'auto.db.supabase',
});
expect(transactionEvent.spans).toContainEqual(redactedSelectSpan);
const selectSpan = transactionEvent.spans?.find(
(s: { description?: string }) => s.description === '[redacted] from(todos)',
);
expect(selectSpan).toBeDefined();
expect(selectSpan!.data).not.toHaveProperty('db.query');
expect(transactionEvent.breadcrumbs).toContainEqual({
timestamp: expect.any(Number),
type: 'supabase',
category: 'db.select',
message: '[redacted] from(todos)',
});
expect(transactionEvent.breadcrumbs).toContainEqual({
timestamp: expect.any(Number),
type: 'supabase',
category: 'db.insert',
message: 'insert(...) [redacted] from(todos)',
});
});
test('Sends server-side Supabase db-operation spans and breadcrumbs to Sentry', async ({ page, baseURL }) => {
const httpTransactionPromise = waitForTransaction('supabase-nextjs', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /api/add-todo-entry'
);
});
await fetch(`${baseURL}/api/add-todo-entry`);
const transactionEvent = await httpTransactionPromise;
expect(transactionEvent.spans).toContainEqual(
expect.objectContaining({
data: expect.objectContaining({
'db.operation': 'insert',
'db.query': ['select(*)'],
'db.system': 'postgresql',
'sentry.op': 'db',
'sentry.origin': 'auto.db.supabase',
}),
description: 'insert(...) select(*) from(todos)',
op: 'db',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
origin: 'auto.db.supabase',
}),
);
expect(transactionEvent.spans).toContainEqual({
data: expect.objectContaining({
'db.operation': 'select',
'db.query': ['select(*)'],
'db.system': 'postgresql',
'sentry.op': 'db',
'sentry.origin': 'auto.db.supabase',
}),
description: 'select(*) from(todos)',
op: 'db',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
origin: 'auto.db.supabase',
});
expect(transactionEvent.breadcrumbs).toContainEqual({
timestamp: expect.any(Number),
type: 'supabase',
category: 'db.select',
message: 'select(*) from(todos)',
data: expect.any(Object),
});
expect(transactionEvent.breadcrumbs).toContainEqual({
timestamp: expect.any(Number),
type: 'supabase',
category: 'db.insert',
message: 'insert(...) select(*) from(todos)',
data: expect.any(Object),
});
});
test('Sends server-side Supabase auth admin `listUsers` span', async ({ page, baseURL }) => {
const httpTransactionPromise = waitForTransaction('supabase-nextjs', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'GET /api/list-users'
);
});
await fetch(`${baseURL}/api/list-users`);
const transactionEvent = await httpTransactionPromise;
expect(transactionEvent.spans).toContainEqual({
data: expect.objectContaining({
'db.operation': 'auth.admin.listUsers',
'db.system': 'postgresql',
'sentry.op': 'db',
'sentry.origin': 'auto.db.supabase',
}),
description: 'auth (admin) listUsers',
op: 'db',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
origin: 'auto.db.supabase',
});
});