|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Sends a server function transaction with auto-instrumentation', async ({ page }) => { |
| 5 | + const transactionEventPromise = waitForTransaction('tanstackstart-react', transactionEvent => { |
| 6 | + return ( |
| 7 | + transactionEvent?.contexts?.trace?.op === 'http.server' && |
| 8 | + !!transactionEvent?.transaction?.startsWith('GET /_serverFn') |
| 9 | + ); |
| 10 | + }); |
| 11 | + |
| 12 | + await page.goto('/test-serverFn'); |
| 13 | + |
| 14 | + await expect(page.getByText('Call server function', { exact: true })).toBeVisible(); |
| 15 | + |
| 16 | + await page.getByText('Call server function', { exact: true }).click(); |
| 17 | + |
| 18 | + const transactionEvent = await transactionEventPromise; |
| 19 | + |
| 20 | + // Check for the auto-instrumented server function span |
| 21 | + expect(Array.isArray(transactionEvent?.spans)).toBe(true); |
| 22 | + expect(transactionEvent?.spans).toEqual( |
| 23 | + expect.arrayContaining([ |
| 24 | + expect.objectContaining({ |
| 25 | + description: expect.stringContaining('GET /_serverFn/'), |
| 26 | + op: 'function.tanstackstart', |
| 27 | + origin: 'auto.function.tanstackstart.server', |
| 28 | + data: { |
| 29 | + 'sentry.op': 'function.tanstackstart', |
| 30 | + 'sentry.origin': 'auto.function.tanstackstart.server', |
| 31 | + 'tanstackstart.function.hash.sha256': expect.any(String), |
| 32 | + }, |
| 33 | + status: 'ok', |
| 34 | + }), |
| 35 | + ]), |
| 36 | + ); |
| 37 | +}); |
| 38 | + |
| 39 | +test('Sends a server function transaction for a nested server function only if it is manually instrumented', async ({ |
| 40 | + page, |
| 41 | +}) => { |
| 42 | + const transactionEventPromise = waitForTransaction('tanstackstart-react', transactionEvent => { |
| 43 | + return ( |
| 44 | + transactionEvent?.contexts?.trace?.op === 'http.server' && |
| 45 | + !!transactionEvent?.transaction?.startsWith('GET /_serverFn') |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + await page.goto('/test-serverFn'); |
| 50 | + |
| 51 | + await expect(page.getByText('Call server function nested')).toBeVisible(); |
| 52 | + |
| 53 | + await page.getByText('Call server function nested').click(); |
| 54 | + |
| 55 | + const transactionEvent = await transactionEventPromise; |
| 56 | + |
| 57 | + expect(Array.isArray(transactionEvent?.spans)).toBe(true); |
| 58 | + |
| 59 | + // Check for the auto-instrumented server function span |
| 60 | + expect(transactionEvent?.spans).toEqual( |
| 61 | + expect.arrayContaining([ |
| 62 | + expect.objectContaining({ |
| 63 | + description: expect.stringContaining('GET /_serverFn/'), |
| 64 | + op: 'function.tanstackstart', |
| 65 | + origin: 'auto.function.tanstackstart.server', |
| 66 | + data: { |
| 67 | + 'sentry.op': 'function.tanstackstart', |
| 68 | + 'sentry.origin': 'auto.function.tanstackstart.server', |
| 69 | + 'tanstackstart.function.hash.sha256': expect.any(String), |
| 70 | + }, |
| 71 | + status: 'ok', |
| 72 | + }), |
| 73 | + ]), |
| 74 | + ); |
| 75 | + |
| 76 | + // Check for the manually instrumented nested span |
| 77 | + expect(transactionEvent?.spans).toEqual( |
| 78 | + expect.arrayContaining([ |
| 79 | + expect.objectContaining({ |
| 80 | + description: 'testNestedLog', |
| 81 | + origin: 'manual', |
| 82 | + status: 'ok', |
| 83 | + }), |
| 84 | + ]), |
| 85 | + ); |
| 86 | + |
| 87 | + // Verify that the auto span is the parent of the nested span |
| 88 | + const autoSpan = transactionEvent?.spans?.find( |
| 89 | + (span: { op?: string; origin?: string }) => |
| 90 | + span.op === 'function.tanstackstart' && span.origin === 'auto.function.tanstackstart.server', |
| 91 | + ); |
| 92 | + const nestedSpan = transactionEvent?.spans?.find( |
| 93 | + (span: { description?: string; origin?: string }) => |
| 94 | + span.description === 'testNestedLog' && span.origin === 'manual', |
| 95 | + ); |
| 96 | + |
| 97 | + expect(autoSpan).toBeDefined(); |
| 98 | + expect(nestedSpan).toBeDefined(); |
| 99 | + expect(nestedSpan?.parent_span_id).toBe(autoSpan?.span_id); |
| 100 | +}); |
0 commit comments