Skip to content

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

fix(web): trace-level scores render in the trace header (#17642)

Trang Nguyene5aeab3e94ac
diff --git a/web/src/components/grouped-score-badge.tsx b/web/src/components/grouped-score-badge.tsx
index 5875c29f3f..c94439f1d9 100644
--- a/web/src/components/grouped-score-badge.tsx
+++ b/web/src/components/grouped-score-badge.tsx
@@ -28,17 +28,17 @@ const groupScoresByName = <
return groups;
}, {});
+const MAX_VISIBLE_SCORE_GROUPS = 3;
+
const partitionScores = <
T extends WithStringifiedMetadata<ScoreDomain> | LastUserScore,
>(
scores: Record<string, T[]>,
- maxVisible?: number,
+ maxVisible: number,
) => {
const sortedScores = Object.entries(scores).sort(([a], [b]) =>
a < b ? -1 : 1,
);
- if (!maxVisible) return { visibleScores: sortedScores, hiddenScores: [] };
-
const visibleScores = sortedScores.slice(0, maxVisible);
const hiddenScores = sortedScores.slice(maxVisible);
return { visibleScores, hiddenScores };
@@ -48,7 +48,7 @@ export const GroupedScoreBadges = <
T extends WithStringifiedMetadata<ScoreDomain> | LastUserScore,
>({
scores,
- maxVisible,
+ maxVisible = MAX_VISIBLE_SCORE_GROUPS,
compact,
expandable = true,
}: {
@@ -69,20 +69,18 @@ export const GroupedScoreBadges = <
// Level tags only when this selection MIXES levels (LFE-10596): a row whose
// scores all share one level (the common case — e.g. a span's own
// observation-level scores) needs no per-chip disambiguation; a mixed row
- // (e.g. the root carrying trace-level and observation-level scores) tags
- // each group so the levels are tellable apart.
+ // tags each group so the levels are tellable apart.
const showLevels =
new Set(scores.map((score) => scoreLevelFromScore(score))).size > 1;
// "+N" expands IN PLACE on click (hover still previews the hidden chips);
// the trailing "−" collapses back to the capped view.
const [expanded, setExpanded] = useState(false);
- const overflows =
- maxVisible !== undefined && Object.keys(groupedScores).length > maxVisible;
+ const overflows = Object.keys(groupedScores).length > maxVisible;
const { visibleScores, hiddenScores } = partitionScores(
groupedScores,
- expanded && expandable ? undefined : maxVisible,
+ expanded && expandable ? Number.POSITIVE_INFINITY : maxVisible,
);
const overflowButtonClassName = cn(
diff --git a/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx b/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx
index 6c72281f0c..994f80065a 100644
--- a/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx
+++ b/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx
@@ -150,8 +150,8 @@ export function ConnectedObservationDetailView({
detachedObservationIsMisplaced && observation.id === detachedObservationId
);
- // Without a TRACE row (v4) this span stands in for the trace, so its badge and
- // its Scores tab both cover the trace-level scores.
+ // Without a TRACE row (v4) this span stands in for the trace, so its Scores
+ // tab covers the trace-level scores.
const ownsTraceLevelScores = traceLevelScoreOwnerIds.has(observation.id);
// For root observations, compute subtree metrics for badge tooltips.
diff --git a/web/src/features/traces/components/SpanContent.tsx b/web/src/features/traces/components/SpanContent.tsx
index 344d9493fa..d3887a2dac 100644
--- a/web/src/features/traces/components/SpanContent.tsx
+++ b/web/src/features/traces/components/SpanContent.tsx
@@ -36,7 +36,6 @@ import type Decimal from "decimal.js";
// How many distinct score groups to show inline on a tree/search row before
// collapsing the rest into a "+N" pill. Keeps dense-score rows compact; the
// full set is always on the node's Scores tab. (The timeline caps at 3.)
-const MAX_INLINE_SCORE_GROUPS = 3;
interface SpanContentProps {
node: TreeNode;
@@ -57,7 +56,7 @@ export function SpanContent({
onHover,
className,
}: SpanContentProps) {
- const { mergedScores, traceLevelScoreOwnerIds } = useTraceData();
+ const { mergedScores } = useTraceData();
const {
showDuration,
showCostTokens,
@@ -99,11 +98,7 @@ export function SpanContent({
const shouldRenderAnyMetrics = shouldRenderDuration || shouldRenderCostTokens;
- const nodeScores = selectNodeScores(
- mergedScores,
- node.id,
- traceLevelScoreOwnerIds,
- );
+ const nodeScores = selectNodeScores(mergedScores, node.id);
const nodeDisplayName = node.name || `Unnamed ${node.type.toLowerCase()}`;
@@ -226,11 +221,7 @@ export function SpanContent({
one/two-line row instead of a tall wrapping grid. */}
{showScores && nodeScores.length > 0 && (
<div className="flex flex-wrap gap-1">
- <GroupedScoreBadges
- compact
- scores={nodeScores}
- maxVisible={MAX_INLINE_SCORE_GROUPS}
- />
+ <GroupedScoreBadges compact scores={nodeScores} />
</div>
)}
</div>
diff --git a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
index 8cb621bb27..2b7405de93 100644
--- a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
+++ b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
@@ -6,6 +6,7 @@
* - Title row with ItemBadge, trace name, options menu
* - Action buttons (Dataset, Annotate, Queue, Comments)
* - Metadata badges (timestamp, environment, release, version, target trace)
+ * - Trace-level score chips
*
* Memoized to prevent unnecessary re-renders when tab state changes.
*/
diff --git a/web/src/features/traces/components/TraceSummaryStrip.tsx b/web/src/features/traces/components/TraceSummaryStrip.tsx
index cbac36e000..c12581ac85 100644
--- a/web/src/features/traces/components/TraceSummaryStrip.tsx
+++ b/web/src/features/traces/components/TraceSummaryStrip.tsx
@@ -2,6 +2,7 @@
import { useMemo, useState } from "react";
+import { GroupedScoreBadges } from "@/src/components/grouped-score-badge";
import { Button } from "@/src/components/ui/button";
import { TagButton } from "@/src/features/tag/components/TagButton";
import {
@@ -19,7 +20,7 @@ import { aggregateTraceMetrics } from "@/src/features/traces/fns/traceAggregatio
const MAX_VISIBLE_TAGS = 3;
export function TraceSummaryStrip() {
- const { trace, observations } = useTraceData();
+ const { trace, observations, mergedScores } = useTraceData();
const [showAllTags, setShowAllTags] = useState(false);
const aggregatedMetrics = useMemo(
@@ -27,6 +28,11 @@ export function TraceSummaryStrip() {
[observations],
);
+ const traceScores = useMemo(
+ () => mergedScores.filter((score) => score.observationId === null),
+ [mergedScores],
+ );
+
const visibleTags = showAllTags
? trace.tags
: trace.tags.slice(0, MAX_VISIBLE_TAGS);
@@ -61,6 +67,7 @@ export function TraceSummaryStrip() {
{trace.userId && (
<UserIdBadge userId={trace.userId} projectId={trace.projectId} />
)}
+ {traceScores.length > 0 && <GroupedScoreBadges scores={traceScores} />}
{trace.tags.length > 0 && (
<div className="flex min-w-0 items-center gap-1">
{visibleTags.map((tag) => (
diff --git a/web/src/features/traces/fns/nodeScores.clienttest.ts b/web/src/features/traces/fns/nodeScores.clienttest.ts
index 3fd1aa9b62..c5bac861cf 100644
--- a/web/src/features/traces/fns/nodeScores.clienttest.ts
+++ b/web/src/features/traces/fns/nodeScores.clienttest.ts
@@ -61,14 +61,12 @@ describe("traceLevelScoreOwnerIds", () => {
});
describe("selectNodeScores", () => {
- const ownerIds = traceLevelScoreOwnerIds(roots({ id: "root", type: "SPAN" }));
-
- it("adds trace-level scores to the owner once and leaves other nodes alone", () => {
- expect(selectNodeScores(scores, "root", ownerIds).map((s) => s.id)).toEqual(
- ["trace-level", "root-level"],
- );
- expect(
- selectNodeScores(scores, "child", ownerIds).map((s) => s.id),
- ).toEqual(["child-level"]);
+ it("gives every node its own scores only, trace-level scores to none", () => {
+ expect(selectNodeScores(scores, "root").map((s) => s.id)).toEqual([
+ "root-level",
+ ]);
+ expect(selectNodeScores(scores, "child").map((s) => s.id)).toEqual([
+ "child-level",
+ ]);
});
});
diff --git a/web/src/features/traces/fns/nodeScores.ts b/web/src/features/traces/fns/nodeScores.ts
index 69101f7ee4..19c0cdc01b 100644
--- a/web/src/features/traces/fns/nodeScores.ts
+++ b/web/src/features/traces/fns/nodeScores.ts
@@ -2,12 +2,11 @@
* Which tree node owns a trace's trace-level scores (`observationId === null`).
*
* v3 traces render a TRACE wrapper row that owns them. v4 events-based traces
- * have no such row, so the top-level span(s) stand in for the trace and own
- * them alongside their own observation-level scores.
+ * have no such row, so the top-level span(s) stand in for the trace.
*
- * Single source of this rule: the tree badge, the timeline badge and the Scores
- * tab all derive from it, so a node's badge count and its Scores tab agree
- * (LFE-14405).
+ * Ownership only widens a node's Scores tab to the trace-level rows. Badges
+ * never mix levels: the trace header carries the trace-level chips, a tree row
+ * carries only its own.
*/
import { type TreeNode } from "../types/treeNode";
@@ -41,12 +40,6 @@ export function traceLevelScoreOwnerIds(
export function selectNodeScores<T extends LeveledScore>(
scores: T[],
nodeId: string,
- traceLevelOwnerIds: Set<string>,
): T[] {
- return traceLevelOwnerIds.has(nodeId)
- ? scores.filter(
- (score) =>
- score.observationId === nodeId || score.observationId === null,
- )
- : scores.filter((score) => score.observationId === nodeId);
+ return scores.filter((score) => score.observationId === nodeId);
}