1+ import { Client } from '../client' ;
12import { InstrumentorMetadata } from '../types' ;
2- import { getPackageVersion } from '../attributes' ;
33import { AVAILABLE_INSTRUMENTORS } from './index' ;
44import { InstrumentationBase } from './base' ;
55
@@ -13,18 +13,18 @@ const debug = require('debug')('agentops:instrumentation:registry');
1313 * libraries are present, and provides methods to create and manage active instances.
1414 */
1515export class InstrumentationRegistry {
16+ private client : Client ;
1617 private instrumentors = new Map < string , typeof InstrumentationBase > ( ) ;
1718 private enabledInstrumentors = new Map < string , InstrumentationBase > ( ) ;
18- private readonly packageVersion : string ;
1919
2020 /**
2121 * Creates a new instrumentation registry.
2222 *
2323 * Automatically discovers and registers all available instrumentations
2424 * from the AVAILABLE_INSTRUMENTORS list.
2525 */
26- constructor ( ) {
27- this . packageVersion = getPackageVersion ( ) ;
26+ constructor ( client : Client ) {
27+ this . client = client ;
2828 }
2929
3030 /**
@@ -40,8 +40,7 @@ export class InstrumentationRegistry {
4040 if ( instrumentorClass . useRuntimeTargeting ) {
4141 const existingInstance = this . enabledInstrumentors . get ( instrumentorClass . identifier ) ;
4242 if ( ! existingInstance ) {
43- // TODO don't hardcode package name
44- const instance = this . createInstance ( instrumentorClass , 'agentops' ) ;
43+ const instance = this . createInstance ( instrumentorClass ) ;
4544 if ( instance ) {
4645 instance . setupRuntimeTargeting ( ) ;
4746 }
@@ -88,14 +87,14 @@ export class InstrumentationRegistry {
8887 * @param packageName - Name of the service/package being instrumented
8988 * @returns The created instrumentation instance, or null if creation failed
9089 */
91- private createInstance ( instrumentorClass : typeof InstrumentationBase , packageName : string ) : InstrumentationBase | undefined {
90+ private createInstance ( instrumentorClass : typeof InstrumentationBase ) : InstrumentationBase | undefined {
9291 const existingInstance = this . enabledInstrumentors . get ( instrumentorClass . identifier ) ;
9392 if ( existingInstance ) {
9493 return existingInstance ;
9594 }
9695
9796 try {
98- const instance = new ( instrumentorClass as any ) ( packageName , this . packageVersion , { } ) ;
97+ const instance = new ( instrumentorClass as any ) ( this . client ) ;
9998 this . enabledInstrumentors . set ( instrumentorClass . identifier , instance ) ;
10099 debug ( `instantiated ${ instrumentorClass . identifier } ` ) ;
101100 return instance ;
@@ -114,15 +113,15 @@ export class InstrumentationRegistry {
114113 * @param serviceName - Name of the service to create instrumentations for
115114 * @returns Array of active instrumentation instances
116115 */
117- getActiveInstrumentors ( serviceName : string ) : InstrumentationBase [ ] {
116+ getActiveInstrumentors ( ) : InstrumentationBase [ ] {
118117 const available : ( typeof InstrumentationBase ) [ ] = this . getAvailable ( ) ;
119118 const instrumentors : InstrumentationBase [ ] = [ ] ;
120119
121120 for ( const instrumentorClass of available ) {
122121 // Check if already enabled, otherwise create new instance
123122 let instrumentor = this . enabledInstrumentors . get ( instrumentorClass . identifier ) ;
124123 if ( ! instrumentor && instrumentorClass . available ) {
125- instrumentor = this . createInstance ( instrumentorClass , serviceName ) ;
124+ instrumentor = this . createInstance ( instrumentorClass ) ;
126125 }
127126
128127 if ( instrumentor ) {
0 commit comments