From 9ce8b48c3e7d43bade8388f4228c708fdd15cac8 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 9 Nov 2022 10:18:40 -1000 Subject: [PATCH 1/3] Opt out of crashlytics with environment variable --- .env.production | 1 + .env.staging | 1 + src/App.js | 9 +++++++++ src/CONFIG.js | 1 + src/components/ErrorBoundary/index.native.js | 7 +++++++ 5 files changed, 19 insertions(+) diff --git a/.env.production b/.env.production index 54f6d921bc82..5e676134d681 100644 --- a/.env.production +++ b/.env.production @@ -6,3 +6,4 @@ EXPENSIFY_PARTNER_PASSWORD=e21965746fd75f82bb66 PUSHER_APP_KEY=268df511a204fbb60884 USE_WEB_PROXY=false ENVIRONMENT=production +SEND_CRASH_REPORTS=true diff --git a/.env.staging b/.env.staging index 8e7d98197967..c789087ebded 100644 --- a/.env.staging +++ b/.env.staging @@ -6,3 +6,4 @@ EXPENSIFY_PARTNER_PASSWORD=e21965746fd75f82bb66 PUSHER_APP_KEY=268df511a204fbb60884 USE_WEB_PROXY=false ENVIRONMENT=staging +SEND_CRASH_REPORTS=true diff --git a/src/App.js b/src/App.js index ef53f1209a7e..328bf6b56638 100644 --- a/src/App.js +++ b/src/App.js @@ -4,6 +4,7 @@ import {LogBox} from 'react-native'; import {GestureHandlerRootView} from 'react-native-gesture-handler'; import {SafeAreaProvider} from 'react-native-safe-area-context'; import Onyx from 'react-native-onyx'; +import crashlytics from '@react-native-firebase/crashlytics'; import CustomStatusBar from './components/CustomStatusBar'; import ErrorBoundary from './components/ErrorBoundary'; import Expensify from './Expensify'; @@ -14,6 +15,14 @@ import ComposeProviders from './components/ComposeProviders'; import SafeArea from './components/SafeArea'; import * as Environment from './libs/Environment/Environment'; import {WindowDimensionsProvider} from './components/withWindowDimensions'; +import CONFIG from './CONFIG'; + +// We do not want to send crash reports if we are on a locally built release version of the app. +// Crashlytics is disabled by default for debug builds, but not local release builds so we are using +// an environment variable to enable them in the staging & production apps and opt-out everywhere else. +if (!CONFIG.SEND_CRASH_REPORTS) { + crashlytics().then(config => config.setCrashlyticsCollectionEnabled(false)); +} // For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx if (window && Environment.isDevelopment()) { diff --git a/src/CONFIG.js b/src/CONFIG.js index 33832ad490c8..57260b676e79 100644 --- a/src/CONFIG.js +++ b/src/CONFIG.js @@ -72,4 +72,5 @@ export default { ONYX_METRICS: lodashGet(Config, 'ONYX_METRICS', 'false') === 'true', DEV_PORT: process.env.PORT || 8080, E2E_TESTING: lodashGet(Config, 'E2E_TESTING', 'false') === 'true', + SEND_CRASH_REPORTS: lodashGet(Config, 'SEND_CRASH_REPORTS', 'false') === 'true', }; diff --git a/src/components/ErrorBoundary/index.native.js b/src/components/ErrorBoundary/index.native.js index e6cbc78b77c4..7c47b83d0a48 100644 --- a/src/components/ErrorBoundary/index.native.js +++ b/src/components/ErrorBoundary/index.native.js @@ -2,8 +2,15 @@ import crashlytics from '@react-native-firebase/crashlytics'; import BaseErrorBoundary from './BaseErrorBoundary'; import Log from '../../libs/Log'; +import CONFIG from '../../CONFIG'; BaseErrorBoundary.defaultProps.logError = (errorMessage, error, errorInfo) => { + // Do not log JS crashes to crashlytics if we are on dev or local release builds. + // They should only be sent on official staging or production versions of the app. + if (!CONFIG.SEND_CRASH_REPORTS) { + return; + } + // Log the error to the server Log.alert(`${errorMessage} - ${error.message}`, {errorInfo}, false); From 9f5e58ade01aada3769bd2695bbbc02d6c42e06b Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 9 Nov 2022 12:06:57 -1000 Subject: [PATCH 2/3] move into platform setup files --- src/App.js | 9 --------- src/setup/platformSetup/index.native.js | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/App.js b/src/App.js index 328bf6b56638..ef53f1209a7e 100644 --- a/src/App.js +++ b/src/App.js @@ -4,7 +4,6 @@ import {LogBox} from 'react-native'; import {GestureHandlerRootView} from 'react-native-gesture-handler'; import {SafeAreaProvider} from 'react-native-safe-area-context'; import Onyx from 'react-native-onyx'; -import crashlytics from '@react-native-firebase/crashlytics'; import CustomStatusBar from './components/CustomStatusBar'; import ErrorBoundary from './components/ErrorBoundary'; import Expensify from './Expensify'; @@ -15,14 +14,6 @@ import ComposeProviders from './components/ComposeProviders'; import SafeArea from './components/SafeArea'; import * as Environment from './libs/Environment/Environment'; import {WindowDimensionsProvider} from './components/withWindowDimensions'; -import CONFIG from './CONFIG'; - -// We do not want to send crash reports if we are on a locally built release version of the app. -// Crashlytics is disabled by default for debug builds, but not local release builds so we are using -// an environment variable to enable them in the staging & production apps and opt-out everywhere else. -if (!CONFIG.SEND_CRASH_REPORTS) { - crashlytics().then(config => config.setCrashlyticsCollectionEnabled(false)); -} // For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx if (window && Environment.isDevelopment()) { diff --git a/src/setup/platformSetup/index.native.js b/src/setup/platformSetup/index.native.js index 02a0629db1d4..89cdb9892ed2 100644 --- a/src/setup/platformSetup/index.native.js +++ b/src/setup/platformSetup/index.native.js @@ -1,3 +1,5 @@ +import crashlytics from '@react-native-firebase/crashlytics'; +import CONFIG from '../../CONFIG'; import PushNotification from '../../libs/Notification/PushNotification'; import * as Report from '../../libs/actions/Report'; import Performance from '../../libs/Performance'; @@ -13,6 +15,13 @@ import '@formatjs/intl-numberformat/locale-data/en'; import '@formatjs/intl-numberformat/locale-data/es'; export default function () { + // We do not want to send crash reports if we are on a locally built release version of the app. + // Crashlytics is disabled by default for debug builds, but not local release builds so we are using + // an environment variable to enable them in the staging & production apps and opt-out everywhere else. + if (!CONFIG.SEND_CRASH_REPORTS) { + crashlytics().setCrashlyticsCollectionEnabled(false); + } + /* * Register callbacks for push notifications. * When the app is completely closed, this code will be executed by a headless JS process thanks to magic in the UrbanAirship RN library. From 7bc444c4891c82bbb0edccb542dc7d3db56c4306 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 9 Nov 2022 14:38:53 -1000 Subject: [PATCH 3/3] remove the check in error boundary --- src/components/ErrorBoundary/index.native.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/components/ErrorBoundary/index.native.js b/src/components/ErrorBoundary/index.native.js index 7c47b83d0a48..e6cbc78b77c4 100644 --- a/src/components/ErrorBoundary/index.native.js +++ b/src/components/ErrorBoundary/index.native.js @@ -2,15 +2,8 @@ import crashlytics from '@react-native-firebase/crashlytics'; import BaseErrorBoundary from './BaseErrorBoundary'; import Log from '../../libs/Log'; -import CONFIG from '../../CONFIG'; BaseErrorBoundary.defaultProps.logError = (errorMessage, error, errorInfo) => { - // Do not log JS crashes to crashlytics if we are on dev or local release builds. - // They should only be sent on official staging or production versions of the app. - if (!CONFIG.SEND_CRASH_REPORTS) { - return; - } - // Log the error to the server Log.alert(`${errorMessage} - ${error.message}`, {errorInfo}, false);