-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtransaction.test.ts
More file actions
107 lines (88 loc) · 3.8 KB
/
transaction.test.ts
File metadata and controls
107 lines (88 loc) · 3.8 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
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
const usesManagedTunnelRoute =
(process.env.E2E_TEST_TUNNEL_ROUTE_MODE ?? 'off') !== 'off' || process.env.E2E_TEST_CUSTOM_TUNNEL_ROUTE === '1';
test.skip(usesManagedTunnelRoute, 'Default e2e suites run only in the proxy variant');
test('Sends a server function transaction with auto-instrumentation', async ({ page }) => {
const transactionEventPromise = waitForTransaction('tanstackstart-react', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
!!transactionEvent?.transaction?.startsWith('GET /_serverFn')
);
});
await page.goto('/test-serverFn');
await expect(page.getByText('Call server function', { exact: true })).toBeVisible();
await page.getByText('Call server function', { exact: true }).click();
const transactionEvent = await transactionEventPromise;
// Check for the auto-instrumented server function span
expect(Array.isArray(transactionEvent?.spans)).toBe(true);
expect(transactionEvent?.spans).toEqual(
expect.arrayContaining([
expect.objectContaining({
description: expect.stringContaining('GET /_serverFn/'),
op: 'function.tanstackstart',
origin: 'auto.function.tanstackstart.server',
data: {
'sentry.op': 'function.tanstackstart',
'sentry.origin': 'auto.function.tanstackstart.server',
'tanstackstart.function.hash.sha256': expect.any(String),
},
status: 'ok',
}),
]),
);
});
test('Sends a server function transaction for a nested server function only if it is manually instrumented', async ({
page,
}) => {
const transactionEventPromise = waitForTransaction('tanstackstart-react', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
!!transactionEvent?.transaction?.startsWith('GET /_serverFn')
);
});
await page.goto('/test-serverFn');
await expect(page.getByText('Call server function nested')).toBeVisible();
await page.getByText('Call server function nested').click();
const transactionEvent = await transactionEventPromise;
expect(Array.isArray(transactionEvent?.spans)).toBe(true);
// Check for the auto-instrumented server function span
expect(transactionEvent?.spans).toEqual(
expect.arrayContaining([
expect.objectContaining({
description: expect.stringContaining('GET /_serverFn/'),
op: 'function.tanstackstart',
origin: 'auto.function.tanstackstart.server',
data: {
'sentry.op': 'function.tanstackstart',
'sentry.origin': 'auto.function.tanstackstart.server',
'tanstackstart.function.hash.sha256': expect.any(String),
},
status: 'ok',
}),
]),
);
// Check for the manually instrumented nested span
expect(transactionEvent?.spans).toEqual(
expect.arrayContaining([
expect.objectContaining({
description: 'testNestedLog',
origin: 'manual',
status: 'ok',
}),
]),
);
// Verify that globalFunctionMiddleware and testNestedLog are sibling spans under the root
const functionMiddlewareSpan = transactionEvent?.spans?.find(
(span: { description?: string; origin?: string }) =>
span.description === 'globalFunctionMiddleware' && span.origin === 'auto.middleware.tanstackstart',
);
const nestedSpan = transactionEvent?.spans?.find(
(span: { description?: string; origin?: string }) =>
span.description === 'testNestedLog' && span.origin === 'manual',
);
expect(functionMiddlewareSpan).toBeDefined();
expect(nestedSpan).toBeDefined();
// Both spans should be siblings under the same parent (root transaction)
expect(nestedSpan?.parent_span_id).toBe(functionMiddlewareSpan?.parent_span_id);
});