From c88648bd76454769f853466363b8ea535188ce4b Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Fri, 18 Oct 2024 16:21:32 -0400 Subject: [PATCH] feat(routes): Capture redirects --- .../app/utils/reactRouter6Compat/router.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/static/app/utils/reactRouter6Compat/router.tsx b/static/app/utils/reactRouter6Compat/router.tsx index 23b6c383dabd44..ba8edbce388e85 100644 --- a/static/app/utils/reactRouter6Compat/router.tsx +++ b/static/app/utils/reactRouter6Compat/router.tsx @@ -1,4 +1,4 @@ -import {Children, isValidElement} from 'react'; +import {Children, isValidElement, useEffect} from 'react'; import { Navigate, type NavigateProps, @@ -6,6 +6,7 @@ import { 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'; @@ -75,6 +76,22 @@ interface RedirectProps extends Omit { */ 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], + }); + }, [routes]); return ; }