azure_sentinel_truncate fix P1 issues

This commit is contained in:
alihacks 2026-04-24 16:35:25 -04:00
parent 3c8e941041
commit fb543fd9c8
2 changed files with 6 additions and 3 deletions

View file

@ -284,13 +284,15 @@ class AzureSentinelLogger(CustomBatchLogger):
entry = deepcopy(payload)
truncated_fields: List[str] = []
prefix = "[truncated by litellm]..."
tail_limit = limit - len(prefix)
if len(msg_str) > limit:
entry["messages"] = "[truncated by litellm]..." + msg_str[-limit:]
entry["messages"] = prefix + msg_str[-tail_limit:]
truncated_fields.append("messages")
if len(resp_str) > limit:
entry["response"] = "[truncated by litellm]..." + resp_str[-limit:]
entry["response"] = prefix + resp_str[-tail_limit:]
truncated_fields.append("response")
truncation_info: Dict[str, Any] = {

View file

@ -199,11 +199,12 @@ def test_column_limit_truncates_large_fields():
# Messages field should be truncated, keeping tail
msg_str = str(result["messages"])
assert msg_str.startswith("[truncated by litellm]...")
assert len(msg_str) <= logger.MAX_COLUMN_CHARS + len("[truncated by litellm]...")
assert len(msg_str) <= logger.MAX_COLUMN_CHARS
# Response field should be truncated, keeping tail
resp_str = str(result["response"])
assert resp_str.startswith("[truncated by litellm]...")
assert len(resp_str) <= logger.MAX_COLUMN_CHARS
# Truncation metadata present
metadata = result.get("metadata", {})