Skip to content

fix(react-router): Ensure that all browser spans have source=route #16984

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
merged 3 commits into from
Jul 15, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 14, 2025

This updates the browser tracing implementation in react router to ensure that we always have parametrized routes.

In the previous implementation, if the parametrized route was the same as the "initial" one, we would just do nothing and the source remains URL. We would also not set the origin of the spans. this is not correct, because we actually ensured this is parametrized (there are simply no parameters in, but still!), so the source should still be route in this case.

@mydea mydea self-assigned this Jul 14, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@RulaKhaled RulaKhaled left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests are failing but otherwise looks good

Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

cursor[bot]

This comment was marked as outdated.

@mydea mydea force-pushed the fn/rr-browser-spans branch from fa36b0b to 4dda614 Compare July 15, 2025 08:24
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Router Patching Dependent on Pageload Span

The router.navigate patching logic was moved inside the if (pageloadSpan) block. Consequently, if no active pageload span exists when the router is instrumented, router.navigate is not patched, preventing navigation transaction creation. This also creates an inconsistency, as the router subscription for updating navigation spans remains outside this block, attempting to update spans that were never created. Navigation patching should occur independently of pageload span existence.

packages/react-router/src/client/hydratedRouter.ts#L54-L66

// Patching navigate for creating accurate navigation transactions
if (typeof router.navigate === 'function') {
const originalNav = router.navigate.bind(router);
router.navigate = function sentryPatchedNavigate(...args) {
maybeCreateNavigationTransaction(
String(args[0]) || '<unknown route>', // will be updated anyway
'url', // this also will be updated once we have the parameterized route
);
return originalNav(...args);
};
}
}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@mydea mydea merged commit 4c1079e into develop Jul 15, 2025
143 checks passed
@mydea mydea deleted the fn/rr-browser-spans branch July 15, 2025 09:00
msonnb pushed a commit that referenced this pull request Jul 15, 2025
…16984)

This updates the browser tracing implementation in react router to
ensure that we always have parametrized routes.

In the previous implementation, if the parametrized route was the same
as the "initial" one, we would just do nothing and the source remains
URL. We would also not set the origin of the spans. this is not correct,
because we actually ensured this is parametrized (there are simply no
parameters in, but still!), so the source should still be `route` in
this case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants