Skip to content

[Feat] AI Gateway - Add Tracing for MCP Calls running through AI Gateway - #21018

Merged
ishaan-jaff merged 17 commits into
mainfrom
litellm_mcp_ui_logs_page_fixes
Feb 12, 2026
Merged

[Feat] AI Gateway - Add Tracing for MCP Calls running through AI Gateway #21018
ishaan-jaff merged 17 commits into
mainfrom
litellm_mcp_ui_logs_page_fixes

Conversation

@ishaan-jaff

@ishaan-jaff ishaan-jaff commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

[Feat] AI Gateway - Add Tracing for MCP Calls running through AI Gateway

Group 7249

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🆕 New Feature
✅ Test

Changes

@vercel

vercel Bot commented Feb 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 12, 2026 5:10pm

Request Review

@greptile-apps

greptile-apps Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR adds tracing for MCP (Model Context Protocol) tool calls flowing through the AI Gateway by threading a litellm_trace_id through MCP tool listing operations and enriching the UI logs view with MCP-aware session visualization.

Backend changes:

  • Threads litellm_trace_id from parent requests into list_mcp_tools spend log entries, enabling trace correlation between LLM calls and their MCP sub-operations
  • Refactors user metadata attachment in _get_tools_from_mcp_servers to use the standard LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata helper instead of manual key extraction
  • Adds _build_ui_spend_logs_response helper that enriches spend log rows with session_total_count via an additional GROUP BY query, so the frontend knows which sessions have multiple calls

Frontend changes:

  • Replaces the standalone SessionView page (which used deprecated Tremor components) with an in-drawer session mode in LogDetailsDrawer
  • Adds a "Type" column to the logs table with LLM/MCP badges
  • Adds session deduplication logic to collapse multi-call sessions into a single representative row
  • New TypeBadges.tsx and utils.ts helper files

Critical issue:

  • LogDetailContent.tsx is imported in LogDetailsDrawer.tsx (line 15) and re-exported from index.ts (lines 3-4), but the file does not exist in this PR. This will cause a build failure.

Missing from the PR checklist:

  • No tests were added in tests/litellm/ (required by contribution guidelines)
  • The _build_ui_spend_logs_response session enrichment logic has no test coverage

Confidence Score: 1/5

  • This PR will fail to build due to a missing LogDetailContent.tsx file that is imported and used in the drawer component.
  • Score of 1 reflects a critical missing file (LogDetailContent.tsx) that will break the frontend build. The backend trace-ID plumbing is sound and low-risk, but the UI changes cannot compile as-is. Additionally, no tests were added as required by the contribution guidelines, and the new _build_ui_spend_logs_response database enrichment logic lacks test coverage.
  • ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx — imports non-existent LogDetailContent component. ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/index.ts — re-exports from same missing file. litellm/proxy/spend_tracking/spend_management_endpoints.py — new GROUP BY query on every page load with no test coverage.

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/server.py Adds litellm_trace_id parameter to _get_tools_from_mcp_servers and threads it into spend log metadata; refactors user metadata attachment to use standard LiteLLMProxyRequestSetup helper instead of manual key extraction.
litellm/proxy/spend_tracking/spend_management_endpoints.py Extracts _build_ui_spend_logs_response helper that enriches spend log rows with session_total_count via a GROUP BY query on session_id. Adds an extra DB query per page load for the v1/UI endpoint. No new tests cover the enrichment logic.
litellm/responses/mcp/litellm_proxy_mcp_handler.py Threads litellm_trace_id through _get_mcp_tools_from_manager, _process_mcp_tools_to_openai_format, and _process_mcp_tools_without_openai_transform. Mostly import reordering and parameter addition.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx Major rewrite: adds session-mode sidebar with trace event list, collapsible panel, and session metrics. Imports missing LogDetailContent component — file does not exist, causing a build failure. Also adds sessionId and accessToken props for fetching session logs via React Query.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/index.ts Re-exports LogDetailContent and LogDetailContentProps from ./LogDetailContent — but the source file does not exist, causing build failure.
ui/litellm-dashboard/src/components/view_logs/columns.tsx Adds a new "Type" column showing LLM/MCP badges; extends LogEntry type with session composition fields; enhances Cost column to show MCP sub-cost breakdown.
ui/litellm-dashboard/src/components/view_logs/index.tsx Replaces separate SessionView page with in-drawer session mode; adds session composition counting and O(n^2) deduplication filter for multi-call sessions; passes sessionId/accessToken to LogDetailsDrawer.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Proxy as LiteLLM Proxy
    participant MCP as MCP Server Manager
    participant DB as Spend Logs DB
    participant UI as Dashboard UI

    Client->>Proxy: responses API / chat completions (with litellm_trace_id)
    Proxy->>MCP: _process_mcp_tools_without_openai_transform(litellm_trace_id)
    MCP->>MCP: _get_mcp_tools_from_manager(litellm_trace_id)
    MCP->>MCP: _get_tools_from_mcp_servers(litellm_trace_id)
    MCP->>DB: Log list_mcp_tools with litellm_trace_id + user metadata
    MCP-->>Proxy: MCP tools list
    Proxy->>Proxy: Execute LLM call + MCP tool calls
    Proxy->>DB: Log LLM call & MCP tool calls (same trace_id / session_id)

    UI->>Proxy: GET /spend/logs/ui
    Proxy->>DB: find_many (paginated spend logs)
    Proxy->>DB: GROUP BY session_id (session_total_count enrichment)
    Proxy-->>UI: Enriched rows with session_total_count
    UI->>UI: Deduplicate multi-call sessions, show Type badges
    UI->>UI: Open drawer → fetch session logs → show trace sidebar
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment thread ui/litellm-dashboard/src/components/view_logs/index.tsx Outdated
Comment thread litellm/proxy/spend_tracking/spend_management_endpoints.py
@ishaan-jaff

Copy link
Copy Markdown
Contributor Author

@greptile review again

@greptile-apps

greptile-apps Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Adds end-to-end tracing for MCP tool calls flowing through the AI Gateway by threading litellm_trace_id through MCP list-tools and call-tool paths, and enriches the UI to display MCP calls alongside LLM calls in a unified trace/session view.

  • Backend: Propagates litellm_trace_id from the parent request through _process_mcp_tools_without_openai_transform_get_mcp_tools_from_manager_get_tools_from_mcp_servers, so MCP spend logs are linked to the originating request. Replaces manual metadata attachment with the standard LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata helper.
  • Spend endpoint: Introduces _build_ui_spend_logs_response that enriches each row with session_total_count via a bounded GROUP BY query, enabling the frontend to identify multi-call sessions.
  • UI — Log table: Adds a "Type" column with LLM/MCP badges, shows MCP cost breakdown in the Cost column, and deduplicates multi-call sessions into a single expandable row using an efficient O(n) representative map.
  • UI — Drawer: Refactors LogDetailsDrawer to support a session mode with a collapsible sidebar showing a trace timeline of LLM and MCP events. Extracts LogDetailContent for reuse. Deletes the old Tremor-based SessionView full-page component.
  • No tests included — the PR checklist shows tests are not complete, which should be addressed before merge.

Confidence Score: 3/5

  • Functionally sound feature addition, but lacks tests and introduces a new DB query on every v1 page load.
  • The backend trace-ID plumbing is clean and follows existing patterns. The UI refactor is well-structured with efficient session deduplication. However: (1) No tests are included despite the PR checklist requiring them, (2) the new GROUP BY query runs on every v1/UI spend-logs page load which could impact performance at scale, and (3) the response format change from raw Prisma objects to model_dump() dicts is a subtle behavioral change that should be verified.
  • litellm/proxy/spend_tracking/spend_management_endpoints.py (new DB query on critical path), ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx (large refactor with new session mode)

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/server.py Adds litellm_trace_id parameter to _get_tools_from_mcp_servers and uses LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata for consistent metadata enrichment. Clean, targeted change.
litellm/proxy/spend_tracking/spend_management_endpoints.py Adds _build_ui_spend_logs_response helper that enriches spend log rows with session_total_count via a GROUP BY query. The query is bounded by page_size. Note: response format changes from raw Prisma objects to explicitly model_dump()-ed dicts — should be functionally equivalent but is a behavioral change worth noting.
litellm/responses/mcp/litellm_proxy_mcp_handler.py Threads litellm_trace_id through _get_mcp_tools_from_manager, _process_mcp_tools_to_openai_format, and _process_mcp_tools_without_openai_transform. Also sorts imports alphabetically. Clean plumbing.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx New file — extracts the log detail rendering logic from LogDetailsDrawer into a standalone component. Well-structured with proper sub-components for errors, tags, metrics, request/response, and metadata sections.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx Major refactor — adds session mode with sidebar trace event list, session log fetching via useQuery, and MCP/LLM type differentiation. Delegates detail rendering to LogDetailContent. Complex but well-organized. Uses navigator.clipboard without error handling.
ui/litellm-dashboard/src/components/view_logs/columns.tsx Adds a new "Type" column with LLM/MCP badges and session composition indicators. Extends LogEntry type with session count fields. Cost column updated to show MCP cost breakdown when applicable.
ui/litellm-dashboard/src/components/view_logs/index.tsx Replaces the old full-page SessionView with inline drawer-based session viewing. Adds session deduplication with efficient O(n) single-pass map. Passes sessionId and accessToken to drawer. Removes sessionSpendLogsCall import as fetching moved to drawer.
ui/litellm-dashboard/src/components/view_logs/table.tsx Adds renderChildRows prop for MCP child row rendering alongside existing renderSubComponent. Renames isLegacyMode to supportsExpansion and fixes row click behavior to be based on onRowClick presence rather than mode.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Proxy as LiteLLM Proxy
    participant MCP as MCP Server
    participant DB as SpendLogs DB
    participant UI as Dashboard UI

    Client->>Proxy: responses API / chat completion (with trace_id)
    Proxy->>MCP: list_mcp_tools (litellm_trace_id)
    MCP-->>Proxy: available tools
    Proxy->>DB: log list_tools (linked by trace_id)
    Proxy->>MCP: call_mcp_tool (litellm_trace_id)
    MCP-->>Proxy: tool result
    Proxy->>DB: log call_tool (linked by trace_id)
    Proxy-->>Client: response with MCP metadata

    UI->>DB: GET /spend/logs/ui (paginated)
    DB-->>UI: rows + session_total_count (GROUP BY)
    Note over UI: Deduplicate sessions, show Type badges
    UI->>UI: Click session row → open drawer
    UI->>DB: GET /spend/logs/session/ui?session_id=X
    DB-->>UI: all session logs
    Note over UI: Sidebar trace timeline (LLM + MCP events)
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread litellm/proxy/spend_tracking/spend_management_endpoints.py Outdated
@ishaan-jaff

Copy link
Copy Markdown
Contributor Author

@greptile review this again

@greptile-apps

greptile-apps Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Adds end-to-end tracing for MCP (Model Context Protocol) tool calls flowing through the AI Gateway by threading litellm_trace_id from the parent request into list_mcp_tools spend log entries, and overhauls the UI logs view to display MCP calls alongside LLM calls with session-aware tracing.

  • Backend: Threads litellm_trace_id through _process_mcp_tools_without_openai_transform_get_mcp_tools_from_manager_get_tools_from_mcp_servers, so MCP list_tools spend-log entries carry the parent trace ID. Switches to the standard LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata helper for consistent metadata enrichment.
  • Backend (spend logs): Adds _build_ui_spend_logs_response that enriches v1 UI spend-log rows with session_total_count via a bounded GROUP BY query, enabling the frontend to identify expandable multi-call sessions.
  • Frontend: Replaces the full-page SessionView with an inline session panel inside LogDetailsDrawer. Adds a collapsible sidebar showing a trace event tree, LLM/MCP type badges in the table, cost sub-breakdowns for MCP calls, and session composition indicators. Extracts LogDetailContent as a reusable component.
  • Bug: Session duration calculation in the drawer uses array indices after a type-based sort (LLM before MCP), producing incorrect values for mixed sessions — should use Math.min/Math.max over all timestamps instead.

Confidence Score: 3/5

  • Mostly safe; backend trace-ID plumbing is clean but the session duration calculation bug in the drawer will display wrong values for mixed LLM+MCP sessions.
  • The backend changes (trace ID threading, metadata enrichment, spend-log enrichment) are well-structured and bounded. However, the frontend has a logic bug where session duration is computed from array indices of a type-sorted list instead of actual min/max timestamps. The pre-submission checklist items (tests, CI) are unchecked. The UI refactor is large and deletes the old SessionView entirely, which raises regression surface.
  • ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx has the session duration bug. ui/litellm-dashboard/src/components/view_logs/index.tsx has significant session deduplication logic that should be tested.

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/server.py Adds litellm_trace_id parameter to _get_tools_from_mcp_servers and switches to using the standard LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata helper for consistent metadata enrichment. Clean, safe changes.
litellm/proxy/spend_tracking/spend_management_endpoints.py Extracts _build_ui_spend_logs_response helper to enrich v1 UI spend-log rows with session_total_count via a GROUP BY query. Bounded by page_size; v2 endpoint is unaffected.
litellm/responses/mcp/litellm_proxy_mcp_handler.py Threads litellm_trace_id through _get_mcp_tools_from_manager, _process_mcp_tools_to_openai_format, and _process_mcp_tools_without_openai_transform. Import reordering throughout.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx New file extracting log detail rendering (error alerts, metrics, request/response, guardrails, metadata) from LogDetailsDrawer into a reusable component for both single-log and session views.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx Major refactor to support session mode: adds sidebar with trace event list, fetches session logs via react-query, and delegates content rendering to LogDetailContent. Session duration calculation uses sort-order indices instead of min/max timestamps (bug).
ui/litellm-dashboard/src/components/view_logs/columns.tsx Adds "Type" column showing LLM/MCP badges, enriches LogEntry type with session fields, and shows MCP cost breakdown in the Cost column.
ui/litellm-dashboard/src/components/view_logs/index.tsx Replaces full-page SessionView with drawer-based session support. Adds session composition calculation, representative-row deduplication for multi-call sessions, and passes sessionId/accessToken to LogDetailsDrawer.

Sequence Diagram

sequenceDiagram
    participant UI as Dashboard UI
    participant Proxy as LiteLLM Proxy
    participant DB as Spend Logs DB
    participant MCP as MCP Server

    UI->>Proxy: POST /responses (with MCP tools)
    Proxy->>Proxy: Generate litellm_trace_id
    Proxy->>MCP: list_tools (litellm_trace_id in metadata)
    MCP-->>Proxy: Available tools
    Proxy->>DB: Log list_mcp_tools (with trace_id)
    Proxy->>MCP: call_mcp_tool
    MCP-->>Proxy: Tool result
    Proxy->>DB: Log call_mcp_tool (with trace_id)
    Proxy-->>UI: Response

    UI->>Proxy: GET /spend/logs (v1)
    Proxy->>DB: Fetch paginated logs
    Proxy->>DB: GROUP BY session_id (counts)
    Proxy-->>UI: Enriched logs with session_total_count

    UI->>UI: Show LLM/MCP badges, session grouping
    UI->>Proxy: GET /session/logs/{session_id}
    Proxy->>DB: Fetch session logs
    Proxy-->>UI: Session log entries
    UI->>UI: Render trace sidebar in drawer
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +191 to +192
const sessionStart = sessionLogs.length > 0 ? new Date(sessionLogs[0].startTime) : null;
const sessionEnd = sessionLogs.length > 0 ? new Date(sessionLogs[sessionLogs.length - 1].endTime) : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sessionLogs is sorted by type (LLM first, MCP second), not strictly by time. Using sessionLogs[0] / sessionLogs[sessionLogs.length - 1] for the session time range will produce wrong values when a session has both LLM and MCP calls — the last MCP call might start before the last LLM call chronologically.

Use Math.min / Math.max across all entries instead:

Suggested change
const sessionStart = sessionLogs.length > 0 ? new Date(sessionLogs[0].startTime) : null;
const sessionEnd = sessionLogs.length > 0 ? new Date(sessionLogs[sessionLogs.length - 1].endTime) : null;
const sessionStart = sessionLogs.length > 0 ? new Date(Math.min(...sessionLogs.map(r => new Date(r.startTime).getTime()))) : null;
const sessionEnd = sessionLogs.length > 0 ? new Date(Math.max(...sessionLogs.map(r => new Date(r.endTime).getTime()))) : null;

ghost pushed a commit that referenced this pull request Feb 12, 2026
- Fix session time range calculation: use Math.min/Math.max across all
  entries instead of relying on array order (sessionLogs is sorted by
  type, not time).

Other Greptile comments were already addressed in the branch:
- LogDetailContent.tsx exists
- Clipboard call already wrapped in try/catch
- Dedup already uses O(1) Map lookup
- model_dump() serialization is documented
- GROUP BY performance comment already present
- Fix session time range calculation: use Math.min/Math.max across all
  entries instead of relying on array order (sessionLogs is sorted by
  type, not time).

Other Greptile comments were already addressed in the branch:
- LogDetailContent.tsx exists
- Clipboard call already wrapped in try/catch
- Dedup already uses O(1) Map lookup
- model_dump() serialization is documented
- GROUP BY performance comment already present
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ishaan-jaff
❌ shin-bot-litellm
You have signed the CLA already but the status is still pending? Let us recheck it.

@ishaan-jaff

Copy link
Copy Markdown
Contributor Author

@greptile review again

@greptile-apps

greptile-apps Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Adds end-to-end tracing for MCP (Model Context Protocol) tool calls running through the AI Gateway by threading litellm_trace_id from the parent request through list_mcp_tools spend logs, and enriches the UI logs table with session-aware MCP visibility.

Backend changes:

  • Propagated litellm_trace_id through the MCP handler chain (litellm_proxy_mcp_handler.pyserver.py) so list_mcp_tools spend log entries link back to their parent request trace
  • Switched from manual user_api_key extraction to the standard LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata helper for consistency
  • Added _build_ui_spend_logs_response in spend_management_endpoints.py that enriches v1 UI responses with session_total_count via a bounded GROUP BY query (the new DB query is in the UI endpoint, not the LLM request critical path)

Frontend changes:

  • Replaced the full-page SessionView with an integrated drawer-based session mode in LogDetailsDrawer, featuring a collapsible sidebar with trace event navigation
  • Added a "Type" column to the logs table with LLM/MCP badges and enriched the Cost column with MCP spend breakdown
  • Extracted LogDetailContent as a reusable component from LogDetailsDrawer
  • Added efficient single-pass session deduplication in index.tsx (addresses prior O(n²) concern)
  • Added MCP_CALL_TYPES constant, TypeBadges component, and getEventDisplayName utility

Note: No tests were added in the tests/litellm/ directory as required by the pre-submission checklist.

Confidence Score: 4/5

  • This PR is safe to merge — changes are well-scoped to tracing plumbing and UI log visualization with no impact on the LLM request critical path.
  • The backend changes are minimal and well-contained: threading a trace ID through existing function signatures and adding a bounded GROUP BY in a UI-only endpoint. The frontend is a larger refactor but follows existing patterns, correctly uses Math.min/Math.max for session timing, and improves deduplication performance. The new DB query is not in the critical request path. Minor deduction for missing tests.
  • litellm/proxy/spend_tracking/spend_management_endpoints.py (new DB query on every v1 page load), ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx (large refactor with session mode logic)

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/server.py Added litellm_trace_id parameter to _get_tools_from_mcp_servers and propagated it into request data for spend log linkage. Switched to standard LiteLLMProxyRequestSetup helper for attaching user auth metadata.
litellm/proxy/spend_tracking/spend_management_endpoints.py Added _build_ui_spend_logs_response helper that enriches rows with session_total_count via a GROUP BY query for v1 UI. New direct DB query is in the UI endpoint, not the LLM request critical path.
litellm/responses/mcp/litellm_proxy_mcp_handler.py Threaded litellm_trace_id parameter through _get_mcp_tools_from_manager, _process_mcp_tools_to_openai_format, and _process_mcp_tools_without_openai_transform. Import re-ordering is style-only.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx New file: extracts the scrollable detail content from LogDetailsDrawer into a reusable component for both single-log and session-mode views.
ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx Major refactor: added session mode with collapsible sidebar, trace event navigation, session metrics. Detail content extracted to LogDetailContent. Session logs fetched via react-query.
ui/litellm-dashboard/src/components/view_logs/columns.tsx Added "Type" column with LLM/MCP badges, enriched "Cost" column with MCP spend breakdown, and added new LogEntry fields for session composition.
ui/litellm-dashboard/src/components/view_logs/index.tsx Removed full-page SessionView, replaced with drawer-based session mode. Added efficient single-pass session deduplication. Multi-call sessions open in the drawer.
ui/litellm-dashboard/src/components/view_logs/table.tsx Added renderChildRows prop for MCP child rows as real table rows alongside existing colspan sub-component pattern for audit logs.

Sequence Diagram

sequenceDiagram
    participant UI as Dashboard UI
    participant API as LiteLLM Proxy
    participant DB as Prisma DB
    participant MCP as MCP Server

    UI->>API: POST /responses (with mcp_tools)
    API->>API: Generate litellm_trace_id
    API->>MCP: list_mcp_tools (with litellm_trace_id)
    MCP-->>API: Tool list
    API->>DB: Log list_mcp_tools (trace_id links to parent)
    API->>MCP: call_mcp_tool (with litellm_trace_id)
    MCP-->>API: Tool result
    API->>DB: Log call_mcp_tool (trace_id links to parent)
    API-->>UI: Response

    Note over UI,DB: UI Log Viewing Flow

    UI->>API: GET /spend/logs/ui (v1)
    API->>DB: Fetch paginated spend logs
    API->>DB: GROUP BY session_id (bounded by page_size)
    DB-->>API: Session counts
    API-->>UI: Enriched logs with session_total_count

    UI->>API: GET /spend/logs/session/ui?session_id=X
    API->>DB: Fetch all logs for session
    DB-->>API: Session logs
    API-->>UI: Session logs (displayed in drawer sidebar)
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +3153 to +3157
counts = await prisma_client.db.litellm_spendlogs.group_by(
by=["session_id"],
where={"session_id": {"in": session_ids}},
count={"session_id": True},
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This GROUP BY query runs on every v1 UI page load. The IN clause is bounded by page_size (typically 25–50 distinct session IDs), so it should be fine at moderate scale. Consider a window function in the main query if performance becomes a concern at scale.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ishaan-jaff
ishaan-jaff merged commit 89565c9 into main Feb 12, 2026
53 of 79 checks passed
@OrionCodeDev OrionCodeDev mentioned this pull request Feb 13, 2026
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…way (BerriAI#21018)

* commit new expansion

* fix MCP

* fix: LiteLLMProxyRequestSetup

* _process_mcp_tools_without_openai_transform

* UI fixes

* UI refactor view logs/sessions

* index

* _add_mcp_tool_metadata_to_final_chunk

* add badges

* add getEventDisplayName

* ui fixes

* backend fix

* fix

* UI fix

* UI fix

* fix row

* fix: address Greptile review feedback on PR BerriAI#21018 (BerriAI#21057)

- Fix session time range calculation: use Math.min/Math.max across all
  entries instead of relying on array order (sessionLogs is sorted by
  type, not time).

Other Greptile comments were already addressed in the branch:
- LogDetailContent.tsx exists
- Clipboard call already wrapped in try/catch
- Dedup already uses O(1) Map lookup
- model_dump() serialization is documented
- GROUP BY performance comment already present

---------

Co-authored-by: shin-bot-litellm <shin-bot-litellm@berri.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants