@sentry/integrations
Version:
Pluggable integrations that can be used to enhance JS SDKs
118 lines (103 loc) • 3.05 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
const utils = require('@sentry/utils');
/** Rewrite event frames paths */
class RewriteFrames {
/**
* @inheritDoc
*/
static __initStatic() {this.id = 'RewriteFrames';}
/**
* @inheritDoc
*/
__init() {this.name = RewriteFrames.id;}
/**
* @inheritDoc
*/
/**
* @inheritDoc
*/
__init2() {this._prefix = 'app:///';}
/**
* @inheritDoc
*/
constructor(options = {}) {;RewriteFrames.prototype.__init.call(this);RewriteFrames.prototype.__init2.call(this);RewriteFrames.prototype.__init3.call(this);
if (options.root) {
this._root = options.root;
}
if (options.prefix) {
this._prefix = options.prefix;
}
if (options.iteratee) {
this._iteratee = options.iteratee;
}
}
/**
* @inheritDoc
*/
setupOnce(addGlobalEventProcessor, getCurrentHub) {
addGlobalEventProcessor(event => {
const self = getCurrentHub().getIntegration(RewriteFrames);
if (self) {
return self.process(event);
}
return event;
});
}
/** JSDoc */
process(originalEvent) {
let processedEvent = originalEvent;
if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) {
processedEvent = this._processExceptionsEvent(processedEvent);
}
return processedEvent;
}
/**
* @inheritDoc
*/
__init3() {this._iteratee = (frame) => {
if (!frame.filename) {
return frame;
}
// Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
const isWindowsFrame = /^[A-Z]:\\/.test(frame.filename);
const startsWithSlash = /^\//.test(frame.filename);
if (isWindowsFrame || startsWithSlash) {
const filename = isWindowsFrame
? frame.filename
.replace(/^[A-Z]:/, '') // remove Windows-style prefix
.replace(/\\/g, '/') // replace all `\\` instances with `/`
: frame.filename;
const base = this._root ? utils.relative(this._root, filename) : utils.basename(filename);
frame.filename = `${this._prefix}${base}`;
}
return frame;
};}
/** JSDoc */
_processExceptionsEvent(event) {
try {
return {
...event,
exception: {
...event.exception,
// The check for this is performed inside `process` call itself, safe to skip here
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
values: event.exception.values.map(value => ({
...value,
...(value.stacktrace && { stacktrace: this._processStacktrace(value.stacktrace) }),
})),
},
};
} catch (_oO) {
return event;
}
}
/** JSDoc */
_processStacktrace(stacktrace) {
return {
...stacktrace,
frames: stacktrace && stacktrace.frames && stacktrace.frames.map(f => this._iteratee(f)),
};
}
} RewriteFrames.__initStatic();
exports.RewriteFrames = RewriteFrames;
//# sourceMappingURL=rewriteframes.js.map