Skip to content

Commit 49e10eb

Browse files
committed
[SDK] Log reason when creating a new session
Track why we need a new session (404, empty response, missing uuid, etc.) and log it once when the decision is made.
1 parent a6c7f3a commit 49e10eb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

eyepop/compute/api.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,36 @@ async def fetch_new_compute_session(
4747
sessions_url = f"{compute_ctx.compute_url}/v1/sessions"
4848

4949
res = None
50-
need_new_session = False
50+
create_reason = None
5151

5252
try:
5353
async with client_session.get(sessions_url, headers=headers) as get_response:
5454
log.debug(f"GET /v1/sessions - status: {get_response.status}")
5555
if get_response.status == 404:
56-
need_new_session = True
56+
create_reason = "no sessions endpoint (404)"
5757
else:
5858
get_response.raise_for_status()
5959
res = await get_response.json()
6060

6161
if not res:
62-
need_new_session = True
62+
create_reason = "empty response"
6363
elif isinstance(res, list) and len(res) == 0:
64-
need_new_session = True
64+
create_reason = "no existing sessions"
6565
elif isinstance(res, dict) and not res.get("session_uuid"):
66-
need_new_session = True
66+
create_reason = "response missing session_uuid"
6767

6868
except aiohttp.ClientResponseError as e:
6969
if e.status == 404:
70-
need_new_session = True
70+
create_reason = "no sessions endpoint (404)"
7171
else:
7272
raise ComputeSessionException(
7373
f"Failed to fetch existing sessions: {e.message}",
7474
) from e
7575
except Exception as e:
7676
raise ComputeSessionException(f"Unexpected error fetching sessions: {str(e)}") from e
7777

78-
if need_new_session:
78+
if create_reason:
79+
log.debug(f"Creating new session: {create_reason}")
7980
try:
8081
body = {}
8182
if compute_ctx.pipeline_image:

0 commit comments

Comments
 (0)