diff --git a/ui/litellm-dashboard/src/components/view_logs/RequestLogsTable.tsx b/ui/litellm-dashboard/src/components/view_logs/RequestLogsTable.tsx index c3d204e1ae3..f45344b9a25 100644 --- a/ui/litellm-dashboard/src/components/view_logs/RequestLogsTable.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/RequestLogsTable.tsx @@ -2,13 +2,14 @@ import type { ColumnFiltersState, OnChangeFn, PaginationState, SortingState } from "@tanstack/react-table"; import { ScrollText } from "lucide-react"; -import { useMemo, useState, type ReactNode } from "react"; +import { useCallback, useMemo, useState, type ReactNode } from "react"; +import { useProjects } from "@/app/(dashboard)/hooks/projects/useProjects"; import { DataTable, DataTableFilterDrawer, DataTableToolbar } from "@/components/shared/DataTable"; import type { Team } from "../key_team_helpers/key_list"; import type { LogEntry } from "./columns"; -import { LOG_FILTER_LABELS, type LogsWindow } from "./log_filter_logic"; +import { LOG_FILTER_LABELS, resolveLogFilterDisplayValue, type LogsWindow } from "./log_filter_logic"; import { RequestLogsFilters } from "./RequestLogsFilters"; import { getRequestLogsTableColumns } from "./RequestLogsTableColumns"; @@ -73,6 +74,8 @@ export function RequestLogsTable({ }: RequestLogsTableProps) { const [filtersOpen, setFiltersOpen] = useState(false); + const { data: projects } = useProjects(); + const columns = useMemo(() => { const deps = { onKeyHashClick, onSessionClick }; return getRequestLogsTableColumns(deps); @@ -80,6 +83,12 @@ export function RequestLogsTable({ const isFiltered = columnFilters.length > 0 || searchValue !== ""; + const formatFilterValue = useCallback( + (columnId: string, value: unknown): string => + resolveLogFilterDisplayValue(columnId, String(value), teams, projects), + [projects, teams], + ); + return ( setFiltersOpen(true)} filterLabels={LOG_FILTER_LABELS} + formatFilterValue={formatFilterValue} showViewOptions={false} > {toolbarChildren} diff --git a/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.test.tsx b/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.test.tsx index 0db26520a8b..dc574817392 100644 --- a/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.test.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.test.tsx @@ -13,9 +13,11 @@ import { LIVE_TAIL_INTERVAL_MS, LOG_FILTER_IDS, LOGS_WINDOW_TICK_MS, + resolveLogFilterDisplayValue, useLogFilterLogic, type PaginatedResponse, } from "./log_filter_logic"; +import type { ProjectResponse } from "@/app/(dashboard)/hooks/projects/useProjects"; vi.mock("../networking", () => ({ uiSpendLogsCall: vi.fn(), @@ -278,6 +280,46 @@ describe("getFilterValue", () => { }); }); +describe("resolveLogFilterDisplayValue", () => { + const teams = [ + { team_id: "team-1", team_alias: "Payments Team" }, + { team_id: "team-2", team_alias: "" }, + ] as Team[]; + const projects = [ + { project_id: "f7e457ae-9fd6-4ed2-a94b-12d495a6d14e", project_alias: "Growth Experiments" }, + { project_id: "project-no-alias", project_alias: null }, + ] as ProjectResponse[]; + + it("resolves a team_id filter to its team_alias", () => { + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.TEAM_ID, "team-1", teams, projects)).toBe("Payments Team"); + }); + + it("resolves a project_id filter to its project_alias", () => { + expect( + resolveLogFilterDisplayValue(LOG_FILTER_IDS.PROJECT_ID, "f7e457ae-9fd6-4ed2-a94b-12d495a6d14e", teams, projects), + ).toBe("Growth Experiments"); + }); + + it("falls back to the raw id when the team is unknown or has no alias", () => { + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.TEAM_ID, "team-2", teams, projects)).toBe("team-2"); + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.TEAM_ID, "team-missing", teams, projects)).toBe("team-missing"); + }); + + it("falls back to the raw id when the project is unknown, has no alias, or the list has not loaded", () => { + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.PROJECT_ID, "project-no-alias", teams, projects)).toBe( + "project-no-alias", + ); + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.PROJECT_ID, "project-missing", teams, projects)).toBe( + "project-missing", + ); + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.PROJECT_ID, "project-1", teams, undefined)).toBe("project-1"); + }); + + it("passes through filters that carry no id-to-name mapping unchanged", () => { + expect(resolveLogFilterDisplayValue(LOG_FILTER_IDS.KEY_HASH, "sk-hash-1", teams, projects)).toBe("sk-hash-1"); + }); +}); + describe("getLiveTailRefetchInterval", () => { it("polls every 15s when live tail is on and on the first page", () => { expect(getLiveTailRefetchInterval(true, 0)).toBe(LIVE_TAIL_INTERVAL_MS); diff --git a/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.tsx b/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.tsx index 99496aab0ac..caaaecf5a0f 100644 --- a/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/log_filter_logic.tsx @@ -4,6 +4,7 @@ import type { ColumnFiltersState, PaginationState, SortingState } from "@tanstac import { uiSpendLogsCall } from "../networking"; import { Team } from "../key_team_helpers/key_list"; import { fetchAllTeams } from "../../components/key_team_helpers/filter_helpers"; +import type { ProjectResponse } from "@/app/(dashboard)/hooks/projects/useProjects"; import { teamListScopeUserId } from "../../utils/roles"; import { defaultPageSize } from "../constants"; import { LOGS_SORT_FIELD_MAP, type LogEntry, type LogsSortField } from "./columns"; @@ -101,6 +102,26 @@ export const getFilterValue = (columnFilters: ColumnFiltersState, columnId: stri return trimmed === "" ? undefined : trimmed; }; +/** + * The Team and Project filter chips carry the id as their filter value (needed for the + * backend query and for re-selecting the right option in the filter drawer), but showing + * that id in the chip is meaningless to a reader. Resolve it back to the alias they picked. + */ +export const resolveLogFilterDisplayValue = ( + columnId: string, + rawValue: string, + teams: readonly Team[], + projects: readonly ProjectResponse[] | undefined, +): string => { + if (columnId === LOG_FILTER_IDS.TEAM_ID) { + return teams.find((team) => team.team_id === rawValue)?.team_alias || rawValue; + } + if (columnId === LOG_FILTER_IDS.PROJECT_ID) { + return projects?.find((project) => project.project_id === rawValue)?.project_alias || rawValue; + } + return rawValue; +}; + export function useLogFilterLogic({ accessToken, token,