diff --git a/agentops/client.py b/agentops/client.py index 8c2fa188..4001d4d1 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -212,7 +212,11 @@ def start_session(self, tags: Optional[List[str]] = None, config: Optional[Confi self._session = Session(uuid4(), tags or self._tags, host_env=get_host_env()) self._worker = Worker(config or self.config) - self._worker.start_session(self._session) + start_session_result = self._worker.start_session(self._session) + if not start_session_result: + self._session = None + return logging.warning("AgentOps: Cannot start session") + logging.info('View info on this session at https://app.agentops.ai/drilldown?session_id={}' .format(self._session.session_id)) diff --git a/agentops/worker.py b/agentops/worker.py index d409ee10..6b7320ef 100644 --- a/agentops/worker.py +++ b/agentops/worker.py @@ -49,10 +49,15 @@ def start_session(self, session: Session) -> None: "session": session.__dict__ } serialized_payload = json.dumps(filter_unjsonable(payload)).encode("utf-8") - HttpClient.post(f'{self.config.endpoint}/sessions', - serialized_payload, - self.config.api_key, - self.config.parent_key) + res = HttpClient.post(f'{self.config.endpoint}/sessions', + serialized_payload, + self.config.api_key, + self.config.parent_key) + + if res.code != 200: + return False + + return True def end_session(self, session: Session) -> None: self.stop_flag.set()