-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathperformance.server.test.ts
More file actions
162 lines (146 loc) · 5.4 KB
/
performance.server.test.ts
File metadata and controls
162 lines (146 loc) · 5.4 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
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { APP_NAME } from '../constants';
test.describe('servery - performance', () => {
test('should send server transaction on pageload', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'GET /performance';
});
await page.goto(`/performance`);
const transaction = await txPromise;
expect(transaction).toMatchObject({
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
},
},
spans: expect.any(Array),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
transaction: 'GET /performance',
type: 'transaction',
transaction_info: { source: 'route' },
platform: 'node',
request: {
url: expect.stringContaining('/performance'),
headers: expect.any(Object),
},
event_id: expect.any(String),
environment: 'qa',
sdk: {
integrations: expect.arrayContaining([expect.any(String)]),
name: 'sentry.javascript.react-router',
version: expect.any(String),
packages: [
{ name: 'npm:@sentry/react-router', version: expect.any(String) },
{ name: 'npm:@sentry/node', version: expect.any(String) },
],
},
tags: {
runtime: 'node',
},
});
});
test('should send server transaction on parameterized route', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'GET /performance/with/:param';
});
await page.goto(`/performance/with/some-param`);
const transaction = await txPromise;
expect(transaction).toMatchObject({
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
},
},
spans: expect.any(Array),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
transaction: 'GET /performance/with/:param',
type: 'transaction',
transaction_info: { source: 'route' },
platform: 'node',
request: {
url: expect.stringContaining('/performance/with/some-param'),
headers: expect.any(Object),
},
event_id: expect.any(String),
environment: 'qa',
sdk: {
integrations: expect.arrayContaining([expect.any(String)]),
name: 'sentry.javascript.react-router',
version: expect.any(String),
packages: [
{ name: 'npm:@sentry/react-router', version: expect.any(String) },
{ name: 'npm:@sentry/node', version: expect.any(String) },
],
},
tags: {
runtime: 'node',
},
});
});
test('should automatically instrument server loader', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'GET /performance/server-loader.data';
});
await page.goto(`/performance`); // initial ssr pageloads do not contain .data requests
await page.waitForTimeout(500); // quick breather before navigation
await page.getByRole('link', { name: 'Server Loader' }).click(); // this will actually trigger a .data request
const transaction = await txPromise;
expect(transaction?.spans?.[transaction.spans?.length - 1]).toMatchObject({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'auto.http.react-router',
'sentry.op': 'function.react-router.loader',
},
description: 'Executing Server Loader',
parent_span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'function.react-router.loader',
origin: 'auto.http.react-router',
});
});
test('should automatically instrument server action', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'POST /performance/server-action.data';
});
await page.goto(`/performance/server-action`);
await page.getByRole('button', { name: 'Submit' }).click(); // this will trigger a .data request
const transaction = await txPromise;
expect(transaction?.spans?.[transaction.spans?.length - 1]).toMatchObject({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'auto.http.react-router',
'sentry.op': 'function.react-router.action',
},
description: 'Executing Server Action',
parent_span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'function.react-router.action',
origin: 'auto.http.react-router',
});
});
});