From 114777be309ba5053baff528326337893378ff02 Mon Sep 17 00:00:00 2001 From: wadrzl55333 Date: Fri, 28 Aug 2026 20:54:43 +0800 Subject: [PATCH] refactor(proxy): move config-callback registration to public util wrapper The helper reached into litellm_logging private APIs; the repo's pyright config has enableTypeIgnoreComments disabled and a strict per-rule budget, so each new private import and call site counts against the gate. Move the instance-registration-with-fallback logic behind a public register_config_custom_logger_callback in litellm.utils, and let the existing _add_custom_logger_callback_to_specific_event carry the fallback (its else branch now registers the string when the custom-logger class cannot initialize). Net change in private API surface: zero. --- litellm/proxy/proxy_server.py | 33 +++------------------------------ litellm/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 429e3d7697e..18791687c16 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -703,34 +703,7 @@ from litellm.types.secret_managers.main import ( from litellm.types.utils import CredentialItem, CustomHuggingfaceTokenizer, RawRequestTypedDict, StandardLoggingPayload from litellm.types.utils import ModelInfo as ModelMapInfo from litellm.utils import _add_custom_logger_callback_to_specific_event - - -def _register_config_custom_logger_callback(callback: str, logging_event: Literal["success", "failure"]) -> None: - """Register a config-file custom-logger name as an instance, not a string. - - Pass-through endpoints log through the async success path only; a string in - ``litellm.success_callback`` never reaches them. Falls back to the string - when the custom-logger class cannot be initialized (e.g. missing env - credentials), so standard-route logging still works. Mirrors the DB-config path. - """ - from litellm.litellm_core_utils.litellm_logging import ( - _init_custom_logger_compatible_class, - ) - - if ( - _init_custom_logger_compatible_class( # pyright: ignore[reportPrivateUsage] # mirrors DB-config path - callback, internal_usage_cache=None, llm_router=None - ) - is None - ): - if logging_event == "success": - litellm.logging_callback_manager.add_litellm_success_callback(callback) - else: - litellm.logging_callback_manager.add_litellm_failure_callback(callback) - return - _add_custom_logger_callback_to_specific_event( # pyright: ignore[reportPrivateUsage] # mirrors DB-config path - callback, logging_event - ) +from litellm.utils import register_config_custom_logger_callback try: @@ -5151,7 +5124,7 @@ class ProxyConfig: # these are litellm callbacks - "langfuse", "sentry", "wandb" else: if callback in litellm._known_custom_logger_compatible_callbacks: - _register_config_custom_logger_callback(callback, "success") + register_config_custom_logger_callback(callback, "success") else: litellm.logging_callback_manager.add_litellm_success_callback(callback) if "prometheus" in callback: @@ -5181,7 +5154,7 @@ class ProxyConfig: # these are litellm callbacks - "langfuse", "sentry", "wandb" else: if callback in litellm._known_custom_logger_compatible_callbacks: - _register_config_custom_logger_callback(callback, "failure") + register_config_custom_logger_callback(callback, "failure") else: litellm.logging_callback_manager.add_litellm_failure_callback(callback) print( # noqa: T201 diff --git a/litellm/utils.py b/litellm/utils.py index 520c40f67c0..2d5af878778 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -593,6 +593,28 @@ def _add_custom_logger_callback_to_specific_event(callback: str, logging_event: litellm.failure_callback.remove(callback) # remove the string from the callback list if callback in litellm._async_failure_callback: litellm._async_failure_callback.remove(callback) # remove the string from the callback list + else: + # Custom-logger class could not be initialized (e.g. missing env + # credentials). Fall back to string registration so standard-route + # logging still works; pass-through endpoints only reach instance + # callbacks, so they keep missing out in this degraded state. + if logging_event == "success": + litellm.logging_callback_manager.add_litellm_success_callback(callback) + else: + litellm.logging_callback_manager.add_litellm_failure_callback(callback) + + +def register_config_custom_logger_callback(callback: str, logging_event: Literal["success", "failure"]) -> None: + """Register a config-file custom-logger name as an instance, not a string. + + Config-file ``success_callback`` / ``failure_callback`` strings previously + landed in ``litellm.success_callback`` as bare strings; pass-through + endpoints log through the async path only, so they never saw them. + Registering the custom-logger instance covers both paths. Falls back to + string registration when the class cannot be initialized (e.g. missing env + credentials), so standard-route logging keeps working. + """ + _add_custom_logger_callback_to_specific_event(callback, logging_event) def _custom_logger_class_exists_in_success_callbacks(