File tree 3 files changed +28
-8
lines changed 3 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ import {
37
37
38
38
import { getEnvelopeEndpointWithUrlEncodedAuth } from './api' ;
39
39
import { createEventEnvelope , createSessionEnvelope } from './envelope' ;
40
- import { IntegrationIndex , setupIntegrations } from './integration' ;
40
+ import { IntegrationIndex , setupIntegration , setupIntegrations } from './integration' ;
41
41
import { Scope } from './scope' ;
42
42
import { updateSession } from './session' ;
43
43
import { prepareEvent } from './utils/prepareEvent' ;
@@ -291,6 +291,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
291
291
}
292
292
}
293
293
294
+ /**
295
+ * @inheritDoc
296
+ */
297
+ public addIntegration ( integration : Integration ) : void {
298
+ setupIntegration ( integration , this . _integrations ) ;
299
+ }
300
+
294
301
/**
295
302
* @inheritDoc
296
303
*/
Original file line number Diff line number Diff line change @@ -88,14 +88,19 @@ export function setupIntegrations(integrations: Integration[]): IntegrationIndex
88
88
const integrationIndex : IntegrationIndex = { } ;
89
89
90
90
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 ) ;
98
92
} ) ;
99
93
100
94
return integrationIndex ;
101
95
}
96
+
97
+ /** Setup a single integration. */
98
+ export function setupIntegration ( integration : Integration , integrationIndex : IntegrationIndex ) : void {
99
+ if ( installedIntegrations . indexOf ( integration . name ) === - 1 ) {
100
+ integrationIndex [ integration . name ] = integration ;
101
+
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,14 @@ export interface Client<O extends ClientOptions = ClientOptions> {
108
108
/** Returns the client's instance of the given integration class, it any. */
109
109
getIntegration < T extends Integration > ( integration : IntegrationClass < T > ) : T | null ;
110
110
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
+ addIntegration ?( integration : Integration ) : void ;
118
+
111
119
/** This is an internal function to setup all integrations that should run on the client */
112
120
setupIntegrations ( ) : void ;
113
121
You can’t perform that action at this time.
0 commit comments