mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-29 01:42:19 +00:00
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.
This commit is contained in:
parent
94ce3b1d50
commit
114777be30
2 changed files with 25 additions and 30 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue