@@ -9,62 +9,55 @@ import { debug } from './utils/debug-logger';
99export const installedIntegrations : string [ ] = [ ] ;
1010
1111/**
12- * Registry to track disabled integrations.
12+ * Registry to track integrations marked as disabled .
1313 * This is used to prevent duplicate instrumentation when higher-level integrations
1414 * (like LangChain) already instrument the underlying libraries (like OpenAI, Anthropic, etc.)
1515 */
16- const DISABLED_INTEGRATIONS = new Set < string > ( ) ;
16+ const MARKED_DISABLED_INTEGRATIONS = new Set < string > ( ) ;
1717
1818/**
1919 * Mark one or more integrations as disabled to prevent their instrumentation from being set up.
20- * @param integrationName The name(s) of the integration(s) to disable
20+ * This should be called during an integration's setupOnce() phase.
21+ * The marked integrations will be skipped when their own setupOnce() is called.
22+ *
23+ * @internal This is an internal API for coordination between integrations, not for public use.
24+ * @param integrationName The name(s) of the integration(s) to mark as disabled
2125 */
22- export function disableIntegrations ( integrationName : string | string [ ] ) : void {
26+ export function _markIntegrationsDisabled ( integrationName : string | string [ ] ) : void {
2327 if ( Array . isArray ( integrationName ) ) {
24- integrationName . forEach ( name => DISABLED_INTEGRATIONS . add ( name ) ) ;
28+ integrationName . forEach ( name => MARKED_DISABLED_INTEGRATIONS . add ( name ) ) ;
2529 } else {
26- DISABLED_INTEGRATIONS . add ( integrationName ) ;
30+ MARKED_DISABLED_INTEGRATIONS . add ( integrationName ) ;
2731 }
2832}
2933
3034/**
31- * Check if an integration has been disabled.
35+ * Check if an integration has been marked as disabled.
36+ *
37+ * @internal This is an internal API for coordination between integrations, not for public use.
3238 * @param integrationName The name of the integration to check
33- * @returns true if the integration is disabled
34- */
35- export function isIntegrationDisabled ( integrationName : string ) : boolean {
36- return DISABLED_INTEGRATIONS . has ( integrationName ) ;
37- }
38-
39- /**
40- * Remove one or more integrations from the disabled list.
41- * @param integrationName The name(s) of the integration(s) to enable
39+ * @returns true if the integration is marked as disabled
4240 */
43- export function enableIntegration ( integrationName : string | string [ ] ) : void {
44- if ( Array . isArray ( integrationName ) ) {
45- integrationName . forEach ( name => DISABLED_INTEGRATIONS . delete ( name ) ) ;
46- } else {
47- DISABLED_INTEGRATIONS . delete ( integrationName ) ;
48- }
41+ export function _isIntegrationMarkedDisabled ( integrationName : string ) : boolean {
42+ return MARKED_DISABLED_INTEGRATIONS . has ( integrationName ) ;
4943}
5044
5145/**
52- * Clear all disabled integrations.
53- * This is automatically called during Sentry.init() to ensure a clean state.
46+ * Clear all integration marks and remove marked integrations from the installed list.
47+ * This is automatically called at the start of Sentry.init() to ensure a clean state
48+ * between different client initializations.
5449 *
55- * This also removes the disabled integrations from the global installedIntegrations list,
50+ * This also removes the marked integrations from the global installedIntegrations list,
5651 * allowing them to run setupOnce() again if they're included in a new client.
52+ *
53+ * @internal This is an internal API for coordination between integrations, not for public use.
5754 */
58- export function clearDisabledIntegrations ( ) : void {
59- // Remove disabled integrations from the installed list so they can setup again
60- DISABLED_INTEGRATIONS . forEach ( integrationName => {
61- const index = installedIntegrations . indexOf ( integrationName ) ;
62- if ( index !== - 1 ) {
63- installedIntegrations . splice ( index , 1 ) ;
64- }
65- } ) ;
55+ export function _clearDisabledIntegrationsMarks ( ) : void {
56+ // Remove marked integrations from the installed list so they can setup again
57+ const filtered = installedIntegrations . filter ( integration => ! MARKED_DISABLED_INTEGRATIONS . has ( integration ) ) ;
58+ installedIntegrations . splice ( 0 , installedIntegrations . length , ...filtered ) ;
6659
67- DISABLED_INTEGRATIONS . clear ( ) ;
60+ MARKED_DISABLED_INTEGRATIONS . clear ( ) ;
6861}
6962
7063/** Map of integrations assigned to a client */
@@ -166,9 +159,9 @@ export function setupIntegration(client: Client, integration: Integration, integ
166159 integrationIndex [ integration . name ] = integration ;
167160
168161 // `setupOnce` is only called the first time
169- if ( installedIntegrations . indexOf ( integration . name ) === - 1 && typeof integration . setupOnce === 'function' ) {
170- // Skip setup if integration is disabled
171- if ( ! isIntegrationDisabled ( integration . name ) ) {
162+ if ( ! installedIntegrations . includes ( integration . name ) && typeof integration . setupOnce === 'function' ) {
163+ // Skip setup if integration is marked as disabled
164+ if ( ! _isIntegrationMarkedDisabled ( integration . name ) ) {
172165 integration . setupOnce ( ) ;
173166 installedIntegrations . push ( integration . name ) ;
174167 }
0 commit comments