mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
Support for is_streamed_request widh datadog (#14673)
This commit is contained in:
parent
a7a6381926
commit
ec61a7152a
2 changed files with 29 additions and 0 deletions
|
|
@ -498,6 +498,7 @@ class DataDogLLMObsLogger(DataDogLogger, CustomBatchLogger):
|
|||
"guardrail_information": standard_logging_payload.get(
|
||||
"guardrail_information", None
|
||||
),
|
||||
"is_streamed_request": self._get_stream_value_from_payload(standard_logging_payload),
|
||||
}
|
||||
|
||||
#########################################################
|
||||
|
|
@ -561,6 +562,31 @@ class DataDogLLMObsLogger(DataDogLogger, CustomBatchLogger):
|
|||
|
||||
return latency_metrics
|
||||
|
||||
def _get_stream_value_from_payload(self, standard_logging_payload: StandardLoggingPayload) -> bool:
|
||||
"""
|
||||
Extract the stream value from standard logging payload.
|
||||
|
||||
The stream field in StandardLoggingPayload is only set to True for completed streaming responses.
|
||||
For non-streaming requests, it's None. The original stream parameter is in model_parameters.
|
||||
|
||||
Returns:
|
||||
bool: True if this was a streaming request, False otherwise
|
||||
"""
|
||||
# Check top-level stream field first (only True for completed streaming)
|
||||
stream_value = standard_logging_payload.get("stream")
|
||||
if stream_value is True:
|
||||
return True
|
||||
|
||||
# Fallback to model_parameters.stream for original request parameters
|
||||
model_params = standard_logging_payload.get("model_parameters", {})
|
||||
if isinstance(model_params, dict):
|
||||
stream_value = model_params.get("stream")
|
||||
if stream_value is True:
|
||||
return True
|
||||
|
||||
# Default to False for non-streaming requests
|
||||
return False
|
||||
|
||||
def _get_spend_metrics(
|
||||
self, standard_logging_payload: StandardLoggingPayload
|
||||
) -> DDLLMObsSpendMetrics:
|
||||
|
|
|
|||
|
|
@ -203,6 +203,9 @@ class TestDataDogLLMObsLogger:
|
|||
assert metadata["cache_hit"] is True
|
||||
assert metadata["cache_key"] == "test-cache-key-789"
|
||||
|
||||
# Test 4: Verify is_streamed_request is in metadata
|
||||
assert metadata["is_streamed_request"] is True
|
||||
|
||||
def test_cache_metadata_fields(self, mock_env_vars, mock_response_obj):
|
||||
"""Test that cache-related metadata fields are correctly tracked"""
|
||||
with patch(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue