Repository navigation
fix(sveltekit): Read load event pathname untracked #25235
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
+185
−14
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions
7
...es/e2e-tests/test-applications/sveltekit-2/src/routes/load-dependencies/+layout.server.ts
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,7 @@ | ||
| let layoutLoadCount = 0; | ||
|
|
||
| // Doesn't read `url`, so SvelteKit should only run it once across child navigations. | ||
| export const load = async () => { | ||
| layoutLoadCount++; | ||
| return { layoutLoadCount }; | ||
| }; |
6 changes: 6 additions & 0 deletions
6
...kages/e2e-tests/test-applications/sveltekit-2/src/routes/load-dependencies/+layout.svelte
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,6 @@ | ||
| <script lang="ts"> | ||
| export let data; | ||
| </script> | ||
|
|
||
| <p id="layout-load-count">Layout loads: {data.layoutLoadCount}</p> | ||
| <slot></slot> |
2 changes: 2 additions & 0 deletions
2
...kages/e2e-tests/test-applications/sveltekit-2/src/routes/load-dependencies/a/+page.svelte
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,2 @@ | ||
| <h2>Page A</h2> | ||
| <a href="/load-dependencies/b">Go to B</a> |
1 change: 1 addition & 0 deletions
1
...kages/e2e-tests/test-applications/sveltekit-2/src/routes/load-dependencies/b/+page.svelte
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 @@ | ||
| <h2>Page B</h2> |
20 changes: 20 additions & 0 deletions
20
dev-packages/e2e-tests/test-applications/sveltekit-2/tests/load-dependencies.test.ts
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,20 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { getSpanOp, waitForStreamedSpan } from '@sentry-internal/test-utils'; | ||
| import { waitForInitialPageload } from './utils'; | ||
|
|
||
| test("doesn't rerun a wrapped layout server load that doesn't depend on the url", async ({ page }) => { | ||
| await waitForInitialPageload(page, { route: '/load-dependencies/a' }); | ||
|
|
||
| const layoutLoadCount = page.locator('#layout-load-count'); | ||
| const initialText = await layoutLoadCount.textContent(); | ||
|
|
||
| const navigationSpanPromise = waitForStreamedSpan('sveltekit-2', span => { | ||
| return span.name === '/load-dependencies/b' && getSpanOp(span) === 'navigation' && span.is_segment; | ||
| }); | ||
|
|
||
| await page.getByText('Go to B').click(); | ||
| await expect(page.getByText('Page B')).toBeVisible(); | ||
| await navigationSpanPromise; | ||
|
|
||
| await expect(layoutLoadCount).toHaveText(initialText!); | ||
| }); |
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
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ import { | |||||
| import { FUNCTION } from '@sentry/conventions/op'; | ||||||
| import type { LoadEvent, ServerLoadEvent } from '@sveltejs/kit'; | ||||||
| import type { SentryWrappedFlag } from '../common/utils'; | ||||||
| import { getRouteId } from '../common/utils'; | ||||||
| import { getPathname, getRouteId } from '../common/utils'; | ||||||
| import { sendErrorToSentry } from './utils'; | ||||||
|
|
||||||
| type PatchedLoadEvent = LoadEvent & SentryWrappedFlag; | ||||||
|
|
@@ -41,7 +41,8 @@ export function wrapLoadWithSentry<T extends (...args: any) => any>(origLoad: T) | |||||
| addNonEnumerableProperty(event, '__sentry_wrapped__', true); | ||||||
|
|
||||||
| const routeId = getRouteId(event) ?? undefined; | ||||||
| const routeOrPathname = routeId ? routeId : event.url.pathname; | ||||||
| const pathname = getPathname(event); | ||||||
| const routeOrPathname = routeId ? routeId : pathname; | ||||||
|
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. super-l: Wouldn't this be the same?
Suggested change
|
||||||
|
|
||||||
| const client = getClient(); | ||||||
| const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client); | ||||||
|
|
@@ -56,7 +57,7 @@ export function wrapLoadWithSentry<T extends (...args: any) => any>(origLoad: T) | |||||
| [CODE_FUNCTION_NAME]: 'load', | ||||||
| [SENTRY_ORIGIN]: 'auto.function.sveltekit', | ||||||
| [SENTRY_SEGMENT_NAME_SOURCE]: routeId ? 'route' : 'url', | ||||||
| [URL_PATH]: event.url.pathname, | ||||||
| [URL_PATH]: pathname, | ||||||
| [HTTP_ROUTE]: routeId, | ||||||
| // Relay infers the description from `code.function.name`, which would drop the route. | ||||||
| ...(hasSpanStreaming && { [SENTRY_DESCRIPTION]: routeOrPathname }), | ||||||
|
|
@@ -113,7 +114,8 @@ export function wrapServerLoadWithSentry<T extends (...args: any) => any>(origSe | |||||
| // server `load` function's data on every route change. We use `getRouteId` which uses | ||||||
| // SvelteKit 2's `untrack` when available, otherwise getOwnPropertyDescriptor for 1.x. | ||||||
| const routeId = getRouteId(event) ?? undefined; | ||||||
| const routeOrPathname = routeId ? routeId : event.url.pathname; | ||||||
| const pathname = getPathname(event); | ||||||
| const routeOrPathname = routeId ? routeId : pathname; | ||||||
|
|
||||||
| const client = getClient(); | ||||||
| const hasSpanStreaming = !!client && hasSpanStreamingEnabled(client); | ||||||
|
|
@@ -128,7 +130,7 @@ export function wrapServerLoadWithSentry<T extends (...args: any) => any>(origSe | |||||
| [SENTRY_ORIGIN]: 'auto.function.sveltekit.server', | ||||||
| [SENTRY_SEGMENT_NAME_SOURCE]: routeId ? 'route' : 'url', | ||||||
| [HTTP_REQUEST_METHOD]: event.request.method, | ||||||
| [URL_PATH]: event.url.pathname, | ||||||
| [URL_PATH]: pathname, | ||||||
| [HTTP_ROUTE]: routeId, | ||||||
| // Relay infers the description from `code.function.name`, which would drop the route. | ||||||
| ...(hasSpanStreaming && { [SENTRY_DESCRIPTION]: routeOrPathname }), | ||||||
|
|
||||||
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
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
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
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
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.
We should make sure that
dataCollection.urlQueryParamsis respected here as well.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.
This should be fine as the path never contains query strings