-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(react-router): Set navigation.route.id from the matched route id
#22373
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
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 |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import { | |
| finalizeNavigationSpanFromHydratedRouter, | ||
| updateNavigationSpanUrlFromLocation, | ||
| } from './utils'; | ||
| import { URL_TEMPLATE } from '@sentry/conventions/attributes'; | ||
| import { NAVIGATION_ROUTE_ID, URL_TEMPLATE } from '@sentry/conventions/attributes'; | ||
|
|
||
| const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window; | ||
|
|
||
|
|
@@ -249,7 +249,7 @@ export function createSentryClientInstrumentation( | |
| const routePattern = pattern || urlPath; | ||
| // Parameterize the active navigation root span. (Route hooks don't fire on initial | ||
| // pageload, so this only affects navigations.) | ||
| updateRootSpanRoute(routePattern, !!pattern); | ||
| updateRootSpanRoute(routePattern, !!pattern, routeId); | ||
|
|
||
| await startSpan( | ||
| { | ||
|
|
@@ -275,7 +275,7 @@ export function createSentryClientInstrumentation( | |
| const urlPath = getPathFromRequest(info.request); | ||
| const pattern = normalizeRoutePath(getPattern(info)); | ||
| const routePattern = pattern || urlPath; | ||
| updateRootSpanRoute(routePattern, !!pattern); | ||
| updateRootSpanRoute(routePattern, !!pattern, routeId); | ||
|
|
||
| await startSpan( | ||
| { | ||
|
|
@@ -360,7 +360,7 @@ export function createSentryClientInstrumentation( | |
| * Updates the active navigation/pageload root span name with the parameterized route, so the | ||
| * transaction reflects the parameterized route pattern (e.g. `/users/:id`). | ||
| */ | ||
| function updateRootSpanRoute(routeName: string, hasPattern: boolean): void { | ||
| function updateRootSpanRoute(routeName: string, hasPattern: boolean, routeId?: string): void { | ||
| if (!hasPattern) { | ||
| return; | ||
| } | ||
|
|
@@ -377,7 +377,11 @@ function updateRootSpanRoute(routeName: string, hasPattern: boolean): void { | |
| } | ||
|
|
||
| updateSpanName(rootSpan, routeName); | ||
| rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: routeName }); | ||
| rootSpan.setAttributes({ | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', | ||
| [URL_TEMPLATE]: routeName, | ||
| ...(routeId && { [NAVIGATION_ROUTE_ID]: routeId }), | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
|
Comment on lines
377
to
387
Contributor
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. Bug: A race condition between parallel loaders on nested routes can cause the Suggested FixInstead of each loader setting the route ID, the instrumentation should deterministically identify the leaf route from the matched routes and set the Prompt for AI AgentAlso affects:
Did we get this right? 👍 / 👎 to inform future reviews.
Member
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. same as cursor above |
||
|
|
||
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.
Non-leaf route id can stick
Medium Severity
In the instrumentation-API path,
navigation.route.idis taken from whichever route'sloader/actionhook runs, not from the leaf match. Once that setssentry.sourcetoroute, the hydrated-router subscribe path early-returns and never corrects it viagetRouteId. Nested apps where only a parent has a client loader can therefore keep a parent route id on the navigation span.Additional Locations (1)
packages/react-router/src/client/hydratedRouter.ts#L134-L141Reviewed by Cursor Bugbot for commit f597246. Configure here.
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 think this is fine since we just follow the exisitng behavior of
url.templatehere