@@ -10,11 +10,13 @@ import {
10
10
MAX_SESSION_LIFE ,
11
11
REPLAY_EVENT_NAME ,
12
12
SESSION_IDLE_DURATION ,
13
+ UNABLE_TO_SEND_REPLAY ,
13
14
VISIBILITY_CHANGE_TIMEOUT ,
14
15
WINDOW ,
15
16
} from './constants' ;
16
17
import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler' ;
17
18
import { handleFetchSpanListener } from './coreHandlers/handleFetch' ;
19
+ import { handleGlobalEventListener } from './coreHandlers/handleGlobalEvent' ;
18
20
import { handleHistorySpanListener } from './coreHandlers/handleHistory' ;
19
21
import { handleXhrSpanListener } from './coreHandlers/handleXhr' ;
20
22
import { createMemoryEntry , createPerformanceEntries , ReplayPerformanceEntry } from './createPerformanceEntry' ;
@@ -33,7 +35,6 @@ import type {
33
35
ReplayPluginOptions ,
34
36
SendReplay ,
35
37
} from './types' ;
36
- import { addInternalBreadcrumb } from './util/addInternalBreadcrumb' ;
37
38
import { captureInternalException } from './util/captureInternalException' ;
38
39
import { createBreadcrumb } from './util/createBreadcrumb' ;
39
40
import { createPayload } from './util/createPayload' ;
@@ -49,7 +50,6 @@ type AddUpdateCallback = () => boolean | void;
49
50
50
51
const BASE_RETRY_INTERVAL = 5000 ;
51
52
const MAX_RETRY_COUNT = 3 ;
52
- const UNABLE_TO_SEND_REPLAY = 'Unable to send Replay' ;
53
53
54
54
export class ReplayContainer {
55
55
public eventBuffer : EventBuffer | null = null ;
@@ -321,7 +321,7 @@ export class ReplayContainer {
321
321
322
322
// Tag all (non replay) events that get sent to Sentry with the current
323
323
// replay ID so that we can reference them later in the UI
324
- addGlobalEventProcessor ( this . handleGlobalEvent ) ;
324
+ addGlobalEventProcessor ( handleGlobalEventListener ( this ) ) ;
325
325
326
326
this . _hasInitializedCoreListeners = true ;
327
327
}
@@ -412,72 +412,6 @@ export class ReplayContainer {
412
412
this . _debouncedFlush ( ) ;
413
413
}
414
414
415
- /**
416
- * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
417
- * events as a tag. Also handles the case where we only want to capture a reply
418
- * when an error occurs.
419
- **/
420
- handleGlobalEvent : ( event : Event ) => Event = ( event : Event ) => {
421
- // Do not apply replayId to the root event
422
- if (
423
- // @ts -ignore new event type
424
- event . type === REPLAY_EVENT_NAME
425
- ) {
426
- // Replays have separate set of breadcrumbs, do not include breadcrumbs
427
- // from core SDK
428
- delete event . breadcrumbs ;
429
- return event ;
430
- }
431
-
432
- // Only tag transactions with replayId if not waiting for an error
433
- if ( event . type !== 'transaction' || ! this . _waitForError ) {
434
- event . tags = { ...event . tags , replayId : this . session ?. id } ;
435
- }
436
-
437
- // Collect traceIds in _context regardless of `_waitForError` - if it's true,
438
- // _context gets cleared on every checkout
439
- if ( event . type === 'transaction' ) {
440
- this . _context . traceIds . add ( String ( event . contexts ?. trace ?. trace_id || '' ) ) ;
441
- return event ;
442
- }
443
-
444
- // XXX: Is it safe to assume that all other events are error events?
445
- // @ts -ignore: Type 'undefined' is not assignable to type 'string'.ts(2345)
446
- this . _context . errorIds . add ( event . event_id ) ;
447
-
448
- const exc = event . exception ?. values ?. [ 0 ] ;
449
- addInternalBreadcrumb ( {
450
- message : `Tagging event (${ event . event_id } ) - ${ event . message } - ${ exc ?. type || 'Unknown' } : ${
451
- exc ?. value || 'n/a'
452
- } `,
453
- } ) ;
454
-
455
- // Need to be very careful that this does not cause an infinite loop
456
- if (
457
- this . _waitForError &&
458
- event . exception &&
459
- event . message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
460
- ) {
461
- setTimeout ( async ( ) => {
462
- // Allow flush to complete before resuming as a session recording, otherwise
463
- // the checkout from `startRecording` may be included in the payload.
464
- // Prefer to keep the error replay as a separate (and smaller) segment
465
- // than the session replay.
466
- await this . flushImmediate ( ) ;
467
-
468
- if ( this . _stopRecording ) {
469
- this . _stopRecording ( ) ;
470
- // Reset all "capture on error" configuration before
471
- // starting a new recording
472
- this . _waitForError = false ;
473
- this . startRecording ( ) ;
474
- }
475
- } ) ;
476
- }
477
-
478
- return event ;
479
- } ;
480
-
481
415
/**
482
416
* Handler for recording events.
483
417
*
0 commit comments