Skip to content

Commit 786a0c9

Browse files
committed
Set up React Router-Sentry integration
1 parent b3923c4 commit 786a0c9

File tree

7 files changed

+41
-16
lines changed

7 files changed

+41
-16
lines changed

src/commons/application/ApplicationWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Classes, NonIdealState } from '@blueprintjs/core';
22
import { IconNames } from '@blueprintjs/icons';
3+
import * as Sentry from '@sentry/react';
34
import classNames from 'classnames';
45
import { useEffect, useMemo, useState } from 'react';
56
import { useDispatch } from 'react-redux';
@@ -37,7 +38,7 @@ const ApplicationWrapper: React.FC = () => {
3738
? playgroundOnlyRouterConfig
3839
: getFullAcademyRouterConfig({ name, isLoggedIn, courseId, academyRoutes });
3940

40-
const r = createBrowserRouter(routerConfig);
41+
const r = Sentry.wrapCreateBrowserRouterV7(createBrowserRouter)(routerConfig);
4142
dispatch(updateReactRouter(r));
4243

4344
return r;

src/commons/navigationBar/NavigationBar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import { IconName, IconNames } from '@blueprintjs/icons';
1616
import classNames from 'classnames';
1717
import React, { useMemo, useState } from 'react';
1818
import { Translation } from 'react-i18next';
19-
import { Location, NavLink, Route, Routes, useLocation } from 'react-router';
19+
import { type Location, NavLink, Route, useLocation } from 'react-router';
2020
import { i18nDefaultLangKeys } from 'src/i18n/i18next';
21+
import { SentryRoutes } from 'src/routes/routerConfig';
2122
import classes from 'src/styles/NavigationBar.module.scss';
2223

2324
import Dropdown from '../dropdown/Dropdown';
@@ -312,7 +313,7 @@ const NavigationBar: React.FC = () => {
312313
{commonNavbarRight}
313314
</Navbar>
314315

315-
<Routes>
316+
<SentryRoutes>
316317
<Route path="/playground/*" element={null} />
317318
<Route path="/contributors" element={null} />
318319
<Route path="/courses/:courseId/sourcecast" element={null} />
@@ -327,7 +328,7 @@ const NavigationBar: React.FC = () => {
327328
) : null
328329
}
329330
/>
330-
</Routes>
331+
</SentryRoutes>
331332
</>
332333
);
333334
};

src/index.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import 'src/styles/index.scss';
44
import { Button, OverlaysProvider } from '@blueprintjs/core';
55
import * as Sentry from '@sentry/react';
66
import { setModulesStaticURL } from 'js-slang/dist/modules/loader';
7+
import { useEffect } from 'react';
78
import { createRoot } from 'react-dom/client';
89
import { Provider } from 'react-redux';
10+
import {
11+
createRoutesFromChildren,
12+
matchRoutes,
13+
useLocation,
14+
useNavigationType
15+
} from 'react-router';
916
import Constants, { Links } from 'src/commons/utils/Constants';
1017
import { showWarningMessage } from 'src/commons/utils/notifications/NotificationsHelper';
1118
import { register as registerServiceWorker } from 'src/commons/utils/RegisterServiceWorker';
@@ -19,7 +26,17 @@ if (Constants.sentryDsn) {
1926
Sentry.init({
2027
dsn: Constants.sentryDsn,
2128
environment: Constants.sourceAcademyEnvironment,
22-
release: `cadet-frontend@${Constants.sourceAcademyVersion}`
29+
release: `cadet-frontend@${Constants.sourceAcademyVersion}`,
30+
integrations: [
31+
Sentry.reactRouterV7BrowserTracingIntegration({
32+
useEffect,
33+
useLocation,
34+
useNavigationType,
35+
createRoutesFromChildren,
36+
matchRoutes
37+
}),
38+
Sentry.replayIntegration()
39+
]
2340
});
2441
const userId = store.getState().session.userId;
2542
Sentry.setUser(typeof userId !== 'undefined' ? { id: userId.toString() } : null);

src/pages/achievement/Achievement.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import { Route, Routes } from 'react-router';
2+
import { Route } from 'react-router';
33
import { useTypedSelector } from 'src/commons/utils/Hooks';
4+
import { SentryRoutes } from 'src/routes/routerConfig';
45

56
import { Role } from '../../commons/application/ApplicationTypes';
67
import NotFound from '../notFound/NotFound';
@@ -14,11 +15,11 @@ const Achievement: React.FC = () => {
1415
role === Role.Admin || role === Role.Staff ? <AchievementControl /> : <NotFound />;
1516

1617
return (
17-
<Routes>
18+
<SentryRoutes>
1819
<Route path="/" element={<AchievementDashboard />}></Route>
1920
<Route path="control" element={toAchievementControl}></Route>
2021
<Route path="*" element={<NotFound />} />
21-
</Routes>
22+
</SentryRoutes>
2223
);
2324
};
2425

src/pages/leaderboard/Leaderboard.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import { Navigate, Route, Routes } from 'react-router';
2+
import { Navigate, Route } from 'react-router';
33
import { useTypedSelector } from 'src/commons/utils/Hooks';
4+
import { SentryRoutes } from 'src/routes/routerConfig';
45

56
import NotFound from '../notFound/NotFound';
67
import OverallLeaderboardWrapper from './subcomponents/OverallLeaderboardWrapper';
@@ -22,7 +23,7 @@ const Leaderboard: React.FC = () => {
2223
const baseLink = `/courses/${courseId}/leaderboard`;
2324

2425
return (
25-
<Routes>
26+
<SentryRoutes>
2627
<Route
2728
path="/"
2829
element={
@@ -46,7 +47,7 @@ const Leaderboard: React.FC = () => {
4647
)
4748
}
4849
></Route>
49-
</Routes>
50+
</SentryRoutes>
5051
);
5152
};
5253

src/pages/leaderboard/subcomponents/ContestLeaderboardWrapper.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useEffect } from 'react';
22
import { useDispatch } from 'react-redux';
3-
import { Navigate, Route, Routes, useLocation, useParams } from 'react-router';
3+
import { Navigate, Route, useLocation, useParams } from 'react-router';
44
import { useTypedSelector } from 'src/commons/utils/Hooks';
55
import LeaderboardActions from 'src/features/leaderboard/LeaderboardActions';
6-
import { LeaderboardContestDetails } from 'src/features/leaderboard/LeaderboardTypes';
6+
import type { LeaderboardContestDetails } from 'src/features/leaderboard/LeaderboardTypes';
7+
import { SentryRoutes } from 'src/routes/routerConfig';
78

89
import NotFound from '../../notFound/NotFound';
910
import ContestLeaderboard from './ContestLeaderboard';
@@ -28,7 +29,7 @@ const ContestLeaderboardWrapper: React.FC = () => {
2829
const baseLink = `/courses/${courseId}/leaderboard`;
2930

3031
return (
31-
<Routes>
32+
<SentryRoutes>
3233
<Route
3334
path="/:id/score"
3435
element={
@@ -71,7 +72,7 @@ const ContestLeaderboardWrapper: React.FC = () => {
7172
></Route>
7273

7374
<Route path="*" element={<Navigate to={baseLink} />}></Route>
74-
</Routes>
75+
</SentryRoutes>
7576
);
7677
};
7778

src/routes/routerConfig.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Navigate, redirect, RouteObject } from 'react-router';
1+
import * as Sentry from '@sentry/react';
2+
import { Navigate, redirect, Routes, type RouteObject } from 'react-router';
23
import Constants from 'src/commons/utils/Constants';
34

45
import Application from '../commons/application/Application';
@@ -150,3 +151,5 @@ export const getFullAcademyRouterConfig = ({
150151
}
151152
];
152153
};
154+
155+
export const SentryRoutes = Sentry.withSentryReactRouterV7Routing(Routes);

0 commit comments

Comments
 (0)