From 4b727fe35b69be67289a681ab7136113cf37d4c5 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 13:01:40 -0800 Subject: [PATCH 1/7] fix request_id field --- ui/litellm-dashboard/src/components/view_logs/columns.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/litellm-dashboard/src/components/view_logs/columns.tsx b/ui/litellm-dashboard/src/components/view_logs/columns.tsx index 62f398ce2654..8903f57cd960 100644 --- a/ui/litellm-dashboard/src/components/view_logs/columns.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/columns.tsx @@ -61,9 +61,11 @@ export const columns: ColumnDef[] = [ header: "Request ID", accessorKey: "request_id", cell: (info: any) => ( - - {String(info.getValue() || "")} - + + + {String(info.getValue() || "")} + + ), }, { From dd840e869fd19f7a9d1f1bf6eaca92dcad9f8412 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 15:40:22 -0800 Subject: [PATCH 2/7] spend logs store time in UTC --- .../proxy/spend_tracking/spend_tracking_utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/spend_tracking/spend_tracking_utils.py b/litellm/proxy/spend_tracking/spend_tracking_utils.py index f918350a889d..ae7c2776ce8b 100644 --- a/litellm/proxy/spend_tracking/spend_tracking_utils.py +++ b/litellm/proxy/spend_tracking/spend_tracking_utils.py @@ -1,6 +1,8 @@ import json import secrets +from datetime import datetime from datetime import datetime as dt +from datetime import timezone from typing import Optional, cast from pydantic import BaseModel @@ -153,9 +155,9 @@ def get_logging_payload( # noqa: PLR0915 call_type=call_type or "", api_key=str(api_key), cache_hit=str(cache_hit), - startTime=start_time, - endTime=end_time, - completionStartTime=completion_start_time, + startTime=_ensure_datetime_utc(start_time), + endTime=_ensure_datetime_utc(end_time), + completionStartTime=_ensure_datetime_utc(completion_start_time), model=kwargs.get("model", "") or "", user=kwargs.get("litellm_params", {}) .get("metadata", {}) @@ -195,6 +197,12 @@ def get_logging_payload( # noqa: PLR0915 raise e +def _ensure_datetime_utc(timestamp: datetime) -> datetime: + """Helper to ensure datetime is in UTC""" + timestamp = timestamp.astimezone(timezone.utc) + return timestamp + + async def get_spend_by_team_and_customer( start_date: dt, end_date: dt, From 00ec40b240b6dbd7049f491baa32c8ba50ab0f5e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 15:41:57 -0800 Subject: [PATCH 3/7] fix ui_view_spend_logs --- .../spend_tracking/spend_management_endpoints.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.py index 8d453bf56ed9..00497c5f45ee 100644 --- a/litellm/proxy/spend_tracking/spend_management_endpoints.py +++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py @@ -1,7 +1,7 @@ #### SPEND MANAGEMENT ##### import collections import os -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from typing import TYPE_CHECKING, Any, List, Optional import fastapi @@ -1688,13 +1688,18 @@ async def ui_view_spend_logs( # noqa: PLR0915 ) try: + # Convert the date strings to datetime objects - start_date_obj = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S") - end_date_obj = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S") + start_date_obj = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S").replace( + tzinfo=timezone.utc + ) + end_date_obj = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S").replace( + tzinfo=timezone.utc + ) # Convert to ISO format strings for Prisma - start_date_iso = start_date_obj.isoformat() + "Z" # Add Z to indicate UTC - end_date_iso = end_date_obj.isoformat() + "Z" # Add Z to indicate UTC + start_date_iso = start_date_obj.isoformat() # Already in UTC, no need to add Z + end_date_iso = end_date_obj.isoformat() # Already in UTC, no need to add Z # Build where conditions where_conditions: dict[str, Any] = { From 0118f2ee314346a4d8d38c72f2019bac084b39ea Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 15:43:54 -0800 Subject: [PATCH 4/7] UI make time filter queries in UTC --- ui/litellm-dashboard/src/components/view_logs/index.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/litellm-dashboard/src/components/view_logs/index.tsx b/ui/litellm-dashboard/src/components/view_logs/index.tsx index c865042c3299..aac8e9c809ec 100644 --- a/ui/litellm-dashboard/src/components/view_logs/index.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/index.tsx @@ -105,10 +105,13 @@ export default function SpendLogsTable({ }; } - const formattedStartTime = moment(startTime).format("YYYY-MM-DD HH:mm:ss"); + const formattedStartTime = moment(startTime).utc().format("YYYY-MM-DD HH:mm:ss"); const formattedEndTime = isCustomDate - ? moment(endTime).format("YYYY-MM-DD HH:mm:ss") - : moment().format("YYYY-MM-DD HH:mm:ss"); + ? moment(endTime).utc().format("YYYY-MM-DD HH:mm:ss") + : moment().utc().format("YYYY-MM-DD HH:mm:ss"); + + console.log("formattedStartTime", formattedStartTime); + console.log("formattedEndTime", formattedEndTime); return await uiSpendLogsCall( accessToken, From d8774bb53d3bdf2991ca4a59c3831f9c24f21de6 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 15:50:44 -0800 Subject: [PATCH 5/7] fix time filters --- .../src/components/view_logs/index.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ui/litellm-dashboard/src/components/view_logs/index.tsx b/ui/litellm-dashboard/src/components/view_logs/index.tsx index aac8e9c809ec..1d97a8e7e241 100644 --- a/ui/litellm-dashboard/src/components/view_logs/index.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/index.tsx @@ -105,13 +105,10 @@ export default function SpendLogsTable({ }; } - const formattedStartTime = moment(startTime).utc().format("YYYY-MM-DD HH:mm:ss"); + const formattedStartTime = moment(startTime).format("YYYY-MM-DD HH:mm:ss"); const formattedEndTime = isCustomDate - ? moment(endTime).utc().format("YYYY-MM-DD HH:mm:ss") - : moment().utc().format("YYYY-MM-DD HH:mm:ss"); - - console.log("formattedStartTime", formattedStartTime); - console.log("formattedEndTime", formattedEndTime); + ? moment(endTime).format("YYYY-MM-DD HH:mm:ss") + : moment().format("YYYY-MM-DD HH:mm:ss"); return await uiSpendLogsCall( accessToken, @@ -179,7 +176,7 @@ export default function SpendLogsTable({

Request Logs

-
+
From 2734fac591dc8b58445864988fdc18abcc5ae1c9 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 16:12:35 -0800 Subject: [PATCH 6/7] fix TimeCellProps --- .../src/components/view_logs/columns.tsx | 5 +-- .../src/components/view_logs/time_cell.tsx | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 ui/litellm-dashboard/src/components/view_logs/time_cell.tsx diff --git a/ui/litellm-dashboard/src/components/view_logs/columns.tsx b/ui/litellm-dashboard/src/components/view_logs/columns.tsx index 8903f57cd960..3a55f5177413 100644 --- a/ui/litellm-dashboard/src/components/view_logs/columns.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/columns.tsx @@ -5,6 +5,7 @@ import React from "react"; import { CountryCell } from "./country_cell"; import { getProviderLogoAndName } from "../provider_info_helpers"; import { Tooltip } from "antd"; +import { TimeCell } from "./time_cell"; export type LogEntry = { request_id: string; @@ -53,9 +54,7 @@ export const columns: ColumnDef[] = [ { header: "Time", accessorKey: "startTime", - cell: (info: any) => ( - {moment(info.getValue()).format("MMM DD HH:mm:ss")} - ), + cell: (info: any) => , }, { header: "Request ID", diff --git a/ui/litellm-dashboard/src/components/view_logs/time_cell.tsx b/ui/litellm-dashboard/src/components/view_logs/time_cell.tsx new file mode 100644 index 000000000000..5c0662adb48c --- /dev/null +++ b/ui/litellm-dashboard/src/components/view_logs/time_cell.tsx @@ -0,0 +1,38 @@ +import * as React from "react"; + +interface TimeCellProps { + utcTime: string; +} + +const getLocalTime = (utcTime: string): string => { + try { + const date = new Date(utcTime); + return date.toLocaleString('en-US', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: true + }).replace(',', ''); + } catch (e) { + return "Error converting time"; + } +}; + +export const TimeCell: React.FC = ({ utcTime }) => { + return ( + + {getLocalTime(utcTime)} + + ); +}; + +export const getTimeZone = (): string => { + return Intl.DateTimeFormat().resolvedOptions().timeZone; +}; \ No newline at end of file From a2ad7eb8cb2236f5ac60daad99a50651a78f4157 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 1 Feb 2025 16:21:45 -0800 Subject: [PATCH 7/7] ui use UTC for filtering time --- ui/litellm-dashboard/src/components/view_logs/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/litellm-dashboard/src/components/view_logs/index.tsx b/ui/litellm-dashboard/src/components/view_logs/index.tsx index 1d97a8e7e241..b4691fd3c4b8 100644 --- a/ui/litellm-dashboard/src/components/view_logs/index.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/index.tsx @@ -105,10 +105,11 @@ export default function SpendLogsTable({ }; } - const formattedStartTime = moment(startTime).format("YYYY-MM-DD HH:mm:ss"); + // Convert times to UTC before formatting + const formattedStartTime = moment(startTime).utc().format("YYYY-MM-DD HH:mm:ss"); const formattedEndTime = isCustomDate - ? moment(endTime).format("YYYY-MM-DD HH:mm:ss") - : moment().format("YYYY-MM-DD HH:mm:ss"); + ? moment(endTime).utc().format("YYYY-MM-DD HH:mm:ss") + : moment().utc().format("YYYY-MM-DD HH:mm:ss"); return await uiSpendLogsCall( accessToken,