Skip to content

Commit

Permalink
error sending metrics when server startup failed preventing error log…
Browse files Browse the repository at this point in the history
…ging (#758)
  • Loading branch information
LukeLalor committed Sep 12, 2024
1 parent 0371009 commit 61ab625
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
8 changes: 3 additions & 5 deletions sdk/eidolon_ai_sdk/bin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,17 @@ async def root():
open_tele = AgentOSKernel.get_instance(OpenTelemetryManager)
await open_tele.start()
try:
time_to_start = time.perf_counter() - t0
report_server_started(time_to_start, len(machine.agent_controllers), False)
logger.info(f"Server Started in {time_to_start:.2f}s")
report_server_started(time.perf_counter() - t0, len(machine.agent_controllers), False)
logger.info(f"Server Started in {time.perf_counter() - t0 :.2f}s")
_status = "running"
yield
finally:
await open_tele.stop()

await machine.stop()
except BaseException:
time_to_start = time.perf_counter() - t0
await report_server_started(time_to_start, -1, True)
logger.exception("Failed to start AgentOS")
report_server_started(time.perf_counter() - t0, -1, True)
raise
finally:
_status = "stopped"
Expand Down
32 changes: 32 additions & 0 deletions sdk/tests/test_server_startup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging
from typing import Iterator
from unittest import mock

import pytest
from fastapi import FastAPI

from eidolon_ai_sdk.bin.server import start_os


class ExceptionThrowing(Iterator):
def __init__(self, exception: Exception):
self.exception = exception

def __iter__(self):
return self

def __next__(self):
raise self.exception


async def test_server_logs_startup_errors():
with pytest.raises(Exception), mock.patch("eidolon_ai_sdk.bin.server.logger.exception") as exception_logger:
async with start_os(
FastAPI(),
ExceptionThrowing(Exception("mocked exception")),
"test_machine",
log_level=logging.INFO,
):
pass
assert exception_logger.called

0 comments on commit 61ab625

Please sign in to comment.