@@ -2,18 +2,29 @@ import type { BrowserOptions } from '@sentry/browser';
22import { init as browserInit } from '@sentry/browser' ;
33import type { Client } from '@sentry/core' ;
44import { applySdkMetadata , setTag } from '@sentry/core' ;
5+ import { BROWSER_TRACING_INTEGRATION_ID } from '../../../browser/build/npm/types/tracing/browserTracingIntegration' ;
6+ import { reactRouterTracingIntegration } from './tracingIntegration' ;
57
68/**
79 * Initializes the client side of the React Router SDK.
810 */
911export function init ( options : BrowserOptions ) : Client | undefined {
10- const opts = {
11- ...options ,
12- } ;
12+ // If BrowserTracing integration was passed to options, replace it with React Router tracing integration
13+ if ( options . integrations && Array . isArray ( options . integrations ) ) {
14+ const hasBrowserTracing = options . integrations . some (
15+ integration => integration . name === BROWSER_TRACING_INTEGRATION_ID ,
16+ ) ;
17+ if ( hasBrowserTracing ) {
18+ options . integrations = options . integrations . filter (
19+ integration => integration . name !== BROWSER_TRACING_INTEGRATION_ID ,
20+ ) ;
21+ options . integrations . push ( reactRouterTracingIntegration ( ) ) ;
22+ }
23+ }
1324
14- applySdkMetadata ( opts , 'react-router' , [ 'react-router' , 'browser' ] ) ;
25+ applySdkMetadata ( options , 'react-router' , [ 'react-router' , 'browser' ] ) ;
1526
16- const client = browserInit ( opts ) ;
27+ const client = browserInit ( options ) ;
1728
1829 setTag ( 'runtime' , 'browser' ) ;
1930
0 commit comments