|
1 | 1 | import { expect, test } from '@playwright/test'; |
2 | | -import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 2 | +import { getSpanOp, waitForStreamedSpan } from '@sentry-internal/test-utils'; |
3 | 3 |
|
4 | | -test('sends a pageload transaction', async ({ page }) => { |
5 | | - const transactionPromise = waitForTransaction('solidstart-2', async transactionEvent => { |
6 | | - return transactionEvent?.transaction === '/' && transactionEvent.contexts?.trace?.op === 'pageload'; |
| 4 | +test('sends a pageload span', async ({ page }) => { |
| 5 | + const spanPromise = waitForStreamedSpan('solidstart-2', span => { |
| 6 | + return span.name === '/' && getSpanOp(span) === 'pageload' && span.is_segment; |
7 | 7 | }); |
8 | 8 |
|
9 | 9 | await page.goto('/'); |
10 | | - const pageloadTransaction = await transactionPromise; |
| 10 | + const pageloadSpan = await spanPromise; |
11 | 11 |
|
12 | | - expect(pageloadTransaction).toMatchObject({ |
13 | | - contexts: { |
14 | | - trace: { |
15 | | - op: 'pageload', |
16 | | - origin: 'auto.pageload.browser', |
17 | | - data: { |
18 | | - 'sentry.segment.name.source': 'route', |
19 | | - 'url.template': '/', |
20 | | - 'url.path': '/', |
21 | | - 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/), |
22 | | - }, |
23 | | - }, |
24 | | - }, |
25 | | - transaction: '/', |
26 | | - transaction_info: { |
27 | | - source: 'route', |
28 | | - }, |
| 12 | + expect(getSpanOp(pageloadSpan)).toBe('pageload'); |
| 13 | + expect(pageloadSpan.attributes).toMatchObject({ |
| 14 | + 'sentry.origin': { value: 'auto.pageload.browser', type: 'string' }, |
| 15 | + 'sentry.op': { value: 'pageload', type: 'string' }, |
| 16 | + 'sentry.segment.name.source': { value: 'route', type: 'string' }, |
| 17 | + 'url.template': { value: '/', type: 'string' }, |
| 18 | + 'url.path': { value: '/', type: 'string' }, |
| 19 | + 'url.full': { value: expect.stringMatching(/^https?:\/\/localhost:\d+\/$/), type: 'string' }, |
29 | 20 | }); |
30 | 21 | }); |
31 | 22 |
|
32 | | -test('sends a navigation transaction with parametrized route', async ({ page }) => { |
33 | | - const transactionPromise = waitForTransaction('solidstart-2', async transactionEvent => { |
34 | | - return transactionEvent?.transaction === '/users/:id' && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 23 | +test('sends a navigation span with parametrized route', async ({ page }) => { |
| 24 | + const spanPromise = waitForStreamedSpan('solidstart-2', span => { |
| 25 | + return span.name === '/users/:id' && getSpanOp(span) === 'navigation' && span.is_segment; |
35 | 26 | }); |
36 | 27 |
|
37 | 28 | await page.goto(`/`); |
38 | 29 | await page.locator('#navLink').click(); |
39 | | - const navigationTransaction = await transactionPromise; |
| 30 | + const navigationSpan = await spanPromise; |
40 | 31 |
|
41 | | - expect(navigationTransaction).toMatchObject({ |
42 | | - contexts: { |
43 | | - trace: { |
44 | | - op: 'navigation', |
45 | | - origin: 'auto.navigation.solidstart.solidrouter', |
46 | | - data: { |
47 | | - 'sentry.segment.name.source': 'route', |
48 | | - 'url.template': '/users/:id', |
49 | | - 'url.path': '/users/5', |
50 | | - 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/5$/), |
51 | | - }, |
52 | | - }, |
53 | | - }, |
54 | | - transaction: '/users/:id', |
55 | | - transaction_info: { |
56 | | - source: 'route', |
57 | | - }, |
| 32 | + expect(getSpanOp(navigationSpan)).toBe('navigation'); |
| 33 | + expect(navigationSpan.attributes).toMatchObject({ |
| 34 | + 'sentry.origin': { value: 'auto.navigation.solidstart.solidrouter', type: 'string' }, |
| 35 | + 'sentry.op': { value: 'navigation', type: 'string' }, |
| 36 | + 'sentry.segment.name.source': { value: 'route', type: 'string' }, |
| 37 | + 'url.template': { value: '/users/:id', type: 'string' }, |
| 38 | + 'url.path': { value: '/users/5', type: 'string' }, |
| 39 | + 'url.full': { value: expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/5$/), type: 'string' }, |
58 | 40 | }); |
59 | 41 | }); |
60 | 42 |
|
61 | | -test('updates the transaction when using the back button', async ({ page }) => { |
| 43 | +test('updates the span when using the back button', async ({ page }) => { |
62 | 44 | // Solid Router sends a `-1` navigation when using the back button. |
63 | 45 | // The sentry solidRouterBrowserTracingIntegration tries to update such |
64 | | - // transactions with the proper name once the `useLocation` hook triggers. |
65 | | - const navigationTxnPromise = waitForTransaction('solidstart-2', async transactionEvent => { |
66 | | - return transactionEvent?.transaction === '/users/:id' && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 46 | + // spans with the proper name once the `useLocation` hook triggers. |
| 47 | + const navigationSpanPromise = waitForStreamedSpan('solidstart-2', span => { |
| 48 | + return span.name === '/users/:id' && getSpanOp(span) === 'navigation' && span.is_segment; |
67 | 49 | }); |
68 | 50 |
|
69 | 51 | await page.goto(`/back-navigation`); |
70 | 52 | await page.locator('#navLink').click(); |
71 | | - const navigationTxn = await navigationTxnPromise; |
| 53 | + const navigationSpan = await navigationSpanPromise; |
72 | 54 |
|
73 | | - expect(navigationTxn).toMatchObject({ |
74 | | - contexts: { |
75 | | - trace: { |
76 | | - op: 'navigation', |
77 | | - origin: 'auto.navigation.solidstart.solidrouter', |
78 | | - data: { |
79 | | - 'sentry.segment.name.source': 'route', |
80 | | - 'url.template': '/users/:id', |
81 | | - 'url.path': '/users/6', |
82 | | - 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/6$/), |
83 | | - }, |
84 | | - }, |
85 | | - }, |
86 | | - transaction: '/users/:id', |
87 | | - transaction_info: { |
88 | | - source: 'route', |
89 | | - }, |
| 55 | + expect(getSpanOp(navigationSpan)).toBe('navigation'); |
| 56 | + expect(navigationSpan.attributes).toMatchObject({ |
| 57 | + 'sentry.origin': { value: 'auto.navigation.solidstart.solidrouter', type: 'string' }, |
| 58 | + 'sentry.op': { value: 'navigation', type: 'string' }, |
| 59 | + 'sentry.segment.name.source': { value: 'route', type: 'string' }, |
| 60 | + 'url.template': { value: '/users/:id', type: 'string' }, |
| 61 | + 'url.path': { value: '/users/6', type: 'string' }, |
| 62 | + 'url.full': { value: expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/6$/), type: 'string' }, |
90 | 63 | }); |
91 | 64 |
|
92 | | - const backNavigationTxnPromise = waitForTransaction('solidstart-2', async transactionEvent => { |
93 | | - return ( |
94 | | - transactionEvent?.transaction === '/back-navigation' && transactionEvent.contexts?.trace?.op === 'navigation' |
95 | | - ); |
| 65 | + const backNavigationSpanPromise = waitForStreamedSpan('solidstart-2', span => { |
| 66 | + return span.name === '/back-navigation' && getSpanOp(span) === 'navigation' && span.is_segment; |
96 | 67 | }); |
97 | 68 |
|
98 | 69 | await page.goBack(); |
99 | | - const backNavigationTxn = await backNavigationTxnPromise; |
| 70 | + const backNavigationSpan = await backNavigationSpanPromise; |
100 | 71 |
|
101 | | - expect(backNavigationTxn).toMatchObject({ |
102 | | - contexts: { |
103 | | - trace: { |
104 | | - op: 'navigation', |
105 | | - origin: 'auto.navigation.solidstart.solidrouter', |
106 | | - data: { |
107 | | - 'sentry.segment.name.source': 'route', |
108 | | - 'url.template': '/back-navigation', |
109 | | - 'url.path': '/back-navigation', |
110 | | - 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/back-navigation$/), |
111 | | - }, |
112 | | - }, |
113 | | - }, |
114 | | - transaction: '/back-navigation', |
115 | | - transaction_info: { |
116 | | - source: 'route', |
117 | | - }, |
| 72 | + expect(getSpanOp(backNavigationSpan)).toBe('navigation'); |
| 73 | + expect(backNavigationSpan.attributes).toMatchObject({ |
| 74 | + 'sentry.origin': { value: 'auto.navigation.solidstart.solidrouter', type: 'string' }, |
| 75 | + 'sentry.op': { value: 'navigation', type: 'string' }, |
| 76 | + 'sentry.segment.name.source': { value: 'route', type: 'string' }, |
| 77 | + 'url.template': { value: '/back-navigation', type: 'string' }, |
| 78 | + 'url.path': { value: '/back-navigation', type: 'string' }, |
| 79 | + 'url.full': { value: expect.stringMatching(/^https?:\/\/localhost:\d+\/back-navigation$/), type: 'string' }, |
118 | 80 | }); |
119 | 81 | }); |
0 commit comments