Skip to content

Commit

Permalink
perf(analytics): adding events to report on caught errors
Browse files Browse the repository at this point in the history
919
  • Loading branch information
charleslavon committed Feb 1, 2024
1 parent ee0f57b commit a8db8e0
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/components/sandbox/Sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
} from './utils/onboarding';
import Welcome from './Welcome';
import MainLoader from './Welcome/MainLoader';
import { recordHandledError } from '@/utils/analytics';

export const Sandbox = ({ onboarding = false }) => {
const near = useVmStore((store) => store.near);
Expand Down Expand Up @@ -319,7 +320,8 @@ export const Sandbox = ({ onboarding = false }) => {
});
changeCode(path, formattedCode);
} catch (e) {
console.log(e);
console.error(e);
recordHandledError({ scope: 'sandbox reformatting', message: e.message || e });
}
};

Expand Down Expand Up @@ -492,6 +494,7 @@ export const Sandbox = ({ onboarding = false }) => {
} catch (e) {
setParsedWidgetProps({});
setPropsError(e.message);
recordHandledError({ scope: 'setting component props within the sandbox editor', message: e.message || e });
}
}, [widgetProps]);

Expand Down
2 changes: 2 additions & 0 deletions src/components/sandbox/TabProps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Editor from '@monaco-editor/react';
import React, { useCallback } from 'react';

import { Tab } from '../utils/const';
import { recordHandledError } from '@/utils/analytics';

const TabProps = ({ tab, widgetProps, setWidgetProps, propsError }) => {
const reformatProps = useCallback(
Expand All @@ -11,6 +12,7 @@ const TabProps = ({ tab, widgetProps, setWidgetProps, propsError }) => {
setWidgetProps(formattedProps);
} catch (e) {
console.log(e);
recordHandledError({ scope: 'sandbox reformatProps', message: e.message || e });
}
},
[setWidgetProps],
Expand Down
3 changes: 2 additions & 1 deletion src/components/vm/VmInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { useSignInRedirect } from '@/hooks/useSignInRedirect';
import { useAuthStore } from '@/stores/auth';
import { useIdosStore } from '@/stores/idosStore';
import { useVmStore } from '@/stores/vm';
import { recordWalletConnect, reset as resetAnalytics } from '@/utils/analytics';
import { recordHandledError, recordWalletConnect, reset as resetAnalytics } from '@/utils/analytics';
import {
commitModalBypassAuthorIds,
commitModalBypassSources,
Expand Down Expand Up @@ -173,6 +173,7 @@ export default function VmInitializer() {
} catch (err) {
const errMsg = err instanceof Error ? err.message : 'Something went wrong';
alert(errMsg);
recordHandledError({ scope: 'requestSignMessage', message: errMsg });
}
},
[near],
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useBosLoaderInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useEffect } from 'react';
import { useBosLoaderStore } from '@/stores/bos-loader';

import { useFlags } from './useFlags';
import { recordHandledError } from '@/utils/analytics';

export function useBosLoaderInitializer() {
const [flags] = useFlags();
Expand Down Expand Up @@ -37,9 +38,9 @@ export function useBosLoaderInitializer() {
hasResolved: true,
redirectMap: data.components,
});
} catch (e) {
} catch (e: any) {
console.error(e);

recordHandledError({ scope: 'requestSignMessage', message: e.message || e });
setStore({
failedToLoad: true,
hasResolved: true,
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useIdOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { idOS } from '@idos-network/idos-sdk';
import { useCallback, useEffect } from 'react';

import { useIdosStore } from '@/stores/idosStore';
import { recordHandledError } from '@/utils/analytics';

export function useIdOS() {
const setIdosStore = useIdosStore((state) => state.set);
Expand All @@ -15,7 +16,9 @@ export function useIdOS() {
})) as any;
setIdosStore({ idOS: idos });
} catch (error: any) {
console.error('Failed to initialize IDOS: ', error);
const scope = 'Failed to initialize IDOS:';
console.error(scope, error);
recordHandledError({ scope, message: error.message || error });
}
}, [setIdosStore]);

Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useDefaultLayout } from '@/hooks/useLayout';
import { useAuthStore } from '@/stores/auth';
import { useIdosStore } from '@/stores/idosStore';
import type { NextPageWithLayout } from '@/utils/types';
import { recordHandledError } from '@/utils/analytics';

const SettingsPage: NextPageWithLayout = () => {
const components = useBosComponents();
Expand Down Expand Up @@ -49,8 +50,10 @@ const SettingsPage: NextPageWithLayout = () => {
});
}
} catch (error: any) {
console.error('Failed to init wallet + idOS: ', error);
const scope = 'Failed to init wallet + idOS: ';
console.error(scope, error);
const errorMessage = error.message ? error.message : 'unknown';
recordHandledError({ scope, message: errorMessage || error });
setError({
type: 'ERROR',
title: 'Falilure during idOS initialization:',
Expand Down
7 changes: 6 additions & 1 deletion src/pages/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { network } from '@/utils/config';
import type { NextPageWithLayout } from '@/utils/types';

import { accountAddressPatternNoSubaccount, emailPattern, getEmailId, isValidEmail } from '../utils/form-validation';
import { recordHandledError } from '@/utils/analytics';

const ErrorText = styled.p`
color: hsla(8, 100%, 33%, 1);
Expand Down Expand Up @@ -76,8 +77,12 @@ const SignUpPage: NextPageWithLayout = () => {
if (data?.result?.code_hash) {
return setIsAccountAvailable(false);
}
} catch (error) {
} catch (error: any) {
console.log(error);
recordHandledError({
scope: 'sign-up: account availability check',
message: error.message || error,
});
setIsAccountAvailable(false);
}
}, []);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export function recordEventWithProps(eventLabel: string, properties: Record<stri
}
}

export function recordHandledError(props: Record<string, string>) {
recordEventWithProps('error-handled', props);
}

export function recordEvent(eventLabel: string) {
if (!rudderAnalytics) return;
try {
Expand Down
30 changes: 21 additions & 9 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ import {
setProcessSuccess,
} from './notificationsLocalStorage';
import type { NotificationSubscriptionData } from './types';
import { recordHandledError } from './analytics';

// min version for iOS to support notifications
export const recommendedIosVersionForNotifications = 16.4;

const handleRequestPermission = () => {
try {
return Notification.requestPermission();
} catch (error) {
console.error('Error while requesting permission.', error);
} catch (error: any) {
const scope = 'Error while requesting Notification permission.';
console.error(scope, error);
recordHandledError({ scope, message: error.message || error });
}
};

const registerServiceWorker = () => {
try {
return navigator.serviceWorker.register('/service-worker.js');
} catch (error) {
console.error('Error while registering service-worker.', error);
} catch (e: any) {
const scope = 'Error while registering service-worker.js';
console.error(scope, e);
recordHandledError({ scope, message: e.message || e });
}
};

Expand All @@ -50,8 +55,9 @@ const handlePushManagerSubscribe = async () => {
userVisibleOnly: true,
applicationServerKey: notificationApplicationServerKey,
});
} catch (e) {
console.error('Error while subscribing to service-worker.', e);
} catch (e: any) {
const scope = 'Error while subscribing to service-worker.';
recordHandledError({ scope, message: e.message || e });
throw e;
}
};
Expand All @@ -65,8 +71,10 @@ export const handlePushManagerUnsubscribe = async (hide: () => void) => {
await pushServerUnsubscribe(subscription);
await unregisterServiceWorker();
await subscription?.unsubscribe();
} catch (error) {
// TODO: handle
} catch (e: any) {
const scope = 'Error while handling unsubscribe';
console.error(scope, e);
recordHandledError({ scope, message: e.message || e });
} finally {
hide();
}
Expand Down Expand Up @@ -129,8 +137,12 @@ export const handleTurnOn = async (accountId: string, hideModal: () => void) =>
});

setProcessSuccess();
} catch (error: unknown) {
} catch (error: any) {
setProcessError(error);
recordHandledError({
scope: 'Error in the attempt to turn on Push Notifications',
message: error.message || error,
});
} finally {
hideModal();
setProcessEnded();
Expand Down

0 comments on commit a8db8e0

Please sign in to comment.