From 9bad5e69d871e2702e789acb50e4fcecc7c00dd7 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 9 Mar 2022 16:50:48 +0530 Subject: [PATCH] feat: count errors --- frappe/model/document.js | 2 +- src/errorHandling.ts | 2 ++ src/telemetry/telemetry.ts | 13 +++++++++++++ src/telemetry/types.ts | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frappe/model/document.js b/frappe/model/document.js index d9ca4b5a..c5ac3107 100644 --- a/frappe/model/document.js +++ b/frappe/model/document.js @@ -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) { diff --git a/src/errorHandling.ts b/src/errorHandling.ts index 924632ec..cecd016d 100644 --- a/src/errorHandling.ts +++ b/src/errorHandling.ts @@ -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); } diff --git a/src/telemetry/telemetry.ts b/src/telemetry/telemetry.ts index bd826eef..67897389 100644 --- a/src/telemetry/telemetry.ts +++ b/src/telemetry/telemetry.ts @@ -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(); } diff --git a/src/telemetry/types.ts b/src/telemetry/types.ts index 60cb6d04..9d982a50 100644 --- a/src/telemetry/types.ts +++ b/src/telemetry/types.ts @@ -27,6 +27,7 @@ export interface Telemetry { closeTime: Timestamp; timeline?: InteractionEvent[]; counts?: Count; + errors: Record; locale: Locale; version: AppVersion; }