3535from agentops .logging import logger
3636from agentops .sdk .core import tracer
3737
38-
39- # Define the structure for instrumentor configurations
40- class InstrumentorConfig (TypedDict ):
41- module_name : str
42- class_name : str
43- min_version : str
44- package_name : NotRequired [str ] # Optional: actual pip package name if different from module
45-
46-
47- # Configuration for supported LLM providers
48- PROVIDERS : dict [str , InstrumentorConfig ] = {
49- "openai" : {
50- "module_name" : "agentops.instrumentation.openai" ,
51- "class_name" : "OpenAIInstrumentor" ,
52- "min_version" : "1.0.0" ,
53- },
54- "anthropic" : {
55- "module_name" : "agentops.instrumentation.anthropic" ,
56- "class_name" : "AnthropicInstrumentor" ,
57- "min_version" : "0.32.0" ,
58- },
59- "ibm_watsonx_ai" : {
60- "module_name" : "agentops.instrumentation.ibm_watsonx_ai" ,
61- "class_name" : "IBMWatsonXInstrumentor" ,
62- "min_version" : "0.1.0" ,
63- },
64- "google.genai" : {
65- "module_name" : "agentops.instrumentation.google_genai" ,
66- "class_name" : "GoogleGenAIInstrumentor" ,
67- "min_version" : "0.1.0" ,
68- "package_name" : "google-genai" , # Actual pip package name
69- },
70- "mem0" : {
71- "module_name" : "agentops.instrumentation.mem0" ,
72- "class_name" : "Mem0Instrumentor" ,
73- "min_version" : "0.1.0" ,
74- "package_name" : "mem0ai" , # Actual pip package name
75- },
76- }
77-
78- # Configuration for utility instrumentors
79- UTILITY_INSTRUMENTORS : dict [str , InstrumentorConfig ] = {
80- "concurrent.futures" : {
81- "module_name" : "agentops.instrumentation.concurrent_futures" ,
82- "class_name" : "ConcurrentFuturesInstrumentor" ,
83- "min_version" : "3.7.0" , # Python 3.7+ (concurrent.futures is stdlib)
84- "package_name" : "python" , # Special case for stdlib modules
85- },
86- }
87-
88- # Configuration for supported agentic libraries
89- AGENTIC_LIBRARIES : dict [str , InstrumentorConfig ] = {
90- "crewai" : {
91- "module_name" : "agentops.instrumentation.crewai" ,
92- "class_name" : "CrewAIInstrumentor" ,
93- "min_version" : "0.56.0" ,
94- },
95- "autogen" : {"module_name" : "agentops.instrumentation.ag2" , "class_name" : "AG2Instrumentor" , "min_version" : "0.1.0" },
96- "agents" : {
97- "module_name" : "agentops.instrumentation.openai_agents" ,
98- "class_name" : "OpenAIAgentsInstrumentor" ,
99- "min_version" : "0.0.1" ,
100- },
101- "google.adk" : {
102- "module_name" : "agentops.instrumentation.google_adk" ,
103- "class_name" : "GoogleADKInstrumentor" ,
104- "min_version" : "0.1.0" ,
105- },
106- }
107-
108- # Combine all target packages for monitoring
109- TARGET_PACKAGES = set (PROVIDERS .keys ()) | set (AGENTIC_LIBRARIES .keys ()) | set (UTILITY_INSTRUMENTORS .keys ())
110-
111- # Create a single instance of the manager
112- # _manager = InstrumentationManager() # Removed
113-
11438# Module-level state variables
11539_active_instrumentors : list [BaseInstrumentor ] = []
11640_original_builtins_import = builtins .__import__ # Store original import
@@ -125,16 +49,6 @@ def _is_installed_package(module_obj: ModuleType, package_name_key: str) -> bool
12549 rather than a local module, especially when names might collide.
12650 `package_name_key` is the key from TARGET_PACKAGES (e.g., 'agents', 'google.adk').
12751 """
128- # Special case for stdlib modules (marked with package_name="python" in UTILITY_INSTRUMENTORS)
129- if (
130- package_name_key in UTILITY_INSTRUMENTORS
131- and UTILITY_INSTRUMENTORS [package_name_key ].get ("package_name" ) == "python"
132- ):
133- logger .debug (
134- f"_is_installed_package: Module '{ package_name_key } ' is a Python standard library module. Considering it an installed package."
135- )
136- return True
137-
13852 if not hasattr (module_obj , "__file__" ) or not module_obj .__file__ :
13953 logger .debug (
14054 f"_is_installed_package: Module '{ package_name_key } ' has no __file__, assuming it might be an SDK namespace package. Returning True."
@@ -227,7 +141,7 @@ def _uninstrument_providers():
227141def _should_instrument_package (package_name : str ) -> bool :
228142 """
229143 Determine if a package should be instrumented based on current state.
230- Handles special cases for agentic libraries, providers, and utility instrumentors .
144+ Handles special cases for agentic libraries and providers .
231145 """
232146 global _has_agentic_library
233147
@@ -236,12 +150,6 @@ def _should_instrument_package(package_name: str) -> bool:
236150 logger .debug (f"_should_instrument_package: '{ package_name } ' already instrumented by AgentOps. Skipping." )
237151 return False
238152
239- # Utility instrumentors should always be instrumented regardless of agentic library state
240- if package_name in UTILITY_INSTRUMENTORS :
241- logger .debug (f"_should_instrument_package: '{ package_name } ' is a utility instrumentor. Always allowing." )
242- return True
243-
244- # Only apply agentic/provider logic if it's NOT a utility instrumentor
245153 is_target_agentic = package_name in AGENTIC_LIBRARIES
246154 is_target_provider = package_name in PROVIDERS
247155
@@ -290,18 +198,14 @@ def _perform_instrumentation(package_name: str):
290198 return
291199
292200 # Get the appropriate configuration for the package
293- # Ensure package_name is a key in either PROVIDERS, AGENTIC_LIBRARIES, or UTILITY_INSTRUMENTORS
294- if (
295- package_name not in PROVIDERS
296- and package_name not in AGENTIC_LIBRARIES
297- and package_name not in UTILITY_INSTRUMENTORS
298- ):
201+ # Ensure package_name is a key in either PROVIDERS or AGENTIC_LIBRARIES
202+ if package_name not in PROVIDERS and package_name not in AGENTIC_LIBRARIES :
299203 logger .debug (
300- f"_perform_instrumentation: Package '{ package_name } ' not found in PROVIDERS, AGENTIC_LIBRARIES, or UTILITY_INSTRUMENTORS . Skipping."
204+ f"_perform_instrumentation: Package '{ package_name } ' not found in PROVIDERS or AGENTIC_LIBRARIES . Skipping."
301205 )
302206 return
303207
304- config = PROVIDERS .get (package_name ) or AGENTIC_LIBRARIES . get ( package_name ) or UTILITY_INSTRUMENTORS [package_name ]
208+ config = PROVIDERS .get (package_name ) or AGENTIC_LIBRARIES [package_name ]
305209 loader = InstrumentorLoader (** config )
306210
307211 # instrument_one already checks loader.should_activate
@@ -423,6 +327,69 @@ def _import_monitor(name: str, globals_dict=None, locals_dict=None, fromlist=(),
423327 return module
424328
425329
330+ # Define the structure for instrumentor configurations
331+ class InstrumentorConfig (TypedDict ):
332+ module_name : str
333+ class_name : str
334+ min_version : str
335+ package_name : NotRequired [str ] # Optional: actual pip package name if different from module
336+
337+
338+ # Configuration for supported LLM providers
339+ PROVIDERS : dict [str , InstrumentorConfig ] = {
340+ "openai" : {
341+ "module_name" : "agentops.instrumentation.openai" ,
342+ "class_name" : "OpenAIInstrumentor" ,
343+ "min_version" : "1.0.0" ,
344+ "package_name" : "openai" , # Actual pip package name
345+ },
346+ "anthropic" : {
347+ "module_name" : "agentops.instrumentation.anthropic" ,
348+ "class_name" : "AnthropicInstrumentor" ,
349+ "min_version" : "0.32.0" ,
350+ "package_name" : "anthropic" , # Actual pip package name
351+ },
352+ "ibm_watsonx_ai" : {
353+ "module_name" : "agentops.instrumentation.ibm_watsonx_ai" ,
354+ "class_name" : "IBMWatsonXInstrumentor" ,
355+ "min_version" : "0.1.0" ,
356+ "package_name" : "ibm-watsonx-ai" , # Actual pip package name
357+ },
358+ "google.genai" : {
359+ "module_name" : "agentops.instrumentation.google_genai" ,
360+ "class_name" : "GoogleGenAIInstrumentor" ,
361+ "min_version" : "0.1.0" ,
362+ "package_name" : "google-genai" , # Actual pip package name
363+ },
364+ }
365+
366+ # Configuration for supported agentic libraries
367+ AGENTIC_LIBRARIES : dict [str , InstrumentorConfig ] = {
368+ "crewai" : {
369+ "module_name" : "agentops.instrumentation.crewai" ,
370+ "class_name" : "CrewAIInstrumentor" ,
371+ "min_version" : "0.56.0" ,
372+ "package_name" : "crewai" , # Actual pip package name
373+ },
374+ "autogen" : {"module_name" : "agentops.instrumentation.ag2" , "class_name" : "AG2Instrumentor" , "min_version" : "0.1.0" },
375+ "agents" : {
376+ "module_name" : "agentops.instrumentation.openai_agents" ,
377+ "class_name" : "OpenAIAgentsInstrumentor" ,
378+ "min_version" : "0.0.1" ,
379+ "package_name" : "openai-agents" ,
380+ },
381+ "google.adk" : {
382+ "module_name" : "agentops.instrumentation.google_adk" ,
383+ "class_name" : "GoogleADKInstrumentor" ,
384+ "min_version" : "0.1.0" ,
385+ "package_name" : "google-adk" , # Actual pip package name
386+ },
387+ }
388+
389+ # Combine all target packages for monitoring
390+ TARGET_PACKAGES = set (PROVIDERS .keys ()) | set (AGENTIC_LIBRARIES .keys ())
391+
392+
426393@dataclass
427394class InstrumentorLoader :
428395 """
@@ -444,13 +411,6 @@ def module(self) -> ModuleType:
444411 def should_activate (self ) -> bool :
445412 """Check if the package is available and meets version requirements."""
446413 try :
447- # Special case for stdlib modules (like concurrent.futures)
448- if self .package_name == "python" :
449- import sys
450-
451- python_version = f"{ sys .version_info .major } .{ sys .version_info .minor } .{ sys .version_info .micro } "
452- return Version (python_version ) >= parse (self .min_version )
453-
454414 # Use explicit package_name if provided, otherwise derive from module_name
455415 if self .package_name :
456416 provider_name = self .package_name
0 commit comments