Skip to content
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

Associate crashes with user info #43063

Merged
merged 32 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
49691ca
Associate crashes with user info
ShridharGoel Jun 4, 2024
6a87f2b
Merge branch 'main' of https://github.com/Expensify/App into associat…
ShridharGoel Jun 6, 2024
e7c6950
Update
ShridharGoel Jun 7, 2024
4ff36f0
Update
ShridharGoel Jun 7, 2024
5a4322c
Update
ShridharGoel Jun 7, 2024
a07c2df
Update
ShridharGoel Jun 7, 2024
782dbd1
Merge branch 'main' of https://github.com/Expensify/App into associat…
ShridharGoel Jun 13, 2024
c0615dd
Update
ShridharGoel Jun 14, 2024
1038428
Update
ShridharGoel Jun 17, 2024
af7b29d
Update
ShridharGoel Jun 17, 2024
117be83
Update
ShridharGoel Jun 18, 2024
d9353aa
Update
ShridharGoel Jun 19, 2024
090c470
Update
ShridharGoel Jun 21, 2024
050b284
Merge branch 'main' of https://github.com/Expensify/App into associat…
ShridharGoel Jun 21, 2024
ca62e42
Show option only if config enabled
ShridharGoel Jun 24, 2024
b5090b9
Update
ShridharGoel Jul 4, 2024
1cb89e1
Update
ShridharGoel Jul 4, 2024
9eeee55
Update
ShridharGoel Jul 4, 2024
3e5f033
Update .eslintrc.js
ShridharGoel Jul 4, 2024
6833ee4
Update ContextMenuActions.tsx
ShridharGoel Jul 4, 2024
10cd8b5
Update ContextMenuActions.tsx
ShridharGoel Jul 4, 2024
2e6eba0
Update
ShridharGoel Jul 6, 2024
598c159
Merge branch 'associate-info' of https://github.com/ShridharGoel/Expe…
ShridharGoel Jul 6, 2024
eef37d5
Add text
ShridharGoel Jul 6, 2024
d0d3484
Update
ShridharGoel Jul 6, 2024
06e2616
Update
ShridharGoel Jul 6, 2024
fe9ce0f
Fixes
ShridharGoel Jul 6, 2024
3afbed8
Fixes
ShridharGoel Jul 7, 2024
4d26455
Update
ShridharGoel Jul 11, 2024
50ab2dd
Update
ShridharGoel Jul 12, 2024
e71d115
Update
ShridharGoel Jul 12, 2024
d4e3795
Delete src/libs/setCrashlyticsUserId/types.ts
ShridharGoel Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -28,6 +28,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 @@ -216,6 +217,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And i think a comment would be helpful in both files, but since it's probably temporary component i am not sure.

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 (
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
<View>
{isCrashlyticsDebugEnabled ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want this button to show on staging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will show in staging if crashlytics_debug_enabled is true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will show in staging if crashlytics_debug_enabled is true.

So we don't need to set that in firebase.json for staging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to show this option only when a developer manually enables the crashlytics_debug_enabled flag. Do let me know your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to show this option only when a developer manually enables the crashlytics_debug_enabled flag. Do let me know your thoughts.

On staging how are we going to enable it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want this PR to work for both staging and production, but not for dev or AdHoc builds by default

Copy link
Contributor

@getusha getusha Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShridharGoel, the button will show for both staging and production, right? I don't see the changes to firebase.json in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user ID changes will work for staging and production. The testing button would show only when firebase.json is updated manually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user ID changes will work for staging and production. The testing button would show only when firebase.json is updated manually.

Sorry i am confused here, then why not remove the testing button after confirming the data is being sent to firebase is correct? if it will only be visible only on dev (which i assume is the only way to update firebase.json)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having the button would help us in testing it if needed in the future. Though it wouldn't be needed by QA team.

<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 @@ -984,6 +984,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 @@ -988,6 +988,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
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const testCrash = () => {};
export default testCrash;
Loading