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