[Feature] UI - Logs: Use backend request_duration_ms and make Duration sortable - #22122
Conversation
…n sortable Use the backend-provided request_duration_ms field instead of computing duration client-side from startTime/endTime. Add sort support for the Duration column, which sends sortBy=request_duration_ms to the API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR replaces the client-side computed
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| ui/litellm-dashboard/src/components/view_logs/columns.tsx | Adds request_duration_ms to sort field map, updates LogEntry type from duration to request_duration_ms, and converts the Duration column to a sortable column with ms-to-seconds conversion. Clean implementation following existing sortable column patterns. |
| ui/litellm-dashboard/src/components/view_logs/index.tsx | Replaces client-side duration computation with direct pass-through of request_duration_ms from backend. Updates RequestViewer display to convert ms to seconds with null-safe handling. |
| ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx | Updates TraceEventRow and session log mapping to use request_duration_ms with a client-side fallback via nullish coalescing for session endpoints that don't yet include the field. |
| ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx | Updates MetricsSection to display duration from request_duration_ms with null-safe ms-to-seconds conversion and a dash fallback. |
| ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.test.tsx | Test fixture updated from duration: 1 to request_duration_ms: 1000 to match the new field name and millisecond units. |
| ui/litellm-dashboard/src/components/view_logs/RequestResponsePanel.test.tsx | Test fixture updated from duration: 1 to request_duration_ms: 1000 to match the new field name and millisecond units. |
| ui/litellm-dashboard/src/components/view_logs/index.test.tsx | Test fixture updated from duration: 1 to request_duration_ms: 1000 to match the new field name and millisecond units. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["/spend/logs/ui endpoint"] -->|"returns request_duration_ms<br/>(COALESCE from DB or computed)"| B["SpendLogsTable (index.tsx)"]
B -->|"passes request_duration_ms<br/>directly to LogEntry"| C["columns.tsx<br/>Duration column cell"]
C -->|"ms / 1000 → seconds display"| D["Table Row"]
E["User clicks Sort by Duration"] -->|"sortBy=request_duration_ms"| A
F["/spend/logs/session/ui endpoint"] -->|"does NOT return<br/>request_duration_ms"| G["LogDetailsDrawer.tsx"]
G -->|"fallback: endTime - startTime"| H["TraceEventRow"]
G -->|"enriched log"| I["LogDetailContent.tsx<br/>Metrics Section"]
I -->|"ms / 1000 → seconds display"| J["Detail Drawer"]
Last reviewed commit: 743b8fd
| .map((row) => ({ | ||
| ...row, | ||
| duration: (Date.parse(row.endTime) - Date.parse(row.startTime)) / 1000, | ||
| request_duration_ms: row.request_duration_ms ?? (Date.parse(row.endTime) - Date.parse(row.startTime)), |
There was a problem hiding this comment.
Good fallback for session endpoint
The nullish coalescing fallback here is necessary and correct — the /spend/logs/session/ui backend endpoint does not currently include request_duration_ms in its SQL SELECT list (see spend_management_endpoints.py:3207-3215), so row.request_duration_ms will be undefined for session logs and this fallback will always kick in.
For full consistency, consider filing a follow-up to add COALESCE(request_duration_ms, ...) to the session endpoint's query as well, similar to what the main /spend/logs/ui endpoint does at line 1943.
…uration [Feature] UI - Logs: Use backend request_duration_ms and make Duration sortable
Summary
Problem
The spend logs Duration column was calculated client-side from
endTime - startTime. This was imprecise and did not support server-side sorting.Fix
request_duration_msfield directly instead of computing duration client-siderequest_duration_msto the sort field map, making the Duration column sortable via the existing sort dropdown patternsortBy=request_duration_msto the/spend/logs/uiendpointTesting
request_duration_ms: 1000instead ofduration: 1Type
🆕 New Feature
✅ Test