-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(e2e): Port the TanStack Start Cloudflare E2E app to span streaming #24173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
51714ad
67c01ae
a6e6ed2
610c814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,99 +1,105 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('Sends a server function transaction with span from wrapFetchWithSentry', async ({ page }) => { | ||
| const transactionEventPromise = waitForTransaction('tanstackstart-react-cloudflare', transactionEvent => { | ||
| return ( | ||
| transactionEvent?.contexts?.trace?.op === 'http.server' && | ||
| !!transactionEvent?.transaction?.startsWith('GET /_serverFn') | ||
| ); | ||
| }); | ||
| import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '@sentry-internal/test-utils'; | ||
|
|
||
| function isServerFnSegment(span: Parameters<typeof getSpanOp>[0]): boolean { | ||
| return ( | ||
| !!span.is_segment && | ||
| getSpanOp(span) === 'http.server' && | ||
| String(span.attributes['url.path']?.value ?? '').startsWith('/_serverFn') | ||
| ); | ||
| } | ||
|
|
||
| test('Sends a server function span with wrapFetchWithSentry', async ({ page }) => { | ||
| const spansPromise = collectStreamedSpans( | ||
| 'tanstackstart-react-cloudflare', | ||
| spans => spans.some(isServerFnSegment) && spans.some(span => span.name === 'GET /_serverFn/testLog'), | ||
| ); | ||
|
|
||
| await page.goto('/test-serverFn'); | ||
|
|
||
| await expect(page.locator('#server-fn-btn')).toBeVisible(); | ||
|
|
||
| await page.locator('#server-fn-btn').click(); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
| const spans = await spansPromise; | ||
|
|
||
| expect(transactionEvent.contexts?.trace).toMatchObject({ | ||
| op: 'http.server', | ||
| origin: 'auto.http.cloudflare', | ||
| const serverSegment = spans.find(isServerFnSegment); | ||
| expect(serverSegment?.attributes).toMatchObject({ | ||
| 'sentry.op': { type: 'string', value: 'http.server' }, | ||
| 'sentry.origin': { type: 'string', value: 'auto.http.cloudflare' }, | ||
| }); | ||
|
|
||
| expect(transactionEvent?.spans).toHaveLength(1); | ||
| expect(transactionEvent?.spans).toEqual([ | ||
| expect.objectContaining({ | ||
| description: 'GET /_serverFn/testLog', | ||
| op: 'function', | ||
| origin: 'auto.function.tanstackstart.server', | ||
| data: { | ||
| 'sentry.op': 'function', | ||
| 'sentry.origin': 'auto.function.tanstackstart.server', | ||
| 'tanstackstart.function.id': expect.any(String), | ||
| 'tanstackstart.function.filename': 'src/routes/test-serverFn.tsx', | ||
| }, | ||
| }), | ||
| ]); | ||
| expect(spans).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| name: 'GET /_serverFn/testLog', | ||
| attributes: expect.objectContaining({ | ||
| 'sentry.op': { type: 'string', value: 'function' }, | ||
| 'sentry.origin': { type: 'string', value: 'auto.function.tanstackstart.server' }, | ||
| 'tanstackstart.function.id': { type: 'string', value: expect.any(String) }, | ||
| 'tanstackstart.function.filename': { type: 'string', value: 'src/routes/test-serverFn.tsx' }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was the assertion on
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was accidentally dropped, thanks for catching! |
||
| }), | ||
| }), | ||
| ]), | ||
| ); | ||
| }); | ||
|
|
||
| test('Sends a server function transaction for a nested server function with manual span', async ({ page }) => { | ||
| const transactionEventPromise = waitForTransaction('tanstackstart-react-cloudflare', transactionEvent => { | ||
| return ( | ||
| transactionEvent?.contexts?.trace?.op === 'http.server' && | ||
| !!transactionEvent?.transaction?.startsWith('GET /_serverFn') | ||
| ); | ||
| }); | ||
| test('Sends a server function span for a nested server function with manual span', async ({ page }) => { | ||
| const spansPromise = collectStreamedSpans( | ||
| 'tanstackstart-react-cloudflare', | ||
| spans => | ||
| spans.some(isServerFnSegment) && | ||
| spans.some(span => span.name === 'GET /_serverFn/testNestedLog') && | ||
| spans.some(span => span.name === 'testNestedLog'), | ||
| ); | ||
|
|
||
| await page.goto('/test-serverFn'); | ||
|
|
||
| await expect(page.locator('#server-fn-nested-btn')).toBeVisible(); | ||
|
|
||
| await page.locator('#server-fn-nested-btn').click(); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
| const spans = await spansPromise; | ||
|
|
||
| expect(transactionEvent.contexts?.trace).toMatchObject({ | ||
| op: 'http.server', | ||
| origin: 'auto.http.cloudflare', | ||
| const serverSegment = spans.find(isServerFnSegment); | ||
| expect(serverSegment?.attributes).toMatchObject({ | ||
| 'sentry.op': { type: 'string', value: 'http.server' }, | ||
| 'sentry.origin': { type: 'string', value: 'auto.http.cloudflare' }, | ||
| }); | ||
|
|
||
| expect(transactionEvent?.spans).toHaveLength(2); | ||
| expect(transactionEvent?.spans).toEqual( | ||
| expect(spans).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| description: 'GET /_serverFn/testNestedLog', | ||
| op: 'function', | ||
| origin: 'auto.function.tanstackstart.server', | ||
| data: { | ||
| 'sentry.op': 'function', | ||
| 'sentry.origin': 'auto.function.tanstackstart.server', | ||
| 'tanstackstart.function.id': expect.any(String), | ||
| 'tanstackstart.function.filename': 'src/routes/test-serverFn.tsx', | ||
| }, | ||
| name: 'GET /_serverFn/testNestedLog', | ||
| attributes: expect.objectContaining({ | ||
| 'sentry.op': { type: 'string', value: 'function' }, | ||
| 'sentry.origin': { type: 'string', value: 'auto.function.tanstackstart.server' }, | ||
| 'tanstackstart.function.id': { type: 'string', value: expect.any(String) }, | ||
| 'tanstackstart.function.filename': { type: 'string', value: 'src/routes/test-serverFn.tsx' }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| }), | ||
| }), | ||
| expect.objectContaining({ | ||
| description: 'testNestedLog', | ||
| origin: 'manual', | ||
| name: 'testNestedLog', | ||
| attributes: expect.objectContaining({ | ||
| 'sentry.origin': { type: 'string', value: 'manual' }, | ||
| }), | ||
| }), | ||
| ]), | ||
| ); | ||
| }); | ||
|
|
||
| test('Sends server-side transaction for page request', async ({ baseURL }) => { | ||
| const transactionEventPromise = waitForTransaction('tanstackstart-react-cloudflare', transactionEvent => { | ||
| return transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'GET /'; | ||
| test('Sends server-side span for page request', async ({ baseURL }) => { | ||
| const serverSpanPromise = waitForStreamedSpan('tanstackstart-react-cloudflare', span => { | ||
| return span.is_segment && getSpanOp(span) === 'http.server' && span.attributes['url.path']?.value === '/'; | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/`); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
| const serverSpan = await serverSpanPromise; | ||
|
|
||
| expect(transactionEvent.transaction).toBe('GET /'); | ||
| expect(transactionEvent.contexts?.trace).toMatchObject({ | ||
| op: 'http.server', | ||
| origin: 'auto.http.cloudflare', | ||
| status: 'ok', | ||
| expect(serverSpan.attributes).toMatchObject({ | ||
| 'sentry.op': { type: 'string', value: 'http.server' }, | ||
| 'sentry.origin': { type: 'string', value: 'auto.http.cloudflare' }, | ||
| }); | ||
| expect(serverSpan.status).toBe('ok'); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.