@embrace-io/web-sdk
Version:
43 lines (42 loc) • 1.71 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_instrumentations_EmbraceInstrumentationBase_EmbraceInstrumentationBase = require("../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.cjs");
//#region src/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.ts
var GlobalExceptionInstrumentation = class extends require_instrumentations_EmbraceInstrumentationBase_EmbraceInstrumentationBase.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
exports.GlobalExceptionInstrumentation = GlobalExceptionInstrumentation;
//# sourceMappingURL=GlobalExceptionInstrumentation.cjs.map