From 0dc2b88c5304e7c9ac9286ac32a3d260875e901d Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Thu, 19 Feb 2026 11:29:18 -0800 Subject: [PATCH] add callback duration header, size-gate debug logging, detailed timing headers --- litellm/proxy/common_request_processing.py | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 7dfa3bb239f..d647de82a5d 100644 --- a/litellm/proxy/common_request_processing.py +++ b/litellm/proxy/common_request_processing.py @@ -24,6 +24,8 @@ from litellm._logging import verbose_proxy_logger from litellm._uuid import uuid from litellm.constants import ( DD_TRACER_STREAMING_CHUNK_YIELD_RESOURCE, + LITELLM_DETAILED_TIMING, + MAX_PAYLOAD_SIZE_FOR_DEBUG_LOG, STREAM_SSE_DATA_PREFIX, ) from litellm.litellm_core_utils.dd_tracing import tracer @@ -434,6 +436,19 @@ class ProxyBaseLLMRequestProcessing: "x-litellm-overhead-duration-ms": str( hidden_params.get("litellm_overhead_time_ms", None) ), + "x-litellm-callback-duration-ms": str( + hidden_params.get("callback_duration_ms", None) + ), + **( + { + "x-litellm-timing-pre-processing-ms": str(hidden_params.get("timing_pre_processing_ms", None)), + "x-litellm-timing-llm-api-ms": str(hidden_params.get("timing_llm_api_ms", None)), + "x-litellm-timing-post-processing-ms": str(hidden_params.get("timing_post_processing_ms", None)), + "x-litellm-timing-message-copy-ms": str(hidden_params.get("timing_message_copy_ms", None)), + } + if LITELLM_DETAILED_TIMING + else {} + ), "x-litellm-fastest_response_batch_completion": ( str(fastest_response_batch_completion) if fastest_response_batch_completion is not None @@ -753,11 +768,19 @@ class ProxyBaseLLMRequestProcessing: self.data.get("model") if isinstance(self.data.get("model"), str) else None ) if verbose_proxy_logger.isEnabledFor(logging.DEBUG): - verbose_proxy_logger.debug( - "Request received by LiteLLM:\n{}".format( - json.dumps(self.data, indent=4, default=str) - ), - ) + _payload_str = json.dumps(self.data, default=str) + if len(_payload_str) > MAX_PAYLOAD_SIZE_FOR_DEBUG_LOG: + verbose_proxy_logger.debug( + "Request received by LiteLLM: payload too large to log (%d bytes, limit %d). Keys: %s", + len(_payload_str), + MAX_PAYLOAD_SIZE_FOR_DEBUG_LOG, + list(self.data.keys()) if isinstance(self.data, dict) else type(self.data).__name__, + ) + else: + verbose_proxy_logger.debug( + "Request received by LiteLLM:\n%s", + json.dumps(self.data, indent=4, default=str), + ) self.data, logging_obj = await self.common_processing_pre_call_logic( request=request,