@@ -5,10 +5,26 @@ import * as moduleModule from 'module';
55import { supportsEsmLoaderHooks } from '../utils/detection' ;
66
77let instrumentationConfigs : InstrumentationConfig [ ] | undefined ;
8- let setupHookFn : ( ( ) => void ) | undefined ;
98
10- function setupHook ( ) : void {
11- if ( ! GLOBAL_OBJ . _sentryInjectLoaderHookRegistered ) {
9+ /**
10+ * Add an instrumentation config to be used by the injection loader.
11+ */
12+ export function addInstrumentationConfig ( config : InstrumentationConfig ) : void {
13+ if ( ! supportsEsmLoaderHooks ( ) ) {
14+ return ;
15+ }
16+
17+ if ( ! instrumentationConfigs ) {
18+ instrumentationConfigs = [ ] ;
19+ }
20+
21+ instrumentationConfigs . push ( config ) ;
22+
23+ GLOBAL_OBJ . _sentryInjectLoaderHookRegister = ( ) => {
24+ if ( GLOBAL_OBJ . _sentryInjectLoaderHookRegistered ) {
25+ return ;
26+ }
27+
1228 GLOBAL_OBJ . _sentryInjectLoaderHookRegistered = true ;
1329
1430 const instrumentations = instrumentationConfigs || [ ] ;
@@ -29,37 +45,5 @@ function setupHook(): void {
2945 } catch ( error ) {
3046 debug . warn ( "Failed to register '@apm-js-collab/tracing-hooks' hook" , error ) ;
3147 }
32- }
33- }
34-
35- /**
36- * Add an instrumentation config to be used by the injection loader.
37- *
38- * This should be called before `initializeInjectionLoader` is called.
39- */
40- export function addInstrumentationConfig ( config : InstrumentationConfig ) : void {
41- if ( ! instrumentationConfigs ) {
42- instrumentationConfigs = [ ] ;
43- }
44-
45- instrumentationConfigs . push ( config ) ;
46-
47- setupHookFn = setupHook ;
48- }
49-
50- /**
51- * Initialize the injection loader - This method is private and not part of the public
52- * API.
53- *
54- * @ignore
55- */
56- export function initializeInjectionLoader ( ) : void {
57- if ( ! supportsEsmLoaderHooks ( ) ) {
58- return ;
59- }
60-
61- if ( setupHookFn ) {
62- setupHookFn ( ) ;
63- setupHookFn = undefined ;
64- }
48+ } ;
6549}
0 commit comments