Skip to content

Commit c92b6c1

Browse files
Prometheus - fix request increment + add route tracking for streaming requests (#11731)
* fix(prometheus.py): remove request increment from inside the log success event it's only done on post-call success/failure * fix(litellm_logging.py): add additional validation step for checking if 'stream' is true prevent double counting on non-stream requests * test: add unit testing to ensure stream is not incorrectly set to true * feat(litellm_logging.py): emit request route in standard logging payload used by prometheus streaming metrics for route * fix: fix otel test * fix: fix linting errors * test: update test * fix: fix linting error
1 parent c96325a commit c92b6c1

File tree

23 files changed

+271
-189
lines changed

23 files changed

+271
-189
lines changed

enterprise/litellm_enterprise/enterprise_callbacks/pagerduty/pagerduty.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ async def async_log_failure_event(self, kwargs, response_obj, start_time, end_ti
115115
user_api_key_team_alias=_meta.get("user_api_key_team_alias"),
116116
user_api_key_end_user_id=_meta.get("user_api_key_end_user_id"),
117117
user_api_key_user_email=_meta.get("user_api_key_user_email"),
118+
user_api_key_request_route=_meta.get("user_api_key_request_route"),
118119
)
119120
)
120121

@@ -195,6 +196,7 @@ async def hanging_response_handler(
195196
user_api_key_team_alias=user_api_key_dict.team_alias,
196197
user_api_key_end_user_id=user_api_key_dict.end_user_id,
197198
user_api_key_user_email=user_api_key_dict.user_email,
199+
user_api_key_request_route=user_api_key_dict.request_route,
198200
)
199201
)
200202

litellm/integrations/prometheus.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ async def async_log_success_event(self, kwargs, response_obj, start_time, end_ti
583583
metadata=standard_logging_payload["metadata"].get("requester_metadata")
584584
or {}
585585
),
586+
route=standard_logging_payload["metadata"].get(
587+
"user_api_key_request_route"
588+
),
586589
)
587590

588591
if (
@@ -795,8 +798,6 @@ def _increment_top_level_request_and_spend_metrics(
795798
enum_values=enum_values,
796799
)
797800

798-
self.litellm_proxy_total_requests_metric.labels(**_labels).inc()
799-
800801
self.litellm_spend_metric.labels(
801802
end_user_id,
802803
user_api_key,

litellm/litellm_core_utils/litellm_logging.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3544,6 +3544,7 @@ def get_standard_logging_metadata(
35443544
vector_store_request_metadata=vector_store_request_metadata,
35453545
usage_object=usage_object,
35463546
requester_custom_headers=None,
3547+
user_api_key_request_route=None,
35473548
)
35483549
if isinstance(metadata, dict):
35493550
# Filter the metadata dictionary to include only the specified keys
@@ -3967,7 +3968,7 @@ def get_standard_logging_object_payload(
39673968
if (
39683969
kwargs.get("complete_streaming_response") is not None
39693970
or kwargs.get("async_complete_streaming_response") is not None
3970-
):
3971+
) and kwargs.get("stream") is True:
39713972
stream = True
39723973

39733974
payload: StandardLoggingPayload = StandardLoggingPayload(
@@ -4069,6 +4070,7 @@ def get_standard_logging_metadata(
40694070
vector_store_request_metadata=None,
40704071
usage_object=None,
40714072
requester_custom_headers=None,
4073+
user_api_key_request_route=None,
40724074
)
40734075
if isinstance(metadata, dict):
40744076
# Filter the metadata dictionary to include only the specified keys

litellm/proxy/_experimental/out/_next/static/chunks/250-562275aca86e6d43.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/webpack-a426aae3231a8df1.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/css/31b7f215e119031e.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 34 deletions
Loading

0 commit comments

Comments
 (0)