|
| 1 | +import * as Sentry from '@sentry/react'; |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom/client'; |
| 4 | +import { |
| 5 | + BrowserRouter, |
| 6 | + Outlet, |
| 7 | + Route, |
| 8 | + RouterProvider, |
| 9 | + Routes, |
| 10 | + createBrowserRouter, |
| 11 | + createRoutesFromChildren, |
| 12 | + matchRoutes, |
| 13 | + useLocation, |
| 14 | + useNavigationType, |
| 15 | + useRoutes, |
| 16 | +} from 'react-router-dom'; |
| 17 | +import Index from './pages/Index'; |
| 18 | + |
| 19 | +const replay = Sentry.replayIntegration(); |
| 20 | + |
| 21 | +Sentry.init({ |
| 22 | + environment: 'qa', // dynamic sampling bias to keep transactions |
| 23 | + dsn: process.env.REACT_APP_E2E_TEST_DSN, |
| 24 | + integrations: [ |
| 25 | + Sentry.reactRouterV6BrowserTracingIntegration({ |
| 26 | + useEffect: React.useEffect, |
| 27 | + useLocation, |
| 28 | + useNavigationType, |
| 29 | + createRoutesFromChildren, |
| 30 | + matchRoutes, |
| 31 | + trackFetchStreamPerformance: true, |
| 32 | + }), |
| 33 | + replay, |
| 34 | + ], |
| 35 | + // We recommend adjusting this value in production, or using tracesSampler |
| 36 | + // for finer control |
| 37 | + tracesSampleRate: 1.0, |
| 38 | + release: 'e2e-test', |
| 39 | + |
| 40 | + // Always capture replays, so we can test this properly |
| 41 | + replaysSessionSampleRate: 1.0, |
| 42 | + replaysOnErrorSampleRate: 0.0, |
| 43 | + |
| 44 | + tunnel: 'http://localhost:3031', |
| 45 | +}); |
| 46 | + |
| 47 | +const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes); |
| 48 | +const sentryUseRoutes = Sentry.wrapUseRoutesV6(useRoutes); |
| 49 | +const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV6(createBrowserRouter); |
| 50 | + |
| 51 | +const DetailsRoutes = () => |
| 52 | + sentryUseRoutes([ |
| 53 | + { |
| 54 | + path: ':detailId', |
| 55 | + element: <div id="details">Details</div>, |
| 56 | + }, |
| 57 | + ]); |
| 58 | + |
| 59 | +const DetailsRoutesAlternative = () => ( |
| 60 | + <SentryRoutes> |
| 61 | + <Route path=":detailId" element={<div id="details">Details</div>} /> |
| 62 | + </SentryRoutes> |
| 63 | +); |
| 64 | + |
| 65 | +const ViewsRoutes = () => |
| 66 | + sentryUseRoutes([ |
| 67 | + { |
| 68 | + index: true, |
| 69 | + element: <div id="views">Views</div>, |
| 70 | + }, |
| 71 | + { |
| 72 | + path: 'views/:viewId/*', |
| 73 | + element: <DetailsRoutes />, |
| 74 | + }, |
| 75 | + { |
| 76 | + path: 'old-views/:viewId/*', |
| 77 | + element: <DetailsRoutesAlternative />, |
| 78 | + }, |
| 79 | + ]); |
| 80 | + |
| 81 | +const ProjectsRoutes = () => ( |
| 82 | + <SentryRoutes> |
| 83 | + <Route path="projects" element={<Outlet />}> |
| 84 | + <Route index element={<div>Project Page Root</div>} /> |
| 85 | + <Route path="*" element={<Outlet />}> |
| 86 | + <Route path=":projectId/*" element={<ViewsRoutes />} /> |
| 87 | + </Route> |
| 88 | + </Route> |
| 89 | + </SentryRoutes> |
| 90 | +); |
| 91 | + |
| 92 | +const router = sentryCreateBrowserRouter([ |
| 93 | + { |
| 94 | + children: [ |
| 95 | + { |
| 96 | + path: '/', |
| 97 | + element: <Index />, |
| 98 | + }, |
| 99 | + { |
| 100 | + path: '/*', |
| 101 | + element: <ProjectsRoutes />, |
| 102 | + }, |
| 103 | + ], |
| 104 | + }, |
| 105 | +]); |
| 106 | + |
| 107 | +const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); |
| 108 | +root.render(<RouterProvider router={router} />); |
0 commit comments