8000 [v7] Drop two consecutive events originating from the same source (eg… · xiaohuoni/sentry-javascript@7bde003 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7bde003

Browse files
committed
[v7] Drop two consecutive events originating from the same source (eg. browser Wrap integrations)
1 parent 24c8a9d commit 7bde003

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

packages/core/src/baseclient.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
8383

8484
protected _eventProcessors: EventProcessor[] = [];
8585

86+
protected _lastException?: unknown;
87+
8688
/**
8789
* Initializes this client instance.
8890
*
@@ -125,6 +127,14 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
125127
* @inheritDoc
126128
*/
127129
public captureException(exception: unknown, captureContext: CaptureContext = {}): string | undefined {
130+
// Drop two consecutive events originating from the same source (eg. browser Wrap integrations)
131+
if (this._lastException && this._lastException === captureContext.hint?.originalException) {
132+
delete this._lastException;
133+
return;
134+
} else {
135+
this._lastException = captureContext.hint?.originalException;
136+
}
137+
128138
// TODO: This is broken. a) we dont pass event_id in hint anymore, b) its sync value assigned in async callback
129139
let eventId = captureContext.hint?.event_id;
130140
const scope = this._getEventScope(captureContext);
@@ -166,6 +176,14 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
166176
* @inheritDoc
167177
*/
168178
public captureEvent(event: SentryEvent, captureContext: CaptureContext = {}): string | undefined {
179+
// Drop two consecutive events originating from the same source (eg. browser Wrap integrations)
180+
if (this._lastException && this._lastException === captureContext.hint?.originalException) {
181+
delete this._lastException;
182+
return;
183+
} else {
184+
this._lastException = captureContext.hint?.originalException;
185+
}
186+
169187
let eventId = captureContext.hint?.event_id;
170188
const scope = this._getEventScope(captureContext);
171189

packages/integration-browser-globalhandlers/src/onerror.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ export class OnError implements Integration {
1919

2020
addInstrumentationHandler({
2121
callback: ({ msg, url, line, column, error }) => {
22-
// TODO: Restore this functinality based on some error metadata
23-
// if (shouldIgnoreOnError()) {
24-
// return;
25-
// }
26-
2722
if (error?.__sentry_own_request__) {
2823
return;
2924
}

packages/integration-browser-globalhandlers/src/onunhandledrejection.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ export class OnUnhandledRejection implements Integration {
3333
// no-empty
3434
}
3535

36-
// TODO: Restore this functinality based on some error metadata
37-
// if (shouldIgnoreOnError()) {
38-
// return;
39-
// }
40-
4136
if (error?.__sentry_own_request__) {
4237
return;
4338
}

packages/integration-browser-wrap/src/wrap.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ export function wrap(fn: WrappedFunction, mechanism?: Mechanism): any {
4848
// is expected behavior and NOT indicative of a bug with sentry.javascript.
4949
return fn.apply(this, wrappedArguments);
5050
} catch (ex) {
51-
// TODO: Fix ignoring next error (read metadata from the ex value itself like we do with `__sentry_own_request__`?)
52-
// ignoreNextOnError();
53-
5451
withScope(scope => {
5552
scope.addEventProcessor((event: SentryEvent) => {
5653
const processedEvent = { ...event };
@@ -68,7 +65,7 @@ export function wrap(fn: WrappedFunction, mechanism?: Mechanism): any {
6865
return processedEvent;
6966
});
7067

71-
captureException(ex);
68+
captureException(ex, { hint: { originalException: ex } });
7269
});
7370

7471
throw ex;

0 commit comments

Comments
 (0)
0