Skip to content

Commit ec61a71

Browse files
authored
Support for is_streamed_request widh datadog (#14673)
1 parent a7a6381 commit ec61a71

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

litellm/integrations/datadog/datadog_llm_obs.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def _get_dd_llm_obs_payload_metadata(
498498
"guardrail_information": standard_logging_payload.get(
499499
"guardrail_information", None
500500
),
501+
"is_streamed_request": self._get_stream_value_from_payload(standard_logging_payload),
501502
}
502503

503504
#########################################################
@@ -561,6 +562,31 @@ def _get_latency_metrics(
561562

562563
return latency_metrics
563564

565+
def _get_stream_value_from_payload(self, standard_logging_payload: StandardLoggingPayload) -> bool:
566+
"""
567+
Extract the stream value from standard logging payload.
568+
569+
The stream field in StandardLoggingPayload is only set to True for completed streaming responses.
570+
For non-streaming requests, it's None. The original stream parameter is in model_parameters.
571+
572+
Returns:
573+
bool: True if this was a streaming request, False otherwise
574+
"""
575+
# Check top-level stream field first (only True for completed streaming)
576+
stream_value = standard_logging_payload.get("stream")
577+
if stream_value is True:
578+
return True
579+
580+
# Fallback to model_parameters.stream for original request parameters
581+
model_params = standard_logging_payload.get("model_parameters", {})
582+
if isinstance(model_params, dict):
583+
stream_value = model_params.get("stream")
584+
if stream_value is True:
585+
return True
586+
587+
# Default to False for non-streaming requests
588+
return False
589+
564590
def _get_spend_metrics(
565591
self, standard_logging_payload: StandardLoggingPayload
566592
) -> DDLLMObsSpendMetrics:

tests/test_litellm/integrations/datadog/test_datadog_llm_observability.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def test_cost_and_trace_id_integration(self, mock_env_vars, mock_response_obj):
203203
assert metadata["cache_hit"] is True
204204
assert metadata["cache_key"] == "test-cache-key-789"
205205

206+
# Test 4: Verify is_streamed_request is in metadata
207+
assert metadata["is_streamed_request"] is True
208+
206209
def test_cache_metadata_fields(self, mock_env_vars, mock_response_obj):
207210
"""Test that cache-related metadata fields are correctly tracked"""
208211
with patch(

0 commit comments

Comments
 (0)