@@ -4,6 +4,7 @@ import { DEBUG_BUILD } from './debug-build';
44import type { Event , EventHint } from './types-hoist/event' ;
55import type { Integration , IntegrationFn } from './types-hoist/integration' ;
66import type { CoreOptions } from './types-hoist/options' ;
7+ import { StreamedSpanJSON } from './types-hoist/span' ;
78import { debug } from './utils/debug-logger' ;
89
910export const installedIntegrations : string [ ] = [ ] ;
@@ -138,15 +139,14 @@ export function setupIntegration(client: Client, integration: Integration, integ
138139 client . addEventProcessor ( processor ) ;
139140 }
140141
141- if ( typeof integration . processSpan === 'function' ) {
142- const callback = integration . processSpan . bind ( integration ) as typeof integration . processSpan ;
143- client . on ( 'processSpan' , span => callback ( span , client ) ) ;
144- }
145-
146- if ( typeof integration . processSegmentSpan === 'function' ) {
147- const callback = integration . processSegmentSpan . bind ( integration ) as typeof integration . processSegmentSpan ;
148- client . on ( 'processSegmentSpan' , span => callback ( span , client ) ) ;
149- }
142+ ( [ 'processSpan' , 'processSegmentSpan' ] as const ) . forEach ( hook => {
143+ const callback = integration [ hook ] ;
144+ if ( typeof callback === 'function' ) {
145+ // The cast is needed because TS can't resolve overloads when the discriminant is a union type.
146+ // Both overloads have the same callback signature so this is safe.
147+ client . on ( hook as 'processSpan' , ( span : StreamedSpanJSON ) => callback . call ( integration , span , client ) ) ;
148+ }
149+ } ) ;
150150
151151 DEBUG_BUILD && debug . log ( `Integration installed: ${ integration . name } ` ) ;
152152}
0 commit comments