Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: increase scale of dashboard USD numbers (#1301)

Max Deichmannfdda5db1a35c
diff --git a/web/src/features/dashboard/components/MetricTable.tsx b/web/src/features/dashboard/components/MetricTable.tsx
index 62d839a8d8..40c38fd2df 100644
--- a/web/src/features/dashboard/components/MetricTable.tsx
+++ b/web/src/features/dashboard/components/MetricTable.tsx
@@ -4,8 +4,9 @@ import { DashboardCard } from "@/src/features/dashboard/components/cards/Dashboa
import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
import { type FilterState } from "@/src/features/filters/types";
import { api } from "@/src/utils/api";
-import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
+import { compactNumberFormatter } from "@/src/utils/numbers";
import { TotalMetric } from "./TotalMetric";
+import { totalCostDashboardFormatted } from "@/src/features/dashboard/lib/dashboard-utils";
export const MetricTable = ({
className,
@@ -69,7 +70,9 @@ export const MetricTable = ({
</RightAlignedCell>,
<RightAlignedCell key={`${i}-cost`}>
{item.sumCalculatedTotalCost
- ? usdFormatter(item.sumCalculatedTotalCost as number, 2, 2)
+ ? totalCostDashboardFormatted(
+ item.sumCalculatedTotalCost as number,
+ )
: "$0"}
</RightAlignedCell>,
])
@@ -91,7 +94,7 @@ export const MetricTable = ({
collapse={{ collapsed: 5, expanded: 20 }}
>
<TotalMetric
- metric={totalTokenCost ? usdFormatter(totalTokenCost, 2, 2) : "$0"}
+ metric={totalCostDashboardFormatted(totalTokenCost)}
description="Total cost"
>
<DocPopup
diff --git a/web/src/features/dashboard/components/ModelUsageChart.tsx b/web/src/features/dashboard/components/ModelUsageChart.tsx
index 132239347b..94c4ec1e61 100644
--- a/web/src/features/dashboard/components/ModelUsageChart.tsx
+++ b/web/src/features/dashboard/components/ModelUsageChart.tsx
@@ -13,11 +13,12 @@ import {
isEmptyTimeSeries,
} from "@/src/features/dashboard/components/hooks";
import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
-import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
+import { compactNumberFormatter } from "@/src/utils/numbers";
import { TabComponent } from "@/src/features/dashboard/components/TabsComponent";
import { BaseTimeSeriesChart } from "@/src/features/dashboard/components/BaseTimeSeriesChart";
import { TotalMetric } from "@/src/features/dashboard/components/TotalMetric";
import { NoData } from "@/src/features/dashboard/components/NoData";
+import { totalCostDashboardFormatted } from "@/src/features/dashboard/lib/dashboard-utils";
export const ModelUsageChart = ({
className,
@@ -105,14 +106,14 @@ export const ModelUsageChart = ({
// had to add this function as tremor under the hodd adds more variables
// to the function call which would break usdFormatter.
const oneValueUsdFormatter = (value: number) => {
- return usdFormatter(value, 2, 2);
+ return totalCostDashboardFormatted(value);
};
const data = [
{
tabTitle: "Total cost",
data: transformedModelCost,
- totalMetric: totalCost ? usdFormatter(totalCost, 2, 2) : usdFormatter(0),
+ totalMetric: totalCostDashboardFormatted(totalCost),
metricDescription: `Token cost`,
formatter: oneValueUsdFormatter,
},
@@ -126,6 +127,7 @@ export const ModelUsageChart = ({
},
];
+ console.log(data, "data", totalCost);
return (
<DashboardCard
className={className}
diff --git a/web/src/features/dashboard/components/UserChart.tsx b/web/src/features/dashboard/components/UserChart.tsx
index bd197a4234..d7b19ca49f 100644
--- a/web/src/features/dashboard/components/UserChart.tsx
+++ b/web/src/features/dashboard/components/UserChart.tsx
@@ -2,7 +2,7 @@ import { api } from "@/src/utils/api";
import { type DateTimeAggregationOption } from "@/src/features/dashboard/lib/timeseries-aggregation";
import { type FilterState } from "@/src/features/filters/types";
import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
-import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
+import { compactNumberFormatter } from "@/src/utils/numbers";
import { TabComponent } from "@/src/features/dashboard/components/TabsComponent";
import { BarList } from "@tremor/react";
import { TotalMetric } from "@/src/features/dashboard/components/TotalMetric";
@@ -10,7 +10,10 @@ import { ExpandListButton } from "@/src/features/dashboard/components/cards/Chev
import { useState } from "react";
import DocPopup from "@/src/components/layouts/doc-popup";
import { NoData } from "@/src/features/dashboard/components/NoData";
-import { createTracesTimeFilter } from "@/src/features/dashboard/lib/dashboard-utils";
+import {
+ createTracesTimeFilter,
+ totalCostDashboardFormatted,
+} from "@/src/features/dashboard/lib/dashboard-utils";
type BarChartDataPoint = {
name: string;
@@ -124,7 +127,8 @@ export const UserChart = ({
const maxNumberOfEntries = { collapsed: 5, expanded: 20 } as const;
- const localUsdFormatter = (value: number) => usdFormatter(value, 2, 2);
+ const localUsdFormatter = (value: number) =>
+ totalCostDashboardFormatted(value);
const data = [
{
@@ -132,7 +136,7 @@ export const UserChart = ({
data: isExpanded
? transformedCost.slice(0, maxNumberOfEntries.expanded)
: transformedCost.slice(0, maxNumberOfEntries.collapsed),
- totalMetric: totalCost ? usdFormatter(totalCost, 2, 2) : usdFormatter(0),
+ totalMetric: totalCostDashboardFormatted(totalCost),
metricDescription: "Total cost",
formatter: localUsdFormatter,
},
diff --git a/web/src/features/dashboard/lib/dashboard-utils.ts b/web/src/features/dashboard/lib/dashboard-utils.ts
index 791c35b7b6..cdc13fa2a6 100644
--- a/web/src/features/dashboard/lib/dashboard-utils.ts
+++ b/web/src/features/dashboard/lib/dashboard-utils.ts
@@ -1,4 +1,5 @@
import { type FilterState } from "@/src/features/filters/types";
+import { usdFormatter } from "@/src/utils/numbers";
// traces do not have a startTime or endTime column, so we need to map these to the timestamp column
export const createTracesTimeFilter = (filters: FilterState) => {
@@ -13,3 +14,11 @@ export const createTracesTimeFilter = (filters: FilterState) => {
}
});
};
+
+export const totalCostDashboardFormatted = (totalCost?: number) => {
+ return totalCost
+ ? totalCost < 5
+ ? usdFormatter(totalCost, 2, 4)
+ : usdFormatter(totalCost, 2, 2)
+ : usdFormatter(0);
+};