UNPKG

@sentry/core

Version:
35 lines (34 loc) • 1.26 kB
import { DEBUG_BUILD } from "../debug-build.js"; import { addGlobalErrorInstrumentationHandler } from "../instrument/globalError.js"; import { addGlobalUnhandledRejectionInstrumentationHandler } from "../instrument/globalUnhandledRejection.js"; import { debug } from "../utils/debug-logger.js"; import { getActiveSpan, getRootSpan } from "../utils/spanUtils.js"; import "./spanstatus.js"; // src/tracing/errors.ts let errorsInstrumented = false; /** * Ensure that global errors automatically set the active span status. */ function registerSpanErrorInstrumentation() { if (errorsInstrumented) return; /** * If an error or unhandled promise occurs, we mark the active root span as failed */ function errorCallback() { const activeSpan = getActiveSpan(); const rootSpan = activeSpan && getRootSpan(activeSpan); if (rootSpan) { const message = "internal_error"; DEBUG_BUILD && debug.log(`[Tracing] Root span: ${message} -> Global error occurred`); rootSpan.setStatus({ code: 2, message }); } } errorsInstrumented = true; addGlobalErrorInstrumentationHandler(errorCallback); addGlobalUnhandledRejectionInstrumentationHandler(errorCallback); } export { registerSpanErrorInstrumentation }; //# sourceMappingURL=errors.js.map