Skip to content

Commit d76f28a

Browse files
Add error and event logging (#231)
1 parent 00ce821 commit d76f28a

File tree

9 files changed

+248
-14
lines changed

9 files changed

+248
-14
lines changed

package-lock.json

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
},
5353
"dependencies": {
5454
"@microsoft/applicationinsights-web": "^3.0.0",
55+
"@sentry/svelte": "^7.100.1",
5556
"@tensorflow/tfjs": "^4.4.0",
5657
"@types/w3c-web-serial": "^1.0.6",
5758
"@types/w3c-web-usb": "^1.0.6",

src/components/Gesture.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import RecordIcon from 'virtual:icons/fluent/record-20-regular';
5151
import CloseIcon from 'virtual:icons/ri/close-line';
5252
import StandardDialog from './dialogs/StandardDialog.svelte';
53+
import { logEvent, logMessage } from '../script/utils/logging';
5354
5455
export let gesture: Gesture;
5556
export let showWalkThrough: Boolean = false;
@@ -147,11 +148,12 @@
147148
// Once duration is over (1000ms default), stop recording
148149
setTimeout(() => {
149150
unsubscribe();
150-
console.log('RECEIVED SAMPLES', get(settings).numSamples, newData.x.length);
151+
logMessage('RECEIVED SAMPLES', get(settings).numSamples, newData.x.length);
151152
if (get(settings).numSamples <= newData.x.length) {
152153
if (isThisRecording) {
153154
const recording = { ID: Date.now(), data: newData } as RecordingData;
154155
addRecording(gesture.getId(), recording);
156+
logEvent({ type: 'Data', action: 'Add recording' });
155157
}
156158
} else {
157159
alertUser($t('alert.recording.disconnectedDuringRecording'));

src/components/NewGestureButton.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import { t } from '../i18n';
1111
import StandardButton, { ButtonVariant } from './StandardButton.svelte';
1212
import AddIcon from 'virtual:icons/ri/add-line';
13+
import { logEvent } from '../script/utils/logging';
1314
1415
export let type: ButtonVariant = 'primary';
1516
export let disabled: boolean = false;
1617
1718
function onClick() {
1819
if (areActionsAllowed(false)) {
1920
addGesture('');
21+
logEvent({ type: 'Data', action: 'Add action' });
2022
}
2123
}
2224
</script>

src/pages/model/ModelPage.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
<script lang="ts">
88
import { ModelView, state } from '../../script/stores/uiStore';
9+
import { logEvent } from '../../script/utils/logging';
910
import ModelPageStackView from './stackview/ModelPageStackView.svelte';
1011
import ModelPageTileView from './tileview/ModelPageTileView.svelte';
12+
13+
if ($state.isPredicting) {
14+
logEvent({ type: 'Data', action: 'Test model' });
15+
}
1116
</script>
1217

1318
{#if $state.modelView == ModelView.TILE}

src/script/microbit-interfacing/MicrobitBluetooth.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Bowser from 'bowser';
88
import StaticConfiguration from '../../StaticConfiguration';
99
import { outputting } from '../stores/uiStore';
10-
import { logError, logMessage } from '../utils/logging';
10+
import { logError, logEvent, logMessage } from '../utils/logging';
1111
import MBSpecs from './MBSpecs';
1212
import MicrobitConnection, { DeviceRequestStates } from './MicrobitConnection';
1313
import { UARTMessageType } from './Microbits';
@@ -83,7 +83,11 @@ export class MicrobitBluetooth implements MicrobitConnection {
8383
}
8484

8585
async connect(...states: DeviceRequestStates[]): Promise<void> {
86-
logMessage('Bluetooth connect', states);
86+
logEvent({
87+
type: this.isReconnect ? 'Reconnect' : 'Connect',
88+
action: 'Bluetooth connect start',
89+
states,
90+
});
8791
if (this.duringExplicitConnectDisconnect) {
8892
logMessage('Skipping connect attempt when one is already in progress');
8993
// Wait for the gattConnectPromise while showing a "connecting" dialog.
@@ -170,8 +174,18 @@ export class MicrobitBluetooth implements MicrobitConnection {
170174
states.forEach(s => this.inUseAs.add(s));
171175
states.forEach(s => stateOnAssigned(s, microbitVersion!));
172176
states.forEach(s => stateOnReady(s));
177+
logEvent({
178+
type: this.isReconnect ? 'Reconnect' : 'Connect',
179+
action: 'Bluetooth connect success',
180+
states,
181+
});
173182
} catch (e) {
174183
logError('Bluetooth connect error', e);
184+
logEvent({
185+
type: this.isReconnect ? 'Reconnect' : 'Connect',
186+
action: 'Bluetooth connect failed',
187+
states,
188+
});
175189
await this.disconnectInternal(false);
176190
throw new Error('Failed to establish a connection!');
177191
} finally {

src/script/microbit-interfacing/MicrobitSerial.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
import { logError, logMessage } from '../utils/logging';
7+
import { logError, logEvent, logMessage } from '../utils/logging';
88
import MicrobitConnection, { DeviceRequestStates } from './MicrobitConnection';
99
import MicrobitUSB from './MicrobitUSB';
1010
import { onAccelerometerChange, onButtonChange } from './change-listeners';
@@ -44,7 +44,11 @@ export class MicrobitSerial implements MicrobitConnection {
4444
) {}
4545

4646
async connect(...states: DeviceRequestStates[]): Promise<void> {
47-
logMessage('Serial connect', states);
47+
logEvent({
48+
type: this.isReconnect ? 'Reconnect' : 'Connect',
49+
action: 'Serial connect start',
50+
states,
51+
});
4852
if (this.isConnecting) {
4953
logMessage('Skipping connect attempt when one is already in progress');
5054
return;
@@ -169,9 +173,18 @@ export class MicrobitSerial implements MicrobitConnection {
169173

170174
stateOnAssigned(DeviceRequestStates.INPUT, this.usb.getModelNumber());
171175
stateOnReady(DeviceRequestStates.INPUT);
172-
logMessage('Serial successfully connected');
176+
logEvent({
177+
type: this.isReconnect ? 'Reconnect' : 'Connect',
178+
action: 'Serial connect success',
179+
states,
180+
});
173181
} catch (e) {
174182
logError('Failed to initialise serial protocol', e);
183+
logEvent({
184+
type: this.isReconnect ? 'Reconnect' : 'Connect',
185+
action: 'Serial connect failed',
186+
states,
187+
});
175188
const reconnectHelp = e instanceof BridgeError ? 'bridge' : 'remote';
176189
await this.disconnectInternal(false, reconnectHelp);
177190
throw e;

src/script/ml.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { gestures } from './stores/Stores';
2323
import Repositories from './repository/Repositories';
2424
import { getPrediction } from './getPrediction';
2525
import { TrainingStatus } from './domain/Model';
26+
import { logEvent } from './utils/logging';
2627

2728
let text: (key: string, vars?: object) => string;
2829
t.subscribe(t => (text = t));
@@ -124,6 +125,19 @@ export async function trainModel(): Promise<void> {
124125

125126
trainingStatus.set(TrainingStatus.Success);
126127
model.set(nn);
128+
logEvent({ type: 'Data', action: 'Train model', ...getNumberOfActionsAndRecordings() });
129+
}
130+
131+
function getNumberOfActionsAndRecordings() {
132+
const gestureData = get(gestures);
133+
let numRecordings = 0;
134+
gestureData.forEach(g => {
135+
numRecordings += g.recordings.length;
136+
});
137+
return {
138+
numActions: gestureData.length,
139+
numRecordings,
140+
};
127141
}
128142

129143
export function isParametersLegal(): boolean {

0 commit comments

Comments
 (0)