|
1 | 1 | /* eslint-disable max-lines */ // TODO: We might want to split this file up
|
2 | 2 | import { addGlobalEventProcessor, getCurrentHub, Scope, setContext } from '@sentry/core';
|
3 |
| -import { Breadcrumb, Client, Event, Integration } from '@sentry/types'; |
| 3 | +import { Breadcrumb, Client, DataCategory, Event, EventDropReason, Integration } from '@sentry/types'; |
4 | 4 | import { addInstrumentationHandler, createEnvelope } from '@sentry/utils';
|
5 | 5 | import debounce from 'lodash.debounce';
|
6 | 6 | import { PerformanceObserverEntryList } from 'perf_hooks';
|
@@ -125,6 +125,11 @@ export class Replay implements Integration {
|
125 | 125 | */
|
126 | 126 | private stopRecording: ReturnType<typeof record> | null = null;
|
127 | 127 |
|
| 128 | + /** |
| 129 | + * We overwrite `client.recordDroppedEvent`, but store the original method here so we can restore it. |
| 130 | + */ |
| 131 | + private _originalRecordDroppedEvent?: Client['recordDroppedEvent']; |
| 132 | + |
128 | 133 | private context: InternalEventContext = {
|
129 | 134 | errorIds: new Set(),
|
130 | 135 | traceIds: new Set(),
|
@@ -433,6 +438,8 @@ export class Replay implements Integration {
|
433 | 438 | // Tag all (non replay) events that get sent to Sentry with the current
|
434 | 439 | // replay ID so that we can reference them later in the UI
|
435 | 440 | addGlobalEventProcessor(this.handleGlobalEvent);
|
| 441 | + // We need to filter out dropped events |
| 442 | + this._overwriteRecordDroppedEvent(); |
436 | 443 |
|
437 | 444 | this.hasInitializedCoreListeners = true;
|
438 | 445 | }
|
@@ -482,6 +489,8 @@ export class Replay implements Integration {
|
482 | 489 | window.removeEventListener('blur', this.handleWindowBlur);
|
483 | 490 | window.removeEventListener('focus', this.handleWindowFocus);
|
484 | 491 |
|
| 492 | + this._restoreRecordDroppedEvent(); |
| 493 | + |
485 | 494 | if (this.performanceObserver) {
|
486 | 495 | this.performanceObserver.disconnect();
|
487 | 496 | this.performanceObserver = null;
|
@@ -1343,4 +1352,39 @@ export class Replay implements Integration {
|
1343 | 1352 | });
|
1344 | 1353 | }
|
1345 | 1354 | }
|
| 1355 | + |
| 1356 | + _overwriteRecordDroppedEvent(): void { |
| 1357 | + const client = getCurrentHub().getClient(); |
| 1358 | + |
| 1359 | + if (!client) { |
| 1360 | + return; |
| 1361 | + } |
| 1362 | + |
| 1363 | + const _originalCallback = client.recordDroppedEvent.bind(client); |
| 1364 | + |
| 1365 | + const recordDroppedEvent: Client['recordDroppedEvent'] = ( |
| 1366 | + reason: EventDropReason, |
| 1367 | + category: DataCategory, |
| 1368 | + event?: Event, |
| 1369 | + ): void => { |
| 1370 | + if (event && event.event_id) { |
| 1371 | + this.context.errorIds.delete(event.event_id); |
| 1372 | + } |
| 1373 | + |
| 1374 | + return _originalCallback(reason, category, event); |
| 1375 | + }; |
| 1376 | + |
| 1377 | + client.recordDroppedEvent = recordDroppedEvent; |
| 1378 | + this._originalRecordDroppedEvent = _originalCallback; |
| 1379 | + } |
| 1380 | + |
| 1381 | + _restoreRecordDroppedEvent(): void { |
| 1382 | + const client = getCurrentHub().getClient(); |
| 1383 | + |
| 1384 | + if (!client || !this._originalRecordDroppedEvent) { |
| 1385 | + return; |
| 1386 | + } |
| 1387 | + |
| 1388 | + client.recordDroppedEvent = this._originalRecordDroppedEvent; |
| 1389 | + } |
1346 | 1390 | }
|
0 commit comments