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

Move some errors to analytics instead of sentry #2529

Merged
merged 8 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
7 changes: 6 additions & 1 deletion app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Engine from '../../../core/Engine';
import Logger from '../../../util/Logger';
import Branch from 'react-native-branch';
import AppConstants from '../../../core/AppConstants';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

/**
* Stack navigator responsible for the onboarding process
Expand Down Expand Up @@ -186,7 +187,11 @@ class App extends PureComponent {

handleDeeplinks = async ({ error, params, uri }) => {
if (error) {
Logger.error(error, 'Deeplink: Error from Branch');
if (error === 'Trouble reaching the Branch servers, please try again shortly.') {
trackErrorAsAnalytics('Branch: Trouble reaching servers', error);
} else {
Logger.error(error, 'Deeplink: Error from Branch');
}
}
const deeplink = params['+non_branch_link'] || uri || null;
try {
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/AssetOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class AssetOverview extends PureComponent {
try {
await SwapsController.fetchTokenWithCache();
} catch (error) {
Logger.error(error, 'Swaps: error while fetching tokens with catche in AssetOverview');
Logger.error(error, 'Swaps: error while fetching tokens with cache in AssetOverview');
}
};

Expand Down
12 changes: 11 additions & 1 deletion app/components/UI/ComponentErrorBoundary/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Logger from '../../../util/Logger';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

class ComponentErrorBoundary extends React.Component {
state = { error: null };
Expand All @@ -17,7 +18,11 @@ class ComponentErrorBoundary extends React.Component {
/**
* Function to be called when there is an error
*/
onError: PropTypes.func
onError: PropTypes.func,
/**
* Will not track as an error, but still log to analytics
*/
dontTrackAsError: PropTypes.bool
};

static getDerivedStateFromError(error) {
Expand All @@ -28,6 +33,11 @@ class ComponentErrorBoundary extends React.Component {
// eslint-disable-next-line no-unused-expressions
this.props.onError?.();

const { componentLabel, dontTrackAsError } = this.props;

if (dontTrackAsError) {
return trackErrorAsAnalytics(`Component Error Boundary: ${componentLabel}`, error?.message);
}
Logger.error(error, { View: this.props.componentLabel, ...errorInfo });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function TransactionNotification(props) {
accounts,
currentNotification,
isInBrowserView,
navigation,
notificationAnimated,
onClose,
transactions,
Expand Down Expand Up @@ -252,7 +251,6 @@ function TransactionNotification(props) {
<TransactionDetails
transactionObject={tx}
transactionDetails={transactionDetails}
navigation={navigation}
close={onCloseDetails}
showSpeedUpModal={onSpeedUpPress}
showCancelModal={onCancelPress}
Expand Down Expand Up @@ -322,10 +320,6 @@ TransactionNotification.propTypes = {
*/
accounts: PropTypes.object,
/**
/* navigation object required to push new views
*/
navigation: PropTypes.object,
/**
* An array that represents the user transactions on chain
*/
transactions: PropTypes.array,
Expand Down
5 changes: 3 additions & 2 deletions app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import useModalHandler from '../../Base/hooks/useModalHandler';
import useBalance from './utils/useBalance';
import useGasPrice from './utils/useGasPrice';
import { decodeApproveData } from '../../../util/transactions';
import Logger from '../../../util/Logger';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const POLLING_INTERVAL = AppConstants.SWAPS.POLLING_INTERVAL;
const EDIT_MODE_GAS = 'EDIT_MODE_GAS';
Expand Down Expand Up @@ -769,7 +769,6 @@ function SwapsQuotesView({
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE
};
Logger.error(error?.description, `Swaps: ${error?.key}`);
if (error?.key === swapsUtils.SwapsError.QUOTES_EXPIRED_ERROR) {
InteractionManager.runAfterInteractions(() => {
const parameters = {
Expand All @@ -785,6 +784,8 @@ function SwapsQuotesView({
Analytics.trackEventWithParameters(ANALYTICS_EVENT_OPTS.NO_QUOTES_AVAILABLE, {});
Analytics.trackEventWithParameters(ANALYTICS_EVENT_OPTS.NO_QUOTES_AVAILABLE, parameters, true);
});
} else {
trackErrorAsAnalytics(`Swaps: ${error?.key}`, error?.description);
}
},
[sourceToken, sourceAmount, destinationToken, hasEnoughTokenBalance, slippage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import StatusText from '../../../Base/StatusText';
import Text from '../../../Base/Text';
import DetailsModal from '../../../Base/DetailsModal';
import { RPC } from '../../../../constants/network';
import { withNavigation } from 'react-navigation';

const styles = StyleSheet.create({
viewOnEtherscan: {
Expand Down Expand Up @@ -249,4 +250,4 @@ const mapStateToProps = state => ({
network: state.engine.backgroundState.NetworkController,
frequentRpcList: state.engine.backgroundState.PreferencesController.frequentRpcList
});
export default connect(mapStateToProps)(TransactionDetails);
export default connect(mapStateToProps)(withNavigation(TransactionDetails));
5 changes: 0 additions & 5 deletions app/components/UI/TransactionElement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ const transactionIconReceivedFailed = require('../../../images/transaction-icons
class TransactionElement extends PureComponent {
static propTypes = {
assetSymbol: PropTypes.string,
/**
/* navigation object required to push new views
*/
navigation: PropTypes.object,
/**
* Asset object (in this case ERC721 token)
*/
Expand Down Expand Up @@ -271,7 +267,6 @@ class TransactionElement extends PureComponent {
<TransactionDetails
transactionObject={tx}
transactionDetails={transactionDetails}
navigation={this.props.navigation}
close={this.onCloseDetailsModal}
/>
</DetailsModal>
Expand Down
10 changes: 8 additions & 2 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { RPC } from '../../../constants/network';
import RPCMethods from '../../../core/RPCMethods';
import AddCustomNetwork from '../../UI/AddCustomNetwork';
import SwitchCustomNetwork from '../../UI/SwitchCustomNetwork';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const { HOMEPAGE_URL, USER_AGENT, NOTIFICATION_NAMES } = AppConstants;
const HOMEPAGE_HOST = 'home.metamask.io';
Expand Down Expand Up @@ -913,8 +914,13 @@ export const BrowserTab = props => {
ensIgnoreList.push(hostname);
return { url: fullUrl, reload: true };
}
Logger.error(err, 'Failed to resolve ENS name');
Alert.alert(strings('browser.error'), strings('browser.failed_to_resolve_ens_name'));
if (err?.message?.startsWith('EnsIpfsResolver - no known ens-ipfs registry for chainId')) {
trackErrorAsAnalytics('Browser: Failed to resolve ENS name for chainId', err?.message);
} else {
Logger.error(err, 'Failed to resolve ENS name');
}

Alert.alert(strings('browser.failed_to_resolve_ens_name'), err.message);
goBack();
}
},
Expand Down
7 changes: 6 additions & 1 deletion app/components/Views/LockScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SecureKeychain from '../../../core/SecureKeychain';
import { baseStyles } from '../../../styles/common';
import Logger from '../../../util/Logger';
import { NavigationActions } from 'react-navigation';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const LOGO_SIZE = 175;
const styles = StyleSheet.create({
Expand Down Expand Up @@ -129,7 +130,11 @@ class LockScreen extends PureComponent {
if (this.unlockAttempts <= 3) {
this.unlockKeychain();
} else {
Logger.error(error, { message: 'Lockscreen:maxAttemptsReached', attemptNumber: this.unlockAttempts });
trackErrorAsAnalytics(
'Lockscreen: Max Attempts Reached',
error?.message,
`Unlock attempts: ${this.unlockAttempts}`
);
this.props.navigation.navigate('Login');
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/components/Views/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { passwordRequirementsMet } from '../../../util/password';
import ErrorBoundary from '../ErrorBoundary';
import WarningExistingUserModal from '../../UI/WarningExistingUserModal';
import Icon from 'react-native-vector-icons/FontAwesome';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const isTextDelete = text => String(text).toLowerCase() === 'delete';
const deviceHeight = Device.getDeviceHeight();
Expand Down Expand Up @@ -311,6 +312,10 @@ class Login extends PureComponent {
error.toLowerCase() === WRONG_PASSWORD_ERROR_ANDROID.toLowerCase()
) {
this.setState({ loading: false, error: strings('login.invalid_password') });

trackErrorAsAnalytics('Login: Invalid Password', error);

return;
} else if (error === PASSCODE_NOT_SET_ERROR) {
Alert.alert(
'Security Alert',
Expand Down
5 changes: 4 additions & 1 deletion app/components/Views/Settings/SecuritySettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import CookieManager from '@react-native-community/cookies';
import Icon from 'react-native-vector-icons/FontAwesome';
import HintModal from '../../../UI/HintModal';
import { trackErrorAsAnalytics } from '../../../../util/analyticsV2';

const isIos = Device.isIos();

Expand Down Expand Up @@ -393,8 +394,10 @@ class Settings extends PureComponent {
} catch (e) {
if (e.message === 'Invalid password') {
Alert.alert(strings('app_settings.invalid_password'), strings('app_settings.invalid_password_message'));
trackErrorAsAnalytics('SecuritySettings: Invalid password', e?.message);
} else {
Logger.error(e, 'SecuritySettings:biometrics');
}
Logger.error(e, 'SecuritySettings:biometrics');
this.setState({ [type]: !enabled, loading: false });
}
};
Expand Down
25 changes: 24 additions & 1 deletion app/util/analyticsV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,30 @@ export const trackEventV2 = (eventName, params) => {
}
};

/**
* This functions logs errors to analytics instead of sentry.
* The objective is to log errors (that are not errors from our side) like “Invalid Password”.
* An error like this generally means a user inserted the wrong password, so logging to sentry doesn't make sense.
* But we still want to log this to analytics so that we are aware of a rapid increase which may mean it's an error from our side, for example, an error with the encryption library.
* @param {String} type
* @param {String} errorMessage
* @param {String} otherInfo
*/
export const trackErrorAsAnalytics = (type, errorMessage, otherInfo) => {
try {
Analytics.trackEventWithParameters(generateOpt('Error occurred'), {
error: true,
type,
errorMessage,
otherInfo
});
} catch (error) {
Logger.error(error, 'Error logging analytics - trackErrorAsAnalytics');
}
};

export default {
ANALYTICS_EVENTS: ANALYTICS_EVENTS_V2,
trackEvent: trackEventV2
trackEvent: trackEventV2,
trackErrorAsAnalytics
};