Skip to content

Commit 36e43d8

Browse files
evanpurkhiserharshithadurai
authored andcommitted
feat(routes): Capture redirects as sentry messages (#79380)
This way we can see if we're actually using all of our redirects
1 parent 90d821c commit 36e43d8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

static/app/utils/reactRouter6Compat/router.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import {Children, isValidElement} from 'react';
1+
import {Children, isValidElement, useEffect} from 'react';
22
import {
33
Navigate,
44
type NavigateProps,
55
Outlet,
66
type RouteObject,
77
useOutletContext,
88
} from 'react-router-dom';
9+
import * as Sentry from '@sentry/react';
910

1011
import {USING_CUSTOMER_DOMAIN} from 'sentry/constants';
1112
import replaceRouterParams from 'sentry/utils/replaceRouterParams';
@@ -75,6 +76,21 @@ interface RedirectProps extends Omit<NavigateProps, 'to'> {
7576
*/
7677
function Redirect({to, ...rest}: RedirectProps) {
7778
const params = useParams();
79+
const routes = useRoutes();
80+
81+
// Capture sentry error for this redirect. This will help us understand if we
82+
// have redirects that are unused or used too much.
83+
useEffect(() => {
84+
const routePath = routes
85+
.map(route => route.path ?? '')
86+
.filter(path => path !== '')
87+
.join('/');
88+
89+
Sentry.captureMessage('Redirect route used', {
90+
level: 'info',
91+
tags: {routePath},
92+
});
93+
}, [routes]);
7894

7995
return <Navigate to={replaceRouterParams(to, params)} {...rest} />;
8096
}

0 commit comments

Comments
 (0)