fix(proxy): fall back to request data when logging object has no call id

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Devin AI 2026-09-15 08:03:45 +00:00
parent bc17459548
commit 0a8eb56ba4
2 changed files with 13 additions and 2 deletions

View file

@ -3431,7 +3431,7 @@ class ProxyBaseLLMRequestProcessing:
logging_obj: Final[LiteLLMLoggingObj | None] = self.data.get("litellm_logging_obj", None)
_log_llm_api_exception(
e,
logging_obj.litellm_call_id if logging_obj is not None else self.data.get("litellm_call_id"),
(logging_obj.litellm_call_id if logging_obj is not None else None) or self.data.get("litellm_call_id"),
)
# Allow callbacks to transform the error response
transformed_exception: Final = await proxy_logging_obj.post_call_failure_hook(

View file

@ -8671,7 +8671,7 @@ class TestErrorLogCarriesCallId:
x-litellm-call-id response header, so a logged exception can be tied to a
specific request."""
async def _invoke(self, data: dict) -> None:
async def _invoke(self, data: dict[str, object]) -> None:
from litellm._logging import verbose_proxy_logger
processor: Final = ProxyBaseLLMRequestProcessing(data=data)
@ -8712,6 +8712,17 @@ class TestErrorLogCarriesCallId:
assert record.litellm_call_id == call_id
assert call_id in record.getMessage()
async def test_call_id_falls_back_when_logging_obj_has_none(self, caplog: pytest.LogCaptureFixture) -> None:
call_id: Final = str(uuid.uuid4())
logging_obj: Final = MagicMock()
logging_obj.litellm_call_id = None
with caplog.at_level("ERROR", logger="LiteLLM Proxy"):
await self._invoke({"litellm_logging_obj": logging_obj, "litellm_call_id": call_id})
record: Final = self._error_record(caplog)
assert record.litellm_call_id == call_id
assert call_id in record.getMessage()
def test_client_disconnect_log_carries_call_id(self, caplog: pytest.LogCaptureFixture) -> None:
from litellm._logging import verbose_proxy_logger
from litellm.proxy.common_request_processing import (