mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
perf: skip redundant redaction when global redaction enabled
When turn_off_message_logging is enabled globally, skip per-callback redaction functions that would re-process already-redacted data. 17% faster async_success_handler when global redaction is ON.
This commit is contained in:
parent
a5e8eb6848
commit
aaef0ce3ea
3 changed files with 25 additions and 7 deletions
|
|
@ -771,7 +771,9 @@ class CustomLogger: # https://docs.litellm.ai/docs/observability/custom_callbac
|
|||
return OLD_LITELLM_METADATA_FIELD
|
||||
|
||||
def redact_standard_logging_payload_from_model_call_details(
|
||||
self, model_call_details: Dict
|
||||
self,
|
||||
model_call_details: Dict,
|
||||
global_redaction_applied: bool = False,
|
||||
) -> Dict:
|
||||
"""
|
||||
Redacts or excludes fields from StandardLoggingPayload before callbacks receive it.
|
||||
|
|
@ -784,6 +786,10 @@ class CustomLogger: # https://docs.litellm.ai/docs/observability/custom_callbac
|
|||
|
||||
This is useful for logging payloads that contain sensitive information.
|
||||
"""
|
||||
# skip redundant redaction if global redaction was already applied
|
||||
if global_redaction_applied:
|
||||
return model_call_details
|
||||
|
||||
import litellm
|
||||
from copy import copy
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ from litellm.litellm_core_utils.model_param_helper import ModelParamHelper
|
|||
from litellm.litellm_core_utils.redact_messages import (
|
||||
redact_message_input_output_from_custom_logger,
|
||||
redact_message_input_output_from_logging,
|
||||
should_redact_message_logging,
|
||||
)
|
||||
from litellm.llms.base_llm.ocr.transformation import OCRResponse
|
||||
from litellm.llms.base_llm.search.transformation import SearchResponse
|
||||
|
|
@ -2483,10 +2484,10 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
global_callbacks=litellm._async_success_callback,
|
||||
)
|
||||
|
||||
_model_call_details = self.model_call_details if hasattr(self, "model_call_details") else {}
|
||||
global_redaction_applied = should_redact_message_logging(_model_call_details)
|
||||
result = redact_message_input_output_from_logging(
|
||||
model_call_details=(
|
||||
self.model_call_details if hasattr(self, "model_call_details") else {}
|
||||
),
|
||||
model_call_details=_model_call_details,
|
||||
result=result,
|
||||
)
|
||||
|
||||
|
|
@ -2512,7 +2513,10 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
)
|
||||
elif isinstance(callback, CustomLogger):
|
||||
result = redact_message_input_output_from_custom_logger(
|
||||
result=result, litellm_logging_obj=self, custom_logger=callback
|
||||
result=result,
|
||||
litellm_logging_obj=self,
|
||||
custom_logger=callback,
|
||||
global_redaction_applied=global_redaction_applied,
|
||||
)
|
||||
self.model_call_details, result = await callback.async_logging_hook(
|
||||
kwargs=self.model_call_details,
|
||||
|
|
@ -2567,7 +2571,8 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
##################################
|
||||
# call redaction hook for custom logger
|
||||
model_call_details = callback.redact_standard_logging_payload_from_model_call_details(
|
||||
model_call_details=model_call_details
|
||||
model_call_details=model_call_details,
|
||||
global_redaction_applied=global_redaction_applied,
|
||||
)
|
||||
##################################
|
||||
if self.stream is True:
|
||||
|
|
|
|||
|
|
@ -30,8 +30,15 @@ else:
|
|||
|
||||
|
||||
def redact_message_input_output_from_custom_logger(
|
||||
litellm_logging_obj: LiteLLMLoggingObject, result, custom_logger: CustomLogger
|
||||
litellm_logging_obj: LiteLLMLoggingObject,
|
||||
result,
|
||||
custom_logger: CustomLogger,
|
||||
global_redaction_applied: bool = False,
|
||||
):
|
||||
# skip redundant redaction if global redaction was already applied
|
||||
if global_redaction_applied:
|
||||
return result
|
||||
|
||||
if (
|
||||
hasattr(custom_logger, "message_logging")
|
||||
and custom_logger.message_logging is not True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue