Skip to content

Commit c216b99

Browse files
committed
slightly reduce bundle size
1 parent 5c44e55 commit c216b99

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

packages/core/src/integration.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DEBUG_BUILD } from './debug-build';
44
import type { Event, EventHint } from './types-hoist/event';
55
import type { Integration, IntegrationFn } from './types-hoist/integration';
66
import type { CoreOptions } from './types-hoist/options';
7+
import { StreamedSpanJSON } from './types-hoist/span';
78
import { debug } from './utils/debug-logger';
89

910
export 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

Comments
 (0)