Merge pull request #5422 from BerriAI/fix_promt

[minor fix Proxy] - prometheus - safe update start / end time
This commit is contained in:
Ishaan Jaff 2024-08-28 16:35:06 -07:00 committed by GitHub
commit f5a8f71080
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -349,19 +349,23 @@ class PrometheusLogger(CustomLogger):
# latency metrics
total_time: timedelta = kwargs.get("end_time") - kwargs.get("start_time")
total_time_seconds = total_time.total_seconds()
api_call_total_time: timedelta = kwargs.get("end_time") - kwargs.get(
"api_call_start_time"
)
api_call_start_time = kwargs.get("api_call_start_time", None)
api_call_total_time_seconds = api_call_total_time.total_seconds()
if api_call_start_time is not None and isinstance(
api_call_start_time, datetime
):
api_call_total_time: timedelta = (
kwargs.get("end_time") - api_call_start_time
)
api_call_total_time_seconds = api_call_total_time.total_seconds()
self.litellm_llm_api_latency_metric.labels(model).observe(
api_call_total_time_seconds
)
# log metrics
self.litellm_request_total_latency_metric.labels(model).observe(
total_time_seconds
)
self.litellm_llm_api_latency_metric.labels(model).observe(
api_call_total_time_seconds
)
# set x-ratelimit headers
if premium_user is True: