Skip to content

Commit

Permalink
Merge pull request #43063 from ShridharGoel/associate-info
Browse files Browse the repository at this point in the history
Associate crashes with user info
  • Loading branch information
roryabraham authored Jul 31, 2024
2 parents 55be36f + d4e3795 commit 3b7e02b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion __mocks__/@react-native-firebase/crashlytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {FirebaseCrashlyticsTypes} from '@react-native-firebase/crashlytics';

type CrashlyticsModule = Pick<FirebaseCrashlyticsTypes.Module, 'log' | 'recordError' | 'setCrashlyticsCollectionEnabled'>;
type CrashlyticsModule = Pick<FirebaseCrashlyticsTypes.Module, 'log' | 'recordError' | 'setCrashlyticsCollectionEnabled' | 'setUserId'>;

type CrashlyticsMock = () => CrashlyticsModule;

Expand All @@ -10,6 +10,7 @@ const crashlyticsMock: CrashlyticsMock = () => ({
log: jest.fn(),
recordError: jest.fn(),
setCrashlyticsCollectionEnabled: jest.fn(),
setUserId: jest.fn(),
});

export default crashlyticsMock;
8 changes: 8 additions & 0 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import NetworkConnection from './libs/NetworkConnection';
import PushNotification from './libs/Notification/PushNotification';
import './libs/Notification/PushNotification/subscribePushNotification';
import Performance from './libs/Performance';
import setCrashlyticsUserId from './libs/setCrashlyticsUserId';
import StartupTimer from './libs/StartupTimer';
// This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection
import './libs/UnreadIndicatorUpdater';
Expand Down Expand Up @@ -238,6 +239,13 @@ function Expensify({
Audio.setAudioModeAsync({playsInSilentModeIOS: true});
}, []);

useEffect(() => {
if (!isAuthenticated) {
return;
}
setCrashlyticsUserId(session?.accountID ?? -1);
}, [isAuthenticated, session?.accountID]);

// Display a blank page until the onyx migration completes
if (!isOnyxMigrated) {
return null;
Expand Down
34 changes: 34 additions & 0 deletions src/components/TestCrash/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import TestToolRow from '@components/TestToolRow';
import useLocalize from '@hooks/useLocalize';
import testCrash from '@libs/testCrash';
import firebase from '../../../firebase.json';

/**
* Adds a button in native dev builds to test the crashlytics integration with user info.
*/
function TestCrash() {
const {translate} = useLocalize();

const isCrashlyticsDebugEnabled = firebase?.['react-native']?.crashlytics_debug_enabled ?? false;

const toolRowTitle = translate('initialSettingsPage.troubleshoot.testCrash');

return (
<View>
{isCrashlyticsDebugEnabled ? (
<TestToolRow title={toolRowTitle}>
<Button
small
text={toolRowTitle}
onPress={testCrash}
/>
</TestToolRow>
) : null}
</View>
);
}

export default TestCrash;
8 changes: 8 additions & 0 deletions src/components/TestCrash/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import {View} from 'react-native';

function TestCrash() {
return <View />;
}

export default TestCrash;
3 changes: 3 additions & 0 deletions src/components/TestToolMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {Network as NetworkOnyx, User as UserOnyx} from '@src/types/onyx';
import Button from './Button';
import {withNetwork} from './OnyxProvider';
import Switch from './Switch';
import TestCrash from './TestCrash';
import TestToolRow from './TestToolRow';
import Text from './Text';

Expand Down Expand Up @@ -88,6 +89,8 @@ function TestToolMenu({user = USER_DEFAULT, network}: TestToolMenuProps) {
onPress={() => Session.invalidateCredentials()}
/>
</TestToolRow>

<TestCrash />
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ export default {
destroy: 'Destroy',
maskExportOnyxStateData: 'Mask fragile user data while exporting Onyx state',
exportOnyxState: 'Export Onyx state',
testCrash: 'Test crash',
},
debugConsole: {
saveLog: 'Save log',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ export default {
destroy: 'Destruir',
maskExportOnyxStateData: 'Enmascare los datos frágiles del usuario mientras exporta el estado Onyx',
exportOnyxState: 'Exportar estado Onyx',
testCrash: 'Prueba de fallo',
},
debugConsole: {
saveLog: 'Guardar registro',
Expand Down
7 changes: 7 additions & 0 deletions src/libs/setCrashlyticsUserId/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import crashlytics from '@react-native-firebase/crashlytics';

const setCrashlyticsUserId = (accountID: string | number) => {
crashlytics().setUserId(accountID.toString());
};

export default setCrashlyticsUserId;
3 changes: 3 additions & 0 deletions src/libs/setCrashlyticsUserId/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const setCrashlyticsUserId = (_: string | number) => {};
export default setCrashlyticsUserId;
6 changes: 6 additions & 0 deletions src/libs/testCrash/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import crashlytics from '@react-native-firebase/crashlytics';

const testCrash = () => {
crashlytics().crash();
};
export default testCrash;
2 changes: 2 additions & 0 deletions src/libs/testCrash/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const testCrash = () => {};
export default testCrash;

0 comments on commit 3b7e02b

Please sign in to comment.