Skip to content

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]

fix(proxy): register a UI-configured arize callback next to otel under OTel v2 (#43906)

devin-ai-integration[bot]e662772ad1d0
diff --git a/litellm/utils.py b/litellm/utils.py
index 71186a28be4..b0a7e4f1a68 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -628,9 +628,12 @@ def _custom_logger_class_exists_in_success_callbacks(
Prevents double adding a custom logger callback to the litellm callbacks
- Matches on the exact class; an instance of a subclass does not count as registered
+ Matches on the exact class and callback name; an instance of a subclass does not count as registered
"""
- return any(type(cb) is type(callback_class) for cb in litellm.success_callback + litellm._async_success_callback)
+ return any(
+ _is_same_registered_custom_logger(cb, callback_class)
+ for cb in litellm.success_callback + litellm._async_success_callback
+ )
def _custom_logger_class_exists_in_failure_callbacks(
@@ -643,9 +646,23 @@ def _custom_logger_class_exists_in_failure_callbacks(
Prevents double adding a custom logger callback to the litellm callbacks
- Matches on the exact class; an instance of a subclass does not count as registered
+ Matches on the exact class and callback name; an instance of a subclass does not count as registered
"""
- return any(type(cb) is type(callback_class) for cb in litellm.failure_callback + litellm._async_failure_callback)
+ return any(
+ _is_same_registered_custom_logger(cb, callback_class)
+ for cb in litellm.failure_callback + litellm._async_failure_callback
+ )
+
+
+def _is_same_registered_custom_logger(existing: object, callback_class: CustomLogger) -> bool:
+ """
+ One logger class can serve several callback names (every OTel v2 preset such as
+ ``otel`` and ``arize`` is an ``OpenTelemetryV2``), so a registered ``otel`` logger
+ must not count as an already registered ``arize`` logger
+ """
+ return type(existing) is type(callback_class) and getattr(existing, "callback_name", None) == getattr(
+ callback_class, "callback_name", None
+ )
def get_request_guardrails(kwargs: dict[str, Any]) -> list[str]:
diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.py
index d743a50aaaa..6c250dc88fb 100644
--- a/tests/test_litellm/proxy/test_proxy_server.py
+++ b/tests/test_litellm/proxy/test_proxy_server.py
@@ -12064,6 +12064,45 @@ def test_db_config_sync_restores_a_code_callback_it_replaced(monkeypatch: pytest
assert litellm.success_callback == ["langfuse_otel"]
+ ("setting_key", "event", "list_name"),
+ [
+ ("success_callback", "success", "_async_success_callback"),
+ ("failure_callback", "failure", "_async_failure_callback"),
+ ],
+)
+def test_db_config_sync_registers_otel_v2_arize_next_to_otel(
+ monkeypatch: pytest.MonkeyPatch, setting_key: str, event: str, list_name: str
+):
+ import litellm.proxy.proxy_server as ps
+ from litellm.integrations.otel.logger import OpenTelemetryV2
+ from litellm.integrations.otel.model.config import is_otel_v2_enabled
+ from litellm.utils import _add_custom_logger_callback_to_specific_event
+
+ _reset_runtime_callbacks(monkeypatch)
+ for extra_list in ("input_callback", "service_callback"):
+ monkeypatch.setattr(litellm, extra_list, [])
+ monkeypatch.setattr(ps, "open_telemetry_logger", None)
+ monkeypatch.setenv("LITELLM_OTEL_V2", "true")
+ monkeypatch.setenv("OTEL_EXPORTER", "console")
+ monkeypatch.setenv("ARIZE_API_KEY", "test-arize-key")
+ monkeypatch.setenv("ARIZE_SPACE_ID", "test-space-id")
+ monkeypatch.setenv("ARIZE_HTTP_ENDPOINT", "http://127.0.0.1:4318/v1/traces")
+ is_otel_v2_enabled.cache_clear()
+ try:
+ getattr(litellm.logging_callback_manager, f"add_litellm_{event}_callback")("helicone")
+ _add_custom_logger_callback_to_specific_event("otel", event)
+ pc = ps.ProxyConfig()
+ for _ in range(2):
+ pc._add_callbacks_from_db_config({"litellm_settings": {setting_key: ["arize"]}})
+ finally:
+ is_otel_v2_enabled.cache_clear()
+
+ v2_names: Final = [cb.callback_name for cb in getattr(litellm, list_name) if isinstance(cb, OpenTelemetryV2)]
+ assert len(v2_names) == 2
+ assert "arize" in v2_names
+
+
@pytest.mark.asyncio
async def test_failed_config_load_keeps_callbacks_the_stored_config_registered(monkeypatch: pytest.MonkeyPatch):
import litellm.proxy.proxy_server as ps
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 52b1714b4d9..4c36f99d2c8 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -4147,6 +4147,40 @@ def test_custom_logger_guards_ignore_subclass_instances(monkeypatch: pytest.Monk
assert _custom_logger_class_exists_in_failure_callbacks(builtin_instance) is True
+def test_custom_logger_guards_distinguish_callback_names(monkeypatch: pytest.MonkeyPatch) -> None:
+ """Regression LIT-9070: every OTel v2 preset (otel, arize, ...) is one OpenTelemetryV2 class,
+ so a class-only guard reported a UI-added arize as already registered whenever otel was
+ active and silently skipped it. The guard has to match on class and callback_name together:
+ the same preset twice is still a duplicate, a sibling preset or a subclass is not."""
+ from litellm.integrations.custom_logger import CustomLogger
+ from litellm.utils import (
+ _custom_logger_class_exists_in_failure_callbacks,
+ _custom_logger_class_exists_in_success_callbacks,
+ )
+
+ class PresetLogger(CustomLogger):
+ def __init__(self, callback_name: str) -> None:
+ super().__init__()
+ self.callback_name: Final = callback_name
+
+ class UserSubclassLogger(PresetLogger):
+ pass
+
+ monkeypatch.setattr(litellm, "success_callback", [PresetLogger("otel"), UserSubclassLogger("arize")])
+ monkeypatch.setattr(litellm, "failure_callback", [PresetLogger("otel"), UserSubclassLogger("arize")])
+ monkeypatch.setattr(litellm, "_async_success_callback", [])
+ monkeypatch.setattr(litellm, "_async_failure_callback", [])
+
+ assert _custom_logger_class_exists_in_success_callbacks(PresetLogger("otel")) is True
+ assert _custom_logger_class_exists_in_failure_callbacks(PresetLogger("otel")) is True
+ assert _custom_logger_class_exists_in_success_callbacks(PresetLogger("arize")) is False
+ assert _custom_logger_class_exists_in_failure_callbacks(PresetLogger("arize")) is False
+ assert _custom_logger_class_exists_in_success_callbacks(UserSubclassLogger("otel")) is False
+ assert _custom_logger_class_exists_in_failure_callbacks(UserSubclassLogger("otel")) is False
+ assert _custom_logger_class_exists_in_success_callbacks(UserSubclassLogger("arize")) is True
+ assert _custom_logger_class_exists_in_failure_callbacks(UserSubclassLogger("arize")) is True
+
+
@pytest.mark.asyncio
async def test_s3_v2_success_callback_registers_alongside_user_subclass(
monkeypatch: pytest.MonkeyPatch,