From b12ba12749faab6e7fff74bc2965e26fd9493350 Mon Sep 17 00:00:00 2001 From: rzeta-10 Date: Mon, 23 Mar 2026 14:13:39 +0530 Subject: [PATCH] address greptile issues - improved error handling and logging, move the test file to correct dir --- litellm/integrations/akto/akto_logger.py | 31 ++++++++++++++++--- .../health_endpoints/_health_endpoints.py | 5 +-- .../test_akto_logger.py | 0 3 files changed, 29 insertions(+), 7 deletions(-) rename tests/{guardrails_tests => logging_callback_tests}/test_akto_logger.py (100%) diff --git a/litellm/integrations/akto/akto_logger.py b/litellm/integrations/akto/akto_logger.py index a213903e053..e0b96ca6cd6 100644 --- a/litellm/integrations/akto/akto_logger.py +++ b/litellm/integrations/akto/akto_logger.py @@ -197,7 +197,8 @@ class AktoLogger(CustomLogger): "status": "unhealthy", "error_message": f"Akto returned status {response.status_code}", } - except Exception: + except Exception as e: + verbose_logger.warning("Akto health check failed: %s", e) return {"status": "unhealthy", "error_message": "Akto health check failed"} # ── Logging callbacks ── @@ -206,7 +207,11 @@ class AktoLogger(CustomLogger): try: data = self.extract_logging_data(kwargs) payload = self.build_akto_payload(data, response_obj=response_obj) - self.sync_http_handler.post(**self.request_kwargs(payload)) + response = self.sync_http_handler.post(**self.request_kwargs(payload)) + if response.status_code >= 400: + verbose_logger.warning( + "Akto ingestion returned %s", response.status_code + ) except Exception as e: verbose_logger.error("Akto logging error: %s", e) @@ -214,7 +219,13 @@ class AktoLogger(CustomLogger): try: data = self.extract_logging_data(kwargs) payload = self.build_akto_payload(data, response_obj=response_obj) - await self.async_http_handler.post(**self.request_kwargs(payload)) + response = await self.async_http_handler.post( + **self.request_kwargs(payload) + ) + if response.status_code >= 400: + verbose_logger.warning( + "Akto ingestion returned %s", response.status_code + ) except Exception as e: verbose_logger.error("Akto logging error: %s", e) @@ -237,7 +248,11 @@ class AktoLogger(CustomLogger): payload = self.build_akto_payload( data, status_code=status, response_obj=response_obj ) - self.sync_http_handler.post(**self.request_kwargs(payload)) + response = self.sync_http_handler.post(**self.request_kwargs(payload)) + if response.status_code >= 400: + verbose_logger.warning( + "Akto ingestion returned %s", response.status_code + ) except Exception as e: verbose_logger.error("Akto logging error (failure): %s", e) @@ -248,6 +263,12 @@ class AktoLogger(CustomLogger): payload = self.build_akto_payload( data, status_code=status, response_obj=response_obj ) - await self.async_http_handler.post(**self.request_kwargs(payload)) + response = await self.async_http_handler.post( + **self.request_kwargs(payload) + ) + if response.status_code >= 400: + verbose_logger.warning( + "Akto ingestion returned %s", response.status_code + ) except Exception as e: verbose_logger.error("Akto logging error (failure): %s", e) diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.py index bbe9e7ec77c..caf324c6c3a 100644 --- a/litellm/proxy/health_endpoints/_health_endpoints.py +++ b/litellm/proxy/health_endpoints/_health_endpoints.py @@ -341,9 +341,10 @@ async def health_services_endpoint( # noqa: PLR0915 "message": "Mock LLM request made - check langfuse.", } elif service == "akto": + from litellm.litellm_core_utils.litellm_logging import aktoLogger as _akto from litellm.integrations.akto.akto_logger import AktoLogger - akto_logger = AktoLogger() + akto_logger = _akto if _akto is not None else AktoLogger() response = await akto_logger.async_health_check() return { "status": response["status"], @@ -353,7 +354,7 @@ async def health_services_endpoint( # noqa: PLR0915 else "Akto is healthy" ), } - + if service == "webhook": user_info = CallInfo( token=user_api_key_dict.token or "", diff --git a/tests/guardrails_tests/test_akto_logger.py b/tests/logging_callback_tests/test_akto_logger.py similarity index 100% rename from tests/guardrails_tests/test_akto_logger.py rename to tests/logging_callback_tests/test_akto_logger.py