|
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, DataCategory, Event, EventDropReason } from '@sentry/types'; |
| 3 | +import { Breadcrumb, Client, Event } 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';
|
@@ -39,6 +39,7 @@ import { createPayload } from './util/createPayload';
|
39 | 39 | import { dedupePerformanceEntries } from './util/dedupePerformanceEntries';
|
40 | 40 | import { isExpired } from './util/isExpired';
|
41 | 41 | import { isSessionExpired } from './util/isSessionExpired';
|
| 42 | +import { overwriteRecordDroppedEvent, restoreRecordDroppedEvent } from './util/monkeyPatchRecordDroppedEvent'; |
42 | 43 |
|
43 | 44 | /**
|
44 | 45 | * Returns true to return control to calling function, otherwise continue with normal batching
|
@@ -108,11 +109,6 @@ export class ReplayContainer {
|
108 | 109 | */
|
109 | 110 | private _stopRecording: ReturnType<typeof record> | null = null;
|
110 | 111 |
|
111 |
| - /** |
112 |
| - * We overwrite `client.recordDroppedEvent`, but store the original method here so we can restore it. |
113 |
| - */ |
114 |
| - private _originalRecordDroppedEvent?: Client['recordDroppedEvent']; |
115 |
| - |
116 | 112 | private _context: InternalEventContext = {
|
117 | 113 | errorIds: new Set(),
|
118 | 114 | traceIds: new Set(),
|
@@ -310,7 +306,7 @@ export class ReplayContainer {
|
310 | 306 | WINDOW.addEventListener('focus', this.handleWindowFocus);
|
311 | 307 |
|
312 | 308 | // We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
|
313 |
| - this._overwriteRecordDroppedEvent(); |
| 309 | + overwriteRecordDroppedEvent(this._context.errorIds); |
314 | 310 |
|
315 | 311 | // There is no way to remove these listeners, so ensure they are only added once
|
316 | 312 | if (!this._hasInitializedCoreListeners) {
|
@@ -374,7 +370,7 @@ export class ReplayContainer {
|
374 | 370 | WINDOW.removeEventListener('blur', this.handleWindowBlur);
|
375 | 371 | WINDOW.removeEventListener('focus', this.handleWindowFocus);
|
376 | 372 |
|
377 |
| - this._restoreRecordDroppedEvent(); |
| 373 | + restoreRecordDroppedEvent(); |
378 | 374 |
|
379 | 375 | if (this._performanceObserver) {
|
380 | 376 | this._performanceObserver.disconnect();
|
@@ -1249,39 +1245,4 @@ export class ReplayContainer {
|
1249 | 1245 | saveSession(this.session);
|
1250 | 1246 | }
|
1251 | 1247 | }
|
1252 |
| - |
1253 |
| - private _overwriteRecordDroppedEvent(): void { |
1254 |
| - const client = getCurrentHub().getClient(); |
1255 |
| - |
1256 |
| - if (!client) { |
1257 |
| - return; |
1258 |
| - } |
1259 |
| - |
1260 |
| - const _originalCallback = client.recordDroppedEvent.bind(client); |
1261 |
| - |
1262 |
| - const recordDroppedEvent: Client['recordDroppedEvent'] = ( |
1263 |
| - reason: EventDropReason, |
1264 |
| - category: DataCategory, |
1265 |
| - event?: Event, |
1266 |
| - ): void => { |
1267 |
| - if (event && event.event_id) { |
1268 |
| - this._context.errorIds.delete(event.event_id); |
1269 |
| - } |
1270 |
| - |
1271 |
| - return _originalCallback(reason, category, event); |
1272 |
| - }; |
1273 |
| - |
1274 |
| - client.recordDroppedEvent = recordDroppedEvent; |
1275 |
| - this._originalRecordDroppedEvent = _originalCallback; |
1276 |
| - } |
1277 |
| - |
1278 |
| - private _restoreRecordDroppedEvent(): void { |
1279 |
| - const client = getCurrentHub().getClient(); |
1280 |
| - |
1281 |
| - if (!client || !this._originalRecordDroppedEvent) { |
1282 |
| - return; |
1283 |
| - } |
1284 |
| - |
1285 |
| - client.recordDroppedEvent = this._originalRecordDroppedEvent; |
1286 |
| - } |
1287 | 1248 | }
|
0 commit comments