🪢 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
chore(single-trace): make tree a little more dense and allow click everywhere (#9183)
Leo Weigand5df5a7cd4871
diff --git a/web/src/components/trace/SpanItem.tsx b/web/src/components/trace/SpanItem.tsxindex ab226ae780..abe3865417 100644--- a/web/src/components/trace/SpanItem.tsx+++ b/web/src/components/trace/SpanItem.tsx@@ -1,6 +1,5 @@import { type TreeNode } from "./lib/types";import { GroupedScoreBadges } from "@/src/components/grouped-score-badge";-import { ItemBadge } from "@/src/components/ItemBadge";import { LevelColors } from "@/src/components/level-colors";import { CommentCountIcon } from "@/src/features/comments/CommentCountIcon";import { cn } from "@/src/utils/tailwind";@@ -73,111 +72,104 @@ export const SpanItem: React.FC<SpanItemProps> = ({);return (- <div className={cn("flex min-w-0 items-start gap-2", className)}>- <div className="relative z-20 flex-shrink-0">- <ItemBadge type={node.type} isSmall className="!size-3" />- </div>-- <div className="flex min-w-0 flex-1 flex-col">- <div className="flex min-w-0 items-center gap-2 overflow-hidden">- <span className="flex-shrink truncate text-xs" title={node.name}>- {node.name}- </span>-- <div className="flex items-center gap-2">- {comments && showComments ? (- <CommentCountIcon count={comments.get(node.id)} />- ) : null}- {node.type !== "TRACE" && node.level && node.level !== "DEFAULT" ? (- <div className="flex">- <span- className={cn(- "rounded-sm p-0.5 text-xs",- LevelColors[node.level as keyof typeof LevelColors]?.bg,- LevelColors[node.level as keyof typeof LevelColors]?.text,- )}- >- {node.level}- </span>- </div>- ) : null}- </div>- </div>+ <div className={cn("flex min-w-0 flex-col", className)}>+ <div className="flex min-w-0 items-center gap-2 overflow-hidden">+ <span className="flex-shrink truncate text-xs" title={node.name}>+ {node.name}+ </span>- {shouldRenderMetrics && (- <div className="flex flex-wrap gap-2">- {duration || node.latency ? (- <span- title={- node.children.length > 0 || node.type === "TRACE"- ? "Aggregated duration of all child observations"- : undefined- }- className={cn(- "text-xs text-muted-foreground",- parentTotalDuration &&- colorCodeMetrics &&- heatMapTextColor({- max: parentTotalDuration,- value:- duration || (node.latency ? node.latency * 1000 : 0),- }),- )}- >- {formatIntervalSeconds(- (duration || (node.latency ? node.latency * 1000 : 0)) / 1000,- )}- </span>- ) : null}- {node.inputUsage || node.outputUsage || node.totalUsage ? (- <span className="text-xs text-muted-foreground">- {formatTokenCounts(- node.inputUsage,- node.outputUsage,- node.totalUsage,- )}- </span>- ) : null}- {totalCost ? (+ <div className="flex items-center gap-2">+ {comments && showComments ? (+ <CommentCountIcon count={comments.get(node.id)} />+ ) : null}+ {node.type !== "TRACE" && node.level && node.level !== "DEFAULT" ? (+ <div className="flex"><span- title={- node.children.length > 0 || node.type === "TRACE"- ? "Aggregated cost of all child observations"- : undefined- }className={cn(- "text-xs text-muted-foreground",- parentTotalCost &&- colorCodeMetrics &&- heatMapTextColor({- max: parentTotalCost,- value: totalCost,- }),+ "rounded-sm p-0.5 text-xs",+ LevelColors[node.level as keyof typeof LevelColors]?.bg,+ LevelColors[node.level as keyof typeof LevelColors]?.text,)}>- {node.children.length > 0 || node.type === "TRACE" ? "∑ " : ""}- {usdFormatter(totalCost.toNumber())}+ {node.level}</span>- ) : null}- </div>- )}-- {showScores &&- ((node.type === "TRACE" &&- scores.find((s) => s.observationId === null)) ||- scores.find((s) => s.observationId === node.id)) && (- <div className="flex flex-wrap gap-1">- <GroupedScoreBadges- compact- scores={- node.type === "TRACE"- ? scores.filter((s) => s.observationId === null)- : scores.filter((s) => s.observationId === node.id)- }- /></div>- )}+ ) : null}+ </div></div>++ {shouldRenderMetrics && (+ <div className="flex flex-wrap gap-2">+ {duration || node.latency ? (+ <span+ title={+ node.children.length > 0 || node.type === "TRACE"+ ? "Aggregated duration of all child observations"+ : undefined+ }+ className={cn(+ "text-xs text-muted-foreground",+ parentTotalDuration &&+ colorCodeMetrics &&+ heatMapTextColor({+ max: parentTotalDuration,+ value: duration || (node.latency ? node.latency * 1000 : 0),+ }),+ )}+ >+ {formatIntervalSeconds(+ (duration || (node.latency ? node.latency * 1000 : 0)) / 1000,+ )}+ </span>+ ) : null}+ {node.inputUsage || node.outputUsage || node.totalUsage ? (+ <span className="text-xs text-muted-foreground">+ {formatTokenCounts(+ node.inputUsage,+ node.outputUsage,+ node.totalUsage,+ )}+ </span>+ ) : null}+ {totalCost ? (+ <span+ title={+ node.children.length > 0 || node.type === "TRACE"+ ? "Aggregated cost of all child observations"+ : undefined+ }+ className={cn(+ "text-xs text-muted-foreground",+ parentTotalCost &&+ colorCodeMetrics &&+ heatMapTextColor({+ max: parentTotalCost,+ value: totalCost,+ }),+ )}+ >+ {node.children.length > 0 || node.type === "TRACE" ? "∑ " : ""}+ {usdFormatter(totalCost.toNumber())}+ </span>+ ) : null}+ </div>+ )}++ {showScores &&+ ((node.type === "TRACE" &&+ scores.find((s) => s.observationId === null)) ||+ scores.find((s) => s.observationId === node.id)) && (+ <div className="flex flex-wrap gap-1">+ <GroupedScoreBadges+ compact+ scores={+ node.type === "TRACE"+ ? scores.filter((s) => s.observationId === null)+ : scores.filter((s) => s.observationId === node.id)+ }+ />+ </div>+ )}</div>);};diff --git a/web/src/components/trace/TraceSearchList.tsx b/web/src/components/trace/TraceSearchList.tsxindex c5e191ff51..5acd6206c9 100644--- a/web/src/components/trace/TraceSearchList.tsx+++ b/web/src/components/trace/TraceSearchList.tsx@@ -6,6 +6,7 @@ import {CommandList,} from "@/src/components/ui/command";import { SpanItem } from "@/src/components/trace/SpanItem";+import { ItemBadge } from "@/src/components/ItemBadge";import { type APIScoreV2 } from "@langfuse/shared";import type Decimal from "decimal.js";import { type TreeNode } from "./lib/types";@@ -54,6 +55,9 @@ export const TraceSearchList: React.FC<TraceSearchListProps> = ({><div className="flex w-full"><div className="flex min-w-0 flex-1 items-start gap-2">+ <div className="relative z-20 flex-shrink-0">+ <ItemBadge type={node.type} isSmall className="!size-3" />+ </div><SpanItemnode={node}scores={scores}diff --git a/web/src/components/trace/TraceTree.tsx b/web/src/components/trace/TraceTree.tsxindex 3bda394aa0..ad7ba58131 100644--- a/web/src/components/trace/TraceTree.tsx+++ b/web/src/components/trace/TraceTree.tsx@@ -8,6 +8,7 @@ import {import { Fragment, useMemo, useRef, useEffect } from "react";import { InfoIcon, ChevronRight } from "lucide-react";import { Button } from "@/src/components/ui/button";+import { ItemBadge } from "@/src/components/ItemBadge";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import {calculateDisplayTotalCost,@@ -173,7 +174,7 @@ const UnmemoizedTreeNodeComponent = ({<Fragment><divclassName={cn(- "relative flex w-full rounded-md px-0 hover:rounded-lg",+ "relative flex w-full cursor-pointer rounded-md px-0 hover:rounded-lg",isSelected ? "bg-muted" : "hover:bg-muted/50",)}style={{@@ -181,66 +182,76 @@ const UnmemoizedTreeNodeComponent = ({paddingBottom: 0,borderRadius: "0.5rem",}}+ onClick={(e) => {+ // Only handle clicks that aren't on the expand/collapse button+ if (!e.currentTarget?.closest("[data-expand-button]")) {+ setCurrentNodeId(node.type === "TRACE" ? undefined : node.id);+ }+ }}><div className="flex w-full pl-2">- {/* Tree structure indicators */}+ {/* 1. Indents: ancestor level indicators */}{indentationLevel > 0 && (<div className="flex flex-shrink-0">- {/* Vertical lines for ancestor levels */}{Array.from({ length: indentationLevel - 1 }, (_, i) => (- <div key={i} className="relative w-6">+ <div key={i} className="relative w-5">{treeLines[i] && (<div className="absolute bottom-0 left-3 top-0 w-px bg-border" />)}</div>))}- {/* Branch indicator for current level */}- <div className="relative w-6">+ </div>+ )}++ {/* 2. Current element bars: up/down/horizontal connectors */}+ {indentationLevel > 0 && (+ <div className="relative w-5 flex-shrink-0">+ <>+ {/* Vertical bar connecting upwards */}<div- className="absolute left-3 w-px bg-border"- style={{- top: 0,- bottom: isLastSibling ? "calc(100% - 12px)" : "12px",- }}+ className={cn(+ "absolute left-3 top-0 w-px bg-border",+ isLastSibling ? "h-3" : "bottom-3",+ )}/>- <div className="absolute left-3 top-3 h-px w-3 bg-border" />+ {/* Vertical bar connecting downwards if not last sibling */}{!isLastSibling && (<div className="absolute bottom-0 left-3 top-3 w-px bg-border" />)}- {/* Downward connector for nodes with children */}- {node.children.length > 0 && !collapsed && (- <div- className="absolute w-px bg-border"- style={{ left: "36px", top: "18px", bottom: 0 }}- />- )}- </div>+ {/* Horizontal bar connecting to icon */}+ <div className="absolute left-3 top-3 h-px w-2 bg-border" />+ </></div>)}- {/* Downward connector placeholder for root */}- {indentationLevel === 0 ? (- <div- className={cn(- "absolute w-px",- node.children.length > 0 && !collapsed- ? "bg-border"- : "bg-transparent",+ {/* 3. Icon + child connector: fixed width container */}+ <div className="relative flex w-6 flex-shrink-0 flex-col py-1.5">+ <div className="relative z-10 flex h-4 items-center justify-center">+ <ItemBadge type={node.type} isSmall className="!size-3" />+ </div>+ {/* Vertical bar downwards if there are expanded children */}+ {node.children.length > 0 && !collapsed && (+ <div className="absolute bottom-0 left-1/2 top-3 w-px bg-border" />+ )}+ {/* Root node downward connector */}+ {indentationLevel === 0 &&+ node.children.length > 0 &&+ !collapsed && (+ <div className="absolute bottom-0 left-1/2 top-3 w-px bg-border" />)}- style={{ left: "20px", top: "18px", bottom: 0 }}- />- ) : null}+ </div>- {/* Node content button */}+ {/* 4. Content button: just the text/metrics content */}{/* eslint-disable-next-line jsx-a11y/role-supports-aria-props */}<buttontype="button"aria-selected={isSelected}- onClick={() =>- setCurrentNodeId(node.type === "TRACE" ? undefined : node.id)- }+ onClick={(e) => {+ e.stopPropagation();+ setCurrentNodeId(node.type === "TRACE" ? undefined : node.id);+ }}className={cn(- "peer relative flex min-w-0 flex-1 items-center rounded-md py-1.5 pl-0 pr-2 text-left",+ "peer relative flex min-w-0 flex-1 items-start rounded-md py-1.5 pl-2 pr-2 text-left",)}ref={currentNodeRef}>@@ -257,10 +268,11 @@ const UnmemoizedTreeNodeComponent = ({/></button>- {/* Expand/Collapse button */}+ {/* 5. Expand/Collapse button */}{node.children.length > 0 && (<div className="flex items-center justify-end py-1 pr-2"><Button+ data-expand-buttonsize="icon"variant="ghost"onClick={(ev) => {@@ -286,8 +298,6 @@ const UnmemoizedTreeNodeComponent = ({</Button></div>)}-- {/* Background handled by container hover/selected classes */}</div></div>