2019-08-23 13:18:47 +00:00
|
|
|
import { Client } from 'bugsnag-react-native';
|
2020-07-24 13:19:17 +00:00
|
|
|
import analytics from '@react-native-firebase/analytics';
|
|
|
|
import crashlytics from '@react-native-firebase/crashlytics';
|
2020-07-22 19:31:38 +00:00
|
|
|
import config from '../../../config';
|
|
|
|
import events from './events';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2019-08-23 13:18:47 +00:00
|
|
|
const bugsnag = new Client(config.BUGSNAG_API_KEY);
|
|
|
|
|
2020-07-24 13:19:17 +00:00
|
|
|
export { analytics };
|
2019-08-23 13:18:47 +00:00
|
|
|
export const loggerConfig = bugsnag.config;
|
|
|
|
export const { leaveBreadcrumb } = bugsnag;
|
2020-07-22 19:31:38 +00:00
|
|
|
export { events };
|
2019-08-23 13:18:47 +00:00
|
|
|
|
2020-02-28 19:51:13 +00:00
|
|
|
let metadata = {};
|
|
|
|
|
|
|
|
export const logServerVersion = (serverVersion) => {
|
|
|
|
metadata = {
|
|
|
|
serverVersion
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-22 19:31:38 +00:00
|
|
|
export const logEvent = (eventName, payload) => {
|
2020-07-31 18:24:38 +00:00
|
|
|
try {
|
|
|
|
analytics().logEvent(eventName, payload);
|
|
|
|
leaveBreadcrumb(eventName, payload);
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2020-07-22 19:31:38 +00:00
|
|
|
};
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
export const setCurrentScreen = (currentScreen) => {
|
|
|
|
analytics().setCurrentScreen(currentScreen);
|
|
|
|
leaveBreadcrumb(currentScreen, { type: 'navigation' });
|
|
|
|
};
|
|
|
|
|
2019-08-31 19:22:58 +00:00
|
|
|
export default (e) => {
|
2020-05-20 12:56:36 +00:00
|
|
|
if (e instanceof Error && e.message !== 'Aborted' && !__DEV__) {
|
2020-02-28 19:51:13 +00:00
|
|
|
bugsnag.notify(e, (report) => {
|
|
|
|
report.metadata = {
|
|
|
|
details: {
|
|
|
|
...metadata
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2020-07-24 13:19:17 +00:00
|
|
|
crashlytics().recordError(e);
|
2019-08-31 19:22:58 +00:00
|
|
|
} else {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
};
|