MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / setupIntegration

Function setupIntegration

packages/core/src/integration.ts:109–152  ·  view source on GitHub ↗
(client: Client, integration: Integration, integrationIndex: IntegrationIndex)

Source from the content-addressed store, hash-verified

107
108/** Setup a single integration. */
109export function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {
110 if (integrationIndex[integration.name]) {
111 DEBUG_BUILD && debug.log(`Integration skipped because it was already installed: ${integration.name}`);
112 return;
113 }
114 integrationIndex[integration.name] = integration;
115
116 // `setupOnce` is only called the first time
117 if (!installedIntegrations.includes(integration.name) && typeof integration.setupOnce === 'function') {
118 integration.setupOnce();
119 installedIntegrations.push(integration.name);
120 }
121
122 // `setup` is run for each client
123 if (integration.setup && typeof integration.setup === 'function') {
124 integration.setup(client);
125 }
126
127 if (typeof integration.preprocessEvent === 'function') {
128 const callback = integration.preprocessEvent.bind(integration) as typeof integration.preprocessEvent;
129 client.on('preprocessEvent', (event, hint) => callback(event, hint, client));
130 }
131
132 if (typeof integration.processEvent === 'function') {
133 const callback = integration.processEvent.bind(integration) as typeof integration.processEvent;
134
135 const processor = Object.assign((event: Event, hint: EventHint) => callback(event, hint, client), {
136 id: integration.name,
137 });
138
139 client.addEventProcessor(processor);
140 }
141
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 });
150
151 DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);
152}
153
154/** Add an integration to the current scope's client. */
155export function addIntegration(integration: Integration): void {

Callers 3

addIntegrationFunction · 0.90
setupIntegrationsFunction · 0.70

Calls 11

pushMethod · 0.80
bindMethod · 0.80
assignMethod · 0.80
addEventProcessorMethod · 0.80
callMethod · 0.80
logMethod · 0.65
setupOnceMethod · 0.65
setupMethod · 0.65
onMethod · 0.65
forEachMethod · 0.65
callbackFunction · 0.50

Tested by

no test coverage detected