Skip to content

Commit

Permalink
Setting session to none if server does not return 200 for /sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
HowieG committed Apr 3, 2024
1 parent 1bf3ac2 commit 0f11a9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
13 changes: 9 additions & 4 deletions agentops/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0f11a9d

Please sign in to comment.