|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { collectStreamedSpans, getSpanOp, hidePage } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +// The correlation between a soft navigation and the SDK's navigation span hangs off the interaction |
| 5 | +// that triggered it, so it only holds while the navigation span is started before the interaction's |
| 6 | +// Event Timing entry is delivered. `reactRouterV6BrowserTracingIntegration` on a data router defers the navigation span until the |
| 7 | +// router's navigation state goes idle, i.e. after loaders resolve, which is the latest any of our |
| 8 | +// instrumentations starts one. |
| 9 | +test('attributes soft navigation web vitals to the navigation span they were measured on', async ({ page }) => { |
| 10 | + const spansPromise = collectStreamedSpans( |
| 11 | + 'react-create-browser-router', |
| 12 | + spansOfTrace => |
| 13 | + spansOfTrace.some(span => getSpanOp(span) === 'navigation' && span.is_segment) && |
| 14 | + spansOfTrace.some(span => getSpanOp(span) === 'ui.webvital.cls'), |
| 15 | + ); |
| 16 | + |
| 17 | + await page.goto('/'); |
| 18 | + await page.locator('#navigation').click(); |
| 19 | + |
| 20 | + // A soft navigation's vitals are finalized at the next soft navigation or on pagehide, so nothing |
| 21 | + // is reported for it until the page goes away. |
| 22 | + await hidePage(page); |
| 23 | + |
| 24 | + const spans = await spansPromise; |
| 25 | + |
| 26 | + const navigationSpan = spans.find(span => getSpanOp(span) === 'navigation' && span.is_segment)!; |
| 27 | + const clsSpan = spans.find(span => getSpanOp(span) === 'ui.webvital.cls')!; |
| 28 | + |
| 29 | + expect(navigationSpan.name).toBe('/user/:id'); |
| 30 | + |
| 31 | + const softNavigationId = navigationSpan.attributes['browser.navigation.id']?.value; |
| 32 | + expect(softNavigationId).toEqual(expect.any(Number)); |
| 33 | + |
| 34 | + // Both sides of the correlation carry the id, so the navigation and its vitals are joinable. |
| 35 | + expect(clsSpan.attributes).toMatchObject({ |
| 36 | + 'browser.navigation.id': { value: softNavigationId, type: 'integer' }, |
| 37 | + 'browser.navigation.type': { value: 'soft-navigation', type: 'string' }, |
| 38 | + }); |
| 39 | + expect(clsSpan.parent_span_id).toBe(navigationSpan.span_id); |
| 40 | +}); |
0 commit comments