Skip to content

Commit

Permalink
[v7] Drop two consecutive events originating from the same source (eg…
Browse files Browse the repository at this point in the history
…. browser Wrap integrations)
  • Loading branch information
kamilogorek committed Mar 23, 2021
1 parent 24c8a9d commit 7bde003
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
18 changes: 18 additions & 0 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {

protected _eventProcessors: EventProcessor[] = [];

protected _lastException?: unknown;

/**
* Initializes this client instance.
*
Expand Down Expand Up @@ -125,6 +127,14 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
* @inheritDoc
*/
public captureException(exception: unknown, captureContext: CaptureContext = {}): string | undefined {
// Drop two consecutive events originating from the same source (eg. browser Wrap integrations)
if (this._lastException && this._lastException === captureContext.hint?.originalException) {
delete this._lastException;
return;
} else {
this._lastException = captureContext.hint?.originalException;
}

// TODO: This is broken. a) we dont pass event_id in hint anymore, b) its sync value assigned in async callback
let eventId = captureContext.hint?.event_id;
const scope = this._getEventScope(captureContext);
Expand Down Expand Up @@ -166,6 +176,14 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
* @inheritDoc
*/
public captureEvent(event: SentryEvent, captureContext: CaptureContext = {}): string | undefined {
// Drop two consecutive events originating from the same source (eg. browser Wrap integrations)
if (this._lastException && this._lastException === captureContext.hint?.originalException) {
delete this._lastException;
return;
} else {
this._lastException = captureContext.hint?.originalException;
}

let eventId = captureContext.hint?.event_id;
const scope = this._getEventScope(captureContext);

Expand Down
5 changes: 0 additions & 5 deletions packages/integration-browser-globalhandlers/src/onerror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export class OnError implements Integration {

addInstrumentationHandler({
callback: ({ msg, url, line, column, error }) => {
// TODO: Restore this functinality based on some error metadata
// if (shouldIgnoreOnError()) {
// return;
// }

if (error?.__sentry_own_request__) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export class OnUnhandledRejection implements Integration {
// no-empty
}

// TODO: Restore this functinality based on some error metadata
// if (shouldIgnoreOnError()) {
// return;
// }

if (error?.__sentry_own_request__) {
return;
}
Expand Down
5 changes: 1 addition & 4 deletions packages/integration-browser-wrap/src/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ export function wrap(fn: WrappedFunction, mechanism?: Mechanism): any {
// is expected behavior and NOT indicative of a bug with sentry.javascript.
return fn.apply(this, wrappedArguments);
} catch (ex) {
// TODO: Fix ignoring next error (read metadata from the ex value itself like we do with `__sentry_own_request__`?)
// ignoreNextOnError();

withScope(scope => {
scope.addEventProcessor((event: SentryEvent) => {
const processedEvent = { ...event };
Expand All @@ -68,7 +65,7 @@ export function wrap(fn: WrappedFunction, mechanism?: Mechanism): any {
return processedEvent;
});

captureException(ex);
captureException(ex, { hint: { originalException: ex } });
});

throw ex;
Expand Down

0 comments on commit 7bde003

Please sign in to comment.