Skip to content

Commit 9efb985

Browse files
authored
Sentry fixes (#1658)
2 parents b0d7fef + 2c2c227 commit 9efb985

File tree

13 files changed

+72
-57
lines changed

13 files changed

+72
-57
lines changed

gui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"@tauri-apps/plugin-dialog": "^2.0.0",
2121
"@tauri-apps/plugin-fs": "2.4.1",
2222
"@tauri-apps/plugin-http": "^2.5.0",
23-
"@tauri-apps/plugin-opener": "^2.4.0",
2423
"@tauri-apps/plugin-log": "~2",
24+
"@tauri-apps/plugin-opener": "^2.4.0",
2525
"@tauri-apps/plugin-os": "^2.0.0",
2626
"@tauri-apps/plugin-shell": "^2.3.0",
2727
"@tauri-apps/plugin-store": "^2.4.1",
@@ -52,6 +52,7 @@
5252
"ts-pattern": "^5.4.0",
5353
"typescript": "^5.6.3",
5454
"use-double-tap": "^1.3.6",
55+
"uuid": "^13.0.0",
5556
"yup": "^1.4.0"
5657
},
5758
"scripts": {

gui/src/components/onboarding/pages/body-proportions/ScaledProportions.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ export function ScaledProportionsPage() {
326326
}
327327
);
328328

329+
useEffect(() => {
330+
if (lastUsed !== null) {
331+
Sentry.metrics.count('scaled_proportions', 1, {
332+
attributes: { calibration: lastUsed },
333+
});
334+
}
335+
}, [lastUsed]);
336+
329337
useEffect(() => {
330338
sendRPCPacket(
331339
RpcMessage.SkeletonConfigRequest,
@@ -334,11 +342,6 @@ export function ScaledProportionsPage() {
334342

335343
return () => {
336344
cancel();
337-
if (lastUsed !== null) {
338-
Sentry.metrics.count('scaled_proportions', 1, {
339-
attributes: { calibration: lastUsed },
340-
});
341-
}
342345
};
343346
}, []);
344347

gui/src/components/providers/ConfigContext.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
import { ReactNode, useContext, useLayoutEffect } from 'react';
1+
import { ReactNode } from 'react';
22
import { ConfigContextC, loadConfig, useConfigProvider } from '@/hooks/config';
3-
import { DEFAULT_LOCALE, LangContext } from '@/i18n/config';
43
import { getSentryOrCompute } from '@/utils/sentry';
54

65
const config = await loadConfig();
76

87
if (config?.errorTracking !== undefined) {
98
// load sentry ASAP to catch early errors
10-
getSentryOrCompute(config.errorTracking ?? false);
9+
getSentryOrCompute(config.errorTracking ?? false, config.uuid);
1110
}
1211

1312
export function ConfigContextProvider({ children }: { children: ReactNode }) {
1413
const context = useConfigProvider(config);
15-
const { changeLocales } = useContext(LangContext);
16-
17-
useLayoutEffect(() => {
18-
changeLocales([config?.lang || DEFAULT_LOCALE]);
19-
}, []);
20-
21-
useLayoutEffect(() => {
22-
if (config?.errorTracking !== undefined) {
23-
// Alows for sentry to refresh if user change the setting once the gui
24-
// is initialized
25-
getSentryOrCompute(config.errorTracking ?? false);
26-
}
27-
}, [config?.errorTracking]);
2814

2915
return (
3016
<ConfigContextC.Provider value={context}>

gui/src/components/settings/pages/HomeScreenSettings.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,10 @@ export function TrackingChecklistSettings({
5555
// that prevent sending a packet for steps that didnt change
5656
if (!value && !ignoredSteps.includes(stepId)) {
5757
ignoreStep(stepId, true);
58-
Sentry.metrics.count('mute_checklist_step', 1, {
59-
attributes: { step: TrackingChecklistStepId[stepId] },
60-
});
6158
}
6259

6360
if (value && ignoredSteps.includes(stepId)) {
6461
ignoreStep(stepId, false);
65-
Sentry.metrics.count('unmute_checklist_step', 1, {
66-
attributes: { step: TrackingChecklistStepId[stepId] },
67-
});
6862
}
6963
}
7064
};

gui/src/hooks/app.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, useContext, useEffect, useState } from 'react';
1+
import { createContext, useContext, useEffect, useLayoutEffect, useState } from 'react';
22
import {
33
DataFeedMessage,
44
DataFeedUpdateT,
@@ -12,8 +12,9 @@ import { useBonesDataFeedConfig, useDataFeedConfig } from './datafeed-config';
1212
import { useWebsocketAPI } from './websocket-api';
1313
import { useAtomValue, useSetAtom } from 'jotai';
1414
import { bonesAtom, datafeedAtom, devicesAtom } from '@/store/app-store';
15-
import { updateSentryContext } from '@/utils/sentry';
15+
import { getSentryOrCompute, updateSentryContext } from '@/utils/sentry';
1616
import { fetchCurrentFirmwareRelease, FirmwareRelease } from './firmware-update';
17+
import { DEFAULT_LOCALE, LangContext } from '@/i18n/config';
1718

1819
export interface AppContext {
1920
currentFirmwareRelease: FirmwareRelease | null;
@@ -22,6 +23,7 @@ export interface AppContext {
2223
export function useProvideAppContext(): AppContext {
2324
const { useRPCPacket, sendDataFeedPacket, useDataFeedPacket, isConnected } =
2425
useWebsocketAPI();
26+
const { changeLocales } = useContext(LangContext);
2527
const { config } = useConfig();
2628
const { dataFeedConfig } = useDataFeedConfig();
2729
const bonesDataFeedConfig = useBonesDataFeedConfig();
@@ -58,14 +60,30 @@ export function useProvideAppContext(): AppContext {
5860
});
5961

6062
useEffect(() => {
63+
if (!config) return;
64+
6165
const interval = setInterval(() => {
62-
fetchCurrentFirmwareRelease().then((res) => setCurrentFirmwareRelease(res));
66+
fetchCurrentFirmwareRelease(config.uuid).then(setCurrentFirmwareRelease);
6367
}, 1000);
6468
return () => {
6569
clearInterval(interval);
6670
};
71+
}, [config?.uuid]);
72+
73+
useLayoutEffect(() => {
74+
changeLocales([config?.lang || DEFAULT_LOCALE]);
6775
}, []);
6876

77+
useLayoutEffect(() => {
78+
if (!config) return;
79+
if (config.errorTracking !== undefined) {
80+
console.log('change');
81+
// Alows for sentry to refresh if user change the setting once the gui
82+
// is initialized
83+
getSentryOrCompute(config.errorTracking ?? false, config.uuid);
84+
}
85+
}, [config]);
86+
6987
return {
7088
currentFirmwareRelease,
7189
};

gui/src/hooks/config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { load, Store } from '@tauri-apps/plugin-store';
99
import { useIsTauri } from './breakpoint';
1010
import { waitUntil } from '@/utils/a11y';
1111
import { isTauri } from '@tauri-apps/api/core';
12+
import { v4 as uuidv4 } from 'uuid';
1213

1314
export interface WindowConfig {
1415
width: number;
@@ -26,6 +27,7 @@ export enum AssignMode {
2627
}
2728

2829
export interface Config {
30+
uuid: string;
2931
debug: boolean;
3032
lang: string;
3133
doneOnboarding: boolean;
@@ -57,6 +59,7 @@ export interface ConfigContext {
5759
}
5860

5961
export const defaultConfig: Config = {
62+
uuid: uuidv4(),
6063
lang: 'en',
6164
debug: false,
6265
doneOnboarding: false,
@@ -117,13 +120,16 @@ export const loadConfig = async () => {
117120
if (!json) throw new Error('Config has ceased existing for some reason');
118121

119122
const loadedConfig = fallbackToDefaults(JSON.parse(json));
120-
// set(loadedConfig);
121-
// setLoading(false);
123+
124+
if (!loadedConfig.uuid) {
125+
// Make sure the config always has a uuid
126+
loadedConfig.uuid = uuidv4();
127+
await store.set('config.json', JSON.stringify(loadedConfig));
128+
}
129+
122130
return loadedConfig;
123131
} catch (e) {
124132
error(e);
125-
// setConfig(defaultConfig);
126-
// setLoading(false);
127133
return null;
128134
}
129135
};

gui/src/hooks/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// implemetation of https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
2-
export function hash(str: string) {
2+
export function normalizedHash(str: string) {
33
let hash = 2166136261;
44
for (let i = 0; i < str.length; i++) {
55
hash ^= str.charCodeAt(i);

gui/src/hooks/firmware-update.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { BoardType, DeviceDataT } from 'solarxr-protocol';
22
import { fetch as tauriFetch } from '@tauri-apps/plugin-http';
33
import { cacheWrap } from './cache';
44
import semver from 'semver';
5-
import { hash } from './crypto';
6-
import { getUserID } from './user';
5+
import { normalizedHash } from './crypto';
76

87
export interface FirmwareRelease {
98
name: string;
@@ -24,7 +23,7 @@ const todaysRange = (deployData: [number, Date][]): number => {
2423
return maxRange;
2524
};
2625

27-
const checkUserCanUpdate = async (url: string, fwVersion: string) => {
26+
const checkUserCanUpdate = async (uuid: string, url: string, fwVersion: string) => {
2827
const deployDataJson = JSON.parse(
2928
(await cacheWrap(
3029
`firmware-${fwVersion}-deploy`,
@@ -56,12 +55,13 @@ const checkUserCanUpdate = async (url: string, fwVersion: string) => {
5655
const todayUpdateRange = todaysRange(deployData);
5756
if (!todayUpdateRange) return false;
5857

59-
const uniqueUserKey = await getUserID();
6058
// Make it so the hash change every version. Prevent the same user from getting the same delay
61-
return hash(`${uniqueUserKey}-${fwVersion}`) <= todayUpdateRange;
59+
return normalizedHash(`${uuid}-${fwVersion}`) <= todayUpdateRange;
6260
};
6361

64-
export async function fetchCurrentFirmwareRelease(): Promise<FirmwareRelease | null> {
62+
export async function fetchCurrentFirmwareRelease(
63+
uuid: string
64+
): Promise<FirmwareRelease | null> {
6565
const releases: any[] | null = JSON.parse(
6666
(await cacheWrap(
6767
'firmware-releases',
@@ -93,6 +93,7 @@ export async function fetchCurrentFirmwareRelease(): Promise<FirmwareRelease | n
9393
}
9494

9595
const userCanUpdate = await checkUserCanUpdate(
96+
uuid,
9697
deployAsset.browser_download_url,
9798
version
9899
);

gui/src/hooks/reset.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export function useReset(options: UseResetOptions, onReseted?: () => void) {
4747
req.bodyParts = parts;
4848
sendRPCPacket(RpcMessage.ResetRequest, req);
4949

50-
Sentry.metrics.count('reset_click', 1, { attributes: options });
50+
Sentry.metrics.count('reset_click', 1, {
51+
attributes: {
52+
resetType: ResetType[options.type],
53+
group: options.type === ResetType.Mounting ? options.group : undefined,
54+
},
55+
});
5156
};
5257

5358
const onResetFinished = () => {

gui/src/hooks/tracking-checklist.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from 'solarxr-protocol';
1111
import { useWebsocketAPI } from './websocket-api';
1212
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
13+
import * as Sentry from '@sentry/react';
1314

1415
export const trackingchecklistIdtoLabel: Record<TrackingChecklistStepId, string> = {
1516
[TrackingChecklistStepId.UNKNOWN]: '',
@@ -165,6 +166,9 @@ export function provideTrackingChecklist() {
165166
res.stepId = step;
166167
res.ignore = ignore;
167168
sendRPCPacket(RpcMessage.IgnoreTrackingChecklistStepRequest, res);
169+
Sentry.metrics.count(ignore ? 'mute_checklist_step' : 'unmute_checklist_step', 1, {
170+
attributes: { step: TrackingChecklistStepId[step] },
171+
});
168172
};
169173

170174
return {

0 commit comments

Comments
 (0)