2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

feat: count errors

This commit is contained in:
18alantom 2022-03-09 16:50:48 +05:30
parent 7696435504
commit 9bad5e69d8
4 changed files with 17 additions and 1 deletions

View File

@ -3,8 +3,8 @@ const Observable = require('frappe/utils/observable');
const naming = require('./naming');
const { isPesa } = require('../utils/index');
const { DEFAULT_INTERNAL_PRECISION } = require('../utils/consts');
const telemetry = require('@/telemetry/telemetry');
const { Verb } = require('@/telemetry/types');
const { default: telemetry } = require('@/telemetry/telemetry');
module.exports = class BaseDocument extends Observable {
constructor(data) {

View File

@ -8,6 +8,7 @@ import {
} from 'frappe/common/errors';
import BaseDocument from 'frappe/model/document';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
import telemetry from './telemetry/telemetry';
import { showMessageDialog, showToast } from './utils';
interface ErrorLog {
@ -74,6 +75,7 @@ export function handleError(
more: object = {},
cb?: Function
) {
telemetry.error(error.name);
if (shouldLog) {
console.error(error);
}

View File

@ -1,3 +1,4 @@
import frappe from 'frappe';
import { cloneDeep } from 'lodash';
import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers';
import { Noun, Telemetry, Verb } from './types';
@ -12,6 +13,7 @@ class TelemetryManager {
this.#telemetryObject.instanceId ||= getInstanceId();
this.#telemetryObject.openTime ||= new Date().valueOf();
this.#telemetryObject.timeline ??= [];
this.#telemetryObject.errors ??= {};
this.#started = true;
}
@ -28,10 +30,21 @@ class TelemetryManager {
this.#telemetryObject.timeline.push({ time, verb, noun, more });
}
error(name: string) {
if (this.#telemetryObject.errors === undefined) {
this.#telemetryObject.errors = {};
}
this.#telemetryObject.errors[name] ??= 0;
this.#telemetryObject.errors[name] += 1;
}
async stop() {
// Will set ids if not set.
this.start();
//@ts-ignore
this.#telemetryObject.version = frappe.store.appVersion ?? '';
this.#telemetryObject.counts = await getCounts();
this.#telemetryObject.closeTime = new Date().valueOf();
}

View File

@ -27,6 +27,7 @@ export interface Telemetry {
closeTime: Timestamp;
timeline?: InteractionEvent[];
counts?: Count;
errors: Record<string, number>;
locale: Locale;
version: AppVersion;
}