Skip to content

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

fix(web): header actions, metrics, scores and +N match across trace, observation and session (#18470)

Trang Nguyen6f73f2733d26
diff --git a/web/src/components/OverflowCountBadge.tsx b/web/src/components/OverflowCountBadge.tsx
new file mode 100644
index 0000000000..a3e9cef12f
--- /dev/null
+++ b/web/src/components/OverflowCountBadge.tsx
@@ -0,0 +1,31 @@
+import { type ComponentPropsWithoutRef, type Ref } from "react";
+
+import { BadgeShell } from "@/src/components/design-system/Badge/Badge";
+
+type OverflowCountBadgeProps = Omit<
+ ComponentPropsWithoutRef<"button">,
+ "children" | "className" | "type"
+> & {
+ count: number;
+ ref?: Ref<HTMLButtonElement>;
+};
+
+/** The "+N" control after a row of chips; works as a popover trigger via asChild. */
+export function OverflowCountBadge({
+ count,
+ ref,
+ ...props
+}: OverflowCountBadgeProps) {
+ return (
+ <BadgeShell asChild color="filled" font="mono" size="md">
+ <button
+ ref={ref}
+ type="button"
+ className="text-muted-foreground cursor-pointer self-center"
+ {...props}
+ >
+ +{count}
+ </button>
+ </BadgeShell>
+ );
+}
diff --git a/web/src/components/grouped-score-badge.tsx b/web/src/components/grouped-score-badge.tsx
index 8d89ca1a9a..d02ea3cb36 100644
--- a/web/src/components/grouped-score-badge.tsx
+++ b/web/src/components/grouped-score-badge.tsx
@@ -1,4 +1,5 @@
-import { BadgeShell } from "@/src/components/design-system/Badge/Badge";
+import { OverflowCountBadge } from "@/src/components/OverflowCountBadge";
+
import {
Popover,
PopoverContent,
@@ -19,15 +20,18 @@ const MAX_VISIBLE_SCORE_GROUPS = 2;
* has to RESERVE room for these badges buckets them identically — two copies of
* the grouping rule are two chances to price a chip that never renders.
*/
-const groupScoresByName = <T extends ChipScore>(
+export const groupScoresByName = <T extends ChipScore>(
scores: T[],
): Record<string, T[]> =>
- scores.reduce<Record<string, T[]>>((groups, score) => {
- const bucket = groups[score.name];
- if (!bucket || !Array.isArray(bucket)) groups[score.name] = [score];
- else bucket.push(score);
- return groups;
- }, {});
+ scores.reduce<Record<string, T[]>>(
+ (groups, score) => {
+ const bucket = groups[score.name];
+ if (!bucket || !Array.isArray(bucket)) groups[score.name] = [score];
+ else bucket.push(score);
+ return groups;
+ },
+ Object.create(null) as Record<string, T[]>,
+ );
const partitionScores = <T extends ChipScore>(
scores: Record<string, T[]>,
@@ -97,17 +101,12 @@ export const GroupedScoreBadges = <T extends ChipScore>({
const overflow = (
<Popover>
<PopoverTrigger asChild>
- <BadgeShell asChild color="filled" size="md">
- <button
- type="button"
- className="text-muted-foreground cursor-pointer self-center font-mono"
- aria-label={`Show all ${Object.keys(groupedScores).length} scores`}
- // Chips render inside clickable rows; opening must not select the row.
- onClick={(event) => event.stopPropagation()}
- >
- +{hiddenScores.length}
- </button>
- </BadgeShell>
+ <OverflowCountBadge
+ count={hiddenScores.length}
+ aria-label={`Show all ${Object.keys(groupedScores).length} scores`}
+ // Chips render inside clickable rows; opening must not select the row.
+ onClick={(event) => event.stopPropagation()}
+ />
</PopoverTrigger>
<PopoverContent
align="start"
diff --git a/web/src/features/sessions/ModernSessionHeader.tsx b/web/src/features/sessions/ModernSessionHeader.tsx
index 1e0af7d6a0..206ccc4384 100644
--- a/web/src/features/sessions/ModernSessionHeader.tsx
+++ b/web/src/features/sessions/ModernSessionHeader.tsx
@@ -1,5 +1,11 @@
-/* eslint-disable no-nested-ternary */
+import { OverflowCountBadge } from "@/src/components/OverflowCountBadge";
+import { groupScoresByName } from "@/src/components/grouped-score-badge";
import { ScoreBadge } from "@/src/components/ScoreBadge/ScoreBadge";
+import {
+ formatMetricCost,
+ formatMetricTokens,
+} from "@/src/features/traces/components/ObservationMetadataBadgesTooltip";
+/* eslint-disable no-nested-ternary */
import { type ScoreDomain } from "@langfuse/shared";
import { Plus, Search, X } from "lucide-react";
import { type ReactNode, type SyntheticEvent, useState } from "react";
@@ -28,11 +34,7 @@ import {
} from "@/src/components/ui/popover";
import { formatIntervalSeconds } from "@/src/utils/dates";
import { type WithStringifiedMetadata } from "@/src/utils/clientSideDomainTypes";
-import {
- compactNumberFormatter,
- numberFormatter,
- usdFormatter,
-} from "@/src/utils/numbers";
+import { numberFormatter } from "@/src/utils/numbers";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
type ModernSessionHeaderProps = {
@@ -69,9 +71,6 @@ const ChipKey = ({ children }: { children: React.ReactNode }) => (
<span>{children}</span>
);
-const compactTokenFormatter = (tokens: number) =>
- compactNumberFormatter(tokens, 0).toLowerCase();
-
const scoreChipValue = (
score: Pick<WithStringifiedMetadata<ScoreDomain>, "stringValue" | "value">,
) => {
@@ -342,20 +341,22 @@ export function ModernSessionHeader({
),
});
- pills.push({
- key: "cost",
- searchText: `cost ${totalCost}`,
- type: "cost",
- content: (
- <Badge
- font="mono"
- color="ghost"
- data-session-header-pill="true"
- text={usdFormatter(totalCost, 2, 3)}
- title={`exact $${totalCost.toFixed(6)}`}
- />
- ),
- });
+ if (totalCost > 0) {
+ pills.push({
+ key: "cost",
+ searchText: `cost ${totalCost}`,
+ type: "cost",
+ content: (
+ <Badge
+ font="mono"
+ color="ghost"
+ data-session-header-pill="true"
+ text={formatMetricCost(totalCost)}
+ title={`exact $${totalCost.toFixed(6)}`}
+ />
+ ),
+ });
+ }
if (totalTokens > 0) {
pills.push({
@@ -372,7 +373,7 @@ export function ModernSessionHeader({
color="ghost"
interactive
data-session-header-pill="true"
- text={`${compactTokenFormatter(totalTokens)} tokens`}
+ text={formatMetricTokens(totalTokens)}
/>
</BreakdownTooltip>
),
@@ -399,14 +400,16 @@ export function ModernSessionHeader({
(detail) => !visibleUserDetailKeySet.has(detail.key),
);
- scores.forEach((score) => {
+ Object.entries(groupScoresByName([...scores])).forEach(([name, group]) => {
pills.push({
- key: `score-${score.id}`,
- searchText: `score ${score.name} ${scoreChipValue(score)}`,
+ key: `score-${name}`,
+ searchText: group
+ .map((score) => `score ${score.name} ${scoreChipValue(score)}`)
+ .join(" "),
type: "score",
content: (
<span data-session-header-pill="true" className="inline-flex min-w-0">
- <ScoreBadge name={score.name} scores={[score]} />
+ <ScoreBadge name={name} scores={group} />
</span>
),
});
@@ -490,14 +493,11 @@ export function ModernSessionHeader({
}}
>
<PopoverTrigger asChild>
- <BadgeShell font="mono" asChild data-session-header-pill="true">
- <button
- type="button"
- aria-label={`Show ${overflowItemCount} more session details`}
- >
- +{overflowItemCount}
- </button>
- </BadgeShell>
+ <OverflowCountBadge
+ count={overflowItemCount}
+ data-session-header-pill="true"
+ aria-label={`Show ${overflowItemCount} more session details`}
+ />
</PopoverTrigger>
<PopoverContent
align="end"
diff --git a/web/src/features/sessions/SessionPages.tsx b/web/src/features/sessions/SessionPages.tsx
index d200ad3303..78b56e8fe3 100644
--- a/web/src/features/sessions/SessionPages.tsx
+++ b/web/src/features/sessions/SessionPages.tsx
@@ -1,3 +1,4 @@
+import { headerActionClassName } from "@/src/features/traces/components/headerActionClassName";
/* eslint-disable no-nested-ternary */
/* eslint-disable @repo/no-style-props, @repo/no-null-render */
import { cn } from "@/src/utils/tailwind";
@@ -324,8 +325,6 @@ const SessionScores = ({
);
};
-const HEADER_ACTION_CLASS =
- "text-foreground-secondary hover:bg-accent hover:text-foreground-secondary";
type SessionAnnotatePayload = AnnotateDrawerPayload<{
type: "session";
sessionId: string;
@@ -1725,7 +1724,7 @@ const LoadedSessionEventsPage: React.FC<{
<Button
variant="ghost"
size="sm"
- className={cn(HEADER_ACTION_CLASS, "gap-1.5")}
+ className={headerActionClassName}
{...getTriggerProps()}
>
<Plus
@@ -1746,7 +1745,7 @@ const LoadedSessionEventsPage: React.FC<{
variant="ghost"
size="sm"
disabled={disabled}
- className={cn(HEADER_ACTION_CLASS, "gap-1.5")}
+ className={headerActionClassName}
onClick={() =>
openDrawer({
scoreTarget: { type: "session", sessionId },
@@ -1766,9 +1765,9 @@ const LoadedSessionEventsPage: React.FC<{
{disabled ? (
<LockIcon className="icon-base text-icon-foreground" />
) : (
- <Plus className="icon-base text-icon-foreground" />
+ <SquarePen className="icon-base text-icon-foreground" />
)}
- Score
+ Annotate
{isModernSessionEnabled && annotationCount > 0 ? (
<ActionButtonCountBadge count={annotationCount} />
) : null}
@@ -1786,7 +1785,7 @@ const LoadedSessionEventsPage: React.FC<{
variant="ghost"
size="sm"
disabled={disabled}
- className={cn(HEADER_ACTION_CLASS, "gap-1.5")}
+ className={headerActionClassName}
onClick={() =>
openDrawer({
type: "comments",
diff --git a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
index 112c4fec89..0db723e52a 100644
--- a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
+++ b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
@@ -1,4 +1,6 @@
+import { HeaderActionButton } from "@/src/components/HeaderActionButton";
import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";
+import { headerActionClassName } from "@/src/features/traces/components/headerActionClassName";
import { prepareTraceAnnotation } from "@/src/features/scores/lib/prepareTraceAnnotation";
/**
* ObservationDetailViewHeader - Extracted header component for ObservationDetailView
@@ -53,7 +55,6 @@ import {
LockIcon,
MessageSquare,
MessageSquareOff,
- MoreHorizontal,
PlusIcon,
SquarePen,
} from "lucide-react";
@@ -185,8 +186,13 @@ export const ObservationDetailViewHeader = memo(
);
const renderAddToButton = (triggerProps: Record<string, unknown> = {}) => (
- <Button variant="secondary" size="sm" className="gap-1" {...triggerProps}>
- <PlusIcon className="icon-base" />
+ <Button
+ variant="ghost"
+ size="sm"
+ className={headerActionClassName}
+ {...triggerProps}
+ >
+ <PlusIcon className="icon-base text-icon-foreground" />
<span>Add to</span>
<DropdownIndicator size="sm" nudge />
</Button>
@@ -331,7 +337,7 @@ export const ObservationDetailViewHeader = memo(
ref: mobileActionsTriggerRef,
})}
>
- <MoreHorizontal className="icon-base text-icon-foreground" />
+ <EllipsisVertical className="icon-base text-icon-foreground" />
</Button>
)}
</DropdownMenu>
@@ -345,7 +351,7 @@ export const ObservationDetailViewHeader = memo(
</div>
{/* Action buttons (desktop inline cluster) */}
{!isMobile && (
- <div className="flex flex-wrap content-start items-center justify-start gap-0.5 @md:justify-end">
+ <div className="flex flex-wrap content-start items-center justify-start gap-1 @md:justify-end">
{observationWithIO ? (
<ConnectedTraceObservationAddToDropdownMenuController
analyticsData={{ source: "TraceDetail", isV4: isV4Enabled }}
@@ -377,6 +383,7 @@ export const ObservationDetailViewHeader = memo(
<Button
variant="ghost"
size="sm"
+ className={headerActionClassName}
disabled={disabled}
onClick={() =>
openDrawer({
@@ -393,9 +400,9 @@ export const ObservationDetailViewHeader = memo(
}
>
{disabled ? (
- <LockIcon className="icon-base mr-1.5" />
+ <LockIcon className="icon-base text-icon-foreground" />
) : (
- <SquarePen className="icon-base mr-1.5" />
+ <SquarePen className="icon-base text-icon-foreground" />
)}
<span>Annotate</span>
</Button>
@@ -408,13 +415,13 @@ export const ObservationDetailViewHeader = memo(
size="sm"
disabled={commentDrawerControl.disabled}
onClick={commentDrawerControl.openDrawer}
- className="gap-1"
+ className={headerActionClassName}
>
{commentDrawerControl.disabled ? (
<MessageSquareOff className="icon-base text-muted-foreground" />
) : (
<>
- <MessageSquare className="icon-base" />
+ <MessageSquare className="icon-base text-icon-foreground" />
<span>{commentActionLabel}</span>
{!!commentCount ? (
<ActionButtonCountBadge count={commentCount} />
@@ -446,16 +453,13 @@ export const ObservationDetailViewHeader = memo(
}}
>
{({ getTriggerProps }) => (
- <Button
- aria-label="Options"
- className="shrink-0"
- size="icon-sm"
- title="Options"
- variant="ghost"
+ <HeaderActionButton
+ label="Options"
+ icon={
+ <EllipsisVertical className="icon-base text-icon-foreground" />
+ }
{...getTriggerProps()}
- >
- <EllipsisVertical className="icon-base" />
- </Button>
+ />
)}
</ConnectedDetailHeaderActionsMenuController>
</div>
diff --git a/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx b/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx
index 9296ec84c8..9201d7128b 100644
--- a/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx
+++ b/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx
@@ -1,8 +1,4 @@
-/**
- * Tooltip-based metadata badges for ObservationDetailView
- * These badges use BreakdownTooltip to show detailed cost/usage information
- * Metric values render in mono; `contents` keeps the wrapper out of layout.
- */
+/** Cost and token metrics for the trace, observation and session headers; breakdowns open on hover. */
import { Badge } from "@/src/components/design-system/Badge/Badge";
import {
@@ -10,7 +6,14 @@ import {
type CostSource,
type PriceSource,
} from "@/src/features/traces/components/BreakdownTooltip";
-import { usdFormatter, numberFormatter } from "@/src/utils/numbers";
+import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
+
+/** Header cost: short, with the exact value on hover. */
+export const formatMetricCost = (cost: number) => usdFormatter(cost, 2, 3);
+
+/** Header tokens, e.g. "21k tokens". */
+export const formatMetricTokens = (tokens: number) =>
+ `${compactNumberFormatter(tokens, 0).toLowerCase()} tokens`;
export function CostBadge({
totalCost,
@@ -24,7 +27,14 @@ export function CostBadge({
costSource?: CostSource;
}) {
if (!hasBreakdown(costDetails)) {
- return <Badge font="mono" color="ghost" text={usdFormatter(totalCost)} />;
+ return (
+ <Badge
+ font="mono"
+ color="ghost"
+ text={formatMetricCost(totalCost)}
+ title={`exact $${totalCost.toFixed(6)}`}
+ />
+ );
}
return (
<BreakdownTooltip
@@ -37,7 +47,7 @@ export function CostBadge({
font="mono"
color="ghost"
interactive
- text={usdFormatter(totalCost)}
+ text={formatMetricCost(totalCost)}
/>
</BreakdownTooltip>
);
@@ -54,7 +64,7 @@ export function UsageBadge({
totalUsage: number;
usageDetails: Record<string, number>;
}) {
- const tokenText = `${numberFormatter(totalUsage, 0)} tokens`;
+ const tokenText = formatMetricTokens(totalUsage);
if (!hasBreakdown(usageDetails)) {
return <Badge font="mono" color="ghost" text={tokenText} />;
diff --git a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
index 668999e111..f1349c1410 100644
--- a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
+++ b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
@@ -1,3 +1,4 @@
+import { HeaderActionButton } from "@/src/components/HeaderActionButton";
import { prepareTraceAnnotation } from "@/src/features/scores/lib/prepareTraceAnnotation";
/**
* TraceDetailViewHeader - Extracted header component for TraceDetailView
@@ -11,6 +12,7 @@ import { prepareTraceAnnotation } from "@/src/features/scores/lib/prepareTraceAn
* Memoized to prevent unnecessary re-renders when tab state changes.
*/
+import { headerActionClassName } from "@/src/features/traces/components/headerActionClassName";
import { memo, useRef } from "react";
import { useReadPath } from "@/src/features/events";
import {
@@ -42,7 +44,6 @@ import {
LockIcon,
MessageSquare,
MessageSquareOff,
- MoreHorizontal,
PlusIcon,
SquarePen,
} from "lucide-react";
@@ -118,16 +119,13 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
}}
>
{({ getTriggerProps }) => (
- <Button
- aria-label="Options"
- className="mt-0.5 shrink-0"
- size="icon-xs"
- title="Options"
- variant="ghost"
+ <HeaderActionButton
+ label="Options"
+ icon={
+ <EllipsisVertical className="icon-base text-icon-foreground" />
+ }
{...getTriggerProps()}
- >
- <EllipsisVertical className="icon-sm text-icon-foreground" />
- </Button>
+ />
)}
</ConnectedDetailHeaderActionsMenuController>
)}
@@ -231,7 +229,7 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
ref: mobileActionsTriggerRef,
})}
>
- <MoreHorizontal className="icon-base text-icon-foreground" />
+ <EllipsisVertical className="icon-base text-icon-foreground" />
</Button>
)}
</DropdownMenu>
@@ -245,7 +243,7 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
</div>
{/* Action buttons (desktop inline cluster) */}
{!isMobile && (
- <div className="flex flex-wrap content-start items-center justify-start gap-0.5 @md:justify-end">
+ <div className="flex flex-wrap content-start items-center justify-start gap-1 @md:justify-end">
<ConnectedTraceObservationAddToDropdownMenuController
analyticsData={{ source: "TraceDetail", isV4 }}
projectId={projectId}
@@ -259,10 +257,10 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
<Button
variant="ghost"
size="sm"
- className="gap-1"
+ className={headerActionClassName}
{...getTriggerProps()}
>
- <PlusIcon className="icon-base" />
+ <PlusIcon className="icon-base text-icon-foreground" />
<span>Add to</span>
<DropdownIndicator size="sm" nudge />
</Button>
@@ -275,6 +273,7 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
<Button
variant="ghost"
size="sm"
+ className={headerActionClassName}
disabled={disabled}
onClick={() =>
openDrawer(
@@ -289,9 +288,9 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
}
>
{disabled ? (
- <LockIcon className="icon-base mr-1.5" />
+ <LockIcon className="icon-base text-icon-foreground" />
) : (
- <SquarePen className="icon-base mr-1.5" />
+ <SquarePen className="icon-base text-icon-foreground" />
)}
<span>Annotate</span>
</Button>
@@ -304,13 +303,13 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
size="sm"
disabled={commentDrawerControl.disabled}
onClick={commentDrawerControl.openDrawer}
- className="gap-1"
+ className={headerActionClassName}
>
{commentDrawerControl.disabled ? (
<MessageSquareOff className="icon-base text-muted-foreground" />
) : (
<>
- <MessageSquare className="icon-base" />
+ <MessageSquare className="icon-base text-icon-foreground" />
<span>{commentActionLabel}</span>
{!!commentCount ? (
<ActionButtonCountBadge count={commentCount} />
diff --git a/web/src/features/traces/components/TraceHeader.tsx b/web/src/features/traces/components/TraceHeader.tsx
index 00c448f60d..79754e7add 100644
--- a/web/src/features/traces/components/TraceHeader.tsx
+++ b/web/src/features/traces/components/TraceHeader.tsx
@@ -1,3 +1,4 @@
+import { OverflowCountBadge } from "@/src/components/OverflowCountBadge";
/** Trace totals, session/user links and tags, above the panels. */
import { useMemo, useState } from "react";
@@ -91,15 +92,11 @@ export function TraceHeader() {
<TagButton key={tag} tag={tag} loading={false} viewOnly />
))}
{hiddenTagCount > 0 && (
- <Button
- variant="tertiary"
- size="icon-sm"
- className="w-fit"
+ <OverflowCountBadge
+ count={hiddenTagCount}
aria-label={`Show ${hiddenTagCount} more tags`}
onClick={() => setShowAllTags(true)}
- >
- +{hiddenTagCount}
- </Button>
+ />
)}
{showAllTags && trace.tags.length > MAX_VISIBLE_TAGS && (
<Button
diff --git a/web/src/features/traces/components/headerActionClassName.ts b/web/src/features/traces/components/headerActionClassName.ts
new file mode 100644
index 0000000000..1607a629b3
--- /dev/null
+++ b/web/src/features/traces/components/headerActionClassName.ts
@@ -0,0 +1,3 @@
+/** Header action buttons (Add to, Annotate, Comment): secondary label, no hover tint. */
+export const headerActionClassName =
+ "gap-1.5 text-foreground-secondary hover:bg-accent hover:text-foreground-secondary";