11import * as Sentry from '@sentry/react' ;
22import packageJson from '../package.json' ;
33import * as React from 'react' ;
4- import { createRoutesFromChildren , matchRoutes } from 'react-router-dom' ;
4+ import {
5+ createRoutesFromChildren ,
6+ matchRoutes ,
7+ useLocation ,
8+ useNavigationType ,
9+ } from 'react-router-dom' ;
510
611// Helper to safely parse Sentry sample rates from environment variables
7- const parseSampleRate = ( value : string | undefined , defaultValue : number ) : number => {
12+ const parseSampleRate = (
13+ value : string | undefined ,
14+ defaultValue : number ,
15+ ) : number => {
816 const parsed = parseFloat ( value ?? String ( defaultValue ) ) ;
917 if ( isNaN ( parsed ) || parsed < 0 || parsed > 1 ) {
1018 return defaultValue ;
@@ -14,7 +22,9 @@ const parseSampleRate = (value: string | undefined, defaultValue: number): numbe
1422
1523const dsn = process . env . REACT_APP_SENTRY_DSN || '' ;
1624const environment =
17- process . env . REACT_APP_FIREBASE_PROJECT_ID || process . env . NODE_ENV || "mobility-feeds-dev" ;
25+ process . env . REACT_APP_FIREBASE_PROJECT_ID ||
26+ process . env . NODE_ENV ||
27+ 'mobility-feeds-dev' ;
1828const release = packageJson . version ;
1929const tracesSampleRate = parseSampleRate (
2030 process . env . REACT_APP_SENTRY_TRACES_SAMPLE_RATE ,
@@ -30,29 +40,29 @@ const replaysOnErrorSampleRate = parseSampleRate(
3040) ;
3141
3242if ( dsn ) {
33- // Prefer dedicated react-router v6 integration if available, else fall back to generic browser tracing with manual routing instrumentation.
3443 const routerTracingIntegration =
35- ( Sentry as any ) . reactRouterV6BrowserTracingIntegration ?. ( {
44+ Sentry . reactRouterV6BrowserTracingIntegration ( {
3645 useEffect : React . useEffect ,
37- reactRouterV6 : { createRoutesFromChildren, matchRoutes } ,
38- } ) ||
39- ( Sentry as any ) . browserTracingIntegration ?.( {
40- routingInstrumentation : ( Sentry as any ) . reactRouterV6Instrumentation ?.(
41- React . useEffect ,
42- true ,
43- createRoutesFromChildren ,
44- matchRoutes ,
45- ) ,
46+ useLocation,
47+ useNavigationType,
48+ createRoutesFromChildren,
49+ matchRoutes,
4650 } ) ;
4751
52+ const integrations = [ ] ;
53+ if ( routerTracingIntegration ) {
54+ integrations . push ( routerTracingIntegration ) ;
55+ }
56+ const replayIntegration = Sentry . replayIntegration ?.( ) ;
57+ if ( replayIntegration ) {
58+ integrations . push ( replayIntegration ) ;
59+ }
60+
4861 Sentry . init ( {
4962 dsn,
5063 environment,
5164 release,
52- integrations : [
53- routerTracingIntegration ,
54- ( Sentry as any ) . replayIntegration ?.( ) ,
55- ] . filter ( Boolean ) ,
65+ integrations : integrations ,
5666 tracesSampleRate,
5767 replaysSessionSampleRate,
5868 replaysOnErrorSampleRate,
0 commit comments