上报格式
如果使用beforeSend 等生命周期,在生命周期中对上报数据进行操作,那么需要关注SDK 的上报格式。
ReportEvent
js
export type SendEvent =
| CustomReport
| HttpReport
| JsErrorReport
| PageviewReport
| PerformanceReport
| PerformanceLongTaskReport
| PerformanceTimingReport
| ResourceErrorReport
| ResourceReport
| BlankReport
export type WebReport = Omit<SendEvent,'common'>
export type ReportEvent<T extends WebReport> = T & {
extra?: Partial<Common>
// 允许额外上报一些 context 覆盖组装上下文,主要在预收集与预加载场景
overrides?: Partial<Common>
}
Common
js
interface Common {
/** 应用标识 */
aid: number
/** 页面标识 */
pid: string
/** 页面访问标识,用于区别同一个 pid 的多次访问 */
view_id: string
/** 用户标识,由接入方设定 */
user_id: string
/** 设备标识,保存在本地存储 */
device_id: string
/** 实例会话标识 */
session_id: string
/** 自定义维度 */
context: { [key: string]: string }
/** 代码部署版本 */
release: string
/** 代码部署环境 */
env: string
/** 环境 */
url: string
protocol: string
domain: string
path: string
query: string
/** 动态变化,需要监听 */
network_type: string
/** 客户端时间戳,发生时间 */
timestamp: number
/** 上报 SDK 版本 */
sdk_version: string
/** 上报 SDK 名称, 以区分第三方 SDK */
sdk_name: string
/** 当前事件命中的有效采样率 */
sample_rate: number
}
Custom
js
interface CustomReport {
/** custom */
ev_type: string
payload: CustomPayload
common: Common
}
interface CustomPayload {
/** 自定义名称, type 为 event时必填 */
name?: string
/** 自定义数值 */
metrics?: { [key: string]: number }
/** 事件本身的维度,不要跟外部 context 合并 */
categories?: { [key: string]: string }
/** 自定义日志内容,可以是日志或者对象的 JSON 表示, type为log 时必填 */
content?: string
/** 自定义日志的级别 debug | info | warn | error */
level?: string
/** 自定义类型 event | log */
type: string
}
Http
js
interface HttpReport {
/** http */
ev_type: string
payload: HttpPayload
common: Common
}
interface HttpPayload {
/** xhr | fetch | request | jsbridge */
api: string
request: HttpReq
response: HttpRes
duration: number
extra?: { [key: string]: string }
trace?: HttpTrace
}
interface HttpReq {
method: string
url: string
protocol: string
domain: string
path: string
query: string
headers?: { [key: string]: string }
body?: string
timestamp: number
}
interface HttpRes {
status: number
is_custom_error: boolean
headers?: { [key: string]: string }
body?: string
timing?: PerformanceResourceTiming
timestamp: number
}
interface HttpTrace {
trace_id: string
trace_host: string
log_id: string
}
JS Error
js
interface JsErrorReport {
/** js_error */
ev_type: string
payload: JsErrorPayload
common: Common
}
interface JsErrorPayload {
error: JsError
breadcrumbs: Array<Breadcrumb>
extra?: { [key: string]: string }
react?: ReactInfo
}
interface JsError {
/** 错误名称 */
name?: string
/** 错误信息 */
message: string
/** 堆栈 */
stack?: string
/** 错误文件名 */
filename?: string
lineno?: string
colno?: string
}
interface Breadcrumb {
/** dom | http */
type: string
/** xpath, keyvalue | url */
message: string
/** ui.click, ui.keypress | post,get */
category: string
/** status: 400 for http */
data?: { [key: string]: string }
timestamp: number
}
interface ReactInfo {
version: string
componentStack: string
}
Pageview
js
interface PageviewReport {
/** pageview */
ev_type: string
payload: PageviewPayload
common: Common
}
interface PageviewPayload {
pid: string
/** 触发原因 init | path change | hash change | history state change | user-set */
source: string
}
Performance Longtask
js
interface PerformanceLongtaskReport {
/** performance_longtask */
ev_type: string
payload: PerformanceLongtaskPayload
common: Common
}
interface PerformanceLongtaskPayload {
/** 性能指标类型, perf => 传统性能, spa => SPA 性能, garfish => garfish 微前端性能 */
type: string
longtasks: Array<PerformanceLongtask>
}
interface PerformanceLongtask {
/** struct PerformanceEntry { */
duration: number
entryType: string
name: string
startTime: number
/** } */
attribution?: Array<TaskAttributionTiming>
}
interface TaskAttributionTiming {
/** struct PerformanceEntry { */
duration: number
entryType: string
name: string
startTime: number
/** } */
containerType: string
containerSrc: string
containerId: string
containerName: string
}
Performance Timing
js
interface PerformanceTimingReport {
/** performance_timing */
ev_type: string
payload: PerformanceTimingPayload
common: Common
}
interface PerformanceTimingPayload {
timing?: PerformanceTiming
navigation_timing?: PerformanceNavigationTiming
/** 是否跳出 */
isBounced: boolean
}
interface PerformanceTiming {
connectEnd: number
connectStart: number
domComplete: number
domContentLoadedEventEnd: number
domContentLoadedEventStart: number
domInteractive: number
domLoading: number
domainLookupEnd: number
domainLookupStart: number
fetchStart: number
loadEventEnd: number
loadEventStart: number
navigationStart: number
redirectEnd: number
redirectStart: number
requestStart: number
responseEnd: number
responseStart: number
secureConnectionStart: number
unloadEventEnd: number
unloadEventStart: number
}
interface PerformanceNavigationTiming {
/** struct PerformanceResourceTiming { */
/** struct PerformanceEntry { */
duration: number
entryType: string
name: string
startTime: number
/** } */
connectEnd: number
connectStart: number
decodedBodySize: number
domainLookupEnd: number
domainLookupStart: number
encodedBodySize: number
fetchStart: number
initiatorType: string
nextHopProtocol: string
redirectEnd: number
redirectStart: number
requestStart: number
responseEnd: number
responseStart: number
secureConnectionStart: number
transferSize: number
workerStart: number
/** } */
domComplete: number
domContentLoadedEventEnd: number
domContentLoadedEventStart: number
domInteractive: number
loadEventEnd: number
loadEventStart: number
redirectCount: number
type: string
unloadEventEnd: number
unloadEventStart: number
}
interface PerformanceResourceTiming {
/** struct PerformanceEntry { */
duration: number
entryType: string
name: string
startTime: number
/** } */
connectEnd: number
connectStart: number
decodedBodySize: number
domainLookupEnd: number
domainLookupStart: number
encodedBodySize: number
fetchStart: number
initiatorType: string
nextHopProtocol: string
redirectEnd: number
redirectStart: number
requestStart: number
responseEnd: number
responseStart: number
secureConnectionStart: number
transferSize: number
workerStart: number
serverTiming?: Array<PerformanceServerTiming>
}
interface PerformanceServerTiming {
description: string
duration: number
name: string
}
Performance
js
interface PerformanceReport {
/** performance */
ev_type: string
payload: PerformancePayload
common: Common
}
interface PerformancePayload {
/** 指标名称 */
name: string
/** 当前值 */
value: number
/** 性能指标类型, perf => 传统性能, spa => SPA 性能 */
type: string
/** 是否支持 */
isSupport?: boolean
/** 是否是Polyfill */
isPolyfill?: boolean
/** 是否跳出 */
isBounced?: boolean
/** 是否自定义 */
isCustom?: boolean
/** 指标的相关信息 */
extra?: { [key: string]: string }
}
Resource Error
js
interface ResourceErrorReport {
/** resource_error */
ev_type: string
payload: ResourceErrorPayload
common: Common
}
interface ResourceErrorPayload {
/** 触发标签的类型 script/link/css */
type: string
url: string
protocol: string
domain: string
path: string
query: string
timing?: PerformanceResourceTiming
}
Resource
js
type ResourcePayload = PerformanceResourceTiming
interface ResourceReport {
/** resource */
ev_type: string
payload: ResourcePayload
common: Common
}
BlankScreen
js
export interface BlankScreenPayload {
//白屏发生的时间
timestamp: number;
/** dom 分 */
score: number;
/** 截图 base64 */
screenshot?: string;
error?: BlankRelatedError;
}
interface BlankRelatedError {
type: string;
message: string;
}