Skip to content

Commit 3c8f407

Browse files
committed
Change options merging, Move react-native raven plugin into repo, Fix unit tests
1 parent 2b0e599 commit 3c8f407

File tree

3 files changed

+274
-53
lines changed

3 files changed

+274
-53
lines changed

docs/index.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ Setup With Cocoapods
110110
In order to use Sentry with cocoapods you have to install the packages with
111111
``npm`` or ``yarn`` and link them locally in your ``Podfile``.
112112

113-
.. code-block:: bash
113+
.. sourcecode:: bash
114114
npm install --save react react-native react-native-sentry
115115

116116
After that change your ``Podfile`` to reference to the packages in your
117117
``node_modules`` folder.
118118

119-
.. code-block:: bash
119+
.. sourcecode:: ruby
120120
platform :ios, '8.0'
121121
use_frameworks!
122122

@@ -187,13 +187,14 @@ These are functions you can call in your javascript code:
187187

188188
// disable stacktrace merging
189189
Sentry.config("___DSN___", {
190-
deactivateStacktraceMerging: true,
191-
logLevel: SentryLog.Debug,
190+
deactivateStacktraceMerging: true, // default: false | Deactivates the stacktrace merging feature
191+
logLevel: SentryLog.Debug, // default SentryLog.None | Possible values: .None, .Error, .Debug, .Verbose
192+
forceRavenClient: true // default false | This will force sentry to use the raven client instead the native client
192193
// These two options will only be considered if stacktrace merging is active
193194
// Here you can add modules that should be ignored or exclude modules
194195
// that should no longer be ignored from stacktrace merging
195-
// ignoreModulesExclude: ["I18nManager"], // Exclude is always stronger than include
196-
// ignoreModulesInclude: ["RNSentry"], // Include modules that should be ignored too
196+
// ignoreModulesExclude: ["I18nManager"], // default: [] | Exclude is always stronger than include
197+
// ignoreModulesInclude: ["RNSentry"], // default: [] | Include modules that should be ignored too
197198
// ---------------------------------
198199
}).install();
199200

lib/Sentry.js

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {
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

76
const {
87
RNSentry
@@ -61,10 +60,10 @@ export const SentryLog = {
6160

6261
export 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

Comments
 (0)