|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Sends a transaction for a request to app router with URL', async ({ page }) => { |
| 5 | + const serverComponentTransactionPromise = waitForTransaction('nextjs-13', transactionEvent => { |
| 6 | + return ( |
| 7 | + transactionEvent?.transaction === 'GET /parameterized/[one]/beep/[two]' && |
| 8 | + transactionEvent.contexts?.trace?.data?.['http.target']?.startsWith('/parameterized/1337/beep/42') |
| 9 | + ); |
| 10 | + }); |
| 11 | + |
| 12 | + await page.goto('/parameterized/1337/beep/42'); |
| 13 | + |
| 14 | + const transactionEvent = await serverComponentTransactionPromise; |
| 15 | + |
| 16 | + expect(transactionEvent.contexts?.trace).toEqual({ |
| 17 | + data: expect.objectContaining({ |
| 18 | + 'sentry.op': 'http.server', |
| 19 | + 'sentry.origin': 'auto', |
| 20 | + 'sentry.sample_rate': 1, |
| 21 | + 'sentry.source': 'route', |
| 22 | + 'http.method': 'GET', |
| 23 | + 'http.response.status_code': 200, |
| 24 | + 'http.route': '/parameterized/[one]/beep/[two]', |
| 25 | + 'http.status_code': 200, |
| 26 | + 'http.target': '/parameterized/1337/beep/42', |
| 27 | + 'otel.kind': 'SERVER', |
| 28 | + 'next.route': '/parameterized/[one]/beep/[two]', |
| 29 | + }), |
| 30 | + op: 'http.server', |
| 31 | + origin: 'auto', |
| 32 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 33 | + status: 'ok', |
| 34 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 35 | + }); |
| 36 | + |
| 37 | + expect(transactionEvent.request).toMatchObject({ |
| 38 | + url: expect.stringContaining('/parameterized/1337/beep/42'), |
| 39 | + }); |
| 40 | + |
| 41 | + // The transaction should not contain any spans with the same name as the transaction |
| 42 | + // e.g. "GET /parameterized/[one]/beep/[two]" |
| 43 | + expect( |
| 44 | + transactionEvent.spans?.filter(span => { |
| 45 | + return span.description === transactionEvent.transaction; |
| 46 | + }), |
| 47 | + ).toHaveLength(0); |
| 48 | +}); |
0 commit comments