-
-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Bugfix async start / Clone Object before send over bridge #358
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,14 +56,8 @@ export class NativeClient { | |
Object.assign(this.options, options); | ||
} | ||
|
||
async customInit() { | ||
return new Promise((resolve, reject) => { | ||
RNSentry.startWithDsnString(this._dsn, this.options, () => { | ||
resolve(); | ||
}, (err) => { | ||
reject(err); | ||
}); | ||
|
||
async install() { | ||
return RNSentry.startWithDsnString(this._dsn, this.options).then(() => { | ||
if (this.options.deactivateStacktraceMerging === false) { | ||
this._activateStacktraceMerging(); | ||
const eventEmitter = new NativeEventEmitter(RNSentryEventEmitter); | ||
|
@@ -77,36 +71,40 @@ export class NativeClient { | |
} | ||
}); | ||
} | ||
RNSentry.setLogLevel(options.logLevel); | ||
RNSentry.setLogLevel(this.options.logLevel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! We missed this. |
||
}); | ||
} | ||
|
||
_cloneObject(obj) { | ||
return JSON.parse(JSON.stringify(obj)); | ||
} | ||
|
||
nativeCrash() { | ||
RNSentry.crash(); | ||
} | ||
|
||
captureEvent(event) { | ||
RNSentry.captureEvent(event); | ||
RNSentry.captureEvent(this._cloneObject(event)); | ||
} | ||
|
||
setUserContext(user) { | ||
RNSentry.setUser(user); | ||
RNSentry.setUser(this._cloneObject(user)); | ||
} | ||
|
||
setTagsContext(tags) { | ||
RNSentry.setTags(tags); | ||
RNSentry.setTags(this._cloneObject(tags)); | ||
} | ||
|
||
setExtraContext(extra) { | ||
RNSentry.setExtra(extra); | ||
RNSentry.setExtra(this._cloneObject(extra)); | ||
} | ||
|
||
addExtraContext(key, value) { | ||
RNSentry.addExtra(key, value); | ||
} | ||
|
||
captureBreadcrumb(breadcrumb) { | ||
RNSentry.captureBreadcrumb(breadcrumb); | ||
RNSentry.captureBreadcrumb(this._cloneObject(breadcrumb)); | ||
} | ||
|
||
clearContext() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ export const SentryLog = { | |
}; | ||
|
||
export const Sentry = { | ||
async install() { | ||
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); | ||
|
@@ -31,7 +31,6 @@ 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, | ||
|
@@ -44,9 +43,20 @@ export const Sentry = { | |
if (Sentry._internalEventStored) Sentry._internalEventStored(); | ||
}); | ||
} | ||
// We need to call install here since this add the callback for sending events | ||
// over the native bridge | ||
Sentry._ravenClient.install(); | ||
if (Sentry._nativeClient) { | ||
Sentry._nativeClient | ||
.install() | ||
.then(() => { | ||
Sentry._ravenClient.install(); | ||
}) | ||
.catch(error => { | ||
throw error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is uncatchable here. We repro'd by throwing in the try {
// install will throw if we test by putting a throw in the `then` callback.
// But since it happens in the future (asynchronously) we cannot catch it.
Sentry.config("legit_dsn_url").install();
} catch (e) {
console.error(e); // I will never be called.
} Perhaps, if I definitely understand the design to not have |
||
}); | ||
} else { | ||
// We need to call install here since this add the callback for sending events | ||
// over the native bridge | ||
Sentry._ravenClient.install(); | ||
} | ||
}, | ||
|
||
config(dsn, options) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HazAT the promise should get rejected her or it will go unanswered. Perhaps that is the objective?