diff --git a/agentops/client/client.py b/agentops/client/client.py index b0a18f1ca..8465c57b6 100644 --- a/agentops/client/client.py +++ b/agentops/client/client.py @@ -56,10 +56,16 @@ def init(self, **kwargs): self.initialized = True - if self.config.auto_start_session: + # Only start a session if auto_start_session is True and we're not already in start_session + # Prevents infinite recursion + if self.config.auto_start_session and not getattr(self, "_in_start_session", False): from agentops.legacy import start_session - start_session() + self._in_start_session = True + try: + start_session() + finally: + self._in_start_session = False def configure(self, **kwargs): """Update client configuration""" diff --git a/agentops/config.py b/agentops/config.py index b496e8039..b663bb8f3 100644 --- a/agentops/config.py +++ b/agentops/config.py @@ -65,7 +65,7 @@ class Config: ) auto_start_session: bool = field( - default_factory=lambda: get_env_bool("AGENTOPS_AUTO_START_SESSION", False), + default_factory=lambda: get_env_bool("AGENTOPS_AUTO_START_SESSION", True), metadata={"description": "Whether to automatically start a session when initializing"}, ) @@ -85,7 +85,7 @@ class Config: ) log_level: Union[str, int] = field( - default_factory=lambda: os.getenv("AGENTOPS_LOG_LEVEL", "WARNING"), + default_factory=lambda: os.getenv("AGENTOPS_LOG_LEVEL", "INFO"), metadata={"description": "Logging level for AgentOps logs"}, ) @@ -170,7 +170,14 @@ def configure( self.env_data_opt_out = env_data_opt_out if log_level is not None: - self.log_level = log_level + if isinstance(log_level, str): + log_level_str = log_level.upper() + if hasattr(logging, log_level_str): + self.log_level = getattr(logging, log_level_str) + else: + self.log_level = logging.INFO + else: + self.log_level = log_level if fail_safe is not None: self.fail_safe = fail_safe diff --git a/agentops/logging/config.py b/agentops/logging/config.py index a51a09bc8..3abfa2d12 100644 --- a/agentops/logging/config.py +++ b/agentops/logging/config.py @@ -28,7 +28,15 @@ def configure_logging(config=None): # Remove type hint temporarily to avoid cir if log_level_env and hasattr(logging, log_level_env): log_level = getattr(logging, log_level_env) else: - log_level = config.log_level if isinstance(config.log_level, int) else logging.CRITICAL + # Handle string log levels from config + if isinstance(config.log_level, str): + log_level_str = config.log_level.upper() + if hasattr(logging, log_level_str): + log_level = getattr(logging, log_level_str) + else: + log_level = logging.INFO + else: + log_level = config.log_level if isinstance(config.log_level, int) else logging.INFO logger.setLevel(log_level) @@ -38,7 +46,7 @@ def configure_logging(config=None): # Remove type hint temporarily to avoid cir # Configure console logging stream_handler = logging.StreamHandler() - stream_handler.setLevel(logging.DEBUG) + stream_handler.setLevel(log_level) stream_handler.setFormatter(AgentOpsLogFormatter()) logger.addHandler(stream_handler) @@ -46,7 +54,7 @@ def configure_logging(config=None): # Remove type hint temporarily to avoid cir log_to_file = os.environ.get("AGENTOPS_LOGGING_TO_FILE", "True").lower() == "true" if log_to_file: file_handler = logging.FileHandler("agentops.log", mode="w") - file_handler.setLevel(logging.DEBUG) + file_handler.setLevel(log_level) formatter = AgentOpsLogFileFormatter("%(asctime)s - %(levelname)s - %(message)s") file_handler.setFormatter(formatter) logger.addHandler(file_handler)