-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy patherrors.server.test.ts
164 lines (146 loc) · 5.14 KB
/
errors.server.test.ts
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
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
test.describe('server-side errors', () => {
test('captures SSR error', async ({ page }) => {
const errorEventPromise = waitForError('astro-4', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === "Cannot read properties of undefined (reading 'x')";
});
const transactionEventPromise = waitForTransaction('astro-4', transactionEvent => {
return transactionEvent.transaction === 'GET /ssr-error';
});
await page.goto('/ssr-error');
const errorEvent = await errorEventPromise;
const transactionEvent = await transactionEventPromise;
expect(transactionEvent).toMatchObject({
transaction: 'GET /ssr-error',
spans: [],
});
const traceId = transactionEvent.contexts?.trace?.trace_id;
const spanId = transactionEvent.contexts?.trace?.span_id;
expect(traceId).toMatch(/[a-f0-9]{32}/);
expect(spanId).toMatch(/[a-f0-9]{16}/);
expect(transactionEvent.contexts?.trace?.parent_span_id).toBeUndefined();
expect(errorEvent).toMatchObject({
contexts: {
app: expect.any(Object),
cloud_resource: expect.any(Object),
culture: expect.any(Object),
device: expect.any(Object),
os: expect.any(Object),
runtime: expect.any(Object),
trace: {
span_id: spanId,
trace_id: traceId,
},
},
environment: 'qa',
event_id: expect.stringMatching(/[a-f0-9]{32}/),
exception: {
values: [
{
mechanism: {
data: {
function: 'astroMiddleware',
},
handled: false,
type: 'astro',
},
stacktrace: expect.any(Object),
type: 'TypeError',
value: "Cannot read properties of undefined (reading 'x')",
},
],
},
platform: 'node',
request: {
cookies: {},
headers: expect.objectContaining({
// demonstrates that requestData integration is getting data
host: 'localhost:3030',
'user-agent': expect.any(String),
}),
method: 'GET',
url: expect.stringContaining('/ssr-error'),
},
sdk: {
integrations: expect.any(Array),
name: 'sentry.javascript.astro',
packages: expect.any(Array),
version: expect.any(String),
},
server_name: expect.any(String),
timestamp: expect.any(Number),
transaction: 'GET /ssr-error',
});
});
test('captures endpoint error', async ({ page }) => {
const errorEventPromise = waitForError('astro-4', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Endpoint Error';
});
const transactionEventApiPromise = waitForTransaction('astro-4', transactionEvent => {
return transactionEvent.transaction === 'GET /endpoint-error/api';
});
const transactionEventEndpointPromise = waitForTransaction('astro-4', transactionEvent => {
return transactionEvent.transaction === 'GET /endpoint-error';
});
await page.goto('/endpoint-error');
await page.getByText('Get Data').click();
const errorEvent = await errorEventPromise;
const transactionEventApi = await transactionEventApiPromise;
const transactionEventEndpoint = await transactionEventEndpointPromise;
expect(transactionEventEndpoint).toMatchObject({
transaction: 'GET /endpoint-error',
spans: [],
});
const traceId = transactionEventEndpoint.contexts?.trace?.trace_id;
const endpointSpanId = transactionEventApi.contexts?.trace?.span_id;
expect(traceId).toMatch(/[a-f0-9]{32}/);
expect(endpointSpanId).toMatch(/[a-f0-9]{16}/);
expect(transactionEventApi).toMatchObject({
transaction: 'GET /endpoint-error/api',
spans: [],
});
const spanId = transactionEventApi.contexts?.trace?.span_id;
const parentSpanId = transactionEventApi.contexts?.trace?.parent_span_id;
expect(spanId).toMatch(/[a-f0-9]{16}/);
// TODO: This is incorrect, for whatever reason, it should be the endpointSpanId ideally
expect(parentSpanId).toMatch(/[a-f0-9]{16}/);
expect(parentSpanId).not.toEqual(endpointSpanId);
expect(errorEvent).toMatchObject({
contexts: {
trace: {
parent_span_id: parentSpanId,
span_id: spanId,
trace_id: traceId,
},
},
exception: {
values: [
{
mechanism: {
data: {
function: 'astroMiddleware',
},
handled: false,
type: 'astro',
},
stacktrace: expect.any(Object),
type: 'Error',
value: 'Endpoint Error',
},
],
},
platform: 'node',
request: {
cookies: {},
headers: expect.objectContaining({
accept: expect.any(String),
}),
method: 'GET',
query_string: 'error=1',
url: expect.stringContaining('endpoint-error/api?error=1'),
},
transaction: 'GET /endpoint-error/api',
});
});
});