插件是应用性能监控全链路版内置的功能,可以通过SDK侧配置决定是否开启和关闭这些功能。插件配置属于一次性配置,初始化后修改不再生效。
使用说明
全文的client代表的是SDK实例。
开启插件
默认情况下所有插件都是开启状态。以下为开启Js Error插件的示例配置。
关闭插件
将插件配置成false则表示关闭插件。以下为关闭Js Error插件的示例配置。
配置插件
页面加载时上报,用于统计PV、UV、页面停留时长。
注意
为了避免引发意外错误,PV 插件自定义的 pid 避免携带特殊符号,推荐使用字母、数字、斜杠(/)、中划线(-)进行命名。
routeMode: 'history' | 'manual' = 'history'
// 指定 history 变化时如何从 URL 中提取 pid
extractPid?: (url: string) => string
发生Js Error、Navigate Error时上报。
// 忽略error message匹配得上的错误
ignoreErrors: (string | RegExp)[] = []
hookOnError: boolean = true
// 监听 App.unhandledRejection
hookOnUnhandledRejection: boolean = true
hookRouteError: boolean = true
收集http、路由切换信息,并在Js Error上报时一并上报。
maxBreadcrumbs?: number = 20
onAddBreadcrumb?: (b: Breadcrumb) => Breadcrumb | false
onMaxBreadcrumbs?: (bs: Breadcrumb[], maxBreadcrumbs: number) => Breadcrumb[]
调用request、downloadFile、uploadFile时上报。
其中trace字段用于配置前后端打通,如果请求路径命中配置的origins,则会在请求头里补充traceparent头和baggage头,便于应用性能监控串联整个链路。
// whether to intercept instance.request
hookRequest: boolean = true
// whether to intercept instance.downloadFile
hookDownloadFile: boolean = true
// whether to intercept instance.uploadFile
hookUploadFile: boolean = true
// ignore the urls or RegExps passed in
ignoreUrls: (string | RegExp)[] = ['/settings/minipro','monitor_browser/collect/batch']
// whether to gather request.body and response.body when response.statusCode >= 400
collectBodyOnError: boolean = false
// developer can extract extra with response.body and httpPayload.if the value returned wasn't undefined or null, it would be set to extra and is_custom_error would be set to true
extraExtractor?: (body: string | any, related: HttpPayload) => { [key: string]: string } | false
// whether to enable trace
trace?: TraceConfig | boolean
export interface TraceConfig {
// session维度采样率,可设置为小于等于1且大于等于0的数,默认为1。表示有多少比例的session增加全链路trace相关请求头。
origins: (string | RegExp)[]
调用setData时上报,默认将计算参数大小改为false,由于setData调用较为频繁,所以开启后可能会对页面性能造成一些小波动。
isCalculateSize: boolean = false
收集启动性能,并在启动完成后上报,没有额外配置项。
// 无需配置,默认开启,如需关闭,请设置为false
收集页面性能,在切换页面后且页面加载完后上报,没有额外配置项。
// 无需配置,默认开启,如需关闭,请设置为false
收集单性能指标,例如:FR、FP、FCP、LCP,目前只有微信、抖音小程序的部分机型能被获取到,没有额外配置项。
// 无需配置,默认开启,如需关闭,请设置为false