-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(astro-5): Add test for current parametrized routes #17054
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
Merged
+170
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/astro-5/src/pages/api/user/[userId].json.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function GET({ params }) { | ||
return new Response( | ||
JSON.stringify({ | ||
greeting: `Hello ${params.userId}`, | ||
userId: params.userId, | ||
}), | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
dev-packages/e2e-tests/test-applications/astro-5/src/pages/user-page/[userId].astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
import Layout from '../../layouts/Layout.astro'; | ||
|
||
export const prerender = false; | ||
|
||
const { userId } = Astro.params; | ||
|
||
const response = await fetch(Astro.url.origin + `/api/user/${userId}.json`) | ||
const data = await response.json(); | ||
|
||
--- | ||
|
||
<Layout title="Dynamic SSR page"> | ||
<h1>{data.greeting}</h1> | ||
|
||
<p>data: {JSON.stringify(data)}</p> | ||
</Layout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,3 +119,147 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => { | |
}); | ||
}); | ||
}); | ||
|
||
test.describe('nested SSR routes (client, server, server request)', () => { | ||
/** The user-page route fetches from an endpoint and creates a deeply nested span structure: | ||
* pageload — /user-page/myUsername123 | ||
* ├── browser.** — multiple browser spans | ||
* └── browser.request — /user-page/myUsername123 | ||
* └── http.server — GET /user-page/[userId] (SSR page request) | ||
* └── http.client — GET /api/user/myUsername123.json (executing fetch call from SSR page - span) | ||
* └── http.server — GET /api/user/myUsername123.json (server request) | ||
*/ | ||
test('sends connected server and client pageload and request spans with the same trace id', async ({ page }) => { | ||
const clientPageloadTxnPromise = waitForTransaction('astro-5', txnEvent => { | ||
return txnEvent?.transaction?.startsWith('/user-page/') ?? false; | ||
}); | ||
|
||
const serverPageRequestTxnPromise = waitForTransaction('astro-5', txnEvent => { | ||
return txnEvent?.transaction?.startsWith('GET /user-page/') ?? false; | ||
}); | ||
|
||
const serverHTTPServerRequestTxnPromise = waitForTransaction('astro-5', txnEvent => { | ||
return txnEvent?.transaction?.startsWith('GET /api/user/') ?? false; | ||
}); | ||
|
||
await page.goto('/user-page/myUsername123'); | ||
|
||
const clientPageloadTxn = await clientPageloadTxnPromise; | ||
const serverPageRequestTxn = await serverPageRequestTxnPromise; | ||
const serverHTTPServerRequestTxn = await serverHTTPServerRequestTxnPromise; | ||
const serverRequestHTTPClientSpan = serverPageRequestTxn.spans?.find( | ||
span => span.op === 'http.client' && span.description?.includes('/api/user/'), | ||
); | ||
|
||
const clientPageloadTraceId = clientPageloadTxn.contexts?.trace?.trace_id; | ||
|
||
// Verify all spans have the same trace ID | ||
expect(clientPageloadTraceId).toEqual(serverPageRequestTxn.contexts?.trace?.trace_id); | ||
expect(clientPageloadTraceId).toEqual(serverHTTPServerRequestTxn.contexts?.trace?.trace_id); | ||
expect(clientPageloadTraceId).toEqual(serverRequestHTTPClientSpan?.trace_id); | ||
|
||
// serverPageRequest has no parent (root span) | ||
expect(serverPageRequestTxn.contexts?.trace?.parent_span_id).toBeUndefined(); | ||
|
||
// clientPageload's parent and serverRequestHTTPClient's parent is serverPageRequest | ||
const serverPageRequestSpanId = serverPageRequestTxn.contexts?.trace?.span_id; | ||
expect(clientPageloadTxn.contexts?.trace?.parent_span_id).toEqual(serverPageRequestSpanId); | ||
expect(serverRequestHTTPClientSpan?.parent_span_id).toEqual(serverPageRequestSpanId); | ||
|
||
// serverHTTPServerRequest's parent is serverRequestHTTPClient | ||
expect(serverHTTPServerRequestTxn.contexts?.trace?.parent_span_id).toEqual(serverRequestHTTPClientSpan?.span_id); | ||
}); | ||
|
||
test('sends parametrized pageload, server and API request transaction names', async ({ page }) => { | ||
const clientPageloadTxnPromise = waitForTransaction('astro-5', txnEvent => { | ||
return txnEvent?.transaction?.startsWith('/user-page/') ?? false; | ||
}); | ||
|
||
const serverPageRequestTxnPromise = waitForTransaction('astro-5', txnEvent => { | ||
return txnEvent?.transaction?.startsWith('GET /user-page/') ?? false; | ||
}); | ||
|
||
const serverHTTPServerRequestTxnPromise = waitForTransaction('astro-5', txnEvent => { | ||
return txnEvent?.transaction?.startsWith('GET /api/user/') ?? false; | ||
}); | ||
|
||
await page.goto('/user-page/myUsername123'); | ||
|
||
const clientPageloadTxn = await clientPageloadTxnPromise; | ||
const serverPageRequestTxn = await serverPageRequestTxnPromise; | ||
const serverHTTPServerRequestTxn = await serverHTTPServerRequestTxnPromise; | ||
|
||
const serverRequestHTTPClientSpan = serverPageRequestTxn.spans?.find( | ||
span => span.op === 'http.client' && span.description?.includes('/api/user/'), | ||
); | ||
|
||
// Client pageload transaction - actual URL with pageload operation | ||
expect(clientPageloadTxn).toMatchObject({ | ||
transaction: '/user-page/myUsername123', // todo: parametrize to '/user-page/[userId]' | ||
transaction_info: { source: 'url' }, | ||
contexts: { | ||
trace: { | ||
op: 'pageload', | ||
origin: 'auto.pageload.browser', | ||
data: { | ||
'sentry.op': 'pageload', | ||
'sentry.origin': 'auto.pageload.browser', | ||
'sentry.source': 'url', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// Server page request transaction - parametrized transaction name with actual URL in data | ||
expect(serverPageRequestTxn).toMatchObject({ | ||
transaction: 'GET /user-page/[userId]', | ||
transaction_info: { source: 'route' }, | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
origin: 'auto.http.astro', | ||
data: { | ||
'sentry.op': 'http.server', | ||
'sentry.origin': 'auto.http.astro', | ||
'sentry.source': 'route', | ||
url: expect.stringContaining('/user-page/myUsername123'), | ||
}, | ||
}, | ||
}, | ||
request: { url: expect.stringContaining('/user-page/myUsername123') }, | ||
}); | ||
|
||
// HTTP client span - actual API URL with client operation | ||
expect(serverRequestHTTPClientSpan).toMatchObject({ | ||
op: 'http.client', | ||
origin: 'auto.http.otel.node_fetch', | ||
description: 'GET http://localhost:3030/api/user/myUsername123.json', // todo: parametrize (this is just a span though - no transaction) | ||
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. l: the |
||
data: { | ||
'sentry.op': 'http.client', | ||
'sentry.origin': 'auto.http.otel.node_fetch', | ||
'url.full': expect.stringContaining('/api/user/myUsername123.json'), | ||
'url.path': '/api/user/myUsername123.json', | ||
url: expect.stringContaining('/api/user/myUsername123.json'), | ||
}, | ||
}); | ||
|
||
// Server HTTP request transaction - should be parametrized (todo: currently not parametrized) | ||
expect(serverHTTPServerRequestTxn).toMatchObject({ | ||
transaction: 'GET /api/user/myUsername123.json', // todo: should be parametrized to 'GET /api/user/[userId].json' | ||
transaction_info: { source: 'route' }, | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
origin: 'auto.http.astro', | ||
data: { | ||
'sentry.op': 'http.server', | ||
'sentry.origin': 'auto.http.astro', | ||
'sentry.source': 'route', | ||
url: expect.stringContaining('/api/user/myUsername123.json'), | ||
}, | ||
}, | ||
}, | ||
request: { url: expect.stringContaining('/api/user/myUsername123.json') }, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if you already thought of a way how to achieve this (if so, ignore me :D) but: We could inject the parameterized route we identify on the server into a tag just like we do with the trace data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already found something :D
working on this in another PR. The parametrized route is in the context of the astro request so this is fairly easy.