Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions lib/NativeClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import {NativeModules, NativeEventEmitter} from 'react-native';
const {RNSentry, RNSentryEventEmitter} = NativeModules;
import {Sentry, SentrySeverity, SentryLog} from './Sentry';

const DEFAULT_MODULE_IGNORES = [
'AccessibilityManager',
'ActionSheetManager',
'AlertManager',
'AppState',
'AsyncLocalStorage',
'Clipboard',
'DevLoadingView',
'DevMenu',
'ExceptionsManager',
'I18nManager',
'ImageEditingManager',
'ImageStoreManager',
'ImageViewManager',
'IOSConstants',
'JSCExecutor',
'JSCSamplingProfiler',
'KeyboardObserver',
'LinkingManager',
'LocationObserver',
'NativeAnimatedModule',
'NavigatorManager',
'NetInfo',
'Networking',
'RedBox',
'ScrollViewManager',
'SettingsManager',
'SourceCode',
'StatusBarManager',
'Timing',
'UIManager',
'Vibration',
'WebSocketModule',
'WebViewManager'
];

export class NativeClient {
constructor(dsn, options) {
if (dsn.constructor !== String) {
throw new Error('Sentry: A DSN must be provided');
}
if (!RNSentry) {
throw new Error('Sentry: There is no native client installed.');
}

this._dsn = dsn;
this._activatedMerging = false;
this.options = {
ignoreModulesExclude: [],
ignoreModulesInclude: [],
deactivateStacktraceMerging: false
};
Object.assign(this.options, options);

RNSentry.startWithDsnString(this._dsn);
if (this.options.deactivateStacktraceMerging === false) {
this._activateStacktraceMerging();
}
RNSentry.setLogLevel(options.logLevel);
}

nativeCrash() {
RNSentry.crash();
}

captureEvent(event) {
RNSentry.captureEvent(event);
}

setUserContext(user) {
RNSentry.setUser(user);
}

setTagsContext(tags) {
RNSentry.setTags(tags);
}

setExtraContext(extra) {
RNSentry.setExtra(extra);
}

addExtraContext(key, value) {
RNSentry.addExtra(key, value);
}

captureBreadcrumb(crumb) {
RNSentry.captureBreadcrumb(crumb);
}

clearContext() {
RNSentry.clearContext();
}

_activateStacktraceMerging = async () => {
return RNSentry.activateStacktraceMerging()
.then(activated => {
if (this._activatedMerging) {
return;
}
this._ignoredModules = {};
const BatchedBridge = require('react-native/Libraries/BatchedBridge/BatchedBridge');
if (typeof __fbBatchedBridgeConfig !== 'undefined') {
__fbBatchedBridgeConfig.remoteModuleConfig.forEach((module, moduleID) => {
if (
module !== null &&
this.options.ignoreModulesExclude.indexOf(module[0]) === -1 &&
(DEFAULT_MODULE_IGNORES.indexOf(module[0]) >= 0 ||
this.options.ignoreModulesInclude.indexOf(module[0]) >= 0)
) {
this._ignoredModules[moduleID] = true;
}
});
} else if (BatchedBridge._remoteModuleTable) {
for (var module in BatchedBridge._remoteModuleTable) {
if (BatchedBridge._remoteModuleTable.hasOwnProperty(module)) {
let moduleName = BatchedBridge._remoteModuleTable[module];
if (
this.options.ignoreModulesExclude.indexOf(moduleName) === -1 &&
(DEFAULT_MODULE_IGNORES.indexOf(moduleName) >= 0 ||
this.options.ignoreModulesInclude.indexOf(moduleName) >= 0)
) {
this._ignoredModules[module] = true;
}
}
}
}
this._activatedMerging = true;
this._overwriteEnqueueNativeCall();
})
.catch(function(reason) {
console.log(reason);
});
};

_overwriteEnqueueNativeCall() {
const BatchedBridge = require('react-native/Libraries/BatchedBridge/BatchedBridge');
const original = BatchedBridge.enqueueNativeCall;
const that = this;
BatchedBridge.enqueueNativeCall = function(
moduleID: number,
methodID: number,
params: Array<any>,
onFail: ?Function,
onSucc: ?Function
) {
if (that._ignoredModules[moduleID]) {
return original.apply(this, arguments);
}
params.push({
__sentry_stack: new Error().stack
});
return original.apply(this, arguments);
};
}
}
91 changes: 91 additions & 0 deletions lib/RavenClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import Raven from 'raven-js';
import {Sentry, SentrySeverity, SentryLog} from './Sentry';

export class RavenClient {
constructor(dsn, options) {
if (dsn.constructor !== String) {
throw new Error('SentryClient: A DSN must be provided');
}
this._dsn = dsn;
this.options = {
allowSecretKey: true,
allowDuplicates: Sentry.isNativeClientAvailable()
};
Object.assign(this.options, options);
Raven.addPlugin(
require('./raven-plugin'),
{
nativeClientAvailable: Sentry.isNativeClientAvailable()
},
data => {
if (Sentry.options.internal) {
data.dist = Sentry.options.internal['dist'];
}
}
);

Raven.config(dsn, this.options).install();
if (options.logLevel >= SentryLog.Debug) {
Raven.debug = true;
}
if (Sentry.isNativeClientAvailable()) {
// We overwrite the default transport handler when the native
// client is available, because we want to send the event with native
Raven.setTransport(options => {
Sentry._captureEvent(options.data);
});
Raven.setBreadcrumbCallback(Sentry._breadcrumbCallback);
const oldCaptureBreadcrumb = Raven.captureBreadcrumb;
Raven.captureBreadcrumb = function(obj) {
if (obj.data && typeof obj.data === 'object') {
obj.data = Object.assign({}, obj.data);
}
return oldCaptureBreadcrumb.apply(this, arguments);
};
}
}

setDataCallback(callback) {
Raven.setDataCallback(callback);
}

setUserContext(user) {
Raven.setUserContext(user);
}

setTagsContext(tags) {
Raven.setTagsContext(tags);
}

setExtraContext(extra) {
Raven.setExtraContext(extra);
}

captureException(ex, options) {
Raven.captureException(ex, options);
}

captureBreadcrumb(msg, options) {
Raven.captureBreadcrumb(msg, options);
}

captureMessage(message, options) {
Raven.captureMessage(message, options);
}

setRelease(release) {
Raven.setRelease(release);
}

clearContext() {
return Raven.clearContext();
}

context(options, func, args) {
return Raven.context(options, func, args);
}

wrap(options, func, _before) {
return Raven.wrap(options, func, _before);
}
}
Loading