RUM 配置
RUM 初始化配置
var rum = uni.requireNativePlugin("GCUniPlugin-RUM");
rum.setConfig({
androidAppId: 'YOUR_ANDROID_APP_ID',
iOSAppId: 'YOUR_IOS_APP_ID',
errorMonitorType: 'all',
deviceMonitorType: ['cpu', 'memory']
});
| 参数名称 |
参数类型 |
必须 |
说明 |
| androidAppId |
string |
是 |
Android 平台 appId |
| iOSAppId |
string |
是 |
iOS 平台 appId |
| samplerate |
number |
否 |
采样率,范围 [0,1],默认 1 |
| sessionOnErrorSampleRate |
number |
否 |
错误采集率,范围 [0,1],默认 0,SDK 0.2.2 以上支持 |
| enableNativeUserAction |
boolean |
否 |
是否开启 Native Action 追踪,纯 uni-app 应用建议关闭,Android 云打包不支持 |
| enableNativeUserResource |
boolean |
否 |
是否开启 Native Resource 自动追踪,Android 云打包不支持。由于 uni-app 在 iOS 端通过系统 API 发起网络请求,开启后 iOS 请求会被自动采集;此时请屏蔽 iOS 侧手动 Resource 采集,避免重复采集 |
| enableNativeUserView |
boolean |
否 |
是否开启 Native View 自动追踪,纯 uni-app 应用建议关闭 |
| errorMonitorType |
string/array |
否 |
错误补充监控类型:all、battery、memory、cpu |
| deviceMonitorType |
string/array |
否 |
页面监控类型:all、battery(仅 Android)、memory、cpu、fps |
| detectFrequency |
string |
否 |
页面监控频率:normal、frequent、rare |
| globalContext |
object |
否 |
自定义全局参数,特殊 key:track_id |
| enableResourceHostIP |
boolean |
否 |
是否采集目标域名 IP,仅影响 enableNativeUserResource = true 的默认采集 |
| enableTrackNativeCrash |
boolean |
否 |
是否开启 Android Java Crash 和 OC/C/C++ 崩溃监测 |
| enableTrackNativeAppANR |
boolean |
否 |
是否开启 Native ANR 监测 |
| enableTrackNativeFreeze |
boolean |
否 |
是否采集 Native Freeze |
| nativeFreezeDurationMs |
number |
否 |
Native Freeze 阈值,范围 [100,),单位毫秒 |
| rumDiscardStrategy |
string |
否 |
丢弃策略:discard、discardOldest |
| rumCacheLimitCount |
number |
否 |
本地缓存最大 RUM 条目数量限制,默认 100000 |
| enableTraceWebView |
boolean |
否 |
是否开启通过原生 SDK 采集 WebView 数据,默认 true,SDK 0.2.6 以上支持 |
| allowWebViewHost |
array |
否 |
允许数据追踪的 WebView host 列表,null 时全采集 |
RUM 用户数据追踪
var rum = uni.requireNativePlugin("GCUniPlugin-RUM");
Action
API - startAction
启动 RUM Action。
RUM 会绑定该 Action 期间可能触发的 Resource、Error、LongTask 事件。避免在 0.1s 内多次调用;同一 View 在同一时间仅关联一个 Action,前一个 Action 未结束时,新 Action 会被丢弃。它与 addAction 互不影响。
rum.startAction({
actionName: 'action name',
actionType: 'action type'
});
| 参数名称 |
参数类型 |
必须 |
参数说明 |
| actionName |
string |
是 |
事件名称 |
| actionType |
string |
是 |
事件类型 |
| property |
object |
否 |
事件上下文 |
API - addAction
添加 Action 事件。此类数据无法关联 Error、Resource、LongTask,无丢弃逻辑。
rum.addAction({
actionName: 'action name',
actionType: 'action type'
});
| 参数名称 |
参数类型 |
必须 |
参数说明 |
| actionName |
string |
是 |
事件名称 |
| actionType |
string |
是 |
事件类型 |
| property |
object |
否 |
事件上下文 |
View
自动采集
推荐在项目 main.js 中导入并调用采集方法:
import { gcViewTracking } from '@/uni_modules/GC-JSPlugin';
gcViewTracking.startTracking();
方式二:App.vue + 首个页面组合配置。可参考 SDK 包示例工程 Hbuilder_Example/App.vue 和 Hbuilder_Example/pages/index/index.vue:
// step 1. 将 GC-JSPlugin 添加到工程 uni_modules
// step 2. 在 App.vue 中添加 Router 监控
<script>
import { gcWatchRouter } from '@/uni_modules/GC-JSPlugin';
export default {
mixins: [gcWatchRouter],
}
</script>
// step 3. 在首个 page 页面添加 pageMixin
<script>
import { gcPageMixin } from '@/uni_modules/GC-JSPlugin';
export default {
mixins: [gcPageMixin],
}
</script>
方式三:仅采集指定页面。可参考 SDK 包示例工程 Hbuilder_Example/pages/rum/index.vue:
<script>
import { gcPageViewMixinOnly } from '@/uni_modules/GC-JSPlugin';
export default {
mixins: [gcPageViewMixinOnly],
}
</script>
手动采集
rum.onCreateView({
viewName: 'Current Page Name',
loadTime: 100000000
});
rum.startView('Current Page Name');
rum.stopView();
API - onCreateView
创建页面加载时长记录。
| 字段 |
类型 |
必须 |
说明 |
| viewName |
string |
是 |
页面名称 |
| loadTime |
number |
是 |
页面加载时间,纳秒级时间戳 |
API - startView
进入页面。
| 字段 |
类型 |
必须 |
说明 |
| viewName |
string |
是 |
页面名称 |
| property |
object |
否 |
事件上下文 |
API - stopView
离开页面。
| 字段 |
类型 |
必须 |
说明 |
| property |
object |
否 |
事件上下文 |
Error
自动采集
import { gcErrorTracking } from '@/uni_modules/GC-JSPlugin';
gcErrorTracking.startTracking();
手动采集
rum.addError({
message: 'Error message',
stack: 'Error stack'
});
API - addError
| 字段 |
类型 |
必须 |
说明 |
| message |
string |
是 |
错误信息 |
| stack |
string |
是 |
堆栈信息 |
| state |
string |
否 |
App 运行状态:unknown、startup、run |
| type |
string |
否 |
错误类型,默认 uniapp_crash |
| property |
object |
否 |
事件上下文 |
Resource
自动采集
SDK 提供 gcRequest.request,继承自 uni.request,可替换原始请求方法以采集 Resource 数据。
+ import { gcRequest } from '@/uni_modules/GC-JSPlugin';
- uni.request({
+ gcRequest.request({
// ...
});
import { gcRequest } from '@/uni_modules/GC-JSPlugin';
gcRequest.request({
url: requestUrl,
method: method,
header: header,
filterPlatform: ['ios'],
timeout: 30000,
success(res) {
console.log('success:' + JSON.stringify(res));
},
fail(err) {
console.log('fail:' + JSON.stringify(err));
},
complete() {
console.log('complete');
}
});
| 额外字段 |
类型 |
必须 |
说明 |
| filterPlatform |
array |
否 |
当启用 enableNativeUserResource 后,为避免 iOS 端自动采集与手动采集重复,可设置 filterPlatform: ["ios"] 屏蔽 iOS 手动采集 |
手动采集
通过手动调用 startResource、stopResource、addResource 自行实现,可参考 GCRequest.js。
API - startResource
| 字段 |
类型 |
必须 |
说明 |
| key |
string |
是 |
请求唯一标识 |
| property |
object |
否 |
事件上下文 |
API - stopResource
| 字段 |
类型 |
必须 |
说明 |
| key |
string |
是 |
请求唯一标识 |
| property |
object |
否 |
事件上下文 |
API - addResource
| 参数名称 |
参数类型 |
必须 |
参数说明 |
| key |
string |
是 |
请求唯一标识 |
| content |
content object |
是 |
请求相关数据 |
content object
| prototype |
参数类型 |
参数说明 |
| url |
string |
请求 URL |
| httpMethod |
string |
HTTP 方法 |
| requestHeader |
object |
请求头 |
| responseHeader |
object |
响应头 |
| responseBody |
string |
响应结果 |
| resourceStatus |
string |
请求结果状态码 |