πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): trace tree cleanup: own metrics only, bare type icons, no token counts (#17590)
Trang Nguyend209f82b26d5
diff --git a/web/src/components/ItemBadge.tsx b/web/src/components/ItemBadge.tsxindex 3f2140efe5..4ef93263d1 100644--- a/web/src/components/ItemBadge.tsx+++ b/web/src/components/ItemBadge.tsx@@ -93,6 +93,18 @@ const iconVariants = cva("h-4 w-4", {},});+/** The type icon alone, no badge chrome. */+export function ItemTypeIcon({+ type,+ className,+}: {+ type: LangfuseItemType;+ className?: string;+}) {+ const Icon = iconMap[type];+ return <Icon className={cn("shrink-0", iconVariants({ type }), className)} />;+}+export function renderFilterIcon(value: string): React.ReactNode {const type = value as LangfuseItemType;const Icon = iconMap[type];diff --git a/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx b/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsxindex 76a63e6c02..141c5f1a73 100644--- a/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx+++ b/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx@@ -23,6 +23,9 @@ export function CostBadge({priceSource?: PriceSource;costSource?: CostSource;}) {+ if (!hasBreakdown(costDetails)) {+ return <Badge text={usdFormatter(totalCost)} />;+ }return (<BreakdownTooltipdetails={costDetails}@@ -35,6 +38,10 @@ export function CostBadge({);}+/** A breakdown of nothing but zeros has nothing to say. */+const hasBreakdown = (details: Record<string, number>) =>+ Object.values(details).some((value) => value > 0);+export function UsageBadge({inputUsage,outputUsage,@@ -53,6 +60,10 @@ export function UsageBadge({true,);+ if (tokenText && !hasBreakdown(usageDetails)) {+ return <Badge text={tokenText} />;+ }+return (<BreakdownTooltip details={usageDetails} isCost={false}>{tokenText ? (diff --git a/web/src/features/traces/components/SpanContent.tsx b/web/src/features/traces/components/SpanContent.tsxindex 8080bf05d3..c6aebcd6c4 100644--- a/web/src/features/traces/components/SpanContent.tsx+++ b/web/src/features/traces/components/SpanContent.tsx@@ -25,8 +25,7 @@ import { ObservationLevelBadge } from "@/src/features/traces/components/Observatimport { CommentCountIcon } from "@/src/features/comments/CommentCountIcon";import { cn } from "@/src/utils/tailwind";import { formatIntervalSeconds } from "@/src/utils/dates";-import { usdFormatter, formatTokenCounts } from "@/src/utils/numbers";-import { getSubtreeDurationOverflowMs } from "@/src/features/traces/fns/getSubtreeDurationOverflowMs";+import { usdFormatter, numberFormatter } from "@/src/utils/numbers";import { heatMapTextColor } from "@/src/features/traces/fns/heatMapTextColor";import { useViewPreferences } from "@/src/features/traces/contexts/ViewPreferencesContext";import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";@@ -61,8 +60,10 @@ export function SpanContent({showComments,} = useViewPreferences();- // Use pre-computed cost from the TreeNode- const totalCost = node.totalCost;+ // Own cost only; sums over children belong to the detail panel, not the row.+ const ownCost =+ node.calculatedTotalCost ??+ (node.calculatedInputCost ?? 0) + (node.calculatedOutputCost ?? 0);const duration =node.endTime && node.startTime@@ -74,23 +75,10 @@ export function SpanContent({const shouldRenderDuration =showDuration && Boolean(duration || node.latency);- // Wall-clock duration of the whole subtree, surfaced as a second badge beside- // the own-span badge when async descendants outlive the parent span (so the- // own-span duration above understates the real elapsed time). See LFE-10475.- // It only complements the own-span badge β never renders alone β so a node- // with no own-span duration (e.g. an in-flight/crashed observation with no- // endTime) shows nothing rather than an orphaned "β" with no anchor.- const subtreeWallClockOverflowMs = showDuration- ? getSubtreeDurationOverflowMs(duration, node.subtreeWallClockDurationMs)- : null;- const shouldRenderSubtreeDuration =- shouldRenderDuration && subtreeWallClockOverflowMs != null;-+ // Tokens stand in for cost only when there is no cost to show.+ const tokenTotal = ownCost ? 0 : (node.totalUsage ?? 0);const shouldRenderCostTokens =- showCostTokens &&- Boolean(- node.inputUsage || node.outputUsage || node.totalUsage || totalCost,- );+ showCostTokens && Boolean(ownCost || tokenTotal);const shouldRenderAnyMetrics = shouldRenderDuration || shouldRenderCostTokens;@@ -164,49 +152,30 @@ export function SpanContent({</span>) : null}- {/* Subtree wall-clock duration β async descendants outlive the parent span */}- {shouldRenderSubtreeDuration ? (+ {/* Tokens, only without a cost */}+ {shouldRenderCostTokens && tokenTotal ? (<span- title="Subtree wall-clock duration (first start β last end)"+ title="Total tokens"className="text-foreground-tertiary text-xs">- {"β "}- {formatIntervalSeconds(subtreeWallClockOverflowMs / 1000)}- </span>- ) : null}-- {/* Token counts */}- {shouldRenderCostTokens &&- (node.inputUsage || node.outputUsage || node.totalUsage) ? (- <span className="text-foreground-tertiary text-xs">- {formatTokenCounts(- node.inputUsage,- node.outputUsage,- node.totalUsage,- )}+ {numberFormatter(tokenTotal, 0)} tokens</span>) : null}{/* Cost */}- {shouldRenderCostTokens && totalCost ? (+ {shouldRenderCostTokens && ownCost ? (<span- title={- node.children.length > 0 || node.type === "TRACE"- ? "Aggregated cost of all child observations"- : undefined- }className={cn("text-foreground-tertiary text-xs",parentTotalCost &&colorCodeMetrics &&heatMapTextColor({max: parentTotalCost,- value: totalCost,+ value: ownCost,}),)}>- {node.children.length > 0 || node.type === "TRACE" ? "β " : ""}- {usdFormatter(totalCost.toNumber())}+ {usdFormatter(ownCost)}</span>) : null}</div>diff --git a/web/src/features/traces/components/TraceSettingsDropdown.tsx b/web/src/features/traces/components/TraceSettingsDropdown.tsxindex 325abb9fe6..c30adf4c5e 100644--- a/web/src/features/traces/components/TraceSettingsDropdown.tsx+++ b/web/src/features/traces/components/TraceSettingsDropdown.tsx@@ -150,7 +150,7 @@ export function TraceViewOptionsMenuItems() {className="px-2 py-1"><div className="flex w-full items-center justify-between">- <span className="mr-2">Show Cost/Tokens</span>+ <span className="mr-2">Show Cost</span><Switchsize="sm"checked={showCostTokens}diff --git a/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsx b/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsxindex b082793c88..88c2d13b5a 100644--- a/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsx+++ b/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsx@@ -60,7 +60,10 @@ import {} from "react";import { useTheme } from "next-themes";import { Scan, Minus, Plus, UnfoldVertical } from "lucide-react";-import { ItemBadge, type LangfuseItemType } from "@/src/components/ItemBadge";+import {+ ItemTypeIcon,+ type LangfuseItemType,+} from "@/src/components/ItemBadge";import {tooltipPlacement,type TooltipPlacement,@@ -2039,11 +2042,14 @@ function GutterContent({/></>) : null}- {/* This row's own spine, descending from its icon to its children. */}+ {/* This row's own spine, descending from below its icon to its children. */}{showName && node.hasChildren && !node.isCollapsed ? (<div- className="bg-border-contrast absolute top-1/2 bottom-0 w-px"- style={{ left: `${railX}px` }}+ className="bg-border-contrast absolute bottom-0 w-px"+ style={{+ left: `${railX}px`,+ top: `calc(50% + ${GUTTER_ICON / 2}px)`,+ }}/>) : null}{/* The connector rails above deliberately do NOT dim: each row draws only@@ -2064,7 +2070,10 @@ function GutterContent({}}><span className="shrink-0">- <ItemBadge type={node.type as LangfuseItemType} isSmall />+ <ItemTypeIcon+ type={node.type as LangfuseItemType}+ className="size-4"+ /></span><spanclassName="text-foreground truncate"diff --git a/web/src/features/traces/components/TraceTimelineDense/TimelineRowMetrics.tsx b/web/src/features/traces/components/TraceTimelineDense/TimelineRowMetrics.tsxindex 045b3ce4d4..593a122bfd 100644--- a/web/src/features/traces/components/TraceTimelineDense/TimelineRowMetrics.tsx+++ b/web/src/features/traces/components/TraceTimelineDense/TimelineRowMetrics.tsx@@ -58,7 +58,7 @@ function createClusterFitter(budgetPx: number, gapPx: number) {}export type RowMetrics = {- /** Already formatted, e.g. `β $0.02`. */+ /** Already formatted, e.g. `$0.02`. */costText?: string | null;};diff --git a/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsx b/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsxindex 90236dc484..76bc1fcba7 100644--- a/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsx+++ b/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsx@@ -108,10 +108,7 @@ export function TraceTimelineCompact() {(nodeId: string): RowMetrics => {const node = nodeMap.get(nodeId);if (!node?.totalCost || !showCostTokens) return {};- const aggregated = node.children.length > 0 || node.type === "TRACE";- return {- costText: `${aggregated ? "β " : ""}${usdFormatter(node.totalCost.toNumber())}`,- };+ return { costText: usdFormatter(node.totalCost.toNumber()) };},[nodeMap, showCostTokens],);diff --git a/web/src/features/traces/components/VirtualizedTreeNodeWrapper.tsx b/web/src/features/traces/components/VirtualizedTreeNodeWrapper.tsxindex 866fe9da8d..912032a015 100644--- a/web/src/features/traces/components/VirtualizedTreeNodeWrapper.tsx+++ b/web/src/features/traces/components/VirtualizedTreeNodeWrapper.tsx@@ -16,7 +16,10 @@import { type ReactNode } from "react";import { Button } from "@/src/components/ui/button";-import { ItemBadge, type LangfuseItemType } from "@/src/components/ItemBadge";+import {+ ItemTypeIcon,+ type LangfuseItemType,+} from "@/src/components/ItemBadge";import { ChevronRight } from "lucide-react";import { cn } from "@/src/utils/tailwind";@@ -74,12 +77,12 @@ export function VirtualizedTreeNodeWrapper({return (<divclassName={cn(- "relative flex w-full cursor-pointer px-0",+ "group relative flex w-full cursor-pointer px-0",// Dim unselected rows in dark only β in light the gray read as washed// out, an accepted light/dark inconsistency.isSelected? "bg-muted text-foreground"- : "hover:bg-muted/50 dark:text-muted-foreground",+ : "hover:bg-accent dark:text-muted-foreground",className,)}style={{@@ -131,8 +134,13 @@ export function VirtualizedTreeNodeWrapper({{/* 3. Icon + child connector: fixed width container */}<div className="relative flex w-6 shrink-0 flex-col py-1.5">- <div className="relative z-10 flex h-4 items-center justify-center">- <ItemBadge type={nodeType} isSmall className="size-3!" />+ <div+ className={cn(+ "relative z-10 flex h-4 items-center justify-center",+ isSelected ? "bg-muted" : "bg-background group-hover:bg-accent",+ )}+ >+ <ItemTypeIcon type={nodeType} className="size-3" /></div>{/* Vertical bar downwards if there are expanded children (skippedwhen children render capped at this same indent β the spine