fix(logging): preserve retry diagnostics without exceptions
Some checks failed
Cost map pins recheck / rerun-cost-map-guard (push) Has been cancelled
LiteLLM Rust DB / db-queries (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled

This commit is contained in:
moe-berri 2026-10-29 18:32:31 -07:00
parent c3ed358cec
commit 98cbd9af71
2 changed files with 14 additions and 7 deletions

View file

@ -22,10 +22,14 @@ from litellm.llms.custom_httpx.http_handler import (
def log_retry_error(details):
exception: Final = "redacted-by-litellm" if litellm.redact_messages_in_debug_logs else details.get("exception")
exception: Final = details.get("exception")
tries: Final = "redacted-by-litellm" if litellm.redact_messages_in_debug_logs else details.get("tries")
if exception:
logging.error("Confident AI Error: %s. Retrying: %s time(s)...", exception, tries)
logging.error(
"Confident AI Error: %s. Retrying: %s time(s)...",
"redacted-by-litellm" if litellm.redact_messages_in_debug_logs else exception,
tries,
)
else:
logging.error("Retrying: %s time(s)...", tries)

View file

@ -126,16 +126,19 @@ if __name__ == "__main__":
@pytest.mark.parametrize("redact", (False, True))
@pytest.mark.parametrize("exception_kind", ("missing", "none", "error"))
def test_retry_diagnostic_hides_exception_and_dynamic_details_only_when_opted_in(
redact: bool, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch
redact: bool, exception_kind: str, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
from litellm.integrations.deepeval.api import log_retry_error
monkeypatch.setattr(litellm, "redact_messages_in_debug_logs", redact)
marker: Final = "synthetic-private-retry-content"
failure: Final = ValueError(marker)
details: Final = {"exception": failure, "tries": 2}
failure: Final = ValueError(marker) if exception_kind == "error" else None
details: Final = {"tries": 2} if exception_kind == "missing" else {"exception": failure, "tries": 2}
log_retry_error(details)
assert (marker in caplog.text) is not redact
assert ("Confident AI Error:" in caplog.text) is (failure is not None)
assert (marker in caplog.text) is (failure is not None and not redact)
assert ("redacted-by-litellm" in caplog.text) is redact
assert details["exception"] is failure
assert details.get("exception") is failure
assert ("exception" in details) is (exception_kind != "missing")