Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
Removed import break (#937)
Alex Reibman704110de6ba5
diff --git a/agentops/logging/instrument_logging.py b/agentops/logging/instrument_logging.pyindex 278bc403..4ca74401 100644--- a/agentops/logging/instrument_logging.py+++ b/agentops/logging/instrument_logging.py@@ -2,47 +2,47 @@ import builtinsimport loggingimport osimport atexit-from datetime import datetime-from typing import Any, TextIO-from agents import Span+from typing import Any_original_print = builtins.printLOGFILE_NAME = "agentops-tmp.log"-## Instrument loggers and print function to log to a file+# Instrument loggers and print function to log to a file++def setup_print_logger() -> None:"""~Monkeypatches~ *Instruments the built-in print function and configures logging to also log to a file.Preserves existing logging configuration and console output behavior."""log_file = os.path.join(os.getcwd(), LOGFILE_NAME)-+file_logger = logging.getLogger('agentops_file_logger')file_logger.setLevel(logging.DEBUG)-+file_handler = logging.FileHandler(log_file)file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))file_handler.setLevel(logging.DEBUG)file_logger.addHandler(file_handler)-+# Ensure the new logger doesn't propagate to rootfile_logger.propagate = False-+def print_logger(*args: Any, **kwargs: Any) -> None:"""Custom print function that logs to file and console.-+Args:*args: Arguments to print**kwargs: Keyword arguments to print"""message = " ".join(str(arg) for arg in args)file_logger.info(message)-+# print to console using original print_original_print(*args, **kwargs)-+# replace the built-in print with oursbuiltins.print = print_logger@@ -56,7 +56,7 @@ def setup_print_logger() -> None:for handler in file_logger.handlers[:]:handler.close()file_logger.removeHandler(handler)-+# Restore the original print functionbuiltins.print = _original_printexcept Exception as e:@@ -64,7 +64,7 @@ def setup_print_logger() -> None:_original_print(f"Error during cleanup: {e}")# Register the cleanup function to run when the process exits- atexit.register(cleanup)+ atexit.register(cleanup)def upload_logfile(trace_id: int) -> None:@@ -83,4 +83,3 @@ def upload_logfile(trace_id: int) -> None:client.api.v4.upload_logfile(log_content, trace_id)os.remove(log_file)-\ No newline at end of filediff --git a/pyproject.toml b/pyproject.tomlindex e8ebade0..fa919eeb 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "agentops"-version = "0.4.7"+version = "0.4.8"authors = [{ name="Alex Reibman", email="[email protected]" },{ name="Shawn Qiu", email="[email protected]" },