Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error sending metrics when server startup failed preventing error log… #758

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Loading