From 193980dd4a9381844411ba620bd05d1f17058296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 30 Dec 2024 16:47:33 +0800 Subject: [PATCH] fix: trace --- src/common/umami.ts | 4 ++-- src/core/index.ts | 4 ++-- src/framework/napcat.ts | 6 +++--- src/shell/base.ts | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/common/umami.ts b/src/common/umami.ts index 854ac388..ead3fdfc 100644 --- a/src/common/umami.ts +++ b/src/common/umami.ts @@ -63,12 +63,12 @@ export class UmamiTraceCore { this.sendRequest(payload); } - sendTrace(eventName: string) { + sendTrace(eventName: string, data: string = '') { const payload = { website: this.website, hostname: this.hostname, title: 'NapCat ' + this.napcatVersion, - url: `/${this.qqversion}/${this.napcatVersion}/${eventName}`, + url: `/${this.qqversion}/${this.napcatVersion}/${eventName}` + (!!data ? `?data=${data}` : ''), referrer: this.referrer, }; this.sendRequest(payload); diff --git a/src/core/index.ts b/src/core/index.ts index 8bbb0e8c..a8b6ebff 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -156,9 +156,9 @@ export class NapCatCore { msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => { if (this.context.workingEnv === NapCatCoreWorkingEnv.Framework) { - UmamiTrace.sendEvent('framework/kickoff'); + UmamiTrace.sendTrace('framework/kickoff'); } else { - UmamiTrace.sendEvent('shell/kickoff'); + UmamiTrace.sendTrace('shell/kickoff'); } // 下线通知 this.context.logger.logError('[KickedOffLine] [' + Info.tipsTitle + '] ' + Info.tipsDesc); diff --git a/src/framework/napcat.ts b/src/framework/napcat.ts index 9d1dc7ef..9966f268 100644 --- a/src/framework/napcat.ts +++ b/src/framework/napcat.ts @@ -26,7 +26,7 @@ export async function NCoreInitFramework( console.log('NapCat Framework App Loading...'); process.on('uncaughtException', (err) => { - UmamiTrace.sendEvent('framework/error', { name: err.name }); + UmamiTrace.sendTrace('framework/error', err.message); console.log('[NapCat] [Error] Unhandled Exception:', err.message); }); @@ -40,8 +40,8 @@ export async function NCoreInitFramework( const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion()); let guid = loginService.getMachineGuid(); UmamiTrace.init(basicInfoWrapper.getFullQQVesion(), guid); - UmamiTrace.sendTrace('framework/boot'); - UmamiTrace.sendEvent('framework/login'); + UmamiTrace.sendTrace('framework/boot/init'); + UmamiTrace.sendTrace('framework/login/success'); //直到登录成功后,执行下一步 const selfInfo = await new Promise((resolveSelfInfo) => { const loginListener = new NodeIKernelLoginListener(); diff --git a/src/shell/base.ts b/src/shell/base.ts index 1c00d063..90364e6b 100644 --- a/src/shell/base.ts +++ b/src/shell/base.ts @@ -33,7 +33,7 @@ import { UmamiTrace } from '@/common/umami'; // NapCat Shell App ES 入口文件 async function handleUncaughtExceptions(logger: LogWrapper) { process.on('uncaughtException', (err) => { - UmamiTrace.sendEvent('framework/error', { name: err.name, message: err.message }); + UmamiTrace.sendTrace('framework/error', err.message); logger.logError('[NapCat] [Error] Unhandled Exception:', err.message); }); process.on('unhandledRejection', (reason, promise) => { @@ -153,7 +153,7 @@ async function handleLogin( }; loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => { - UmamiTrace.sendEvent('shell/qrlogin/error', { errType, errCode, errMsg }); + UmamiTrace.sendTrace('shell/qrlogin/error?', [errType, errCode, errMsg].toString()); if (!isLogined) { logger.logError('[Core] [Login] Login Error,ErrCode: ', errCode, ' ErrMsg:', errMsg); if (errType == 1 && errCode == 3) { @@ -164,7 +164,7 @@ async function handleLogin( }; loginListener.onLoginFailed = (args) => { - UmamiTrace.sendEvent('shell/login/error', { args }); + UmamiTrace.sendTrace('shell/login/error', args.toString()); logger.logError('[Core] [Login] Login Error , ErrInfo: ', args.toString()); }; @@ -299,9 +299,9 @@ export async function NCoreInitShell() { const dataTimestape = new Date().getTime().toString(); o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']); UmamiTrace.init(basicInfoWrapper.getFullQQVesion(), loginService.getMachineGuid()); - UmamiTrace.sendTrace('shell/boot'); + UmamiTrace.sendTrace('shell/boot/init'); const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList); - UmamiTrace.sendEvent('shell/login'); + UmamiTrace.sendTrace('shell/login/success'); const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129'; o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));