UNPKG

@embrace-io/web-sdk

Version:
1 lines 2.6 kB
{"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.epochMillisFromOrigin(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.epochMillisFromOrigin(event.timeStamp),\n handler: 'promise_rejection',\n });\n };\n\n if (this._config.enabled) {\n this.enable();\n }\n }\n\n public onDisable(): void {\n window.removeEventListener('error', this._onErrorHandler);\n window.removeEventListener(\n 'unhandledrejection',\n this._onUnhandledRejectionHandler,\n );\n }\n\n public onEnable(): 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,CAAC,GAAG;EAC1E,MAAM;GACJ,qBAAqB;GACrB,wBAAwB;GACxB;GACA;GACA,QAAQ,CAAC;EACX,CAAC;EACD,KAAK,mBAAmB,UAAsB;GAC5C,KAAK,WAAW,aAAa,MAAM,SAAS,MAAM,SAAS;IACzD,SAAS;IACT,WAAW,KAAK,KAAK,sBAAsB,MAAM,SAAS;IAC1D,SAAS;GACX,CAAC;EACH;EACA,KAAK,gCAAgC,UAAiC;GACpE,KAAK,WAAW,aAAa,MAAM,QAAQ;IACzC,SAAS;IACT,WAAW,KAAK,KAAK,sBAAsB,MAAM,SAAS;IAC1D,SAAS;GACX,CAAC;EACH;EAEA,IAAI,KAAK,QAAQ,SACf,KAAK,OAAO;CAEhB;CAEA,YAAyB;EACvB,OAAO,oBAAoB,SAAS,KAAK,eAAe;EACxD,OAAO,oBACL,sBACA,KAAK,4BACP;CACF;CAEA,WAAwB;EACtB,OAAO,iBAAiB,SAAS,KAAK,eAAe;EACrD,OAAO,iBACL,sBACA,KAAK,4BACP;CACF;AACF"}