|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Captures a pageload transaction', async ({ page }) => { |
| 5 | + const transactionEventPromise = waitForTransaction('react-create-browser-router', event => { |
| 6 | + return event.contexts?.trace?.op === 'pageload'; |
| 7 | + }); |
| 8 | + |
| 9 | + await page.goto('/'); |
| 10 | + |
| 11 | + const transactionEvent = await transactionEventPromise; |
| 12 | + expect(transactionEvent.contexts?.trace).toEqual({ |
| 13 | + data: { |
| 14 | + deviceMemory: expect.any(String), |
| 15 | + effectiveConnectionType: expect.any(String), |
| 16 | + hardwareConcurrency: expect.any(String), |
| 17 | + 'lcp.element': 'body > div#root > input#exception-button[type="button"]', |
| 18 | + 'lcp.id': 'exception-button', |
| 19 | + 'lcp.size': 1650, |
| 20 | + 'sentry.idle_span_finish_reason': 'idleTimeout', |
| 21 | + 'sentry.op': 'pageload', |
| 22 | + 'sentry.origin': 'auto.pageload.react.reactrouter_v6', |
| 23 | + 'sentry.sample_rate': 1, |
| 24 | + 'sentry.source': 'route', |
| 25 | + 'performance.timeOrigin': expect.any(Number), |
| 26 | + 'performance.activationStart': expect.any(Number), |
| 27 | + 'lcp.renderTime': expect.any(Number), |
| 28 | + 'lcp.loadTime': expect.any(Number), |
| 29 | + }, |
| 30 | + op: 'pageload', |
| 31 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 32 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 33 | + origin: 'auto.pageload.react.reactrouter_v6', |
| 34 | + }); |
| 35 | + |
| 36 | + expect(transactionEvent).toEqual( |
| 37 | + expect.objectContaining({ |
| 38 | + transaction: '/', |
| 39 | + type: 'transaction', |
| 40 | + transaction_info: { |
| 41 | + source: 'route', |
| 42 | + }, |
| 43 | + }), |
| 44 | + ); |
| 45 | + |
| 46 | + expect(transactionEvent.spans).toContainEqual({ |
| 47 | + data: { |
| 48 | + 'sentry.origin': 'auto.ui.browser.metrics', |
| 49 | + 'sentry.op': 'browser.domContentLoadedEvent', |
| 50 | + }, |
| 51 | + description: page.url(), |
| 52 | + op: 'browser.domContentLoadedEvent', |
| 53 | + parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 54 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 55 | + start_timestamp: expect.any(Number), |
| 56 | + timestamp: expect.any(Number), |
| 57 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 58 | + origin: 'auto.ui.browser.metrics', |
| 59 | + }); |
| 60 | + expect(transactionEvent.spans).toContainEqual({ |
| 61 | + data: { |
| 62 | + 'sentry.origin': 'auto.ui.browser.metrics', |
| 63 | + 'sentry.op': 'browser.connect', |
| 64 | + }, |
| 65 | + description: page.url(), |
| 66 | + op: 'browser.connect', |
| 67 | + parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 68 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 69 | + start_timestamp: expect.any(Number), |
| 70 | + timestamp: expect.any(Number), |
| 71 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 72 | + origin: 'auto.ui.browser.metrics', |
| 73 | + }); |
| 74 | + expect(transactionEvent.spans).toContainEqual({ |
| 75 | + data: { |
| 76 | + 'sentry.origin': 'auto.ui.browser.metrics', |
| 77 | + 'sentry.op': 'browser.request', |
| 78 | + }, |
| 79 | + description: page.url(), |
| 80 | + op: 'browser.request', |
| 81 | + parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 82 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 83 | + start_timestamp: expect.any(Number), |
| 84 | + timestamp: expect.any(Number), |
| 85 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 86 | + origin: 'auto.ui.browser.metrics', |
| 87 | + }); |
| 88 | + expect(transactionEvent.spans).toContainEqual({ |
| 89 | + data: { |
| 90 | + 'sentry.origin': 'auto.ui.browser.metrics', |
| 91 | + 'sentry.op': 'browser.response', |
| 92 | + }, |
| 93 | + description: page.url(), |
| 94 | + op: 'browser.response', |
| 95 | + parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 96 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 97 | + start_timestamp: expect.any(Number), |
| 98 | + timestamp: expect.any(Number), |
| 99 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 100 | + origin: 'auto.ui.browser.metrics', |
| 101 | + }); |
| 102 | +}); |
| 103 | + |
| 104 | +test('Captures a navigation transaction', async ({ page }) => { |
| 105 | + const transactionEventPromise = waitForTransaction('react-create-browser-router', event => { |
| 106 | + return event.contexts?.trace?.op === 'navigation'; |
| 107 | + }); |
| 108 | + |
| 109 | + await page.goto('/'); |
| 110 | + const linkElement = page.locator('id=navigation'); |
| 111 | + await linkElement.click(); |
| 112 | + |
| 113 | + const transactionEvent = await transactionEventPromise; |
| 114 | + expect(transactionEvent.contexts?.trace).toEqual({ |
| 115 | + data: expect.objectContaining({ |
| 116 | + deviceMemory: expect.any(String), |
| 117 | + effectiveConnectionType: expect.any(String), |
| 118 | + hardwareConcurrency: expect.any(String), |
| 119 | + 'sentry.idle_span_finish_reason': 'idleTimeout', |
| 120 | + 'sentry.op': 'navigation', |
| 121 | + 'sentry.origin': 'auto.navigation.react.reactrouter_v6', |
| 122 | + 'sentry.sample_rate': 1, |
| 123 | + 'sentry.source': 'route', |
| 124 | + }), |
| 125 | + op: 'navigation', |
| 126 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 127 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 128 | + origin: 'auto.navigation.react.reactrouter_v6', |
| 129 | + }); |
| 130 | + |
| 131 | + expect(transactionEvent).toEqual( |
| 132 | + expect.objectContaining({ |
| 133 | + transaction: '/user/:id', |
| 134 | + type: 'transaction', |
| 135 | + transaction_info: { |
| 136 | + source: 'route', |
| 137 | + }, |
| 138 | + }), |
| 139 | + ); |
| 140 | + |
| 141 | + expect(transactionEvent.spans).toEqual([]); |
| 142 | +}); |
0 commit comments