只接错误监控
只想要错误监控、不采行为与性能?lens 的采集能力都是 opt-in——只装 ErrorPlugin 即可,其它一概不产生。
前置:已能构造并初始化
TripoLens(app/configUrl/endpoint三个必填),见 快速开始。
步骤
ts
import { TripoLens, ErrorPlugin } from '@tripo3d/lens';
const trace = new TripoLens({
app: 'shop',
configUrl: 'https://cdn.example.com/lens/config.json',
endpoint: 'https://your-gateway.example.com/v2/trace/events',
plugins: [
new ErrorPlugin({ captureApi: true }), // 只装错误插件
],
});
await trace.init();- 归因与身份是基础能力、始终装配,但不会产生行为 / 性能事件。
- 错误受
errorsConsent 管控(当前默认全开);若你接了 Consent 弹窗,确保errors维度已授权。
调整采集范围
| 想要 | 怎么做 |
|---|---|
| 采 API 失败(fetch/XHR HTTP 错) | new ErrorPlugin({ captureApi: true })(默认关,属侵入操作) |
| 采 SSR 服务端错误 | captureSsr: true + 服务端接线,见 SSR 采集 |
| 关掉资源 / 白屏错误 | captureResource: false / captureWhiteScreen: false(默认开) |
| 手动上报 | trace.captureException(err, extras) / trace.captureMessage(msg, level) |
| 控量 | errorRateLimit / errorSessionMax(确定性限流,非随机采样) |
完整选项见 错误收集。
错误不被随机采样
错误无节点级采样率、内置默认 100% 入管线(仅远程 control.tech 坐标级规则可覆盖),「控量」靠插件内确定性限流与远程配置的 error.filter 前置过滤,而不是概率采样。
验证
临时触发一个错误,在 Network 面板或 DevTools 观察发往 /v2/trace/events 的请求:
ts
throw new Error('lens-test');相关
- 错误收集:全部选项、错误子类、手动捕获
- Consent 授权 · 排查:没有上报