mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-02 01:28:38 +00:00
* fix(logging): stop dumping the request body at every layer under --detailed_debug The proxy dumped the full request body at every layer it passed through (proxy entry, pre-call, router, SDK call echo, param mapping, logging object), so one Codex "hi" wrote over 500KB of debug log. Keep the inbound request line and the outgoing provider request, summarize large values in the SDK call echo, and stop per-request lines that report nothing (callback disable checks with no disable header, cost map name probes, response id decode misses, vector store path misses). * fix(logging): summarize tools in the param mapping debug lines Non-Default params and Final returned optional params still printed full tool definitions, so a Codex-style request repeated them twice more. Use the same size summary as the SDK call echo and cover tools in the test. * perf(logging): build the param mapping debug summary only when debug is on
98 lines
No EOL
4.8 KiB
Python
98 lines
No EOL
4.8 KiB
Python
from typing import List, Optional
|
|
|
|
import litellm
|
|
from litellm._logging import verbose_logger
|
|
from litellm.constants import X_LITELLM_DISABLE_CALLBACKS
|
|
from litellm.integrations.custom_logger import CustomLogger
|
|
from litellm.litellm_core_utils.llm_request_utils import (
|
|
get_proxy_server_request_headers,
|
|
)
|
|
from litellm.types.utils import StandardCallbackDynamicParams
|
|
|
|
|
|
class EnterpriseCallbackControls:
|
|
@staticmethod
|
|
def is_callback_disabled_dynamically(
|
|
callback: litellm.CALLBACK_TYPES,
|
|
litellm_params: dict,
|
|
standard_callback_dynamic_params: StandardCallbackDynamicParams
|
|
) -> bool:
|
|
"""
|
|
Check if a callback is disabled via the x-litellm-disable-callbacks header or via `litellm_disabled_callbacks` in standard_callback_dynamic_params.
|
|
|
|
Args:
|
|
callback: The callback to check (can be string, CustomLogger instance, or callable)
|
|
litellm_params: Parameters containing proxy server request info
|
|
|
|
Returns:
|
|
bool: True if the callback should be disabled, False otherwise
|
|
"""
|
|
from litellm.litellm_core_utils.custom_logger_registry import (
|
|
CustomLoggerRegistry,
|
|
)
|
|
|
|
try:
|
|
disabled_callbacks = EnterpriseCallbackControls.get_disabled_callbacks(litellm_params, standard_callback_dynamic_params)
|
|
if disabled_callbacks is not None:
|
|
verbose_logger.debug(f"Checking if {callback} is in dynamically disabled callbacks: {disabled_callbacks}")
|
|
#########################################################
|
|
# premium user check
|
|
#########################################################
|
|
if not EnterpriseCallbackControls._should_allow_dynamic_callback_disabling():
|
|
return False
|
|
#########################################################
|
|
if isinstance(callback, str):
|
|
if callback.lower() in disabled_callbacks:
|
|
verbose_logger.debug(f"Not logging to {callback} because it is disabled via {X_LITELLM_DISABLE_CALLBACKS}")
|
|
return True
|
|
elif isinstance(callback, CustomLogger):
|
|
# get the string name of the callback
|
|
callback_str = CustomLoggerRegistry.get_callback_str_from_class_type(callback.__class__)
|
|
if callback_str is not None and callback_str.lower() in disabled_callbacks:
|
|
verbose_logger.debug(f"Not logging to {callback_str} because it is disabled via {X_LITELLM_DISABLE_CALLBACKS}")
|
|
return True
|
|
return False
|
|
except Exception as e:
|
|
verbose_logger.debug(
|
|
f"Error checking disabled callbacks header: {str(e)}"
|
|
)
|
|
return False
|
|
@staticmethod
|
|
def get_disabled_callbacks(litellm_params: dict, standard_callback_dynamic_params: StandardCallbackDynamicParams) -> Optional[List[str]]:
|
|
"""
|
|
Get the disabled callbacks from the standard callback dynamic params.
|
|
"""
|
|
|
|
#########################################################
|
|
# check if disabled via headers
|
|
#########################################################
|
|
request_headers = get_proxy_server_request_headers(litellm_params)
|
|
disabled_callbacks = request_headers.get(X_LITELLM_DISABLE_CALLBACKS, None)
|
|
if disabled_callbacks is not None:
|
|
disabled_callbacks = set([cb.strip().lower() for cb in disabled_callbacks.split(",")])
|
|
return list(disabled_callbacks)
|
|
|
|
|
|
#########################################################
|
|
# check if disabled via request body
|
|
#########################################################
|
|
if standard_callback_dynamic_params.get("litellm_disabled_callbacks", None) is not None:
|
|
return standard_callback_dynamic_params.get("litellm_disabled_callbacks", None)
|
|
|
|
return None
|
|
|
|
@staticmethod
|
|
def _should_allow_dynamic_callback_disabling():
|
|
import litellm
|
|
from litellm.proxy._types import CommonProxyErrors
|
|
from litellm.proxy.proxy_server import premium_user
|
|
|
|
# Check if admin has disabled this feature
|
|
if litellm.allow_dynamic_callback_disabling is not True:
|
|
verbose_logger.debug("Dynamic callback disabling is disabled by admin via litellm.allow_dynamic_callback_disabling")
|
|
return False
|
|
|
|
if premium_user:
|
|
return True
|
|
verbose_logger.warning(f"Disabling callbacks using request headers is an enterprise feature. {CommonProxyErrors.not_premium_user.value}")
|
|
return False |