M5(T-M5-06): 可观测——BridgeTracer 全链路 traceId + ErrorCenter→APM sink

- Message 加非协议 traceId 字段(不进 toJson/toArray,对 H5 透明)
- BridgeController 在 OUTBOUND/INBOUND/HANDLER/RESPONSE/DISPATCH/RETURN/DROP
  各阶段打点,一条桥消息往返可经 traceId 还原
- entry 新增 ErrorReporter.installErrorSink(),打通 ErrorCenter Report→APM/Crash
  上报通道(结构化字段就位,接入真实 SDK 仅改 reportToApm)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lanterngamescn
2026-06-26 07:09:14 +08:00
co-authored by Claude Opus 4.8
parent 9be1a23635
commit b461b291f5
4 changed files with 61 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
/**
* 错误上报接入点(T-M5-06 可观测)。entry 层向 common 的 ErrorCenter 注入 sink
* 把 Report 策略的错误转发到 APM/Crash 平台。
*
* common 层不依赖 UI / 第三方上报 SDK,故由本文件在启动时 setSink;接入真实平台
* (如华为 APM / Bugly)只改这里的 reportToApm(),对各能力 Provider 透明。
*/
import { ErrorCenter, ErrorStrategy } from 'common';
import { AppError } from 'contracts';
import { hilog } from '@kit.PerformanceAnalysisKit';
const DOMAIN = 0x9527;
const TAG = 'ErrorReporter';
/** 转发到 APM/Crash 平台。当前为预留实现(结构化记录),接入 SDK 时在此替换。 */
function reportToApm(error: AppError): void {
// TODO(M6+): 接入华为 APM / Crash SDK,上报 { kind, code, message, cause }。
// 现阶段:结构化打到 hilog,保证上报链路已贯通、字段就位。
const code: string = error.code !== undefined ? String(error.code) : '-';
hilog.error(DOMAIN, TAG, 'APM report | kind=%{public}s code=%{public}s msg=%{public}s',
error.kind, code, error.message);
}
/** 在应用启动时调用,安装错误 sink。 */
export function installErrorSink(): void {
ErrorCenter.setSink((error: AppError, strategy: ErrorStrategy): void => {
if (strategy === ErrorStrategy.Report) {
reportToApm(error);
}
// Notify/Block 的用户可见处置由 UI 层(容器/路由)按场景实现;
// Silent 已由 ErrorCenter 记日志,此处不重复。
});
}
@@ -4,6 +4,7 @@ import { window } from '@kit.ArkUI';
import { EventBus } from 'common';
import { WeChatApi } from 'feature_capabilities';
import { AppEvents } from '../routes/AppRoutes';
import { installErrorSink } from '../di/ErrorReporter';
const DOMAIN = 0x0000;
@@ -15,6 +16,8 @@ export default class EntryAbility extends UIAbility {
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
}
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
// 可观测(T-M5-06):安装错误上报 sink,打通 ErrorCenter → APM/Crash 通道
installErrorSink();
// 微信回调(冷启动经 want 拉回):交 SDK 解析 → 路由到 Share/Login 回调
WeChatApi.getInstance().handleWant(want);
}