UNPKG

@embrace-io/web-sdk

Version:
42 lines (41 loc) 1.47 kB
import { EmbraceInstrumentationBase } from "../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.js"; //#region src/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.ts var GlobalExceptionInstrumentation = class extends EmbraceInstrumentationBase { _onErrorHandler; _onUnhandledRejectionHandler; constructor({ diag, perf } = {}) { super({ instrumentationName: "GlobalExceptionInstrumentation", instrumentationVersion: "1.0.0", diag, perf, config: {} }); this._onErrorHandler = (event) => { this.logManager.logException(event.error || event.message, { handled: false, timestamp: this.perf.epochMillisFromOrigin(event.timeStamp), handler: "global_exception" }); }; this._onUnhandledRejectionHandler = (event) => { this.logManager.logException(event.reason, { handled: false, timestamp: this.perf.epochMillisFromOrigin(event.timeStamp), handler: "promise_rejection" }); }; if (this._config.enabled) this.enable(); } onDisable() { window.removeEventListener("error", this._onErrorHandler); window.removeEventListener("unhandledrejection", this._onUnhandledRejectionHandler); } onEnable() { window.addEventListener("error", this._onErrorHandler); window.addEventListener("unhandledrejection", this._onUnhandledRejectionHandler); } }; //#endregion export { GlobalExceptionInstrumentation }; //# sourceMappingURL=GlobalExceptionInstrumentation.js.map