docs: rn-log → rn-bugcollect 重命名
Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
父节点
dc96fa8422
当前提交
a53438a3f0
24
CLAUDE.md
24
CLAUDE.md
@ -18,7 +18,7 @@ XuqmGroup React Native SDK monorepo。为集成宿主 App(如 YiwangxinApp4)
|
|||||||
| `@xuqm/rn-im` | packages/im | 0.2.2 | IM 会话、消息(代码冻结,仅文档) |
|
| `@xuqm/rn-im` | packages/im | 0.2.2 | IM 会话、消息(代码冻结,仅文档) |
|
||||||
| `@xuqm/rn-xwebview` | packages/xwebview | 0.2.2 | WebView 容器 + JSBridge UI 组件 |
|
| `@xuqm/rn-xwebview` | packages/xwebview | 0.2.2 | WebView 容器 + JSBridge UI 组件 |
|
||||||
| `@xuqm/rn-license` | packages/license | 0.3.0 | 证书授权(代码冻结,仅文档) |
|
| `@xuqm/rn-license` | packages/license | 0.3.0 | 证书授权(代码冻结,仅文档) |
|
||||||
| `@xuqm/rn-log` | packages/log | 0.1.0 | 日志、错误追踪、漏斗分析(新) |
|
| `@xuqm/rn-bugcollect` | packages/bugcollect | 0.1.0 | 日志、错误追踪、漏斗分析(新) |
|
||||||
|
|
||||||
**代码冻结模块(push/im/license):不修改代码,仅补充文档。**
|
**代码冻结模块(push/im/license):不修改代码,仅补充文档。**
|
||||||
|
|
||||||
@ -59,20 +59,20 @@ XuqmSDK.setUserInfo(null) // 登出,触发所有子 SDK 登出
|
|||||||
|
|
||||||
子 SDK 自动订阅 `setUserInfo` 事件:Push 自动注册/解绑 token,IM 自动登录/断开,Update 更新 userId。
|
子 SDK 自动订阅 `setUserInfo` 事件:Push 自动注册/解绑 token,IM 自动登录/断开,Update 更新 userId。
|
||||||
|
|
||||||
## 日志 SDK(@xuqm/rn-log)
|
## 日志 SDK(@xuqm/rn-bugcollect)
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { XLog } from '@xuqm/rn-log'
|
import { BugCollect } from '@xuqm/rn-bugcollect'
|
||||||
|
|
||||||
XLog.setLogLevel('debug')
|
BugCollect.setLogLevel('debug')
|
||||||
XLog.setEnvironment('production')
|
BugCollect.setEnvironment('production')
|
||||||
XLog.startCapture() // 开启全局错误捕获
|
BugCollect.startCapture() // 开启全局错误捕获
|
||||||
XLog.event('page_view', { page: 'home' })
|
BugCollect.event('page_view', { page: 'home' })
|
||||||
XLog.captureError(new Error('xxx'))
|
BugCollect.captureError(new Error('xxx'))
|
||||||
XLog.defineFunnel('checkout', ['cart_view', 'checkout_start', 'payment_done'])
|
BugCollect.defineFunnel('checkout', ['cart_view', 'checkout_start', 'payment_done'])
|
||||||
```
|
```
|
||||||
|
|
||||||
`logApiUrl` 由 SDK 在 init 后从 `/api/sdk/config` 自动获取,无需 App 传入。
|
`bugCollectApiUrl` 由 SDK 在 init 后从 `/api/sdk/config` 自动获取,无需 App 传入。
|
||||||
|
|
||||||
## 关键约束
|
## 关键约束
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ XLog.defineFunnel('checkout', ['cart_view', 'checkout_start', 'payment_done'])
|
|||||||
- `XuqmSDK.setUserInfo()` 现有字段不得删除
|
- `XuqmSDK.setUserInfo()` 现有字段不得删除
|
||||||
- 新增字段一律为可选,有合理默认值
|
- 新增字段一律为可选,有合理默认值
|
||||||
- 不允许静默降级(autoInit 失败时 `__DEV__` 模式 throw)
|
- 不允许静默降级(autoInit 失败时 `__DEV__` 模式 throw)
|
||||||
- rn-common 与 rn-log 解耦:rn-common 可独立使用;rn-log peerDep rn-common
|
- rn-common 与 rn-bugcollect 解耦:rn-common 可独立使用;rn-bugcollect peerDep rn-common
|
||||||
|
|
||||||
## XWebView JSBridge 标准 Handler
|
## XWebView JSBridge 标准 Handler
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ XLog.defineFunnel('checkout', ['cart_view', 'checkout_start', 'payment_done'])
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn workspace @xuqm/rn-common typecheck
|
yarn workspace @xuqm/rn-common typecheck
|
||||||
yarn workspace @xuqm/rn-log typecheck
|
yarn workspace @xuqm/rn-bugcollect typecheck
|
||||||
yarn workspace @xuqm/rn-update typecheck
|
yarn workspace @xuqm/rn-update typecheck
|
||||||
yarn workspace @xuqm/rn-push typecheck
|
yarn workspace @xuqm/rn-push typecheck
|
||||||
yarn workspace @xuqm/rn-im typecheck
|
yarn workspace @xuqm/rn-im typecheck
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
# @xuqm/rn-log
|
# @xuqm/rn-bugcollect
|
||||||
|
|
||||||
XuqmGroup RN SDK 日志模块。提供日志采集、错误追踪、漏斗分析能力。
|
XuqmGroup RN SDK 错误采集模块。提供日志采集、错误追踪、漏斗分析能力。
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn add @xuqm/rn-log
|
yarn add @xuqm/rn-bugcollect
|
||||||
```
|
```
|
||||||
|
|
||||||
Peer dependencies:`@xuqm/rn-common >= 0.4.0`,`@react-native-async-storage/async-storage >= 1.21.0`,`react-native >= 0.76`
|
Peer dependencies:`@xuqm/rn-common >= 0.4.0`,`@react-native-async-storage/async-storage >= 1.21.0`,`react-native >= 0.76`
|
||||||
@ -13,40 +13,40 @@ Peer dependencies:`@xuqm/rn-common >= 0.4.0`,`@react-native-async-storage/as
|
|||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { XLog } from '@xuqm/rn-log'
|
import { BugCollect } from '@xuqm/rn-bugcollect'
|
||||||
|
|
||||||
// 1. 设置日志级别
|
// 1. 设置日志级别
|
||||||
XLog.setLogLevel('debug') // 'debug' | 'info' | 'warn' | 'error'
|
BugCollect.setLogLevel('debug') // 'debug' | 'info' | 'warn' | 'error'
|
||||||
|
|
||||||
// 2. 设置环境标签
|
// 2. 设置环境标签
|
||||||
XLog.setEnvironment('production') // 'development' | 'staging' | 'production'
|
BugCollect.setEnvironment('production') // 'development' | 'staging' | 'production'
|
||||||
|
|
||||||
// 3. 开启全局错误捕获(App 启动时调用一次)
|
// 3. 开启全局错误捕获(App 启动时调用一次)
|
||||||
XLog.startCapture()
|
BugCollect.startCapture()
|
||||||
|
|
||||||
// 4. 记录自定义事件
|
// 4. 记录自定义事件
|
||||||
XLog.event('page_view', { page: 'home' })
|
BugCollect.event('page_view', { page: 'home' })
|
||||||
|
|
||||||
// 5. 上报错误
|
// 5. 上报错误
|
||||||
try { ... } catch (e) { XLog.captureError(e) }
|
try { ... } catch (e) { BugCollect.captureError(e) }
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
### XLog 对象
|
### BugCollect 对象
|
||||||
|
|
||||||
| API | 说明 |
|
| API | 说明 |
|
||||||
|-----|------|
|
|-----|------|
|
||||||
| `XLog.setLogLevel(level)` | 设置最低日志级别(低于此级别的事件被丢弃) |
|
| `BugCollect.setLogLevel(level)` | 设置最低日志级别(低于此级别的事件被丢弃) |
|
||||||
| `XLog.setEnvironment(env)` | 设置环境标签(附加到每个事件) |
|
| `BugCollect.setEnvironment(env)` | 设置环境标签(附加到每个事件) |
|
||||||
| `XLog.startCapture()` | 开启全局 JS 错误和未处理 Promise rejection 捕获 |
|
| `BugCollect.startCapture()` | 开启全局 JS 错误和未处理 Promise rejection 捕获 |
|
||||||
| `XLog.event(name, properties?)` | 记录自定义分析事件 |
|
| `BugCollect.event(name, properties?)` | 记录自定义分析事件 |
|
||||||
| `XLog.captureError(error, metadata?)` | 上报 JS 异常 |
|
| `BugCollect.captureError(error, metadata?)` | 上报 JS 异常 |
|
||||||
| `XLog.warn(message, metadata?)` | 记录警告(需级别允许) |
|
| `BugCollect.warn(message, metadata?)` | 记录警告(需级别允许) |
|
||||||
| `XLog.info(message, metadata?)` | 记录信息事件(需级别允许) |
|
| `BugCollect.info(message, metadata?)` | 记录信息事件(需级别允许) |
|
||||||
| `XLog.defineFunnel(id, steps)` | 定义漏斗(按步骤顺序追踪转化) |
|
| `BugCollect.defineFunnel(id, steps)` | 定义漏斗(按步骤顺序追踪转化) |
|
||||||
| `XLog.getFunnelProgress(funnelId)` | 获取客户端漏斗进度 |
|
| `BugCollect.getFunnelProgress(funnelId)` | 获取客户端漏斗进度 |
|
||||||
| `XLog.flush()` | 立即刷新所有待发送事件(如 App 进后台前调用) |
|
| `BugCollect.flush()` | 立即刷新所有待发送事件(如 App 进后台前调用) |
|
||||||
|
|
||||||
### 事件类型
|
### 事件类型
|
||||||
|
|
||||||
@ -62,28 +62,28 @@ try { ... } catch (e) { XLog.captureError(e) }
|
|||||||
### 漏斗分析示例
|
### 漏斗分析示例
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { XLog } from '@xuqm/rn-log'
|
import { BugCollect } from '@xuqm/rn-bugcollect'
|
||||||
|
|
||||||
// 定义漏斗
|
// 定义漏斗
|
||||||
XLog.defineFunnel('checkout', ['cart_view', 'checkout_start', 'payment_done'])
|
BugCollect.defineFunnel('checkout', ['cart_view', 'checkout_start', 'payment_done'])
|
||||||
|
|
||||||
// 在业务代码中记录步骤事件(SDK 自动推进漏斗)
|
// 在业务代码中记录步骤事件(SDK 自动推进漏斗)
|
||||||
XLog.event('cart_view')
|
BugCollect.event('cart_view')
|
||||||
XLog.event('checkout_start')
|
BugCollect.event('checkout_start')
|
||||||
XLog.event('payment_done')
|
BugCollect.event('payment_done')
|
||||||
|
|
||||||
// 查询进度
|
// 查询进度
|
||||||
const progress = XLog.getFunnelProgress('checkout')
|
const progress = BugCollect.getFunnelProgress('checkout')
|
||||||
console.log(progress?.completedSteps) // ['cart_view', 'checkout_start', 'payment_done']
|
console.log(progress?.completedSteps) // ['cart_view', 'checkout_start', 'payment_done']
|
||||||
```
|
```
|
||||||
|
|
||||||
## 工作原理
|
## 工作原理
|
||||||
|
|
||||||
1. **LogQueue**:事件先进入内存队列,按批次异步上传到 `logApiUrl`
|
1. **LogQueue**:事件先进入内存队列,按批次异步上传到 `bugCollectApiUrl`
|
||||||
2. **ErrorCapture**:`startCapture()` 注册全局 `ErrorUtils` handler,自动捕获未处理异常
|
2. **ErrorCapture**:`startCapture()` 注册全局 `ErrorUtils` handler,自动捕获未处理异常
|
||||||
3. **Fingerprint**:为每个错误生成指纹(基于 message + stack),用于服务端去重聚合
|
3. **Fingerprint**:为每个错误生成指纹(基于 message + stack),用于服务端去重聚合
|
||||||
4. **FunnelTracker**:客户端维护漏斗进度,服务端跨 session 聚合
|
4. **FunnelTracker**:客户端维护漏斗进度,服务端跨 session 聚合
|
||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
|
|
||||||
`logApiUrl` 和 `logEnabled` 由 `@xuqm/rn-common` 在 init 后从 `/api/sdk/config` 自动获取,无需 App 传入。
|
`bugCollectApiUrl` 和 `bugCollectEnabled` 由 `@xuqm/rn-common` 在 init 后从 `/api/sdk/config` 自动获取,无需 App 传入。
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户