UNPKG

@sentry/integrations

Version:
84 lines (71 loc) 2.45 kB
Object.defineProperty(exports, '__esModule', { value: true }); const utils = require('@sentry/utils'); /** Send Console API calls as Sentry Events */ class CaptureConsole { /** * @inheritDoc */ static __initStatic() {this.id = 'CaptureConsole';} /** * @inheritDoc */ __init() {this.name = CaptureConsole.id;} /** * @inheritDoc */ __init2() {this._levels = utils.CONSOLE_LEVELS;} /** * @inheritDoc */ constructor(options = {}) {;CaptureConsole.prototype.__init.call(this);CaptureConsole.prototype.__init2.call(this); if (options.levels) { this._levels = options.levels; } } /** * @inheritDoc */ setupOnce(_, getCurrentHub) { if (!('console' in utils.GLOBAL_OBJ)) { return; } this._levels.forEach((level) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any if (!(level in (utils.GLOBAL_OBJ ).console)) { return; } // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access utils.fill((utils.GLOBAL_OBJ ).console, level, (originalConsoleMethod) => (...args) => { const hub = getCurrentHub(); if (hub.getIntegration(CaptureConsole)) { hub.withScope(scope => { scope.setLevel(utils.severityLevelFromString(level)); scope.setExtra('arguments', args); scope.addEventProcessor(event => { event.logger = 'console'; return event; }); let message = utils.safeJoin(args, ' '); if (level === 'assert') { if (args[0] === false) { message = `Assertion failed: ${utils.safeJoin(args.slice(1), ' ') || 'console.assert'}`; scope.setExtra('arguments', args.slice(1)); hub.captureMessage(message); } } else if (level === 'error' && args[0] instanceof Error) { hub.captureException(args[0]); } else { hub.captureMessage(message); } }); } // this fails for some browsers. :( if (originalConsoleMethod) { originalConsoleMethod.apply(utils.GLOBAL_OBJ.console, args); } }); }); } } CaptureConsole.__initStatic(); exports.CaptureConsole = CaptureConsole; //# sourceMappingURL=captureconsole.js.map