11import {
22 NativeModules
33} from 'react-native' ;
4- import Raven from 'raven-js' ;
5- require ( 'raven-js/plugins/react-native' ) ( Raven ) ;
4+ import Raven from 'raven-js' ; ;
65
76const {
87 RNSentry
@@ -61,10 +60,10 @@ export const SentryLog = {
6160
6261export class Sentry {
6362 static install ( ) {
64- if ( RNSentry && RNSentry . nativeClientAvailable ) {
65- Sentry . _client = new NativeClient ( Sentry . _dsn , Sentry . _options ) ;
63+ if ( RNSentry && RNSentry . nativeClientAvailable && Sentry . options . forceRavenClient === false ) {
64+ Sentry . _client = new NativeClient ( Sentry . _dsn , Sentry . options ) ;
6665 } else {
67- Sentry . _client = new RavenClient ( Sentry . _dsn , Sentry . _options ) ;
66+ Sentry . _client = new RavenClient ( Sentry . _dsn , Sentry . options ) ;
6867 }
6968 }
7069
@@ -73,7 +72,12 @@ export class Sentry {
7372 throw new Error ( 'Sentry: A DSN must be provided' ) ;
7473 }
7574 Sentry . _dsn = dsn ;
76- Sentry . _options = options ;
75+ Sentry . options = {
76+ logLevel : SentryLog . None ,
77+ forceRavenClient : false ,
78+ }
79+ Object . assign ( Sentry . options , options ) ;
80+ Sentry . _originalConsole = console || { } ;
7781 return Sentry ;
7882 }
7983
@@ -102,23 +106,11 @@ export class Sentry {
102106 }
103107
104108 static log = ( level , message ) => {
105- if ( Sentry . _options && Sentry . _options . logLevel ) {
106- if ( Sentry . _options . logLevel < level ) {
109+ if ( Sentry . options && Sentry . options . logLevel ) {
110+ if ( Sentry . options . logLevel < level ) {
107111 return ;
108112 }
109- switch ( level ) {
110- case SentryLog . Error :
111- console . error ( message ) ;
112- break ;
113- case SentryLog . Debug :
114- console . debug ( message ) ;
115- break ;
116- case SentryLog . Verbose :
117- console . log ( message ) ;
118- break ;
119- default :
120- return
121- }
113+ Sentry . _originalConsole . log ( message ) ;
122114 }
123115 }
124116}
@@ -134,24 +126,15 @@ class NativeClient {
134126
135127 this . _dsn = dsn ;
136128 this . _activatedMerging = false ;
137- RNSentry . startWithDsnString ( this . _dsn ) ;
138-
139- this . _deactivateStacktraceMerging = false ;
140- if ( options && options . deactivateStacktraceMerging ) {
141- this . _deactivateStacktraceMerging = true ;
129+ this . options = {
130+ ignoreModulesExclude : [ ] ,
131+ ignoreModulesInclude : [ ] ,
132+ deactivateStacktraceMerging : false
142133 }
143- if ( options && options . logLevel ) {
144- RNSentry . setLogLevel ( options . logLevel ) ;
145- }
146- this . _ignoreModulesExclude = [ ] ;
147- if ( options && options . ignoreModulesExclude ) {
148- this . _ignoreModulesExclude = options . ignoreModulesExclude ;
149- }
150- this . _ignoreModulesInclude = [ ] ;
151- if ( options && options . ignoreModulesInclude ) {
152- this . _ignoreModulesInclude = options . ignoreModulesInclude ;
153- }
154- if ( this . _deactivateStacktraceMerging === false ) {
134+ Object . assign ( this . options , options ) ;
135+
136+ RNSentry . startWithDsnString ( this . _dsn ) ;
137+ if ( this . options . deactivateStacktraceMerging === false ) {
155138 this . _activateStacktraceMerging ( ) ;
156139 }
157140 }
@@ -200,9 +183,9 @@ class NativeClient {
200183 this . _ignoredModules = { } ;
201184 __fbBatchedBridgeConfig . remoteModuleConfig . forEach ( ( module , moduleID ) => {
202185 if ( module !== null &&
203- this . _ignoreModulesExclude . indexOf ( module [ 0 ] ) == - 1 &&
186+ this . options . ignoreModulesExclude . indexOf ( module [ 0 ] ) == - 1 &&
204187 ( DEFAULT_MODULE_IGNORES . indexOf ( module [ 0 ] ) >= 0 ||
205- this . _ignoreModulesInclude . indexOf ( module [ 0 ] ) >= 0 ) ) {
188+ this . options . ignoreModulesInclude . indexOf ( module [ 0 ] ) >= 0 ) ) {
206189 this . _ignoredModules [ moduleID ] = true ;
207190 }
208191 } ) ;
@@ -232,15 +215,13 @@ class RavenClient {
232215 if ( dsn . constructor !== String ) {
233216 throw new Error ( 'SentryClient: A DSN must be provided' ) ;
234217 }
235-
236218 this . _dsn = dsn ;
237- if ( options === null || options === undefined ) {
238- options = { } ;
219+ this . options = {
220+ allowSecretKey : true ,
239221 }
240- Object . assign ( options , {
241- allowSecretKey : true
242- } ) ;
243- Raven . config ( dsn , options ) . install ( ) ;
222+ Object . assign ( this . options , options ) ;
223+ Raven . addPlugin ( require ( './raven-plugin' ) ) ;
224+ Raven . config ( dsn , this . options ) . install ( ) ;
244225 }
245226
246227 crash = ( ) => {
0 commit comments