diff --git a/agentops/__init__.py b/agentops/__init__.py index 70712b57..54ca039b 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -60,13 +60,12 @@ def init( (i.e. Crew determining when tasks are complete and ending the session) Attributes: """ + Client().unsuppress_logs() if Client().is_initialized: return logger.warning("AgentOps has already been initialized") if tags is not None: - Client().add_pre_init_warning( - "The 'tags' parameter is deprecated. Use 'default_tags' instead" - ) + logger.warning("The 'tags' parameter is deprecated. Use 'default_tags' instead") if default_tags is None: default_tags = tags @@ -147,6 +146,8 @@ def start_session( e.g. ["test_run"]. inherited_session_id: (str, optional): Set the session ID to inherit from another client """ + Client().unsuppress_logs() + if not Client().is_initialized: return logger.warning( "AgentOps has not been initialized yet. Please call agentops.init() before starting a session" @@ -169,6 +170,8 @@ def end_session( end_state_reason (str, optional): The reason for ending the session. video (str, optional): URL to a video recording of the session """ + Client().unsuppress_logs() + if Client().is_multi_session: return logger.warning( "Could not end session - multiple sessions detected. You must use session.end_session() instead of agentops.end_session()" @@ -193,6 +196,8 @@ def record(event: Union[Event, ErrorEvent]): Args: event (Event): The event to record. """ + Client().unsuppress_logs() + if Client().is_multi_session: return logger.warning( "Could not record event - multiple sessions detected. You must use session.record() instead of agentops.record()" @@ -294,6 +299,8 @@ def get_session(session_id: str): Args: session_id (str): the session id for the session to be retreived """ + Client().unsuppress_logs() + return Client().get_session(session_id) diff --git a/agentops/client.py b/agentops/client.py index b0f9f140..4007e410 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -24,7 +24,7 @@ ) from .session import Session, active_sessions from .host_env import get_host_env -from .log_config import logger, unsuppress_logs +from .log_config import logger from .meta_client import MetaClient from .config import Configuration from .llm_tracker import LlmTracker @@ -82,10 +82,7 @@ def configure( ) def initialize(self) -> Union[Session, None]: - unsuppress_logs() - - for message in Client()._pre_init_messages: - logger.warning(message) + self.unsuppress_logs() if self._config.api_key is None: return logger.error( @@ -404,6 +401,20 @@ def get_session(self, session_id: str): if session.session_id == session_id: return session + def unsuppress_logs(self): + logging_level = os.getenv("AGENTOPS_LOGGING_LEVEL", "INFO") + log_levels = { + "CRITICAL": logging.CRITICAL, + "ERROR": logging.ERROR, + "INFO": logging.INFO, + "WARNING": logging.WARNING, + "DEBUG": logging.DEBUG, + } + logger.setLevel(log_levels.get(logging_level, "INFO")) + + for message in self._pre_init_messages: + logger.warning(message) + def end_all_sessions(self): for s in self._sessions: s.end_session() diff --git a/agentops/log_config.py b/agentops/log_config.py index be271ad2..f814fb52 100644 --- a/agentops/log_config.py +++ b/agentops/log_config.py @@ -51,15 +51,3 @@ def format(self, record): file_handler.setFormatter(formatter) file_handler.setFormatter(formatter) logger.addHandler(file_handler) - - -def unsuppress_logs(): - logging_level = os.getenv("AGENTOPS_LOGGING_LEVEL", "INFO") - log_levels = { - "CRITICAL": logging.CRITICAL, - "ERROR": logging.ERROR, - "INFO": logging.INFO, - "WARNING": logging.WARNING, - "DEBUG": logging.DEBUG, - } - logger.setLevel(log_levels.get(logging_level, "INFO"))