File tree Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ import {
3737
3838import { getEnvelopeEndpointWithUrlEncodedAuth } from './api' ;
3939import { createEventEnvelope , createSessionEnvelope } from './envelope' ;
40- import { IntegrationIndex , setupIntegrations } from './integration' ;
40+ import { IntegrationIndex , setupIntegration , setupIntegrations } from './integration' ;
4141import { Scope } from './scope' ;
4242import { updateSession } from './session' ;
4343import { prepareEvent } from './utils/prepareEvent' ;
@@ -291,6 +291,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
291291 }
292292 }
293293
294+ /**
295+ * @inheritDoc
296+ */
297+ public addIntegration ( integration : Integration ) : void {
298+ setupIntegration ( integration , this . _integrations ) ;
299+ }
300+
294301 /**
295302 * @inheritDoc
296303 */
Original file line number Diff line number Diff line change @@ -88,14 +88,19 @@ export function setupIntegrations(integrations: Integration[]): IntegrationIndex
8888 const integrationIndex : IntegrationIndex = { } ;
8989
9090 integrations . forEach ( integration => {
91- integrationIndex [ integration . name ] = integration ;
92-
93- if ( installedIntegrations . indexOf ( integration . name ) === - 1 ) {
94- integration . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
95- installedIntegrations . push ( integration . name ) ;
96- __DEBUG_BUILD__ && logger . log ( `Integration installed: ${ integration . name } ` ) ;
97- }
91+ setupIntegration ( integration , integrationIndex ) ;
9892 } ) ;
9993
10094 return integrationIndex ;
10195}
96+
97+ /** Setup a single integration. */
98+ export function setupIntegration ( integration : Integration , integrationIndex : IntegrationIndex ) : void {
99+ integrationIndex [ integration . name ] = integration ;
100+
101+ if ( installedIntegrations . indexOf ( integration . name ) === - 1 ) {
102+ integration . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
103+ installedIntegrations . push ( integration . name ) ;
104+ __DEBUG_BUILD__ && logger . log ( `Integration installed: ${ integration . name } ` ) ;
105+ }
106+ }
Original file line number Diff line number Diff line change @@ -108,6 +108,16 @@ export interface Client<O extends ClientOptions = ClientOptions> {
108108 /** Returns the client's instance of the given integration class, it any. */
109109 getIntegration < T extends Integration > ( integration : IntegrationClass < T > ) : T | null ;
110110
111+ /**
112+ * Add an integration to the client.
113+ * This can be used to e.g. lazy load integrations.
114+ * In most cases, this should not be necessary, and you're better off just passing the integrations via `integrations: []` at initialization time.
115+ * However, if you find the need to conditionally load & add an integration, you can use `addIntegration` to do so.
116+ *
117+ * TODO (v8): Make this a required method.
118+ * */
119+ addIntegration ?( integration : Integration ) : void ;
120+
111121 /** This is an internal function to setup all integrations that should run on the client */
112122 setupIntegrations ( ) : void ;
113123
Original file line number Diff line number Diff line change @@ -222,7 +222,7 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
222222 */
223223 tracesSampler ?: ( samplingContext : SamplingContext ) => number | boolean ;
224224
225- // TODO v8 : Narrow the response type to `ErrorEvent` - this is technically a breaking change.
225+ // TODO (v8) : Narrow the response type to `ErrorEvent` - this is technically a breaking change.
226226 /**
227227 * An event-processing callback for error and message events, guaranteed to be invoked after all other event
228228 * processors, which allows an event to be modified or dropped.
@@ -236,7 +236,7 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
236236 */
237237 beforeSend ?: ( event : ErrorEvent , hint : EventHint ) => PromiseLike < Event | null > | Event | null ;
238238
239- // TODO v8 : Narrow the response type to `TransactionEvent` - this is technically a breaking change.
239+ // TODO (v8) : Narrow the response type to `TransactionEvent` - this is technically a breaking change.
240240 /**
241241 * An event-processing callback for transaction events, guaranteed to be invoked after all other event
242242 * processors. This allows an event to be modified or dropped before it's sent.
You can’t perform that action at this time.
0 commit comments