From 4e67f5be1cb1de7df133a396817c575aaa0af9be Mon Sep 17 00:00:00 2001 From: Jesus Velarde Date: Sat, 7 Nov 2026 16:11:51 -0800 Subject: [PATCH] fix(proxy): drop a key logging entry whose referenced credential holds no logging values --- litellm/proxy/common_utils/callback_utils.py | 14 +++++++------- .../proxy/common_utils/test_callback_utils.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/litellm/proxy/common_utils/callback_utils.py b/litellm/proxy/common_utils/callback_utils.py index 6746e465c10..c80e470003f 100644 --- a/litellm/proxy/common_utils/callback_utils.py +++ b/litellm/proxy/common_utils/callback_utils.py @@ -761,18 +761,18 @@ def _with_credential(entry: Mapping[str, object]) -> Mapping[str, object] | None credential_name: Final = entry.get("litellm_credential_name") if not isinstance(credential_name, str): return entry - if CredentialAccessor.find_credential(credential_name) is None: - verbose_proxy_logger.warning( - "Ignoring key logging entry for %s: credential %r is not defined", - entry.get("callback_name"), - credential_name, - ) - return None credential_vars: Final = { name: str(value) for name, value in CredentialAccessor.get_credential_values(credential_name).items() if name in CALLBACK_VAR_NAMES and value is not None } + if not credential_vars: + verbose_proxy_logger.warning( + "Ignoring key logging entry for %s: credential %r is not defined or holds no logging values", + entry.get("callback_name"), + credential_name, + ) + return None return {**entry, "callback_vars": {**credential_vars, **string_keyed(entry.get("callback_vars"))}} diff --git a/tests/unit/proxy/common_utils/test_callback_utils.py b/tests/unit/proxy/common_utils/test_callback_utils.py index 66a9e31cfce..f57ab902c45 100644 --- a/tests/unit/proxy/common_utils/test_callback_utils.py +++ b/tests/unit/proxy/common_utils/test_callback_utils.py @@ -808,6 +808,24 @@ def test_key_logging_entries_merges_each_referenced_credential_under_its_entry(m ] +@pytest.mark.parametrize( + "credential_values", + [{"api_key": "sk-model-key"}, {"arize_api_key": None}], + ids=["model-credential", "null-values"], +) +def test_key_logging_entries_drops_an_entry_whose_credential_supplies_no_logging_values( + monkeypatch: pytest.MonkeyPatch, credential_values: dict[str, object] +) -> None: + monkeypatch.setattr(litellm, "credential_list", [_credential("model-only", credential_values)]) + kept: Final = {"callback_name": "langfuse", "callback_vars": {"langfuse_public_key": "pk"}} + entries: Final = [ + kept, + {"callback_name": "arize", "litellm_credential_name": "model-only", "callback_vars": {}}, + ] + + assert key_logging_entries({"logging": entries}) == (kept,) + + def test_key_logging_entries_drops_an_entry_whose_credential_is_not_defined(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(litellm, "credential_list", [_credential("space-a", {"arize_api_key": "key-a"})]) kept: Final = {"callback_name": "langfuse", "callback_vars": {"langfuse_public_key": "pk"}}