{"version":3,"file":"errors.js","sources":["../../../src/tracing/errors.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport { addGlobalErrorInstrumentationHandler } from '../instrument/globalError';\nimport { addGlobalUnhandledRejectionInstrumentationHandler } from '../instrument/globalUnhandledRejection';\nimport { debug } from '../utils/debug-logger';\nimport { getActiveSpan, getRootSpan } from '../utils/spanUtils';\nimport { SPAN_STATUS_ERROR } from './spanstatus';\n\nlet errorsInstrumented = false;\n\n/**  Only exposed for testing */\nexport function _resetErrorsInstrumented(): void {\n  errorsInstrumented = false;\n}\n\n/**\n * Ensure that global errors automatically set the active span status.\n */\nexport function registerSpanErrorInstrumentation(): void {\n  if (errorsInstrumented) {\n    return;\n  }\n\n  /**\n   * If an error or unhandled promise occurs, we mark the active root span as failed\n   */\n  function errorCallback(): void {\n    const activeSpan = getActiveSpan();\n    const rootSpan = activeSpan && getRootSpan(activeSpan);\n    if (rootSpan) {\n      const message = 'internal_error';\n      DEBUG_BUILD && debug.log(`[Tracing] Root span: ${message} -> Global error occurred`);\n      rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message });\n    }\n  }\n\n  // The function name will be lost when bundling but we need to be able to identify this listener later to maintain the\n  // node.js default exit behaviour\n  errorCallback.tag = 'sentry_tracingErrorCallback';\n\n  errorsInstrumented = true;\n  addGlobalErrorInstrumentationHandler(errorCallback);\n  addGlobalUnhandledRejectionInstrumentationHandler(errorCallback);\n}\n"],"names":[],"mappings":";;;;;;;AAOA,IAAI,kBAAA,GAAqB,KAAK;;AAO9B;AACA;AACA;AACO,SAAS,gCAAgC,GAAS;AACzD,EAAE,IAAI,kBAAkB,EAAE;AAC1B,IAAI;AACJ,EAAE;;AAEF;AACA;AACA;AACA,EAAE,SAAS,aAAa,GAAS;AACjC,IAAI,MAAM,UAAA,GAAa,aAAa,EAAE;AACtC,IAAI,MAAM,WAAW,UAAA,IAAc,WAAW,CAAC,UAAU,CAAC;AAC1D,IAAI,IAAI,QAAQ,EAAE;AAClB,MAAM,MAAM,OAAA,GAAU,gBAAgB;AACtC,MAAM,WAAA,IAAe,KAAK,CAAC,GAAG,CAAC,CAAC,qBAAqB,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC1F,MAAM,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAA,EAAS,CAAC;AAC9D,IAAI;AACJ,EAAE;;AAEF;AACA;AACA,EAAE,aAAa,CAAC,GAAA,GAAM,6BAA6B;;AAEnD,EAAE,kBAAA,GAAqB,IAAI;AAC3B,EAAE,oCAAoC,CAAC,aAAa,CAAC;AACrD,EAAE,iDAAiD,CAAC,aAAa,CAAC;AAClE;;;;"}