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
13 changes: 11 additions & 2 deletions android/src/main/java/io/sentry/RNSentryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.facebook.react.ReactApplication;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand Down Expand Up @@ -90,13 +91,20 @@ public Map<String, Object> getConstants() {
}

@ReactMethod
public void startWithDsnString(String dsnString, final ReadableMap options) {
public void startWithDsnString(String dsnString, final ReadableMap options, Callback successCallback, Callback errorCallback) {
if (sentryClient != null) {
logger.info(String.format("Already started, use existing client '%s'", dsnString));
return;
}

sentryClient = Sentry.init(dsnString, new AndroidSentryClientFactory(this.getReactApplicationContext()));
try {
sentryClient = Sentry.init(dsnString, new AndroidSentryClientFactory(this.getReactApplicationContext()));
} catch (Exception e) {
logger.info(String.format("Catching on startWithDsnString, calling callback" + e.getMessage()));
errorCallback.invoke(e.getMessage());
return;
}

androidHelper = new AndroidEventBuilderHelper(this.getReactApplicationContext());
sentryClient.addEventSendCallback(new EventSendCallback() {
@Override
Expand Down Expand Up @@ -143,6 +151,7 @@ public boolean shouldSend(Event event) {
}
});
logger.info(String.format("startWithDsnString '%s'", dsnString));
successCallback.invoke();
}

@ReactMethod
Expand Down
37 changes: 23 additions & 14 deletions lib/NativeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ export class NativeClient {
deactivateStacktraceMerging: true
};
Object.assign(this.options, options);
}

RNSentry.startWithDsnString(this._dsn, this.options);
if (this.options.deactivateStacktraceMerging === false) {
this._activateStacktraceMerging();
const eventEmitter = new NativeEventEmitter(RNSentryEventEmitter);
eventEmitter.addListener(RNSentryEventEmitter.MODULE_TABLE, moduleTable => {
try {
this._updateIgnoredModules(JSON.parse(moduleTable.payload));
} catch (e) {
// https://github.com/getsentry/react-native-sentry/issues/241
// under some circumstances the the JSON is not valid
// the reason for this is yet to be found
}
async customInit() {
return new Promise((resolve, reject) => {
RNSentry.startWithDsnString(this._dsn, this.options, () => {
resolve();
}, (err) => {
reject(err);
});
}
RNSentry.setLogLevel(options.logLevel);

if (this.options.deactivateStacktraceMerging === false) {
this._activateStacktraceMerging();
const eventEmitter = new NativeEventEmitter(RNSentryEventEmitter);
eventEmitter.addListener(RNSentryEventEmitter.MODULE_TABLE, moduleTable => {
try {
this._updateIgnoredModules(JSON.parse(moduleTable.payload));
} catch (e) {
// https://github.com/getsentry/react-native-sentry/issues/241
// under some circumstances the the JSON is not valid
// the reason for this is yet to be found
}
});
}
RNSentry.setLogLevel(options.logLevel);
});
}

nativeCrash() {
Expand Down
3 changes: 2 additions & 1 deletion lib/Sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SentryLog = {
};

export const Sentry = {
install() {
async install() {
// We have to first setup raven otherwise react-native will freeze the options
// and some properties like ignoreErrors can not be mutated by raven-js
Sentry._ravenClient = new RavenClient(Sentry._dsn, Sentry.options);
Expand All @@ -31,6 +31,7 @@ export const Sentry = {
Sentry.options.disableNativeIntegration === false
) {
Sentry._nativeClient = new NativeClient(Sentry._dsn, Sentry.options);
await Sentry._nativeClient.customInit();
Sentry.eventEmitter = new NativeEventEmitter(RNSentryEventEmitter);
Sentry.eventEmitter.addListener(
RNSentryEventEmitter.EVENT_SENT_SUCCESSFULLY,
Expand Down