Skip to content

Instantly share code, notes, and snippets.

@SudoPlz
Last active March 19, 2018 15:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SudoPlz/62f172292c7c6fb9b47e5f7dd2cd735b to your computer and use it in GitHub Desktop.
Save SudoPlz/62f172292c7c6fb9b47e5f7dd2cd735b to your computer and use it in GitHub Desktop.
import { Client, Configuration } from 'bugsnag-react-native';
module.exports = { // cached singleton instance
instance: null,
create(key, store, codeBundleId) {
if (this.instance === null) {
if (key == null) {
throw new Error(`Crash Reporter should be created with a
key as the first param. i.e .create(key, reduxStore)`);
}
const bugsnagConfig = new Configuration(key);
bugsnagConfig.shouldNotify = () => !__DEV__;
// code bundle id
if (codeBundleId) {
bugsnagConfig.codeBundleId = codeBundleId;
}
bugsnagConfig.notifyReleaseStages = ['production', 'staging', 'testflight'];
bugsnagConfig.registerBeforeSendCallback((report) => {
const state = JSON.parse(JSON.stringify(store.getState()));
const metadata = report.metadata || {};
// add our calendar state as metadata
metadata.calendar = state.calendar;
if (metadata.app == null) {
metadata.app = {};
}
// if the codebundleid is null, add it to the metadata
if (metadata.app.codeBundleId == null) {
metadata.app.codeBundleId = codeBundleId;
}
report.metadata = metadata;
});
this.instance = new Client(bugsnagConfig);
}
return this.instance;
},
};
CrashReporter.create(CONFIG.BUGSNAG_KEY, store, curAppVersion);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment