11import type { BaseClient } from '@sentry/core' ;
22import { addGlobalEventProcessor , getCurrentHub } from '@sentry/core' ;
3+ import type { Client , DynamicSamplingContext } from '@sentry/types' ;
34import { addInstrumentationHandler } from '@sentry/utils' ;
45
56import { handleAfterSendEvent } from '../coreHandlers/handleAfterSendEvent' ;
@@ -25,15 +26,23 @@ export function addGlobalListeners(replay: ReplayContainer): void {
2526 addInstrumentationHandler ( 'history' , handleHistorySpanListener ( replay ) ) ;
2627 handleNetworkBreadcrumbs ( replay ) ;
2728
28- // If a custom client has no hooks yet, we continue to use the "old" implementation
29- const hasHooks = ! ! ( client && client . on ) ;
30-
3129 // Tag all (non replay) events that get sent to Sentry with the current
3230 // replay ID so that we can reference them later in the UI
33- addGlobalEventProcessor ( handleGlobalEventListener ( replay , ! hasHooks ) ) ;
31+ addGlobalEventProcessor ( handleGlobalEventListener ( replay , ! hasHooks ( client ) ) ) ;
3432
35- if ( hasHooks ) {
36- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37- ( client as BaseClient < any > ) . on ( 'afterSendEvent' , handleAfterSendEvent ( replay ) ) ;
33+ // If a custom client has no hooks yet, we continue to use the "old" implementation
34+ if ( hasHooks ( client ) ) {
35+ client . on ( 'afterSendEvent' , handleAfterSendEvent ( replay ) ) ;
36+ client . on ( 'createDsc' , ( dsc : DynamicSamplingContext ) => {
37+ const replayId = replay . getSessionId ( ) ;
38+ if ( replayId ) {
39+ dsc . replay_id = replayId ;
40+ }
41+ } ) ;
3842 }
3943}
44+
45+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46+ function hasHooks ( client : Client | undefined ) : client is BaseClient < any > {
47+ return ! ! ( client && client . on ) ;
48+ }
0 commit comments