The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(logging): preserve callback order in get_combined_callback_list (#33005)
devin-ai-integration[bot]f7fc679f27d6
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 461ab62b815..5494ea11b36 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -3074,7 +3074,7 @@ class Logging(LiteLLMLoggingBaseClass):def get_combined_callback_list(self, dynamic_success_callbacks: Optional[List], global_callbacks: List) -> List:if dynamic_success_callbacks is None:return list(global_callbacks)- return list(set(dynamic_success_callbacks + global_callbacks))+ return list(dict.fromkeys(dynamic_success_callbacks + global_callbacks))def _remove_internal_litellm_callbacks(self, callbacks: List) -> List:"""diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.pyindex 62fc28256cd..9f36e729330 100644--- a/litellm/proxy/utils.py+++ b/litellm/proxy/utils.py@@ -833,7 +833,7 @@ class ProxyLogging:def get_combined_callback_list(self, dynamic_success_callbacks: Optional[List], global_callbacks: List) -> List:if dynamic_success_callbacks is None:return list(global_callbacks)- return list(set(dynamic_success_callbacks + global_callbacks))+ return list(dict.fromkeys(dynamic_success_callbacks + global_callbacks))def _parse_pre_mcp_call_hook_response(self,diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.pyindex ade2c677745..34a87c95611 100644--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py@@ -32,6 +32,13 @@ def logging_obj():)+def test_get_combined_callback_list_preserves_insertion_order(logging_obj):+ assert logging_obj.get_combined_callback_list(+ dynamic_success_callbacks=["prometheus", "langfuse", "datadog", "otel", "s3"],+ global_callbacks=["langfuse", "gcs_bucket", "arize", "logfire"],+ ) == ["prometheus", "langfuse", "datadog", "otel", "s3", "gcs_bucket", "arize", "logfire"]++def test_get_masked_api_base(logging_obj):api_base = "https://api.openai.com/v1"masked_api_base = logging_obj._get_masked_api_base(api_base)diff --git a/tests/test_litellm/proxy/utils/proxy_logging/test_callback_capabilities_class.py b/tests/test_litellm/proxy/utils/proxy_logging/test_callback_capabilities_class.pyindex 45b81acbce1..9452e8042bd 100644--- a/tests/test_litellm/proxy/utils/proxy_logging/test_callback_capabilities_class.py+++ b/tests/test_litellm/proxy/utils/proxy_logging/test_callback_capabilities_class.py@@ -330,6 +330,13 @@ def test_get_combined_callback_list_matrix(proxy_logging):}+def test_get_combined_callback_list_preserves_insertion_order(proxy_logging):+ assert proxy_logging.get_combined_callback_list(+ dynamic_success_callbacks=["prometheus", "langfuse", "datadog", "otel", "s3"],+ global_callbacks=["langfuse", "gcs_bucket", "arize", "logfire"],+ ) == ["prometheus", "langfuse", "datadog", "otel", "s3", "gcs_bucket", "arize", "logfire"]++def test_get_combined_callback_list_unhashable_dynamic_raises(proxy_logging):with pytest.raises(TypeError):proxy_logging.get_combined_callback_list(