11import { initAndBind , setExtra } from "@sentry/core" ;
22import { Hub , makeMain } from "@sentry/hub" ;
33import { RewriteFrames } from "@sentry/integrations" ;
4- import { defaultIntegrations , getCurrentHub } from "@sentry/react" ;
4+ import {
5+ defaultIntegrations ,
6+ ErrorBoundary ,
7+ getCurrentHub ,
8+ } from "@sentry/react" ;
59import { StackFrame } from "@sentry/types" ;
610import { getGlobalObject , logger } from "@sentry/utils" ;
11+ import * as React from "react" ;
712
813import { ReactNativeClient } from "./client" ;
914import {
@@ -13,9 +18,10 @@ import {
1318 Release ,
1419 StallTracking ,
1520} from "./integrations" ;
16- import { ReactNativeOptions } from "./options" ;
21+ import { ReactNativeOptions , ReactNativeWrapperOptions } from "./options" ;
1722import { ReactNativeScope } from "./scope" ;
18- import { ReactNativeTracing } from "./tracing" ;
23+ import { TouchEventBoundary } from "./touchevents" ;
24+ import { ReactNativeProfiler , ReactNativeTracing } from "./tracing" ;
1925
2026const IGNORED_DEFAULT_INTEGRATIONS = [
2127 "GlobalHandlers" , // We will use the react-native internal handlers
@@ -31,9 +37,9 @@ const DEFAULT_OPTIONS: ReactNativeOptions = {
3137} ;
3238
3339/**
34- * Inits the SDK
40+ * Inits the SDK and returns the final options.
3541 */
36- export function init ( passedOptions : ReactNativeOptions ) : void {
42+ function _init < O = ReactNativeOptions > ( passedOptions : O ) : O {
3743 const reactNativeHub = new Hub ( undefined , new ReactNativeScope ( ) ) ;
3844 makeMain ( reactNativeHub ) ;
3945
@@ -106,6 +112,44 @@ export function init(passedOptions: ReactNativeOptions): void {
106112 if ( getGlobalObject < any > ( ) . HermesInternal ) {
107113 getCurrentHub ( ) . setTag ( "hermes" , "true" ) ;
108114 }
115+
116+ return options ;
117+ }
118+
119+ /**
120+ * Inits the Sentry React Native SDK without any wrapping
121+ */
122+ export function init ( options : ReactNativeOptions ) : void {
123+ _init ( options ) ;
124+ }
125+
126+ /**
127+ * Inits the Sentry React Native SDK with automatic instrumentation and wrapped features.
128+ */
129+ export function initWith (
130+ RootComponent : React . ComponentType ,
131+ passedOptions : ReactNativeWrapperOptions
132+ ) : React . FC {
133+ const options = _init ( passedOptions ) ;
134+
135+ const profilerProps = {
136+ ...options . profilerProps ,
137+ name : RootComponent . displayName ?? "Root" ,
138+ } ;
139+
140+ const RootApp : React . FC = ( appProps ) => {
141+ return (
142+ < ErrorBoundary { ...options . errorBoundaryProps } >
143+ < TouchEventBoundary { ...options . touchEventBoundaryProps } >
144+ < ReactNativeProfiler { ...profilerProps } >
145+ < RootComponent { ...appProps } />
146+ </ ReactNativeProfiler >
147+ </ TouchEventBoundary >
148+ </ ErrorBoundary >
149+ ) ;
150+ } ;
151+
152+ return RootApp ;
109153}
110154
111155/**
0 commit comments