diff --git a/packages/browser/src/integrations/dedupe.ts b/packages/browser/src/integrations/dedupe.ts index 07fe3eccfb6a..641823bbde3c 100644 --- a/packages/browser/src/integrations/dedupe.ts +++ b/packages/browser/src/integrations/dedupe.ts @@ -27,7 +27,7 @@ export class Dedupe implements Integration { if (self) { // Juuust in case something goes wrong try { - if (self._shouldDropEvent(currentEvent, self._previousEvent)) { + if (_shouldDropEvent(currentEvent, self._previousEvent)) { logger.warn(`Event dropped due to being a duplicate of previously captured event.`); return null; } @@ -40,164 +40,164 @@ export class Dedupe implements Integration { return currentEvent; }); } +} - /** JSDoc */ - private _shouldDropEvent(currentEvent: Event, previousEvent?: Event): boolean { - if (!previousEvent) { - return false; - } - - if (this._isSameMessageEvent(currentEvent, previousEvent)) { - return true; - } - - if (this._isSameExceptionEvent(currentEvent, previousEvent)) { - return true; - } - +/** JSDoc */ +function _shouldDropEvent(currentEvent: Event, previousEvent?: Event): boolean { + if (!previousEvent) { return false; } - /** JSDoc */ - private _isSameMessageEvent(currentEvent: Event, previousEvent: Event): boolean { - const currentMessage = currentEvent.message; - const previousMessage = previousEvent.message; + if (_isSameMessageEvent(currentEvent, previousEvent)) { + return true; + } - // If neither event has a message property, they were both exceptions, so bail out - if (!currentMessage && !previousMessage) { - return false; - } + if (_isSameExceptionEvent(currentEvent, previousEvent)) { + return true; + } - // If only one event has a stacktrace, but not the other one, they are not the same - if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) { - return false; - } + return false; +} - if (currentMessage !== previousMessage) { - return false; - } +/** JSDoc */ +function _isSameMessageEvent(currentEvent: Event, previousEvent: Event): boolean { + const currentMessage = currentEvent.message; + const previousMessage = previousEvent.message; - if (!this._isSameFingerprint(currentEvent, previousEvent)) { - return false; - } + // If neither event has a message property, they were both exceptions, so bail out + if (!currentMessage && !previousMessage) { + return false; + } - if (!this._isSameStacktrace(currentEvent, previousEvent)) { - return false; - } + // If only one event has a stacktrace, but not the other one, they are not the same + if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) { + return false; + } - return true; + if (currentMessage !== previousMessage) { + return false; } - /** JSDoc */ - private _getFramesFromEvent(event: Event): StackFrame[] | undefined { - const exception = event.exception; + if (!_isSameFingerprint(currentEvent, previousEvent)) { + return false; + } - if (exception) { - try { - // @ts-ignore Object could be undefined - return exception.values[0].stacktrace.frames; - } catch (_oO) { - return undefined; - } - } else if (event.stacktrace) { - return event.stacktrace.frames; - } - return undefined; + if (!_isSameStacktrace(currentEvent, previousEvent)) { + return false; } - /** JSDoc */ - private _isSameStacktrace(currentEvent: Event, previousEvent: Event): boolean { - let currentFrames = this._getFramesFromEvent(currentEvent); - let previousFrames = this._getFramesFromEvent(previousEvent); + return true; +} - // If neither event has a stacktrace, they are assumed to be the same - if (!currentFrames && !previousFrames) { - return true; - } +/** JSDoc */ +function _isSameExceptionEvent(currentEvent: Event, previousEvent: Event): boolean { + const previousException = _getExceptionFromEvent(previousEvent); + const currentException = _getExceptionFromEvent(currentEvent); - // If only one event has a stacktrace, but not the other one, they are not the same - if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) { - return false; - } + if (!previousException || !currentException) { + return false; + } - currentFrames = currentFrames as StackFrame[]; - previousFrames = previousFrames as StackFrame[]; + if (previousException.type !== currentException.type || previousException.value !== currentException.value) { + return false; + } - // If number of frames differ, they are not the same - if (previousFrames.length !== currentFrames.length) { - return false; - } + if (!_isSameFingerprint(currentEvent, previousEvent)) { + return false; + } - // Otherwise, compare the two - for (let i = 0; i < previousFrames.length; i++) { - const frameA = previousFrames[i]; - const frameB = currentFrames[i]; - - if ( - frameA.filename !== frameB.filename || - frameA.lineno !== frameB.lineno || - frameA.colno !== frameB.colno || - frameA.function !== frameB.function - ) { - return false; - } - } + if (!_isSameStacktrace(currentEvent, previousEvent)) { + return false; + } + + return true; +} + +/** JSDoc */ +function _isSameStacktrace(currentEvent: Event, previousEvent: Event): boolean { + let currentFrames = _getFramesFromEvent(currentEvent); + let previousFrames = _getFramesFromEvent(previousEvent); + // If neither event has a stacktrace, they are assumed to be the same + if (!currentFrames && !previousFrames) { return true; } - /** JSDoc */ - private _getExceptionFromEvent(event: Event): Exception | undefined { - return event.exception && event.exception.values && event.exception.values[0]; + // If only one event has a stacktrace, but not the other one, they are not the same + if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) { + return false; } - /** JSDoc */ - private _isSameExceptionEvent(currentEvent: Event, previousEvent: Event): boolean { - const previousException = this._getExceptionFromEvent(previousEvent); - const currentException = this._getExceptionFromEvent(currentEvent); + currentFrames = currentFrames as StackFrame[]; + previousFrames = previousFrames as StackFrame[]; - if (!previousException || !currentException) { - return false; - } + // If number of frames differ, they are not the same + if (previousFrames.length !== currentFrames.length) { + return false; + } - if (previousException.type !== currentException.type || previousException.value !== currentException.value) { + // Otherwise, compare the two + for (let i = 0; i < previousFrames.length; i++) { + const frameA = previousFrames[i]; + const frameB = currentFrames[i]; + + if ( + frameA.filename !== frameB.filename || + frameA.lineno !== frameB.lineno || + frameA.colno !== frameB.colno || + frameA.function !== frameB.function + ) { return false; } + } - if (!this._isSameFingerprint(currentEvent, previousEvent)) { - return false; - } + return true; +} - if (!this._isSameStacktrace(currentEvent, previousEvent)) { - return false; - } +/** JSDoc */ +function _isSameFingerprint(currentEvent: Event, previousEvent: Event): boolean { + let currentFingerprint = currentEvent.fingerprint; + let previousFingerprint = previousEvent.fingerprint; + // If neither event has a fingerprint, they are assumed to be the same + if (!currentFingerprint && !previousFingerprint) { return true; } - /** JSDoc */ - private _isSameFingerprint(currentEvent: Event, previousEvent: Event): boolean { - let currentFingerprint = currentEvent.fingerprint; - let previousFingerprint = previousEvent.fingerprint; + // If only one event has a fingerprint, but not the other one, they are not the same + if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) { + return false; + } + + currentFingerprint = currentFingerprint as string[]; + previousFingerprint = previousFingerprint as string[]; - // If neither event has a fingerprint, they are assumed to be the same - if (!currentFingerprint && !previousFingerprint) { - return true; - } + // Otherwise, compare the two + try { + return !!(currentFingerprint.join('') === previousFingerprint.join('')); + } catch (_oO) { + return false; + } +} - // If only one event has a fingerprint, but not the other one, they are not the same - if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) { - return false; - } +/** JSDoc */ +function _getExceptionFromEvent(event: Event): Exception | undefined { + return event.exception && event.exception.values && event.exception.values[0]; +} - currentFingerprint = currentFingerprint as string[]; - previousFingerprint = previousFingerprint as string[]; +/** JSDoc */ +function _getFramesFromEvent(event: Event): StackFrame[] | undefined { + const exception = event.exception; - // Otherwise, compare the two + if (exception) { try { - return !!(currentFingerprint.join('') === previousFingerprint.join('')); + // @ts-ignore Object could be undefined + return exception.values[0].stacktrace.frames; } catch (_oO) { - return false; + return undefined; } + } else if (event.stacktrace) { + return event.stacktrace.frames; } + return undefined; } diff --git a/packages/integrations/src/dedupe.ts b/packages/integrations/src/dedupe.ts index 07fe3eccfb6a..641823bbde3c 100644 --- a/packages/integrations/src/dedupe.ts +++ b/packages/integrations/src/dedupe.ts @@ -27,7 +27,7 @@ export class Dedupe implements Integration { if (self) { // Juuust in case something goes wrong try { - if (self._shouldDropEvent(currentEvent, self._previousEvent)) { + if (_shouldDropEvent(currentEvent, self._previousEvent)) { logger.warn(`Event dropped due to being a duplicate of previously captured event.`); return null; } @@ -40,164 +40,164 @@ export class Dedupe implements Integration { return currentEvent; }); } +} - /** JSDoc */ - private _shouldDropEvent(currentEvent: Event, previousEvent?: Event): boolean { - if (!previousEvent) { - return false; - } - - if (this._isSameMessageEvent(currentEvent, previousEvent)) { - return true; - } - - if (this._isSameExceptionEvent(currentEvent, previousEvent)) { - return true; - } - +/** JSDoc */ +function _shouldDropEvent(currentEvent: Event, previousEvent?: Event): boolean { + if (!previousEvent) { return false; } - /** JSDoc */ - private _isSameMessageEvent(currentEvent: Event, previousEvent: Event): boolean { - const currentMessage = currentEvent.message; - const previousMessage = previousEvent.message; + if (_isSameMessageEvent(currentEvent, previousEvent)) { + return true; + } - // If neither event has a message property, they were both exceptions, so bail out - if (!currentMessage && !previousMessage) { - return false; - } + if (_isSameExceptionEvent(currentEvent, previousEvent)) { + return true; + } - // If only one event has a stacktrace, but not the other one, they are not the same - if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) { - return false; - } + return false; +} - if (currentMessage !== previousMessage) { - return false; - } +/** JSDoc */ +function _isSameMessageEvent(currentEvent: Event, previousEvent: Event): boolean { + const currentMessage = currentEvent.message; + const previousMessage = previousEvent.message; - if (!this._isSameFingerprint(currentEvent, previousEvent)) { - return false; - } + // If neither event has a message property, they were both exceptions, so bail out + if (!currentMessage && !previousMessage) { + return false; + } - if (!this._isSameStacktrace(currentEvent, previousEvent)) { - return false; - } + // If only one event has a stacktrace, but not the other one, they are not the same + if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) { + return false; + } - return true; + if (currentMessage !== previousMessage) { + return false; } - /** JSDoc */ - private _getFramesFromEvent(event: Event): StackFrame[] | undefined { - const exception = event.exception; + if (!_isSameFingerprint(currentEvent, previousEvent)) { + return false; + } - if (exception) { - try { - // @ts-ignore Object could be undefined - return exception.values[0].stacktrace.frames; - } catch (_oO) { - return undefined; - } - } else if (event.stacktrace) { - return event.stacktrace.frames; - } - return undefined; + if (!_isSameStacktrace(currentEvent, previousEvent)) { + return false; } - /** JSDoc */ - private _isSameStacktrace(currentEvent: Event, previousEvent: Event): boolean { - let currentFrames = this._getFramesFromEvent(currentEvent); - let previousFrames = this._getFramesFromEvent(previousEvent); + return true; +} - // If neither event has a stacktrace, they are assumed to be the same - if (!currentFrames && !previousFrames) { - return true; - } +/** JSDoc */ +function _isSameExceptionEvent(currentEvent: Event, previousEvent: Event): boolean { + const previousException = _getExceptionFromEvent(previousEvent); + const currentException = _getExceptionFromEvent(currentEvent); - // If only one event has a stacktrace, but not the other one, they are not the same - if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) { - return false; - } + if (!previousException || !currentException) { + return false; + } - currentFrames = currentFrames as StackFrame[]; - previousFrames = previousFrames as StackFrame[]; + if (previousException.type !== currentException.type || previousException.value !== currentException.value) { + return false; + } - // If number of frames differ, they are not the same - if (previousFrames.length !== currentFrames.length) { - return false; - } + if (!_isSameFingerprint(currentEvent, previousEvent)) { + return false; + } - // Otherwise, compare the two - for (let i = 0; i < previousFrames.length; i++) { - const frameA = previousFrames[i]; - const frameB = currentFrames[i]; - - if ( - frameA.filename !== frameB.filename || - frameA.lineno !== frameB.lineno || - frameA.colno !== frameB.colno || - frameA.function !== frameB.function - ) { - return false; - } - } + if (!_isSameStacktrace(currentEvent, previousEvent)) { + return false; + } + + return true; +} + +/** JSDoc */ +function _isSameStacktrace(currentEvent: Event, previousEvent: Event): boolean { + let currentFrames = _getFramesFromEvent(currentEvent); + let previousFrames = _getFramesFromEvent(previousEvent); + // If neither event has a stacktrace, they are assumed to be the same + if (!currentFrames && !previousFrames) { return true; } - /** JSDoc */ - private _getExceptionFromEvent(event: Event): Exception | undefined { - return event.exception && event.exception.values && event.exception.values[0]; + // If only one event has a stacktrace, but not the other one, they are not the same + if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) { + return false; } - /** JSDoc */ - private _isSameExceptionEvent(currentEvent: Event, previousEvent: Event): boolean { - const previousException = this._getExceptionFromEvent(previousEvent); - const currentException = this._getExceptionFromEvent(currentEvent); + currentFrames = currentFrames as StackFrame[]; + previousFrames = previousFrames as StackFrame[]; - if (!previousException || !currentException) { - return false; - } + // If number of frames differ, they are not the same + if (previousFrames.length !== currentFrames.length) { + return false; + } - if (previousException.type !== currentException.type || previousException.value !== currentException.value) { + // Otherwise, compare the two + for (let i = 0; i < previousFrames.length; i++) { + const frameA = previousFrames[i]; + const frameB = currentFrames[i]; + + if ( + frameA.filename !== frameB.filename || + frameA.lineno !== frameB.lineno || + frameA.colno !== frameB.colno || + frameA.function !== frameB.function + ) { return false; } + } - if (!this._isSameFingerprint(currentEvent, previousEvent)) { - return false; - } + return true; +} - if (!this._isSameStacktrace(currentEvent, previousEvent)) { - return false; - } +/** JSDoc */ +function _isSameFingerprint(currentEvent: Event, previousEvent: Event): boolean { + let currentFingerprint = currentEvent.fingerprint; + let previousFingerprint = previousEvent.fingerprint; + // If neither event has a fingerprint, they are assumed to be the same + if (!currentFingerprint && !previousFingerprint) { return true; } - /** JSDoc */ - private _isSameFingerprint(currentEvent: Event, previousEvent: Event): boolean { - let currentFingerprint = currentEvent.fingerprint; - let previousFingerprint = previousEvent.fingerprint; + // If only one event has a fingerprint, but not the other one, they are not the same + if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) { + return false; + } + + currentFingerprint = currentFingerprint as string[]; + previousFingerprint = previousFingerprint as string[]; - // If neither event has a fingerprint, they are assumed to be the same - if (!currentFingerprint && !previousFingerprint) { - return true; - } + // Otherwise, compare the two + try { + return !!(currentFingerprint.join('') === previousFingerprint.join('')); + } catch (_oO) { + return false; + } +} - // If only one event has a fingerprint, but not the other one, they are not the same - if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) { - return false; - } +/** JSDoc */ +function _getExceptionFromEvent(event: Event): Exception | undefined { + return event.exception && event.exception.values && event.exception.values[0]; +} - currentFingerprint = currentFingerprint as string[]; - previousFingerprint = previousFingerprint as string[]; +/** JSDoc */ +function _getFramesFromEvent(event: Event): StackFrame[] | undefined { + const exception = event.exception; - // Otherwise, compare the two + if (exception) { try { - return !!(currentFingerprint.join('') === previousFingerprint.join('')); + // @ts-ignore Object could be undefined + return exception.values[0].stacktrace.frames; } catch (_oO) { - return false; + return undefined; } + } else if (event.stacktrace) { + return event.stacktrace.frames; } + return undefined; }