UNPKG

@dash0/sdk-web

Version:

Dash0's Web SDK to collect telemetry from end-users' web browsers

31 lines (30 loc) 1.18 kB
import { addSpanEvent } from "./span"; import { addAttribute } from "./attributes"; import { SPAN_EVENT_NAME_EXCEPTION, EXCEPTION_MESSAGE, EXCEPTION_STACKTRACE, EXCEPTION_TYPE, SPAN_STATUS_ERROR, } from "../../semantic-conventions"; export function recordException(span, exception) { const attributes = []; if (typeof exception === "string") { addAttribute(attributes, EXCEPTION_MESSAGE, exception); } else if (exception) { if (exception.code) { addAttribute(attributes, EXCEPTION_TYPE, exception.code.toString()); } else if (exception.name) { addAttribute(attributes, EXCEPTION_TYPE, exception.name); } if (exception.message) { addAttribute(attributes, EXCEPTION_MESSAGE, exception.message); } if (exception.stack) { addAttribute(attributes, EXCEPTION_STACKTRACE, exception.stack); } addSpanEvent(span, SPAN_EVENT_NAME_EXCEPTION, attributes); } } export function errorToSpanStatus(e) { return { code: SPAN_STATUS_ERROR, message: e && typeof e === "object" && "message" in e ? e.message : String(e), }; }