The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
(UI - View Logs Table) - Show country of origin for logs (#7856)
Ishaan Jafff60756c81558
diff --git a/ui/litellm-dashboard/src/components/view_logs/columns.tsx b/ui/litellm-dashboard/src/components/view_logs/columns.tsxindex 18395176d03..0d889d0ec6d 100644--- a/ui/litellm-dashboard/src/components/view_logs/columns.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/columns.tsx@@ -1,5 +1,8 @@import type { ColumnDef } from "@tanstack/react-table";+import { getCountryFromIP } from "./ip_lookup";import moment from "moment";+import React from "react";+import { CountryCell } from "./country_cell";export type LogEntry = {request_id: string;@@ -35,10 +38,10 @@ export const columns: ColumnDef<LogEntry>[] = [style: { cursor: "pointer" },}}>- {row.getIsExpanded() ? "👇" : "👉"}+ {row.getIsExpanded() ? "▼" : "▶"}</button>) : (- "🔵"+ "●");},},@@ -140,6 +143,11 @@ export const columns: ColumnDef<LogEntry>[] = [);},},+ {+ header: "Country",+ accessorKey: "requester_ip_address",+ cell: (info: any) => <CountryCell ipAddress={info.getValue()} />,+ },];const formatMessage = (message: any): string => {diff --git a/ui/litellm-dashboard/src/components/view_logs/country_cell.tsx b/ui/litellm-dashboard/src/components/view_logs/country_cell.tsxnew file mode 100644index 00000000000..af511edbacd--- /dev/null+++ b/ui/litellm-dashboard/src/components/view_logs/country_cell.tsx@@ -0,0 +1,27 @@+import * as React from "react";+import { getCountryFromIP } from "./ip_lookup";++interface CountryCellProps {+ ipAddress: string | null;+}++export const CountryCell: React.FC<CountryCellProps> = ({ ipAddress }) => {+ const [country, setCountry] = React.useState<string>("-");++ React.useEffect(() => {+ if (!ipAddress) return;++ let mounted = true;+ getCountryFromIP(ipAddress)+ .then(result => {+ if (mounted) setCountry(result);+ })+ .catch(() => {+ if (mounted) setCountry("-");+ });++ return () => { mounted = false };+ }, [ipAddress]);++ return <span>{country}</span>;+};\ No newline at end of filediff --git a/ui/litellm-dashboard/src/components/view_logs/index.tsx b/ui/litellm-dashboard/src/components/view_logs/index.tsxindex dd351b12ed1..2d7c4a672cf 100644--- a/ui/litellm-dashboard/src/components/view_logs/index.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/index.tsx@@ -56,8 +56,9 @@ export default function SpendLogsTable({}return (- <div className="w-[90%] mx-auto px-4">- <div className="bg-white rounded-lg shadow w-full">+ <div className="px-4 md:px-8 py-8 w-full">+ <h1 className="text-xl font-semibold mb-4">Traces</h1>+ <div className="bg-white rounded-lg shadow overflow-hidden"><div className="p-4 border-b flex justify-between items-center"><div className="flex space-x-4 items-center"><inputdiff --git a/ui/litellm-dashboard/src/components/view_logs/ip_lookup.tsx b/ui/litellm-dashboard/src/components/view_logs/ip_lookup.tsxnew file mode 100644index 00000000000..ea68b2333d6--- /dev/null+++ b/ui/litellm-dashboard/src/components/view_logs/ip_lookup.tsx@@ -0,0 +1,22 @@+export async function getCountryFromIP(ip: string): Promise<string> {+ try {+ const response = await fetch(`http://ip-api.com/json/${ip}`);+ const data = await response.json();+ console.log("ip lookup data", data);++ // Convert country code to flag emoji (each capital letter is converted to regional indicator symbol)+ const flagEmoji = data.countryCode+ ? data.countryCode+ .toUpperCase()+ .split('')+ .map((char: string) => String.fromCodePoint(char.charCodeAt(0) + 127397))+ .join('')+ : '';++ // Return country name with flag emoji+ return data.country ? `${flagEmoji} ${data.country}` : 'Unknown';+ } catch (error) {+ console.error('Error looking up IP:', error);+ return 'Unknown';+ }+}diff --git a/ui/litellm-dashboard/src/components/view_logs/table.tsx b/ui/litellm-dashboard/src/components/view_logs/table.tsxindex 2a766a7172e..326cac0792a 100644--- a/ui/litellm-dashboard/src/components/view_logs/table.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/table.tsx@@ -25,7 +25,7 @@ interface DataTableProps<TData, TValue> {}export function DataTable<TData, TValue>({- data,+ data = [],columns,getRowCanExpand,renderSubComponent,@@ -60,7 +60,7 @@ export function DataTable<TData, TValue>({))}</TableHead><TableBody>- {table.getRowModel().rows?.length ? (+ {table.getRowModel().rows.length > 0 ? (table.getRowModel().rows.map((row) => (<Fragment key={row.id}><TableRow>