Skip to main content

Reporting JavaScript Errors and Adding Breadcrumbs

API​

const traceId = window.TINGYUN.captureException(err, options)

Request Parameters:

  • err: Error object, required. Standard Error object or custom object containing error information message and error stack stack. If there is no stack, you need to pass fileName.
    • message: String type, error message.
    • stack: String type, error stack.
    • fileName: String type, error file name.
    • lineNumber: Error line number.
    • columnNumber: Error column number.
  • options: Custom options, optional, object type.
    • breadcrumbs: Array, value passed for Breadcrumbs.
      • timestamp: Required, 10-digit POSIX timestamp or 10-digit timestamp with three decimals, e.g., 1661511702 or 1661511822.445.
      • type: Required, string type.
      • category: Required, string type.
      • level: Required, string type.
      • data: Required, object type.
      • message: Required, string type.
      • Other fields, optional.

Return Parameter:

  • traceId: The JS error traceId generated by the agent. By default, the agent parses the file name, line, and column from the stack. If the stack cannot be obtained in lower version IE browsers, you must pass fileName. Otherwise, JS errors with empty file names will not be reported by default. Line and column numbers also support manual passing. When fileName, lineNumber, and columnNumber are passed at the same time, the agent will not parse from the stack again.

Example​

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"
}
}
// ...
]
})