Skip to content
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

feat(routes): Capture redirects as sentry messages #79380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion static/app/utils/reactRouter6Compat/router.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Children, isValidElement} from 'react';
import {Children, isValidElement, useEffect} from 'react';
import {
Navigate,
type NavigateProps,
Outlet,
type RouteObject,
useOutletContext,
} from 'react-router-dom';
import * as Sentry from '@sentry/react';

import {USING_CUSTOMER_DOMAIN} from 'sentry/constants';
import replaceRouterParams from 'sentry/utils/replaceRouterParams';
Expand Down Expand Up @@ -75,6 +76,22 @@ interface RedirectProps extends Omit<NavigateProps, 'to'> {
*/
function Redirect({to, ...rest}: RedirectProps) {
const params = useParams();
const routes = useRoutes();

// Capture sentry error for this redirect. This will help us understand if we
// have redirects that are unused or used too much.
useEffect(() => {
const routePath = routes
.map(route => route.path ?? '')
.filter(path => path !== '')
.join('/');

Sentry.captureMessage('Redirect route used', {
level: 'info',
tags: {routePath},
fingerprint: [routePath],
Copy link
Member

Choose a reason for hiding this comment

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

Do you want one error per route? Or have a single error with route as a tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm. Maybe it's OK to just have one, and we can use discover to drill down

});
}, [routes]);

return <Navigate to={replaceRouterParams(to, params)} {...rest} />;
}
Expand Down
Loading