@arms/rum-reactnative 0.1.1 → 0.1.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +399 -15
  2. package/RumSdkReactnative.podspec +28 -0
  3. package/android/build.gradle +83 -0
  4. package/android/gradle.properties +6 -0
  5. package/android/src/main/AndroidManifest.xml +13 -0
  6. package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +512 -0
  7. package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +33 -0
  8. package/android/src/main/java/com/rumsdkreactnative/crash/CrashContextManager.kt +157 -0
  9. package/android/src/main/java/com/rumsdkreactnative/crash/CrashHandler.kt +444 -0
  10. package/android/src/main/java/com/rumsdkreactnative/crash/CrashInitProvider.kt +50 -0
  11. package/android/src/main/java/com/rumsdkreactnative/crash/NdkCrashHandler.kt +66 -0
  12. package/android/src/main/jni/CMakeLists.txt +21 -0
  13. package/android/src/main/jni/rum_backtrace.c +144 -0
  14. package/android/src/main/jni/rum_crash_handler.c +200 -0
  15. package/android/src/main/jni/rum_crash_writer.c +442 -0
  16. package/android/src/main/jni/rum_module_info.c +316 -0
  17. package/android/src/main/jni/rum_module_info.h +54 -0
  18. package/android/src/main/jni/rum_test_crash.cpp +55 -0
  19. package/app.plugin.js +11 -0
  20. package/docs/ReactNative SDK/351/205/215/347/275/256/345/217/202/350/200/203.md" +671 -0
  21. package/docs/SDK /347/211/210/346/234/254/350/257/264/346/230/216.md" +12 -0
  22. package/docs//346/216/245/345/205/245ReactNative/345/272/224/347/224/250.md +238 -0
  23. package/ios/PrivacyInfo.xcprivacy +93 -0
  24. package/ios/RumCrashReporter.h +38 -0
  25. package/ios/RumCrashReporter.mm +861 -0
  26. package/ios/RumSdkReactnative.h +5 -0
  27. package/ios/RumSdkReactnative.mm +291 -0
  28. package/ios/fishhook/fishhook.c +264 -0
  29. package/ios/fishhook/fishhook.h +76 -0
  30. package/lib/commonjs/NativeRumSdkReactnative.js +50 -0
  31. package/lib/commonjs/collector/action/index.js +108 -0
  32. package/lib/commonjs/collector/exception/crash.js +148 -0
  33. package/lib/commonjs/collector/exception/index.js +238 -0
  34. package/lib/commonjs/collector/index.js +42 -0
  35. package/lib/commonjs/collector/resource/api.js +286 -0
  36. package/lib/commonjs/collector/view/perf.js +79 -0
  37. package/lib/commonjs/collector/view/pv.js +88 -0
  38. package/lib/commonjs/expoConfigPlugin.js +37 -0
  39. package/lib/commonjs/index.js +29 -0
  40. package/lib/commonjs/package.json +1 -0
  41. package/lib/commonjs/plugin.js +47 -0
  42. package/lib/commonjs/processor/default-processor.js +27 -0
  43. package/lib/commonjs/processor/session-processor.js +47 -0
  44. package/lib/commonjs/reporter/index.js +148 -0
  45. package/lib/commonjs/reporter/monitor-reporter.js +43 -0
  46. package/lib/commonjs/shell.js +91 -0
  47. package/lib/commonjs/types/client.js +6 -0
  48. package/lib/commonjs/types/crash.js +37 -0
  49. package/lib/commonjs/types/index.js +2 -0
  50. package/lib/commonjs/utils/action.js +305 -0
  51. package/lib/commonjs/utils/api.js +83 -0
  52. package/lib/commonjs/utils/base.js +95 -0
  53. package/lib/commonjs/utils/crash.js +146 -0
  54. package/lib/commonjs/utils/platform.js +162 -0
  55. package/lib/commonjs/utils/session.js +158 -0
  56. package/lib/commonjs/utils/url.js +59 -0
  57. package/lib/commonjs/utils/view.js +93 -0
  58. package/lib/module/NativeRumSdkReactnative.js +47 -0
  59. package/lib/module/collector/action/index.js +45 -10
  60. package/lib/module/collector/exception/crash.js +143 -0
  61. package/lib/module/collector/exception/index.js +144 -46
  62. package/lib/module/collector/index.js +8 -0
  63. package/lib/module/collector/resource/api.js +6 -6
  64. package/lib/module/collector/view/pv.js +13 -2
  65. package/lib/module/expoConfigPlugin.js +33 -0
  66. package/lib/module/index.js +1 -0
  67. package/lib/module/plugin.js +4 -1
  68. package/lib/module/processor/session-processor.js +22 -0
  69. package/lib/module/reporter/index.js +102 -16
  70. package/lib/module/reporter/monitor-reporter.js +38 -0
  71. package/lib/module/shell.js +32 -7
  72. package/lib/module/types/crash.js +33 -0
  73. package/lib/module/utils/action.js +299 -0
  74. package/lib/module/utils/api.js +10 -10
  75. package/lib/module/utils/base.js +9 -9
  76. package/lib/module/utils/crash.js +141 -0
  77. package/lib/module/utils/platform.js +127 -72
  78. package/lib/module/utils/session.js +23 -4
  79. package/lib/module/utils/view.js +2 -1
  80. package/lib/typescript/commonjs/package.json +1 -0
  81. package/lib/typescript/commonjs/src/NativeRumSdkReactnative.d.ts +49 -0
  82. package/lib/typescript/{src → commonjs/src}/collector/action/index.d.ts +7 -1
  83. package/lib/typescript/commonjs/src/collector/exception/crash.d.ts +28 -0
  84. package/lib/typescript/{src → commonjs/src}/collector/exception/index.d.ts +7 -0
  85. package/lib/typescript/commonjs/src/collector/index.d.ts +6 -0
  86. package/lib/typescript/{src → commonjs/src}/collector/view/pv.d.ts +2 -2
  87. package/lib/typescript/commonjs/src/expoConfigPlugin.d.ts +28 -0
  88. package/lib/typescript/commonjs/src/index.d.ts +6 -0
  89. package/lib/typescript/{src → commonjs/src}/processor/session-processor.d.ts +2 -0
  90. package/lib/typescript/{src → commonjs/src}/reporter/index.d.ts +3 -1
  91. package/lib/typescript/commonjs/src/reporter/monitor-reporter.d.ts +8 -0
  92. package/lib/typescript/commonjs/src/shell.d.ts +57 -0
  93. package/lib/typescript/{src → commonjs/src}/types/client.d.ts +2 -2
  94. package/lib/typescript/commonjs/src/types/crash.d.ts +95 -0
  95. package/lib/typescript/commonjs/src/utils/action.d.ts +63 -0
  96. package/lib/typescript/{src → commonjs/src}/utils/api.d.ts +1 -1
  97. package/lib/typescript/commonjs/src/utils/crash.d.ts +12 -0
  98. package/lib/typescript/commonjs/src/utils/platform.d.ts +22 -0
  99. package/lib/typescript/{src → commonjs/src}/utils/session.d.ts +4 -0
  100. package/lib/typescript/module/src/NativeRumSdkReactnative.d.ts +49 -0
  101. package/lib/typescript/module/src/collector/action/index.d.ts +21 -0
  102. package/lib/typescript/module/src/collector/exception/crash.d.ts +28 -0
  103. package/lib/typescript/module/src/collector/exception/index.d.ts +32 -0
  104. package/lib/typescript/module/src/collector/index.d.ts +6 -0
  105. package/lib/typescript/module/src/collector/resource/api.d.ts +21 -0
  106. package/lib/typescript/module/src/collector/view/perf.d.ts +1 -0
  107. package/lib/typescript/module/src/collector/view/pv.d.ts +16 -0
  108. package/lib/typescript/module/src/expoConfigPlugin.d.ts +28 -0
  109. package/lib/typescript/module/src/index.d.ts +6 -0
  110. package/lib/typescript/module/src/plugin.d.ts +3 -0
  111. package/lib/typescript/module/src/processor/default-processor.d.ts +6 -0
  112. package/lib/typescript/module/src/processor/session-processor.d.ts +11 -0
  113. package/lib/typescript/module/src/reporter/index.d.ts +18 -0
  114. package/lib/typescript/module/src/reporter/monitor-reporter.d.ts +8 -0
  115. package/lib/typescript/module/src/shell.d.ts +57 -0
  116. package/lib/typescript/module/src/types/client.d.ts +27 -0
  117. package/lib/typescript/module/src/types/crash.d.ts +95 -0
  118. package/lib/typescript/module/src/types/index.d.ts +118 -0
  119. package/lib/typescript/module/src/utils/action.d.ts +63 -0
  120. package/lib/typescript/module/src/utils/api.d.ts +59 -0
  121. package/lib/typescript/module/src/utils/base.d.ts +8 -0
  122. package/lib/typescript/module/src/utils/crash.d.ts +12 -0
  123. package/lib/typescript/module/src/utils/platform.d.ts +22 -0
  124. package/lib/typescript/module/src/utils/session.d.ts +41 -0
  125. package/lib/typescript/module/src/utils/url.d.ts +17 -0
  126. package/lib/typescript/module/src/utils/view.d.ts +13 -0
  127. package/package.json +61 -26
  128. package/LICENSE +0 -20
  129. package/lib/module/collector/action/index.js.map +0 -1
  130. package/lib/module/collector/exception/index.js.map +0 -1
  131. package/lib/module/collector/resource/api.js.map +0 -1
  132. package/lib/module/collector/view/perf.js.map +0 -1
  133. package/lib/module/collector/view/pv.js.map +0 -1
  134. package/lib/module/index.js.map +0 -1
  135. package/lib/module/plugin.js.map +0 -1
  136. package/lib/module/processor/default-processor.js.map +0 -1
  137. package/lib/module/processor/session-processor.js.map +0 -1
  138. package/lib/module/reporter/index.js.map +0 -1
  139. package/lib/module/shell.js.map +0 -1
  140. package/lib/module/types/client.js.map +0 -1
  141. package/lib/module/types/index.js.map +0 -1
  142. package/lib/module/utils/api.js.map +0 -1
  143. package/lib/module/utils/base.js.map +0 -1
  144. package/lib/module/utils/platform.js.map +0 -1
  145. package/lib/module/utils/session.js.map +0 -1
  146. package/lib/module/utils/url.js.map +0 -1
  147. package/lib/module/utils/view.js.map +0 -1
  148. package/lib/typescript/src/collector/action/index.d.ts.map +0 -1
  149. package/lib/typescript/src/collector/exception/index.d.ts.map +0 -1
  150. package/lib/typescript/src/collector/resource/api.d.ts.map +0 -1
  151. package/lib/typescript/src/collector/view/perf.d.ts.map +0 -1
  152. package/lib/typescript/src/collector/view/pv.d.ts.map +0 -1
  153. package/lib/typescript/src/index.d.ts +0 -4
  154. package/lib/typescript/src/index.d.ts.map +0 -1
  155. package/lib/typescript/src/plugin.d.ts.map +0 -1
  156. package/lib/typescript/src/processor/default-processor.d.ts.map +0 -1
  157. package/lib/typescript/src/processor/session-processor.d.ts.map +0 -1
  158. package/lib/typescript/src/reporter/index.d.ts.map +0 -1
  159. package/lib/typescript/src/shell.d.ts +0 -26
  160. package/lib/typescript/src/shell.d.ts.map +0 -1
  161. package/lib/typescript/src/types/client.d.ts.map +0 -1
  162. package/lib/typescript/src/types/index.d.ts.map +0 -1
  163. package/lib/typescript/src/utils/api.d.ts.map +0 -1
  164. package/lib/typescript/src/utils/base.d.ts.map +0 -1
  165. package/lib/typescript/src/utils/platform.d.ts +0 -15
  166. package/lib/typescript/src/utils/platform.d.ts.map +0 -1
  167. package/lib/typescript/src/utils/session.d.ts.map +0 -1
  168. package/lib/typescript/src/utils/url.d.ts.map +0 -1
  169. package/lib/typescript/src/utils/view.d.ts.map +0 -1
  170. /package/lib/typescript/{src → commonjs/src}/collector/resource/api.d.ts +0 -0
  171. /package/lib/typescript/{src → commonjs/src}/collector/view/perf.d.ts +0 -0
  172. /package/lib/typescript/{src → commonjs/src}/plugin.d.ts +0 -0
  173. /package/lib/typescript/{src → commonjs/src}/processor/default-processor.d.ts +0 -0
  174. /package/lib/typescript/{src → commonjs/src}/types/index.d.ts +0 -0
  175. /package/lib/typescript/{src → commonjs/src}/utils/base.d.ts +0 -0
  176. /package/lib/typescript/{src → commonjs/src}/utils/url.d.ts +0 -0
  177. /package/lib/typescript/{src → commonjs/src}/utils/view.d.ts +0 -0
  178. /package/lib/typescript/{package.json → module/package.json} +0 -0
@@ -0,0 +1,671 @@
1
+ # React Native SDK配置参考
2
+
3
+ ARMS用户体验监控React Native SDK提供一系列配置项,让您能够通过设置参数来满足额外需求。本文介绍React Native应用常用的SDK配置。
4
+
5
+ ## SDK配置
6
+
7
+ | 参数 | 类型 | 描述 | 是否必填 | 默认值 |
8
+ |------|------|------|----------|--------|
9
+ | endpoint | string | 上报地址 | 是 | - |
10
+ | env | string | 应用环境:<br/>• `prod`:线上环境<br/>• `gray`:灰度环境<br/>• `pre`:预发环境<br/>• `daily`:日常环境<br/>• `local`:本地环境 | 否 | `'prod'` |
11
+ | version | string | 应用版本号 | 否 | - |
12
+ | user | object | 用户信息配置,详细说明请参见[user配置](#user-配置) | 否 | - |
13
+ | beforeReport | function | 上报前钩子函数,在发送RUM事件之前调用 | 否 | - |
14
+ | reportConfig | object | 上报配置,详细说明请参见[reportConfig配置](#reportconfig-配置) | 否 | - |
15
+ | sessionConfig | object | Session的采样、存储等配置,详细说明请参见[sessionConfig配置](#sessionconfig-配置) | 否 | - |
16
+ | collectors | object | 采集器配置,详细说明请参见[collectors配置](#collectors-配置) | 否 | - |
17
+ | tracing | boolean \| object | 链路追踪配置 | 否 | `false` |
18
+ | parseResourceName | function | 解析资源名称(resource.name),入参为当前资源的URL | 否 | - |
19
+ | parseViewName | function | 自定义解析页面名称 | 否 | - |
20
+ | evaluateApi | function | 自定义解析API事件,详细说明请参见[evaluateApi配置](#evaluateapi-配置) | 否 | - |
21
+ | filters | object | 事件过滤配置,详细说明请参见[filters配置](#filters-配置) | 否 | - |
22
+ | properties | object | 自定义属性,可对所有事件生效,详细说明请参见[properties配置](#properties-配置) | 否 | - |
23
+
24
+ ## user 配置
25
+
26
+ | 参数 | 类型 | 描述 | 是否必填 | 默认值 |
27
+ |------|------|------|----------|--------|
28
+ | name | string | 用户名称,作为业务用户标识 | 否 | - |
29
+ | tags | string | 用户标签 | 否 | - |
30
+
31
+ > **说明**:如果需要关联业务自有账号体系,建议使用`user.name`或者`user.tags`,而不是修改`user.id`。强制覆盖SDK生成的`user.id`,会影响UV的计算。`user.id`由SDK自动生成并维护,不可自行设置。
32
+
33
+ ### 示例
34
+
35
+ ```typescript
36
+ armsRum.init({
37
+ endpoint: '<your-endpoint>',
38
+ user: {
39
+ name: 'zhangsan',
40
+ tags: 'vip',
41
+ },
42
+ });
43
+ ```
44
+
45
+ ## reportConfig 配置
46
+
47
+ | 参数 | 类型 | 描述 | 是否必填 | 默认值 |
48
+ |------|------|------|----------|--------|
49
+ | flushTime | number | 上报时间间隔(ms)<br/>取值范围:[0, 10000] | 否 | 3000 |
50
+ | maxEventCount | number | 一次上报最大数量<br/>取值范围:[1, 100] | 否 | 20 |
51
+
52
+ ### 示例
53
+
54
+ ```typescript
55
+ armsRum.init({
56
+ endpoint: '<your-endpoint>',
57
+ reportConfig: {
58
+ flushTime: 0, // 立即上报
59
+ maxEventCount: 50, // 一次最多上报50个事件
60
+ },
61
+ });
62
+ ```
63
+
64
+ > **注意**:`flushTime`设置为0时会立即上报每个事件,生产环境建议保持默认值或适当增大以减少网络请求频率。
65
+
66
+ ## sessionConfig 配置
67
+
68
+ | 参数 | 类型 | 描述 | 是否必填 | 默认值 |
69
+ |------|------|------|----------|--------|
70
+ | sampleRate | number | Session采样率:[0, 1]<br/>例如:0.5表示50%采样率 | 否 | 1 |
71
+ | maxDuration | number | Session最大持续时间,单位为毫秒(ms)<br/>默认24小时 | 否 | 86400000 |
72
+ | overtime | number | Session超时时间,单位为毫秒(ms)<br/>默认1小时无活动则过期 | 否 | 3600000 |
73
+
74
+ ### Session存储说明
75
+
76
+ SDK在本地存储了以下信息:
77
+
78
+ - `_arms_uid`:唯一标识用户ID,对应`user.id`
79
+ - `_arms_session`:具备语义化的Session信息,格式为:`${sessionId}-${sampled}-${startTime}-${lastTime}`
80
+ - `sessionId`:Session唯一标识
81
+ - `sampled`:是否命中采样
82
+ - `startTime`:Session的开始时间戳
83
+ - `lastTime`:Session最后一次活跃时间戳
84
+
85
+ ### 示例
86
+
87
+ ```typescript
88
+ armsRum.init({
89
+ endpoint: '<your-endpoint>',
90
+ sessionConfig: {
91
+ sampleRate: 0.5, // 采样率50%
92
+ maxDuration: 86400000, // Session最大持续24小时
93
+ overtime: 3600000, // 1小时无活动则Session过期
94
+ },
95
+ });
96
+ ```
97
+
98
+ ## collectors 配置
99
+
100
+ Collector是RUM SDK用于收集React Native应用监控数据的最小单元。目前RUM SDK内置了API、异常等丰富的采集器。
101
+
102
+ | 参数 | 类型 | 描述 | 是否必填 | 默认值 |
103
+ |------|------|------|----------|--------|
104
+ | api | boolean \| object | 监听API请求(XMLHttpRequest / fetch) | 否 | true |
105
+ | jsError | boolean \| object | 监听JS错误 | 否 | true |
106
+ | consoleError | boolean \| object | 监听Console错误 | 否 | true |
107
+
108
+ ### 示例
109
+
110
+ 关闭API请求监控:
111
+
112
+ ```typescript
113
+ armsRum.init({
114
+ endpoint: '<your-endpoint>',
115
+ collectors: {
116
+ api: false,
117
+ },
118
+ });
119
+ ```
120
+
121
+ 关闭所有采集器:
122
+
123
+ ```typescript
124
+ armsRum.init({
125
+ endpoint: '<your-endpoint>',
126
+ collectors: {
127
+ api: false,
128
+ jsError: false,
129
+ consoleError: false,
130
+ },
131
+ });
132
+ ```
133
+
134
+ ## tracing 链路追踪配置
135
+
136
+ 支持布尔值开关或详细配置对象:
137
+
138
+ ```typescript
139
+ tracing: {
140
+ enable: true, // 是否启用链路追踪
141
+ sample: 0.1, // 采样率(0-1之间)
142
+ propagatorTypes: ['tracecontext', 'b3'], // 传播协议类型
143
+ allowedUrls: [ // 允许注入追踪头的URL规则
144
+ {
145
+ match: 'https://api.example.com/',
146
+ propagatorTypes: ['tracecontext']
147
+ }
148
+ ]
149
+ }
150
+ ```
151
+
152
+ 支持的传播协议:
153
+
154
+ | 协议 | 说明 |
155
+ |------|------|
156
+ | `tracecontext` | W3C Trace Context |
157
+ | `b3` | Zipkin B3 单头传播 |
158
+ | `b3multi` | Zipkin B3 多头传播 |
159
+ | `jaeger` | Jaeger |
160
+ | `sw8` | SkyWalking |
161
+
162
+ ### 示例
163
+
164
+ ```typescript
165
+ armsRum.init({
166
+ endpoint: '<your-endpoint>',
167
+ tracing: {
168
+ enable: true,
169
+ sample: 0.1, // 10%采样
170
+ propagatorTypes: ['tracecontext'],
171
+ allowedUrls: [
172
+ {
173
+ match: 'https://api.example.com/',
174
+ propagatorTypes: ['tracecontext']
175
+ },
176
+ {
177
+ match: 'https://backend.example.com/',
178
+ propagatorTypes: ['b3', 'tracecontext']
179
+ }
180
+ ],
181
+ },
182
+ });
183
+ ```
184
+
185
+ ## evaluateApi 配置
186
+
187
+ `evaluateApi`提供对API(request)事件的自定义解析。SDK会传入以下三个参数:
188
+
189
+ | 参数 | 类型 | 描述 |
190
+ |------|------|------|
191
+ | request | object | 请求信息,包括url、headers、method等 |
192
+ | response | object | 响应信息,包括status、headers、body等 |
193
+ | error | Error | 可选参数,当请求失败时传入 |
194
+
195
+ 该函数支持异步函数,返回Promise<IApiBaseAttr>。IApiBaseAttr的定义如下:
196
+
197
+ | 参数 | 类型 | 描述 | 是否必填 |
198
+ |------|------|------|----------|
199
+ | name | string | API名称,一般是对URL的收敛,最大1000字符。<br/>例如URL为`/list/123`,收敛name字段后显示为`/list/$id`。<br/>**重要**:该字段的优先级高于`parseResourceName`返回的内容 | 否 |
200
+ | message | string | API信息,一个简短的用于描述API概况字符串,最大1000字符 | 否 |
201
+ | success | number | 请求成功状态:<br/>• 1:成功<br/>• 0:失败<br/>• -1:未知 | 否 |
202
+ | duration | number | API总耗时(毫秒) | 否 |
203
+ | status_code | number \| string | API状态码 | 否 |
204
+ | snapshots | string | API快照,可用于存储reqHeaders、params、resHeaders等。<br/>**说明**:该字段主要用于排查接口异常的原因,没有索引,不能根据该字段进行筛选或聚合,只接受字符串类型,最大5000字符 | 否 |
205
+
206
+ ### 示例
207
+
208
+ ```typescript
209
+ armsRum.init({
210
+ endpoint: '<your-endpoint>',
211
+ evaluateApi: async (request, response, error) => {
212
+ // 返回的字段会覆盖默认内容,不返回的字段会依然使用SDK自动生成内容
213
+ return {
214
+ name: '/api/user/profile',
215
+ success: error ? 0 : 1,
216
+ duration: response?.duration || 0,
217
+ status_code: response?.status || 0,
218
+ snapshots: JSON.stringify({
219
+ params: request?.body || '',
220
+ reqHeaders: request?.headers || {},
221
+ resHeaders: response?.headers || {},
222
+ }),
223
+ properties: {
224
+ prop_msg: 'custom msg',
225
+ prop_num: 1,
226
+ },
227
+ };
228
+ },
229
+ });
230
+ ```
231
+
232
+ ## filters 配置
233
+
234
+ `filters`用于过滤无需上报的事件,目前支持`resource`和`exception`两种事件。
235
+
236
+ | 参数 | 类型 | 描述 | 是否必填 |
237
+ |------|------|------|----------|
238
+ | resource | MatchOption \| MatchOption[] | 对采集到的资源事件进行过滤,包括静态资源和API(XMLHttpRequest/fetch) | 否 |
239
+ | exception | MatchOption \| MatchOption[] | 对采集到的异常事件进行过滤 | 否 |
240
+ | view | MatchOption \| MatchOption[] | 对采集到的视图事件进行过滤 | 否 |
241
+
242
+ ### MatchOption类型
243
+
244
+ ```typescript
245
+ type MatchOption = string | RegExp | ((value: string, error?: Error) => boolean);
246
+ ```
247
+
248
+ - **string**:匹配任何以该值开头的URL,如`https://api.aliyun.com`可以匹配`https://api.aliyun.com/v1/resource`
249
+ - **RegExp**:使用提供的RegExp和URL执行test
250
+ - **function**:以URL作为参数进行计算,返回true表示匹配。当过滤异常的时候会传入第二个参数为Error对象
251
+
252
+ 当传入为`MatchOption[]`时,条件顺序执行,有一项满足就会被过滤。
253
+
254
+ ### 示例
255
+
256
+ ```typescript
257
+ armsRum.init({
258
+ endpoint: '<your-endpoint>',
259
+ filters: {
260
+ // 过滤异常
261
+ exception: [
262
+ 'Test error', // 以'Test error'开头的error.message
263
+ /^Script error\.?$/, // 正则表达式匹配error.message
264
+ (msg, error) => {
265
+ return msg.includes('example-error');
266
+ },
267
+ ],
268
+ // 过滤资源或API
269
+ resource: [
270
+ 'https://example.com/', // 以'https://example.com/'开头的resource
271
+ /localhost/i,
272
+ (url) => {
273
+ return url.includes('example-resource');
274
+ },
275
+ ],
276
+ // 过滤视图
277
+ view: [
278
+ '/internal/', // 过滤内部页面
279
+ ],
280
+ },
281
+ });
282
+ ```
283
+
284
+ ## properties 配置
285
+
286
+ Properties是RUM提供的自定义属性,可为任何上报事件配置该属性。
287
+
288
+ | 参数 | 类型 | 描述 | 是否必填 |
289
+ |------|------|------|----------|
290
+ | [key: string] | string \| number | • key必须是符合JSON规范的字符串,key的最大长度为50字符,key超出部分会被截断<br/>• value为string时,最大长度为2000字符。value为非string\|number时,该键值对会被移除 | 否 |
291
+
292
+ ### 使用说明
293
+
294
+ - 使用`evaluateApi`、`sendCustom`、`sendException`、`sendResource`等可以单独为某个事件增加properties,仅对单个事件生效
295
+ - 全局properties和事件properties在存储时会进行合并
296
+ - 事件properties优先级高于全局properties,合并时相同的key,事件properties会覆盖全局properties
297
+ - 合并后properties键值对数量不可超过20对,超出会基于key进行排序后移除
298
+
299
+ ### 示例
300
+
301
+ 全局配置properties时,所有上报的事件都会拥有:
302
+
303
+ ```typescript
304
+ armsRum.init({
305
+ endpoint: '<your-endpoint>',
306
+ properties: {
307
+ prop_string: 'xx',
308
+ prop_number: 2,
309
+ // key和value超出范围会被截断
310
+ more_than_50_key_limit_012345678901234567890123456789: 'yy',
311
+ more_than_2000_value_limit: new Array(2003).join('1'),
312
+ // 以下不符合要求的键值对会被移除
313
+ prop_null: null,
314
+ prop_undefined: undefined,
315
+ prop_bool: true,
316
+ },
317
+ });
318
+ ```
319
+
320
+ 为单个事件添加properties:
321
+
322
+ ```typescript
323
+ // 自定义业务事件
324
+ armsRum.sendCustom({
325
+ type: 'order_placed',
326
+ name: 'OrderEvent',
327
+ value: 1,
328
+ properties: {
329
+ order_id: 'ORD-12345',
330
+ amount: 99.99,
331
+ },
332
+ });
333
+
334
+ // 自定义异常
335
+ armsRum.sendException({
336
+ name: 'CustomError',
337
+ message: 'Something went wrong',
338
+ properties: {
339
+ error_code: 'E001',
340
+ module: 'payment',
341
+ },
342
+ });
343
+ ```
344
+
345
+ ## 其他配置
346
+
347
+ RUM SDK支持配置基于IP和UserAgent等解析所得到的公共属性,主动配置字段优先级高于自动解析。
348
+
349
+ | 参数 | 类型 | 描述 | 是否必填 |
350
+ |------|------|------|----------|
351
+ | device | object | 设备信息 | 否 |
352
+ | os | object | 系统、容器信息 | 否 |
353
+ | geo | object | 行政地理信息 | 否 |
354
+ | isp | object | 运营商信息 | 否 |
355
+ | net | object | 网络信息 | 否 |
356
+
357
+ 以上字段具体可配置项请参考日志数据说明中[公共属性](https://help.aliyun.com/zh/arms/user-experience-monitoring/log-data-description)部分。
358
+
359
+ ### 示例
360
+
361
+ ```typescript
362
+ armsRum.init({
363
+ endpoint: '<your-endpoint>',
364
+ geo: {
365
+ country: 'China',
366
+ province: 'Zhejiang',
367
+ city: 'Hangzhou',
368
+ },
369
+ net: {
370
+ type: 'wifi',
371
+ },
372
+ });
373
+ ```
374
+
375
+ ## beforeReport 钩子
376
+
377
+ 在事件上报前进行修改或过滤:
378
+
379
+ ```typescript
380
+ armsRum.init({
381
+ endpoint: '<your-endpoint>',
382
+ beforeReport(event) {
383
+ // 返回修改后的event
384
+ // 返回false则丢弃该事件
385
+ if (event.type === 'resource' && event.url?.includes('test')) {
386
+ return false; // 丢弃测试资源事件
387
+ }
388
+
389
+ // 添加自定义属性
390
+ if (event.properties) {
391
+ event.properties.custom_field = 'custom_value';
392
+ }
393
+
394
+ return event;
395
+ },
396
+ });
397
+ ```
398
+
399
+ ## 完整配置示例
400
+
401
+ ```typescript
402
+ import armsRum from '@arms/rum-reactnative';
403
+
404
+ armsRum.init({
405
+ // 基础配置
406
+ endpoint: '<your-endpoint>',
407
+ env: 'prod',
408
+ version: '1.0.0',
409
+
410
+ // 用户配置
411
+ user: {
412
+ name: 'zhangsan',
413
+ tags: 'vip',
414
+ },
415
+
416
+ // 采集器配置
417
+ collectors: {
418
+ api: true,
419
+ jsError: true,
420
+ consoleError: true,
421
+ },
422
+
423
+ // 链路追踪
424
+ tracing: {
425
+ enable: true,
426
+ sample: 0.1,
427
+ propagatorTypes: ['tracecontext'],
428
+ allowedUrls: [
429
+ {
430
+ match: 'https://api.example.com/',
431
+ propagatorTypes: ['tracecontext']
432
+ }
433
+ ],
434
+ },
435
+
436
+ // 事件过滤
437
+ filters: {
438
+ resource: ['https://cdn.example.com/'],
439
+ exception: [/^Script error/],
440
+ },
441
+
442
+ // 全局自定义属性
443
+ properties: {
444
+ channel: 'appstore',
445
+ app_version: '1.0.0',
446
+ },
447
+
448
+ // 上报配置
449
+ reportConfig: {
450
+ flushTime: 5000,
451
+ maxEventCount: 30,
452
+ },
453
+
454
+ // Session配置
455
+ sessionConfig: {
456
+ sampleRate: 1,
457
+ maxDuration: 86400000,
458
+ overtime: 3600000,
459
+ },
460
+
461
+ // 上报前钩子
462
+ beforeReport(event) {
463
+ return event;
464
+ },
465
+
466
+ // 自定义API解析
467
+ evaluateApi: async (request, response, error) => {
468
+ return {
469
+ name: request?.url || 'unknown',
470
+ success: error ? 0 : 1,
471
+ duration: response?.duration || 0,
472
+ };
473
+ },
474
+ });
475
+ ```
476
+
477
+ ## SDK API
478
+
479
+ RUM SDK开放API,用于修改上报自定义数据、动态修改SDK配置等。
480
+
481
+ ### getConfig()
482
+
483
+ 获取当前SDK配置对象。
484
+
485
+ ```typescript
486
+ const config = armsRum.getConfig();
487
+ console.log(config);
488
+ ```
489
+
490
+ ### setConfig(key, value) / setConfig(config)
491
+
492
+ 动态更新SDK配置。
493
+
494
+ ```typescript
495
+ // 单个配置更新
496
+ armsRum.setConfig('version', '1.2.0');
497
+ armsRum.setConfig('env', 'pre');
498
+
499
+ // 批量配置更新
500
+ const currentConfig = armsRum.getConfig();
501
+ armsRum.setConfig({
502
+ ...currentConfig,
503
+ version: '1.2.0',
504
+ env: 'pre',
505
+ });
506
+ ```
507
+
508
+ ### sendCustom(payload)
509
+
510
+ 上报自定义业务数据,必须包含`type`、`name`和`value`三个属性,否则无法上报。
511
+
512
+ | 参数 | 类型 | 描述 | 是否必填 |
513
+ |------|------|------|----------|
514
+ | type | string | 类型 | 是 |
515
+ | name | string | 名称 | 是 |
516
+ | group | string | 分组 | 否 |
517
+ | value | number | 值 | 是 |
518
+ | properties | object | 自定义属性 | 否 |
519
+
520
+ ```typescript
521
+ armsRum.sendCustom({
522
+ // 必选
523
+ type: 'CustomEventType1',
524
+ name: 'customEventName2',
525
+ value: 111.11,
526
+ // 可选
527
+ group: 'customEventGroup3',
528
+ properties: {
529
+ prop_msg: 'custom msg',
530
+ prop_num: 1,
531
+ },
532
+ });
533
+ ```
534
+
535
+ ### sendException(payload | Error)
536
+
537
+ 上报自定义异常数据。可以直接传入Error对象,或传入包含以下属性的对象:
538
+
539
+ | 参数 | 类型 | 描述 | 是否必填 |
540
+ |------|------|------|----------|
541
+ | name | string | 异常名称 | 是 |
542
+ | message | string | 异常信息 | 是 |
543
+ | file | string | 异常发生文件 | 否 |
544
+ | stack | string | 异常堆栈信息 | 否 |
545
+ | line | number | 异常发生的行数 | 否 |
546
+ | column | number | 异常发生的列数 | 否 |
547
+ | properties | object | 自定义属性 | 否 |
548
+
549
+ ```typescript
550
+ // 方式一:传入Error对象
551
+ try {
552
+ // 业务逻辑
553
+ } catch (error) {
554
+ armsRum.sendException(error);
555
+ }
556
+
557
+ // 方式二:传入自定义对象
558
+ armsRum.sendException({
559
+ // 必选
560
+ name: 'customErrorName',
561
+ message: 'custom error message',
562
+ // 可选
563
+ file: 'custom exception filename',
564
+ stack: 'custom exception error.stack',
565
+ line: 1,
566
+ column: 2,
567
+ properties: {
568
+ prop_msg: 'custom msg',
569
+ prop_num: 1,
570
+ },
571
+ });
572
+ ```
573
+
574
+ ### sendResource(payload)
575
+
576
+ 上报自定义资源,必须包含`name`、`type`和`duration`三个属性,否则无法上报。
577
+
578
+ | 参数 | 类型 | 描述 | 是否必填 |
579
+ |------|------|------|----------|
580
+ | name | string | 资源名 | 是 |
581
+ | type | string | 资源类型,例如:css、javascript、xmlhttprequest、fetch、api、image、font、other | 是 |
582
+ | duration | number | 请求耗时(毫秒) | 是 |
583
+ | success | number | 请求成功状态:<br/>• 1:成功<br/>• 0:失败<br/>• -1:未知 | 否 |
584
+ | method | string | 请求方法 | 否 |
585
+ | status_code | number \| string | 请求状态码 | 否 |
586
+ | message | string | 请求消息 | 否 |
587
+ | url | string | 请求地址 | 否 |
588
+ | trace_id | string | 链路追踪ID | 否 |
589
+ | properties | object | 自定义属性 | 否 |
590
+
591
+ ```typescript
592
+ armsRum.sendResource({
593
+ // 以下必选
594
+ name: 'getListByPage',
595
+ type: 'api',
596
+ duration: 800,
597
+ // 以下可选
598
+ url: 'https://www.aliyun.com/data/getListByPage',
599
+ success: 1,
600
+ method: 'GET',
601
+ status_code: 200,
602
+ properties: {
603
+ prop_msg: 'custom msg',
604
+ prop_num: 1,
605
+ },
606
+ });
607
+ ```
608
+
609
+ ### sendView(payload)
610
+
611
+ 上报自定义视图事件。当`type`为`custom`时,必须包含`t1`、`t2`、`t3`中至少一个自定义性能指标,否则无法上报。
612
+
613
+ | 参数 | 类型 | 描述 | 是否必填 |
614
+ |------|------|------|----------|
615
+ | type | string | 视图类型:`pv`(页面浏览)、`perf`(性能指标)、`webvitals`、`custom`(自定义指标)| 是 |
616
+ | t1 | number | 自定义性能指标1(type为`custom`时至少需要t1/t2/t3之一) | 否 |
617
+ | t2 | number | 自定义性能指标2 | 否 |
618
+ | t3 | number | 自定义性能指标3 | 否 |
619
+ | properties | object | 自定义属性 | 否 |
620
+
621
+ ```typescript
622
+ // 上报自定义性能指标
623
+ armsRum.sendView({
624
+ type: 'custom',
625
+ t1: 1500,
626
+ properties: {
627
+ page_type: 'home',
628
+ },
629
+ });
630
+
631
+ // 上报页面浏览事件
632
+ armsRum.sendView({
633
+ type: 'pv',
634
+ properties: {
635
+ page_type: 'detail',
636
+ },
637
+ });
638
+ ```
639
+
640
+ ### sendEvent(payload)
641
+
642
+ 上报通用自定义事件。
643
+
644
+ ```typescript
645
+ armsRum.sendEvent({
646
+ type: 'custom_event',
647
+ name: 'ButtonClick',
648
+ properties: {
649
+ button_id: 'submit_btn',
650
+ },
651
+ });
652
+ ```
653
+
654
+ ### startTrackingViews(navigationRef)
655
+
656
+ 启动页面导航追踪,需要传入React Navigation的navigation引用。
657
+
658
+ ```typescript
659
+ import { useNavigationContainerRef } from '@react-navigation/native';
660
+
661
+ const navigationContainerRef = useNavigationContainerRef();
662
+ armsRum.startTrackingViews(navigationContainerRef.current);
663
+ ```
664
+
665
+ ### stopTrackingViews()
666
+
667
+ 停止页面导航追踪。
668
+
669
+ ```typescript
670
+ armsRum.stopTrackingViews();
671
+ ```
@@ -0,0 +1,12 @@
1
+ # SDK版本说明
2
+
3
+ 本文主要介绍了ARMS用户体验监控React Native SDK的版本更新历史。
4
+
5
+ ## 版本列表
6
+
7
+ | 版本 | 发布时间 | 发布说明 |
8
+ |------|----------|----------|
9
+ | v0.1.3 | 2026年07月 | 原生崩溃采集安全加固与自监控系统集成:<br/>• 修复 Android/iOS 原生崩溃采集多项安全漏洞(缓冲区溢出、路径遍历、crash_id 校验)<br/>• 提升采集稳定性(栈帧上限 256、线程安全、多格式时间戳解析)<br/>• 集成 rum-core Telemetry 自监控,SDK 内部异常自动上报<br/>• 公开导出 logger、callMonitored 供用户扩展使用 |
10
+ | v0.1.2 | 2026年05月12日 | 包名正式化与核心采集能力修复:<br/>• rum-core 升级至 >=0.1.4,包管理迁移至 Yarn 3 workspaces<br/>• 修复 PV 路由采集(首屏丢失、无 path 路由过滤、navigationRef 时序)<br/>• 修复 API 监控默认配置误关闭、propagatorTypes 空值崩溃<br/>• Reporter AppState 回调 this 绑定修复<br/>• 完善 README、接入指南、配置参考等文档 |
11
+ | v0.1.1 | 2025年11月28日 | React Native SDK首个正式版本,提供各种配置、API,并提供了以下采集能力:<br/>• API监控(XMLHttpRequest / fetch),包括链路追踪等特性的支持<br/>• 异常监控(JS Error、Promise Rejection、console.error)<br/>• Session相关功能(采样、超时管理)<br/>• 自定义上报(Custom、Exception、Resource、View、Event)<br/>• React Navigation集成支持 |
12
+ | v0.1.0 | 2025年08月20日 | React Native首个版本,提供各种配置、API,并提供了以下采集能力:<br/>• API监控(XMLHttpRequest / fetch),包括链路追踪等特性的支持<br/>• 异常监控(JS Error、Promise Rejection、console.error)<br/>• Session相关功能(采样、超时管理)<br/>• 自定义上报(Custom、Exception、Resource、View、Event)<br/>• React Navigation集成支持 |