上报JS错误并添加面包屑
API
const traceId = window.TINGYUN.captureException(err, options)
请求参数:
- err:错误对象,必选。标准Error对象或包含错误信息
message
和错误堆栈stack
的自定义对象。如果没有stack需要传递fileName。message
:字符串类型,错误信息。stack
:字符串类型,错误堆栈。fileName
:字符串类型,错误文件名。lineNumber
:错误行号。columnNumber
:错误列号。
- options:自定义选项,可选,对象类型。
breadcrumbs
:数组,传入Breadcrumbs 面包屑的值。timestamp
:必选,10位 posix时间戳或者10位时间戳后面带三位小数,如1661511702或者1661511822.445。type
:必选,字符串类型。category
:必选,字符串类型。level
:必选,字符串类型。data
: 必选,对象类型。message
:必选,字符串类型。- 其余字段,可选。
返回参数:
- traceId:探针生成的JS错误traceId。探针默认从堆栈(stack)中解析文件名、行和列,如果低版本IE浏览器拿不到堆栈,务必传递fileName,否则空文件名的JS错误默认不上传,行列号也支持手动传递。当同时传递fileName、lineNumber和 columnNumber时,探针不会再从stack解析。
示例
window.TINGYUN.captureException({
message: 'Uncaught ReferenceError: a is not defined',
stack: 'ReferenceError: a is not defined\n at triggerError (http://localhost:5500/event_merge/:44:13)\n at HTMLButtonElement.onclick (http://localhost:5500/event_merge/:39:39)'
}, {
breadcrumbs: [
{
"timestamp": 1646734787.111,
"type": "default",
"category": "navigation",
"level": "info",
"message": "123",
"data": {
"from": "/organizations/sentry/issues/",
"to": "/organizations/sentry/performance/"
}
},
{
"timestamp": 1646734787,
"type": "http",
"category": "fetch",
"level": "info",
"message": "123",
"data": {
"__span": "bca29be770e45a58",
"method": "GET",
"status_code": 200,
"url": "/api/0/prompts-activity/?feature=sdk_updates&organization_id=1"
}
}
......
]
})