mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(ui): surface x-litellm-call-id in Logs search, table and drawer
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
25af172b85
commit
7576178b50
8 changed files with 166 additions and 40 deletions
|
|
@ -2339,7 +2339,7 @@ def _build_spend_log_search_condition(
|
|||
f"(request_id = {raw} OR ("
|
||||
f"\"startTime\" >= ({window_start}::timestamptz AT TIME ZONE 'UTC') "
|
||||
f"AND \"startTime\" <= ({window_end}::timestamptz AT TIME ZONE 'UTC') "
|
||||
f'AND (api_key = {raw} OR team_id = {raw} OR "user" = {raw} OR end_user = {raw} '
|
||||
f'AND (litellm_call_id = {raw} OR api_key = {raw} OR team_id = {raw} OR "user" = {raw} OR end_user = {raw} '
|
||||
f"OR session_id = {raw} OR model_id = {raw})))"
|
||||
)
|
||||
return _SpendLogSearchCondition(sql=sql, params=(search, start_date, end_date))
|
||||
|
|
@ -2448,7 +2448,7 @@ async def ui_view_spend_logs(
|
|||
search: str | None = fastapi.Query(
|
||||
default=None,
|
||||
description=(
|
||||
"Match a log whose request_id, api_key (hash), team_id, user, end_user, "
|
||||
"Match a log whose request_id, litellm_call_id, api_key (hash), team_id, user, end_user, "
|
||||
"session_id, or model_id equals this value. request_id matches across all time; the other columns "
|
||||
"match inside start_date/end_date, which stay required"
|
||||
),
|
||||
|
|
|
|||
|
|
@ -51,6 +51,24 @@ export async function sendChatCompletion(request: APIRequestContext, opts: ChatO
|
|||
return body.id as string;
|
||||
}
|
||||
|
||||
export interface ServedChat {
|
||||
/** The completion id, which the Logs table calls Request ID. */
|
||||
requestId: string;
|
||||
/** The proxy's own correlation id, returned as x-litellm-call-id and used for OTEL traces. */
|
||||
callId: string;
|
||||
}
|
||||
|
||||
/** POST /v1/chat/completions and return both the completion id and the proxy's x-litellm-call-id. */
|
||||
export async function sendChatCompletionWithCallId(request: APIRequestContext, opts: ChatOptions): Promise<ServedChat> {
|
||||
const res = await postChatCompletion(request, opts);
|
||||
expect(res.ok(), `chat completion for ${opts.model} failed (${res.status()}): ${await res.text()}`).toBe(true);
|
||||
const callId = res.headers()["x-litellm-call-id"];
|
||||
expect(callId, "proxy did not return an x-litellm-call-id header").toBeTruthy();
|
||||
const body = await res.json();
|
||||
expect(body.choices?.[0]?.message?.content).toContain(MOCK_RESPONSE_TEXT);
|
||||
return { requestId: body.id as string, callId };
|
||||
}
|
||||
|
||||
export interface ChatAttempt {
|
||||
status: number;
|
||||
body: string;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
CHAT_MODEL_A,
|
||||
MOCK_RESPONSE_TEXT,
|
||||
sendChatCompletion,
|
||||
sendChatCompletionWithCallId,
|
||||
waitForSpendLog,
|
||||
waitForSpendLogByPrompt,
|
||||
} from "../../helpers/traffic";
|
||||
|
|
@ -95,6 +96,33 @@ test.describe("Logs page", () => {
|
|||
await expect(drawer.getByText(MOCK_RESPONSE_TEXT, { exact: false }).first()).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
|
||||
test("a served request's Logs row and drawer show its x-litellm-call-id", async ({ page, request }) => {
|
||||
const prompt = `logs-call-id-prompt-${uniqueSuffix()}`;
|
||||
const { requestId, callId } = await sendChatCompletionWithCallId(request, {
|
||||
model: CHAT_MODEL_A,
|
||||
prompt,
|
||||
});
|
||||
expect(callId, "call id must differ from the provider response id for this check to mean anything").not.toBe(requestId);
|
||||
await waitForSpendLog(request, requestId);
|
||||
|
||||
await navigateToPage(page, Page.Logs);
|
||||
await dismissFeedbackPopup(page);
|
||||
const search = visibleTestId(page, "datatable-search");
|
||||
await expect(search).toBeVisible({ timeout: 20_000 });
|
||||
await search.fill(callId);
|
||||
|
||||
// Searching by the header value finds the row; the row itself must show that same id so it can be
|
||||
// correlated with the OTEL trace by eye.
|
||||
const row = requestLogsRows(page).filter({ hasText: requestId });
|
||||
await expect(row, `no logs row for call id ${callId}`).toHaveCount(1, { timeout: 30_000 });
|
||||
await expect(row, `Logs row for ${requestId} does not display its x-litellm-call-id ${callId}`).toContainText(callId);
|
||||
|
||||
await row.click();
|
||||
const drawer = page.getByRole("dialog").first();
|
||||
await expect(drawer.getByText("Request & Response")).toBeVisible({ timeout: 20_000 });
|
||||
await expect(drawer.getByText(callId, { exact: false }).first(), `drawer does not show x-litellm-call-id ${callId}`).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
// Split out because only the copy path needs a secure context; folding it in would
|
||||
// take the drawer-rendering coverage down with it.
|
||||
test("the drawer copies the request and the response to the clipboard", async ({ page, request }) => {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ def _filter_logs_by_date_range(logs, where):
|
|||
_SEARCH_CLAUSE_RE = re.compile(
|
||||
r'\(request_id = \$(\d+) OR \("startTime" >= \(\$(\d+)::timestamptz AT TIME ZONE \'UTC\'\) '
|
||||
r'AND "startTime" <= \(\$(\d+)::timestamptz AT TIME ZONE \'UTC\'\) '
|
||||
r'AND \(api_key = \$\1 OR team_id = \$\1 OR "user" = \$\1 OR end_user = \$\1 '
|
||||
r'AND \(litellm_call_id = \$\1 OR api_key = \$\1 OR team_id = \$\1 OR "user" = \$\1 OR end_user = \$\1 '
|
||||
r"OR session_id = \$\1 OR model_id = \$\1\)\)\)"
|
||||
)
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ def _matches_spend_log_search(log, search):
|
|||
return True
|
||||
if not _filter_logs_by_date_range([log], {"startTime": {"gte": search["gte"], "lte": search["lte"]}}):
|
||||
return False
|
||||
columns = ("api_key", "team_id", "user", "end_user", "session_id", "model_id")
|
||||
columns = ("litellm_call_id", "api_key", "team_id", "user", "end_user", "session_id", "model_id")
|
||||
return any(log.get(col) == search["value"] for col in columns)
|
||||
|
||||
|
||||
|
|
@ -3043,7 +3043,7 @@ def test_build_spend_log_search_condition_windows_every_branch_except_request_id
|
|||
assert condition.sql == (
|
||||
"(request_id = $3 OR (\"startTime\" >= ($4::timestamptz AT TIME ZONE 'UTC') "
|
||||
"AND \"startTime\" <= ($5::timestamptz AT TIME ZONE 'UTC') "
|
||||
'AND (api_key = $3 OR team_id = $3 OR "user" = $3 OR end_user = $3 OR session_id = $3 OR model_id = $3)))'
|
||||
'AND (litellm_call_id = $3 OR api_key = $3 OR team_id = $3 OR "user" = $3 OR end_user = $3 OR session_id = $3 OR model_id = $3)))'
|
||||
)
|
||||
assert condition.params == ("key-hash-7", start, end)
|
||||
|
||||
|
|
@ -3069,6 +3069,8 @@ def _search_fixture_logs(today):
|
|||
{**base, "request_id": "req-user", "user": "user-7", "startTime": recent},
|
||||
{**base, "request_id": "req-end-user", "end_user": "cust-7", "startTime": recent},
|
||||
{**base, "request_id": "req-model", "model_id": "mdl-7", "startTime": recent},
|
||||
{**base, "request_id": "chatcmpl-x", "litellm_call_id": "call-recent", "startTime": recent},
|
||||
{**base, "request_id": "chatcmpl-old", "litellm_call_id": "call-old", "startTime": old},
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -3103,6 +3105,8 @@ def _five_day_window(today):
|
|||
("user-7", {"req-user"}),
|
||||
("cust-7", {"req-end-user"}),
|
||||
("mdl-7", {"req-model"}),
|
||||
("call-recent", {"chatcmpl-x"}),
|
||||
("call-old", set()),
|
||||
("no-such-id", set()),
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,23 @@ describe("DrawerHeader sidebar toggle", () => {
|
|||
expect(within(row).getByText("gpt-4o")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the x-litellm-call-id with its own copy button when it differs from the request id", () => {
|
||||
renderHeader(logEntry({ request_id: "chatcmpl-h", litellm_call_id: "call-h" }), false);
|
||||
|
||||
expect(screen.getByText("chatcmpl-h")).toBeInTheDocument();
|
||||
expect(screen.getByText("call-h")).toBeInTheDocument();
|
||||
expect(screen.getByText("call id")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Copy Request ID" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Copy Call ID" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("omits the call id caption and button when the ids match", () => {
|
||||
renderHeader(logEntry({ request_id: "same-h", litellm_call_id: "same-h" }), false);
|
||||
|
||||
expect(screen.queryByText("call id")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Copy Call ID" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("falls back to the request id row when the log names no model", () => {
|
||||
renderHeader(logEntry({ model: "", custom_llm_provider: "" }), true);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ export function DrawerHeader({
|
|||
const providerInfo = provider ? getProviderLogoAndName(provider) : null;
|
||||
const showToggleWithProvider = isSidebarCollapsed && Boolean(providerInfo || log.model);
|
||||
const showToggleWithRequestId = isSidebarCollapsed && !showToggleWithProvider;
|
||||
const callId: string | null =
|
||||
log.litellm_call_id && log.litellm_call_id !== log.request_id ? log.litellm_call_id : null;
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
@ -85,7 +87,17 @@ export function DrawerHeader({
|
|||
}}
|
||||
>
|
||||
{showToggleWithRequestId && <SidebarToggle isCollapsed onToggle={onToggleSidebar} />}
|
||||
<RequestIdSection requestId={log.request_id} />
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<CopyableId value={log.request_id} label="Request ID" fontSize={FONT_SIZE_HEADER} />
|
||||
{callId && (
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-muted-foreground" style={{ fontSize: 10 }}>
|
||||
call id
|
||||
</span>
|
||||
<CopyableId value={callId} label="Call ID" fontSize={FONT_SIZE_MEDIUM} muted />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<NavigationSection onPrevious={onPrevious} onNext={onNext} onClose={onClose} />
|
||||
</div>
|
||||
|
||||
|
|
@ -143,12 +155,22 @@ function ModelProviderSection({
|
|||
/**
|
||||
* Request ID display with copy functionality
|
||||
*/
|
||||
function RequestIdSection({ requestId }: { requestId: string }) {
|
||||
function CopyableId({
|
||||
value,
|
||||
label,
|
||||
fontSize,
|
||||
muted,
|
||||
}: {
|
||||
value: string;
|
||||
label: string;
|
||||
fontSize: number;
|
||||
muted?: boolean;
|
||||
}) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(requestId);
|
||||
await navigator.clipboard.writeText(value);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1200);
|
||||
} catch {
|
||||
|
|
@ -157,38 +179,36 @@ function RequestIdSection({ requestId }: { requestId: string }) {
|
|||
};
|
||||
|
||||
return (
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span
|
||||
className="font-semibold"
|
||||
style={{
|
||||
fontSize: FONT_SIZE_HEADER,
|
||||
fontFamily: FONT_FAMILY_MONO,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
display: "block",
|
||||
}}
|
||||
/>
|
||||
}
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span
|
||||
className={muted ? "text-muted-foreground" : "font-semibold"}
|
||||
style={{
|
||||
fontSize,
|
||||
fontFamily: FONT_FAMILY_MONO,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
display: "block",
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{value}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={copied ? "Copied!" : `Copy ${label}`}
|
||||
onClick={handleCopy}
|
||||
className="ml-1 align-middle text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{requestId}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={copied ? "Copied!" : "Copy Request ID"}
|
||||
onClick={handleCopy}
|
||||
className="ml-1 align-middle text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{copied ? <Check className="size-3.5" /> : <Copy className="size-3.5" />}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{requestId}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
{copied ? <Check className="size-3.5" /> : <Copy className="size-3.5" />}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{value}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -267,10 +267,35 @@ describe("batch rows", () => {
|
|||
});
|
||||
|
||||
it("leaves ordinary request ids untouched", () => {
|
||||
renderRows([logEntry({ request_id: "chatcmpl-42" })]);
|
||||
renderRows([logEntry({ request_id: "chatcmpl-42", litellm_call_id: "chatcmpl-42" })]);
|
||||
|
||||
expect(screen.getByText("chatcmpl-42")).toBeInTheDocument();
|
||||
expect(screen.queryByText("batch cost")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("call id")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Request ID column", () => {
|
||||
it("shows the x-litellm-call-id under the request id when they differ", () => {
|
||||
renderRows([logEntry({ request_id: "chatcmpl-9", litellm_call_id: "call-uuid-9" })]);
|
||||
|
||||
expect(screen.getByText("chatcmpl-9")).toBeInTheDocument();
|
||||
expect(screen.getByText("call-uuid-9")).toBeInTheDocument();
|
||||
expect(screen.getByText("call id")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the id once when request id and call id are the same", () => {
|
||||
renderRows([logEntry({ request_id: "same-id-7", litellm_call_id: "same-id-7" })]);
|
||||
|
||||
expect(screen.getAllByText("same-id-7")).toHaveLength(1);
|
||||
expect(screen.queryByText("call id")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows only the request id when the row carries no call id", () => {
|
||||
renderRows([logEntry({ request_id: "chatcmpl-no-call", litellm_call_id: null })]);
|
||||
|
||||
expect(screen.getByText("chatcmpl-no-call")).toBeInTheDocument();
|
||||
expect(screen.queryByText("call id")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -160,6 +160,20 @@ export const getRequestLogsTableColumns = ({
|
|||
</div>
|
||||
);
|
||||
}
|
||||
if (log.litellm_call_id && log.litellm_call_id !== log.request_id) {
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
<IdCell value={log.request_id} variant="plain" />
|
||||
<IdCell
|
||||
value={log.litellm_call_id}
|
||||
variant="plain"
|
||||
copyable
|
||||
tooltip={`x-litellm-call-id ${log.litellm_call_id}`}
|
||||
/>
|
||||
<span className="text-[10px] text-muted-foreground">call id</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return <IdCell value={log.request_id} variant="plain" />;
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue