{"version":3,"file":"GlobalExceptionInstrumentation.cjs","names":["EmbraceInstrumentationBase"],"sources":["../../../../src/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.ts"],"sourcesContent":["import { EmbraceInstrumentationBase } from '../../EmbraceInstrumentationBase/index.ts';\nimport type { GlobalExceptionInstrumentationArgs } from './types.ts';\n\nexport class GlobalExceptionInstrumentation extends EmbraceInstrumentationBase {\n  private readonly _onErrorHandler: (event: ErrorEvent) => void;\n  private readonly _onUnhandledRejectionHandler: (\n    event: PromiseRejectionEvent,\n  ) => void;\n\n  public constructor({ diag, perf }: GlobalExceptionInstrumentationArgs = {}) {\n    super({\n      instrumentationName: 'GlobalExceptionInstrumentation',\n      instrumentationVersion: '1.0.0',\n      diag,\n      perf,\n      config: {},\n    });\n    this._onErrorHandler = (event: ErrorEvent) => {\n      this.logManager.logException(event.error || event.message, {\n        handled: false,\n        timestamp: this.perf.epochMillisFromOriginOffset(event.timeStamp),\n        handler: 'global_exception',\n      });\n    };\n    this._onUnhandledRejectionHandler = (event: PromiseRejectionEvent) => {\n      this.logManager.logException(event.reason, {\n        handled: false,\n        timestamp: this.perf.epochMillisFromOriginOffset(event.timeStamp),\n        handler: 'promise_rejection',\n      });\n    };\n\n    if (this._config.enabled) {\n      this.enable();\n    }\n  }\n\n  public disable(): void {\n    window.removeEventListener('error', this._onErrorHandler);\n    window.removeEventListener(\n      'unhandledrejection',\n      this._onUnhandledRejectionHandler,\n    );\n  }\n\n  public enable(): void {\n    window.addEventListener('error', this._onErrorHandler);\n    window.addEventListener(\n      'unhandledrejection',\n      this._onUnhandledRejectionHandler,\n    );\n  }\n}\n"],"mappings":";;;AAGA,IAAa,iCAAb,cAAoDA,+EAAAA,2BAA2B;CAC7E;CACA;CAIA,YAAmB,EAAE,MAAM,SAA6C,EAAE,EAAE;AAC1E,QAAM;GACJ,qBAAqB;GACrB,wBAAwB;GACxB;GACA;GACA,QAAQ,EAAE;GACX,CAAC;AACF,OAAK,mBAAmB,UAAsB;AAC5C,QAAK,WAAW,aAAa,MAAM,SAAS,MAAM,SAAS;IACzD,SAAS;IACT,WAAW,KAAK,KAAK,4BAA4B,MAAM,UAAU;IACjE,SAAS;IACV,CAAC;;AAEJ,OAAK,gCAAgC,UAAiC;AACpE,QAAK,WAAW,aAAa,MAAM,QAAQ;IACzC,SAAS;IACT,WAAW,KAAK,KAAK,4BAA4B,MAAM,UAAU;IACjE,SAAS;IACV,CAAC;;AAGJ,MAAI,KAAK,QAAQ,QACf,MAAK,QAAQ;;CAIjB,UAAuB;AACrB,SAAO,oBAAoB,SAAS,KAAK,gBAAgB;AACzD,SAAO,oBACL,sBACA,KAAK,6BACN;;CAGH,SAAsB;AACpB,SAAO,iBAAiB,SAAS,KAAK,gBAAgB;AACtD,SAAO,iBACL,sBACA,KAAK,6BACN"}