Skip to content

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

fix(web): header metrics as plain text on trace, observation and session headers (#17757)

Trang Nguyena486a7d3f0b4
diff --git a/web/src/components/SingleLineOverflowList.tsx b/web/src/components/SingleLineOverflowList.tsx
index bec7bbba6d..d1eff9c9ea 100644
--- a/web/src/components/SingleLineOverflowList.tsx
+++ b/web/src/components/SingleLineOverflowList.tsx
@@ -1,3 +1,4 @@
+import { cn } from "@/src/utils/tailwind";
import { type ReactNode, useEffect, useRef, useState } from "react";
/**
@@ -12,10 +13,10 @@ import { type ReactNode, useEffect, useRef, useState } from "react";
// Rows of boxed pills read fine at gap-2; rows of mostly-plain text (the
// session header's metrics/attributes/links) need more air to scan as
-// separate facts, matching the trace headers' gap-x-3.
+// separate facts, matching the trace headers' gap-6; bordered chips pull to 4px.
const SPACING_CLASS = {
compact: "gap-2",
- comfortable: "gap-3",
+ comfortable: "gap-6",
} as const;
export function SingleLineOverflowList<TItem>({
items,
@@ -25,6 +26,7 @@ export function SingleLineOverflowList<TItem>({
renderOverflow,
trailingContent,
spacing = "compact",
+ isTightItem,
}: {
items: readonly TItem[];
additionalOverflowCount: number;
@@ -36,6 +38,8 @@ export function SingleLineOverflowList<TItem>({
}) => ReactNode;
trailingContent?: ReactNode;
spacing?: keyof typeof SPACING_CLASS;
+ /** Tight items sit 4px from a preceding tight item instead of the row gap. */
+ isTightItem?: (item: TItem) => boolean;
}) {
const gapClass = SPACING_CLASS[spacing];
const measurementRowRef = useRef<HTMLDivElement>(null);
@@ -132,7 +136,11 @@ export function SingleLineOverflowList<TItem>({
<span
key={key}
data-overflow-item-key={key}
- className="flex items-center"
+ data-tight={isTightItem?.(item) ? "true" : undefined}
+ className={cn(
+ "flex items-center",
+ isTightItem?.(item) && "[[data-tight]+&]:-ml-5",
+ )}
>
{renderItem(item)}
</span>
@@ -148,7 +156,11 @@ export function SingleLineOverflowList<TItem>({
<span
key={key}
data-overflow-visible-item="true"
- className="flex items-center"
+ data-tight={isTightItem?.(item) ? "true" : undefined}
+ className={cn(
+ "flex items-center",
+ isTightItem?.(item) && "[[data-tight]+&]:-ml-5",
+ )}
>
{renderItem(item)}
</span>
diff --git a/web/src/components/design-system/Badge/Badge.stories.tsx b/web/src/components/design-system/Badge/Badge.stories.tsx
index cd3b107c5d..db60f1778c 100644
--- a/web/src/components/design-system/Badge/Badge.stories.tsx
+++ b/web/src/components/design-system/Badge/Badge.stories.tsx
@@ -23,6 +23,7 @@ const allColors = Object.keys({
violet: true,
teal: true,
green: true,
+ ghost: true,
} satisfies Record<Color, true>) as Color[];
export const Default = meta.story({});
@@ -42,6 +43,15 @@ export const Small = meta.story({
args: { text: "DEBUG", size: "sm" },
});
+export const GhostInteractive = meta.story({
+ args: {
+ color: "ghost",
+ interactive: true,
+ label: "cost",
+ text: "$0.0042",
+ },
+});
+
export const VariantMatrix = meta.story({
parameters: {
controls: {
diff --git a/web/src/components/design-system/Badge/Badge.tsx b/web/src/components/design-system/Badge/Badge.tsx
index 096f9aeadc..7a3c8e11c9 100644
--- a/web/src/components/design-system/Badge/Badge.tsx
+++ b/web/src/components/design-system/Badge/Badge.tsx
@@ -17,6 +17,11 @@ const badgeVariants = cva(
violet: "border-transparent bg-light-violet text-dark-violet",
teal: "border-transparent bg-light-teal text-dark-teal",
green: "border-transparent bg-light-green text-dark-green",
+ ghost: "border-0 bg-transparent px-0 text-foreground-secondary",
+ },
+ interactive: {
+ true: "decoration-border-contrast underline decoration-dashed underline-offset-[3px]",
+ false: "",
},
size: {
default: "h-5.5 gap-1.5 pr-1.5 pl-2",
@@ -26,6 +31,7 @@ const badgeVariants = cva(
defaultVariants: {
color: "primary",
size: "default",
+ interactive: false,
},
},
);
@@ -45,11 +51,17 @@ export function BadgeShell({
asChild = false,
color,
size,
+ interactive,
...props
}: BadgeShellProps) {
const Component = asChild ? Slot : "span";
- return <Component className={badgeVariants({ color, size })} {...props} />;
+ return (
+ <Component
+ className={badgeVariants({ color, size, interactive })}
+ {...props}
+ />
+ );
}
type BadgeProps = Omit<BadgeShellProps, "asChild" | "children"> & {
@@ -66,6 +78,7 @@ export function Badge({
text,
label,
title,
+ interactive,
trailingIcon: TrailingIcon,
trailingIconTone = "default",
...props
@@ -73,7 +86,14 @@ export function Badge({
return (
<BadgeShell color={color} {...props}>
{label && <span className="shrink-0">{label}</span>}
- <span className="truncate" title={title ?? text}>
+ <span
+ className={cn(
+ "overflow-x-clip overflow-y-visible text-ellipsis whitespace-nowrap",
+ interactive &&
+ "decoration-border-contrast underline decoration-dashed underline-offset-[3px]",
+ )}
+ title={title ?? text}
+ >
{text}
</span>
{TrailingIcon && (
diff --git a/web/src/components/layouts/page-header.tsx b/web/src/components/layouts/page-header.tsx
index 7ce67fb038..f7f59de77b 100644
--- a/web/src/components/layouts/page-header.tsx
+++ b/web/src/components/layouts/page-header.tsx
@@ -62,6 +62,9 @@ export type PageHeaderProps = {
container?: boolean;
tabsProps?: PageTabsProps;
className?: string;
+ /** Bottom border and bottom padding; pages whose own strip follows the
+ * header directly turn both off so title and strip read as one block. */
+ divider?: boolean;
showSidebarTrigger?: boolean;
leadingControl?: ReactNode;
titleBadges?: ReactNode;
@@ -81,6 +84,7 @@ const PageHeader = ({
tabsProps,
container = false,
className,
+ divider = true,
showSidebarTrigger = true,
leadingControl,
titleBadges,
@@ -97,7 +101,8 @@ const PageHeader = ({
return (
<div
className={cn([
- "top-banner-offset bg-background sticky z-30 w-full border-b shadow-xs",
+ "top-banner-offset bg-background sticky z-30 w-full",
+ divider && "border-b",
className,
])}
id="page-header"
@@ -162,7 +167,8 @@ const PageHeader = ({
<div>
<div
className={cn(
- "flex min-h-11 w-full flex-wrap items-center justify-between gap-1 px-3 py-1 md:flex-nowrap",
+ "flex w-full flex-wrap items-center justify-between gap-1 px-3 md:flex-nowrap",
+ divider ? "min-h-11 py-1" : "min-h-0 pt-2 pb-0",
container && containerLayoutClassName,
)}
>
diff --git a/web/src/features/models/components/UpsertModelFormDialog/UpsertModelFormDialog.clienttest.tsx b/web/src/features/models/components/UpsertModelFormDialog/UpsertModelFormDialog.clienttest.tsx
index 234763f03e..6194a9c273 100644
--- a/web/src/features/models/components/UpsertModelFormDialog/UpsertModelFormDialog.clienttest.tsx
+++ b/web/src/features/models/components/UpsertModelFormDialog/UpsertModelFormDialog.clienttest.tsx
@@ -181,8 +181,7 @@ describe("UpsertModelFormDialog price editor", () => {
const label = within(trigger).getByText("claude-sonnet-4-5");
expect(trigger.tagName).toBe("BUTTON");
- expect(label.parentElement).toHaveClass("border-border");
- expect(label.parentElement?.querySelector("svg")).not.toBeNull();
+ expect(label).toHaveClass("underline");
});
it("keeps every keystroke of a usage type that extends an existing one", () => {
diff --git a/web/src/features/sessions/ModernSession.clienttest.tsx b/web/src/features/sessions/ModernSession.clienttest.tsx
index 808d664880..50fe450080 100644
--- a/web/src/features/sessions/ModernSession.clienttest.tsx
+++ b/web/src/features/sessions/ModernSession.clienttest.tsx
@@ -53,7 +53,6 @@ const defaultProps = {
outputUsage: 0,
totalTokens: 0,
totalCost: 0,
- environment: undefined,
users: [],
scores: [],
minTimestamp: new Date("2026-01-01T00:00:00.000Z"),
diff --git a/web/src/features/sessions/ModernSession.tsx b/web/src/features/sessions/ModernSession.tsx
index 9fc316263a..32746a7615 100644
--- a/web/src/features/sessions/ModernSession.tsx
+++ b/web/src/features/sessions/ModernSession.tsx
@@ -21,7 +21,6 @@ type ModernSessionProps = {
| "outputUsage"
| "totalTokens"
| "totalCost"
- | "environment"
| "users"
| "scores"
| "minTimestamp"
@@ -96,12 +95,12 @@ export function ModernSession({
<ModernSessionHeader
projectId={projectId}
countTraces={session.countTraces}
- traces={headerTraces}
+ minTimestamp={session.minTimestamp}
+ maxTimestamp={session.maxTimestamp}
tokensIn={session.inputUsage}
tokensOut={session.outputUsage}
totalTokens={session.totalTokens}
totalCost={session.totalCost ?? 0}
- environment={session.environment ?? null}
users={session.users ?? []}
metadataJsonPaths={metadataJsonPaths}
scores={session.scores}
diff --git a/web/src/features/sessions/ModernSessionHeader.clienttest.tsx b/web/src/features/sessions/ModernSessionHeader.clienttest.tsx
index a49207d053..74e77bfa45 100644
--- a/web/src/features/sessions/ModernSessionHeader.clienttest.tsx
+++ b/web/src/features/sessions/ModernSessionHeader.clienttest.tsx
@@ -48,15 +48,12 @@ vi.mock("@/src/components/SingleLineOverflowList", () => ({
const defaultProps = {
projectId: "project-1",
countTraces: 3,
- traces: {
- state: "loaded" as const,
- data: [{ latencyMs: null, observationCount: 7 }],
- },
+ minTimestamp: new Date("2026-01-01T00:00:00.000Z"),
+ maxTimestamp: new Date("2026-01-01T00:00:01.000Z"),
tokensIn: 0,
tokensOut: 0,
totalTokens: 0,
totalCost: 0.12,
- environment: null,
users: [],
metadataJsonPaths: {
paths: [],
@@ -79,13 +76,13 @@ describe("ModernSessionHeader", () => {
fireEvent.click(
screen.getByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
);
expect(
screen.queryByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
).not.toBeInTheDocument();
expect(
@@ -108,13 +105,13 @@ describe("ModernSessionHeader", () => {
);
fireEvent.click(
screen.getByRole("button", {
- name: "Show trace and span counts in session header",
+ name: "Show trace count in session header",
}),
);
expect(
screen.getByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
).toBeInTheDocument();
expect(
@@ -141,7 +138,7 @@ describe("ModernSessionHeader", () => {
expect(
screen.queryByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
).not.toBeInTheDocument();
fireEvent.click(
@@ -151,7 +148,7 @@ describe("ModernSessionHeader", () => {
);
expect(
screen.getByRole("button", {
- name: "Show trace and span counts in session header",
+ name: "Show trace count in session header",
}),
).toBeInTheDocument();
});
@@ -175,19 +172,17 @@ describe("ModernSessionHeader", () => {
it("preserves preferences for details that are temporarily unavailable", () => {
const storageKey = sessionHeaderVisibilityStorageKey("project-1");
- localStorage.setItem(storageKey, JSON.stringify(["latency"]));
- render(
- <ModernSessionHeader {...defaultProps} traces={{ state: "loading" }} />,
- );
+ localStorage.setItem(storageKey, JSON.stringify(["tokens"]));
+ render(<ModernSessionHeader {...defaultProps} />);
fireEvent.click(
screen.getByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
);
expect(JSON.parse(localStorage.getItem(storageKey) ?? "[]")).toEqual([
- "latency",
+ "tokens",
"traces",
]);
});
diff --git a/web/src/features/sessions/ModernSessionHeader.stories.tsx b/web/src/features/sessions/ModernSessionHeader.stories.tsx
index 2f2a9146cc..5b77a4b854 100644
--- a/web/src/features/sessions/ModernSessionHeader.stories.tsx
+++ b/web/src/features/sessions/ModernSessionHeader.stories.tsx
@@ -14,7 +14,6 @@ const makeScore = (
): SessionScore =>
({
projectId: "project-1",
- environment: "default",
source: "EVAL",
authorUserId: null,
comment: null,
@@ -55,20 +54,12 @@ const manyUsers = Array.from(
const defaultArgs = {
projectId: "project-1",
countTraces: 24,
- traces: {
- state: "loaded",
- data: [
- { latencyMs: 1_240, observationCount: 42 },
- { latencyMs: 2_310, observationCount: 38 },
- { latencyMs: 4_620, observationCount: 51 },
- { latencyMs: 8_760, observationCount: 55 },
- ],
- },
+ minTimestamp: new Date("2026-09-11T10:00:00Z"),
+ maxTimestamp: new Date("2026-09-11T10:04:12Z"),
tokensIn: 18_420,
tokensOut: 6_310,
totalTokens: 24_730,
totalCost: 0.084291,
- environment: "production",
metadataJsonPaths: {
paths: [],
@@ -82,11 +73,9 @@ const defaultArgs = {
const minimalArgs = {
...defaultArgs,
- traces: { state: "loading" },
tokensIn: 0,
tokensOut: 0,
totalTokens: 0,
- environment: null,
users: [],
scores: [],
} satisfies ComponentProps<typeof ModernSessionHeader>;
@@ -163,7 +152,7 @@ export const TestSearchesHiddenPills = meta.story({
await expect(
overflowButton.getBoundingClientRect().left -
lastVisiblePill.getBoundingClientRect().right,
- ).toBeLessThanOrEqual(8);
+ ).toBeLessThanOrEqual(24);
const overflowButtonRect = overflowButton.getBoundingClientRect();
const lastVisiblePillRect = lastVisiblePill.getBoundingClientRect();
await expect(
@@ -180,7 +169,7 @@ export const TestSearchesHiddenPills = meta.story({
trailingButton.getBoundingClientRect().left -
overflowButton.getBoundingClientRect().right;
await expect(trailingGap).toBeGreaterThanOrEqual(0);
- await expect(trailingGap).toBeLessThanOrEqual(8);
+ await expect(trailingGap).toBeLessThanOrEqual(24);
await userEvent.click(overflowButton);
@@ -345,14 +334,10 @@ export const TestCompactsTokenCounts = meta.story({
canvasElement.querySelectorAll<HTMLElement>(
"[data-overflow-visible-item='true'] [data-session-header-pill='true']",
),
- ).find((pill) => pill.textContent?.trim().startsWith("tokens"));
+ ).find((pill) => pill.textContent?.trim().endsWith("tokens"));
await expect(tokenPill).toBeInTheDocument();
- await expect(tokenPill).toHaveTextContent(/649k.*7k.*655k/);
- await expect(tokenPill).toHaveAttribute(
- "title",
- "tokens 648,714 in, 6,697 out, 655,411 total",
- );
+ await expect(tokenPill).toHaveTextContent(/^655k\s*tokens$/);
},
});
@@ -376,7 +361,7 @@ export const TestHidesAndRevealsDetails = meta.story({
const canvas = within(canvasElement);
const hideTraceDetail = await canvas.findByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
});
const visibleTraceDetail = hideTraceDetail.closest(
"[data-overflow-visible-item='true']",
@@ -393,7 +378,7 @@ export const TestHidesAndRevealsDetails = meta.story({
await userEvent.click(hideTraceDetail);
await expect(
canvas.queryByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
).not.toBeInTheDocument();
await expect(
@@ -410,7 +395,7 @@ export const TestHidesAndRevealsDetails = meta.story({
name: "Search session details",
});
const showTraceDetail = await body.findByRole("button", {
- name: "Show trace and span counts in session header",
+ name: "Show trace count in session header",
});
showTraceDetail.focus();
await waitFor(() => expect(showTraceDetail).toBeVisible());
@@ -418,7 +403,7 @@ export const TestHidesAndRevealsDetails = meta.story({
await expect(
canvas.getByRole("button", {
- name: "Hide trace and span counts in session header",
+ name: "Hide trace count in session header",
}),
).toBeInTheDocument();
await expect(localStorage.getItem(storageKey)).toBe(JSON.stringify([]));
diff --git a/web/src/features/sessions/ModernSessionHeader.tsx b/web/src/features/sessions/ModernSessionHeader.tsx
index c0c294fcd4..5836d30341 100644
--- a/web/src/features/sessions/ModernSessionHeader.tsx
+++ b/web/src/features/sessions/ModernSessionHeader.tsx
@@ -1,22 +1,14 @@
/* eslint-disable no-nested-ternary */
import { ScoreBadge } from "@/src/components/ScoreBadge/ScoreBadge";
-import { percentile, type ScoreDomain } from "@langfuse/shared";
-import {
- ArrowRight,
- Sigma,
- ArrowUpRight,
- Eye,
- EyeOff,
- Plus,
- Search,
- X,
-} from "lucide-react";
+import { type ScoreDomain } from "@langfuse/shared";
+import { ArrowUpRight, Eye, EyeOff, Plus, Search, X } from "lucide-react";
import { type ReactNode, type SyntheticEvent, useRef, useState } from "react";
import Link from "next/link";
import { Badge, BadgeShell } from "@/src/components/design-system/Badge/Badge";
import { SingleLineOverflowList } from "@/src/components/SingleLineOverflowList";
+import { BreakdownTooltip } from "@/src/features/traces/components/BreakdownTooltip";
import {
MAX_STORED_HIDDEN_SESSION_HEADER_DETAILS,
parseStoredHiddenSessionHeaderDetails,
@@ -55,20 +47,12 @@ import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
type ModernSessionHeaderProps = {
projectId: string;
countTraces: number;
- traces:
- | { state: "loading" }
- | {
- state: "loaded";
- data: ReadonlyArray<{
- latencyMs: number | null;
- observationCount: number;
- }>;
- };
+ minTimestamp: Date;
+ maxTimestamp: Date;
tokensIn: number;
tokensOut: number;
totalTokens: number;
totalCost: number;
- environment: string | null;
users: readonly string[];
metadataJsonPaths: SessionMetadataJsonPathState;
scores: ReadonlyArray<WithStringifiedMetadata<ScoreDomain>>;
@@ -76,8 +60,7 @@ type ModernSessionHeaderProps = {
type SessionHeaderDetailType =
| "cost"
- | "environment"
- | "latency"
+ | "duration"
| "metadata"
| "score"
| "tokens"
@@ -100,8 +83,6 @@ const ChipKey = ({ children }: { children: React.ReactNode }) => (
<span>{children}</span>
);
-const ChipDot = () => <span className="text-foreground-tertiary">·</span>;
-
const compactTokenFormatter = (tokens: number) =>
compactNumberFormatter(tokens, 0).toLowerCase();
@@ -121,6 +102,7 @@ const UserChip = ({ projectId, user }: { projectId: string; user: string }) => (
className="ph-no-capture inline-flex max-w-[280px] min-w-0"
>
<Badge
+ color="ghost"
data-session-header-pill="true"
label="user"
text={user}
@@ -341,12 +323,12 @@ const MetadataJsonPathEditorContent = ({
export function ModernSessionHeader({
projectId,
countTraces,
- traces,
+ minTimestamp,
+ maxTimestamp,
tokensIn,
tokensOut,
totalTokens,
totalCost,
- environment,
users,
metadataJsonPaths,
scores,
@@ -388,98 +370,41 @@ export function ModernSessionHeader({
isV4: true,
});
};
- const latencies =
- traces.state === "loaded"
- ? traces.data.flatMap((trace) =>
- trace.latencyMs !== null && trace.latencyMs > 0
- ? [trace.latencyMs]
- : [],
- )
- : [];
- const spanCount =
- traces.state === "loaded"
- ? traces.data.reduce((total, trace) => total + trace.observationCount, 0)
- : null;
- const p50LatencyMs = latencies.length > 0 ? percentile(latencies, 0.5) : null;
- const p95LatencyMs =
- latencies.length > 0 ? percentile(latencies, 0.95) : null;
+ const durationSeconds = Math.max(
+ (maxTimestamp.getTime() - minTimestamp.getTime()) / 1000,
+ 0,
+ );
const pills: SessionHeaderDetail[] = [
{
key: "traces",
- searchText: `traces ${countTraces} spans ${spanCount ?? ""}`,
- visibilityLabel: "trace and span counts",
+ searchText: `traces ${countTraces}`,
+ visibilityLabel: "trace count",
type: "traces",
content: (
- <BadgeShell data-session-header-pill="true">
+ <BadgeShell color="ghost" data-session-header-pill="true">
<span>
- {numberFormatter(countTraces, 0)} <ChipKey>traces</ChipKey>
+ {numberFormatter(countTraces, 0)}{" "}
+ <ChipKey>{countTraces === 1 ? "trace" : "traces"}</ChipKey>
</span>
- {spanCount !== null ? (
- <>
- <ChipDot />
- <span>
- {numberFormatter(spanCount, 0)} <ChipKey>spans</ChipKey>
- </span>
- </>
- ) : null}
</BadgeShell>
),
},
];
- if (p50LatencyMs !== null) {
- pills.push({
- key: "latency",
- searchText: `latency p50 ${p50LatencyMs} p95 ${p95LatencyMs ?? ""}`,
- visibilityLabel: "latency percentiles",
- type: "latency",
- content: (
- <BadgeShell data-session-header-pill="true">
- <span>
- <ChipKey>p50</ChipKey> {formatIntervalSeconds(p50LatencyMs / 1000)}
- </span>
- {p95LatencyMs !== null ? (
- <>
- <ChipDot />
- <span>
- <ChipKey>p95</ChipKey>{" "}
- {formatIntervalSeconds(p95LatencyMs / 1000)}
- </span>
- </>
- ) : null}
- </BadgeShell>
- ),
- });
- }
-
- if (totalTokens > 0) {
- const exactTokenCounts = `${numberFormatter(tokensIn, 0)} in, ${numberFormatter(tokensOut, 0)} out, ${numberFormatter(totalTokens, 0)} total`;
- pills.push({
- key: "tokens",
- searchText: `tokens ${tokensIn} ${tokensOut} ${totalTokens}`,
- visibilityLabel: "token usage",
- type: "tokens",
- content: (
- <BadgeShell
- data-session-header-pill="true"
- title={`tokens ${exactTokenCounts}`}
- >
- <span>tokens</span>
- <span>{compactTokenFormatter(tokensIn)}</span>
- <ArrowRight
- aria-hidden
- className="text-foreground-tertiary -mx-0.5 size-3 shrink-0"
- />
- <span>{compactTokenFormatter(tokensOut)}</span>
- <Sigma
- aria-hidden
- className="text-foreground-tertiary -mr-0.5 size-3 shrink-0"
- />
- <span>{compactTokenFormatter(totalTokens)}</span>
- </BadgeShell>
- ),
- });
- }
+ pills.push({
+ key: "duration",
+ searchText: `duration ${durationSeconds}`,
+ visibilityLabel: "duration",
+ type: "duration",
+ content: (
+ <Badge
+ color="ghost"
+ data-session-header-pill="true"
+ text={formatIntervalSeconds(durationSeconds)}
+ title="session duration"
+ />
+ ),
+ });
pills.push({
key: "cost",
@@ -488,36 +413,32 @@ export function ModernSessionHeader({
type: "cost",
content: (
<Badge
+ color="ghost"
data-session-header-pill="true"
- label="cost"
text={usdFormatter(totalCost, 2, 3)}
title={`exact $${totalCost.toFixed(6)}`}
/>
),
});
- scores.forEach((score, index) => {
- pills.push({
- key: sessionHeaderDynamicDetailKey("score", score.id),
- searchText: `score ${score.name} ${scoreChipValue(score)}`,
- visibilityLabel: `score ${index + 1}`,
- type: "score",
- content: (
- <span data-session-header-pill="true" className="inline-flex min-w-0">
- <ScoreBadge name={score.name} scores={[score]} />
- </span>
- ),
- });
- });
-
- if (environment) {
+ if (totalTokens > 0) {
pills.push({
- key: "environment",
- searchText: `environment env ${environment}`,
- visibilityLabel: "environment",
- type: "environment",
+ key: "tokens",
+ searchText: `tokens ${tokensIn} ${tokensOut} ${totalTokens}`,
+ visibilityLabel: "token usage",
+ type: "tokens",
content: (
- <Badge data-session-header-pill="true" label="env" text={environment} />
+ <BreakdownTooltip
+ details={{ input: tokensIn, output: tokensOut, total: totalTokens }}
+ isCost={false}
+ >
+ <Badge
+ color="ghost"
+ interactive
+ data-session-header-pill="true"
+ text={`${compactTokenFormatter(totalTokens)} tokens`}
+ />
+ </BreakdownTooltip>
),
});
}
@@ -542,6 +463,20 @@ export function ModernSessionHeader({
(detail) => !visibleUserDetailKeySet.has(detail.key),
);
+ scores.forEach((score, index) => {
+ pills.push({
+ key: sessionHeaderDynamicDetailKey("score", score.id),
+ searchText: `score ${score.name} ${scoreChipValue(score)}`,
+ visibilityLabel: `score ${index + 1}`,
+ type: "score",
+ content: (
+ <span data-session-header-pill="true" className="inline-flex min-w-0">
+ <ScoreBadge name={score.name} scores={[score]} />
+ </span>
+ ),
+ });
+ });
+
metadataJsonPaths.paths.forEach((path, index) => {
const display = getConfiguredMetadataDisplay(
path,
@@ -607,13 +542,15 @@ export function ModernSessionHeader({
};
return (
- <div className="bg-header border-b px-4 py-2">
+ <div className="border-b px-4 pt-0 pb-1.5">
<SingleLineOverflowList
+ spacing="comfortable"
items={visiblePills}
additionalOverflowCount={
overflowUserDetails.length + manuallyHiddenPills.length
}
getKey={(pill) => pill.key}
+ isTightItem={(pill) => pill.type === "score"}
renderItem={(pill) => (
<SessionHeaderDetailWithVisibilityControl
detail={pill}
diff --git a/web/src/features/sessions/SessionPages.tsx b/web/src/features/sessions/SessionPages.tsx
index 77a7aedade..ab4efb4088 100644
--- a/web/src/features/sessions/SessionPages.tsx
+++ b/web/src/features/sessions/SessionPages.tsx
@@ -1691,6 +1691,7 @@ const LoadedSessionEventsPage: React.FC<{
headerProps={{
title: sessionId,
itemType: "SESSION",
+ divider: false,
breadcrumb: [
{
name: "Sessions",
diff --git a/web/src/features/traces/TracePage.tsx b/web/src/features/traces/TracePage.tsx
index 4cbe3dac34..6a40905139 100644
--- a/web/src/features/traces/TracePage.tsx
+++ b/web/src/features/traces/TracePage.tsx
@@ -94,6 +94,7 @@ export function TracePage({
headerProps={{
title: trace.data.id,
itemType: "TRACE",
+ divider: false,
breadcrumb: [
{
name: "Traces",
diff --git a/web/src/features/traces/components/CollapsibleBadgeRow.tsx b/web/src/features/traces/components/CollapsibleBadgeRow.tsx
index a55dda23cb..01407e6be2 100644
--- a/web/src/features/traces/components/CollapsibleBadgeRow.tsx
+++ b/web/src/features/traces/components/CollapsibleBadgeRow.tsx
@@ -28,7 +28,7 @@ export function CollapsibleBadgeRow({
// Desktop: unchanged full wrapped badge row.
if (!isMobile) {
return (
- <div className={cn("flex flex-wrap items-center gap-1", className)}>
+ <div className={cn("flex flex-wrap items-center gap-6", className)}>
{children}
</div>
);
@@ -39,7 +39,7 @@ export function CollapsibleBadgeRow({
<div className="flex items-start gap-1">
<div
className={cn(
- "flex min-w-0 flex-1 items-center gap-1",
+ "flex min-w-0 flex-1 items-center gap-6",
// Collapsed: one clipped line. `[&>*]:shrink-0` stops flex from
// squeezing badges below their content width (which made long ones
// like "Time to first token" wrap vertically into a multi-line row);
diff --git a/web/src/features/traces/components/ObservationDetailView/components/ModelBadge.tsx b/web/src/features/traces/components/ObservationDetailView/components/ModelBadge.tsx
index cff272c530..29efa578b9 100644
--- a/web/src/features/traces/components/ObservationDetailView/components/ModelBadge.tsx
+++ b/web/src/features/traces/components/ObservationDetailView/components/ModelBadge.tsx
@@ -4,7 +4,7 @@
*/
import { Badge } from "@/src/components/design-system/Badge/Badge";
-import { ExternalLinkIcon, PlusCircle } from "lucide-react";
+import { ExternalLinkIcon } from "lucide-react";
import Link from "next/link";
import { UpsertModelFormDialog } from "@/src/features/models";
@@ -27,7 +27,7 @@ export function ModelBadge({
className="inline-flex"
title="View model details"
>
- <Badge text={model} trailingIcon={ExternalLinkIcon} />
+ <Badge color="ghost" text={model} trailingIcon={ExternalLinkIcon} />
</Link>
);
}
@@ -54,7 +54,7 @@ export function ModelBadge({
}}
>
<button type="button" className="inline-flex cursor-pointer">
- <Badge text={model} trailingIcon={PlusCircle} />
+ <Badge color="ghost" interactive text={model} />
</button>
</UpsertModelFormDialog>
);
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 e848bb80bf..2caf3817c5 100644
--- a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
+++ b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
@@ -20,6 +20,7 @@ import { type ObservationReturnTypeWithMetadata } from "@/src/server/api/routers
import { ItemBadge } from "@/src/components/ItemBadge";
import { AnnotateDrawerController } from "@/src/features/scores";
import { ConnectedTraceObservationAddToDropdownMenuController } from "@/src/features/traces/components/ConnectedTraceObservationAddToDropdownMenuController";
+import { Badge } from "@/src/components/design-system/Badge/Badge";
import { PromptBadge } from "@/src/features/traces/components/PromptBadge";
import {
LatencyBadge,
@@ -170,6 +171,14 @@ export const ObservationDetailViewHeader = memo(
}
: undefined;
+ const timestampBadge = preparedDate && (
+ <Badge
+ color="ghost"
+ text={preparedDate.display}
+ title={preparedDate.title}
+ />
+ );
+
return (
<div className="@container shrink-0 space-y-2 border-b p-2">
{/* Title row with actions */}
@@ -178,7 +187,7 @@ export const ObservationDetailViewHeader = memo(
<ItemBadge type={observation.type as ObservationType} isSmall />
<span
className={cn(
- "mb-0 min-w-0 truncate font-bold",
+ "mb-0 min-w-0 truncate text-lg leading-7 font-bold",
isMobile && "flex-1",
)}
title={observation.name || observation.id}
@@ -475,80 +484,76 @@ export const ObservationDetailViewHeader = memo(
)}
</div>
- {/* Metadata badges */}
-
- <div className="flex flex-col gap-2">
- {/* Timestamp */}
- {preparedDate ? (
- <div className="flex flex-wrap items-center gap-1 text-sm">
- <span title={preparedDate.title}>{preparedDate.display}</span>
- </div>
- ) : null}
-
- {/* Other badges */}
- {!isAnnotationMode && (
- <CollapsibleBadgeRow>
- <LatencyBadge latencySeconds={latencySeconds} />
- <TimeToFirstTokenBadge
- timeToFirstToken={observation.timeToFirstToken}
- />
- {evaluatorId &&
- (observation.environment ===
- LangfuseInternalTraceEnvironment.LLMJudge ||
- observation.environment ===
- LangfuseInternalTraceEnvironment.CodeEval) &&
- !evaluatorId.startsWith("managed:") && (
- <EvaluatorBadge
- evaluatorId={evaluatorId}
- evaluatorName={evaluator.data?.name}
- projectId={projectId}
- />
- )}
- {displayedTotalCost != null && displayedCostDetails && (
- <CostBadge
- totalCost={displayedTotalCost}
- costDetails={displayedCostDetails}
- costSource={costSource}
- priceSource={priceSource}
- />
- )}
- {subtreeMetrics
- ? subtreeMetrics.hasGenerationLike &&
- subtreeMetrics.usageDetails &&
- hasBreakdown(subtreeMetrics.usageDetails) && (
- <UsageBadge
- totalUsage={subtreeMetrics.totalUsage}
- usageDetails={subtreeMetrics.usageDetails}
- />
- )
- : isGenerationLike(observation.type) &&
- observation.usageDetails &&
- hasBreakdown(observation.usageDetails) && (
- <UsageBadge
- totalUsage={totalUsage}
- usageDetails={observation.usageDetails}
- />
- )}
- {observation.model && (
- <ModelBadge
- model={observation.model}
- internalModelId={observation.internalModelId}
- projectId={projectId}
- usageDetails={observation.usageDetails}
- />
- )}
- {observation.level !== "DEFAULT" && (
- <ObservationLevelBadge level={observation.level} />
- )}
- {observation.promptId && (
- <PromptBadge
- promptId={observation.promptId}
+ {/* Metadata line */}
+ {isAnnotationMode ? (
+ timestampBadge && (
+ <div className="flex items-center">{timestampBadge}</div>
+ )
+ ) : (
+ <CollapsibleBadgeRow>
+ {timestampBadge}
+ <LatencyBadge latencySeconds={latencySeconds} />
+ <TimeToFirstTokenBadge
+ timeToFirstToken={observation.timeToFirstToken}
+ />
+ {evaluatorId &&
+ (observation.environment ===
+ LangfuseInternalTraceEnvironment.LLMJudge ||
+ observation.environment ===
+ LangfuseInternalTraceEnvironment.CodeEval) &&
+ !evaluatorId.startsWith("managed:") && (
+ <EvaluatorBadge
+ evaluatorId={evaluatorId}
+ evaluatorName={evaluator.data?.name}
projectId={projectId}
/>
)}
- </CollapsibleBadgeRow>
- )}
- </div>
+ {displayedTotalCost != null && displayedCostDetails && (
+ <CostBadge
+ totalCost={displayedTotalCost}
+ costDetails={displayedCostDetails}
+ costSource={costSource}
+ priceSource={priceSource}
+ />
+ )}
+ {subtreeMetrics
+ ? subtreeMetrics.hasGenerationLike &&
+ subtreeMetrics.totalUsage > 0 &&
+ subtreeMetrics.usageDetails &&
+ hasBreakdown(subtreeMetrics.usageDetails) && (
+ <UsageBadge
+ totalUsage={subtreeMetrics.totalUsage}
+ usageDetails={subtreeMetrics.usageDetails}
+ />
+ )
+ : isGenerationLike(observation.type) &&
+ totalUsage > 0 &&
+ observation.usageDetails &&
+ hasBreakdown(observation.usageDetails) && (
+ <UsageBadge
+ totalUsage={totalUsage}
+ usageDetails={observation.usageDetails}
+ />
+ )}
+ {observation.model && (
+ <ModelBadge
+ model={observation.model}
+ internalModelId={observation.internalModelId}
+ projectId={projectId}
+ usageDetails={observation.usageDetails}
+ />
+ )}
+ {observation.level !== "DEFAULT" && (
+ <ObservationLevelBadge level={observation.level} />
+ )}
+ {observation.promptId && (
+ <PromptBadge
+ promptId={observation.promptId}
+ projectId={projectId}
+ />
+ )}
+ </CollapsibleBadgeRow>
+ )}
</div>
);
},
diff --git a/web/src/features/traces/components/ObservationMetadataBadgesSimple/ObservationMetadataBadgesSimple.tsx b/web/src/features/traces/components/ObservationMetadataBadgesSimple/ObservationMetadataBadgesSimple.tsx
index 53d581db66..1887622510 100644
--- a/web/src/features/traces/components/ObservationMetadataBadgesSimple/ObservationMetadataBadgesSimple.tsx
+++ b/web/src/features/traces/components/ObservationMetadataBadgesSimple/ObservationMetadataBadgesSimple.tsx
@@ -14,7 +14,7 @@ export function LatencyBadge({
}) {
if (latencySeconds == null) return null;
- return <Badge label="latency" text={formatIntervalSeconds(latencySeconds)} />;
+ return <Badge color="ghost" text={formatIntervalSeconds(latencySeconds)} />;
}
export function TimeToFirstTokenBadge({
@@ -24,5 +24,11 @@ export function TimeToFirstTokenBadge({
}) {
if (timeToFirstToken == null) return null;
- return <Badge label="ttft" text={formatIntervalSeconds(timeToFirstToken)} />;
+ return (
+ <Badge
+ color="ghost"
+ label="ttft"
+ text={formatIntervalSeconds(timeToFirstToken)}
+ />
+ );
}
diff --git a/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx b/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx
index b6861f5572..22d57ca42f 100644
--- a/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx
+++ b/web/src/features/traces/components/ObservationMetadataBadgesTooltip.tsx
@@ -3,14 +3,13 @@
* These badges use BreakdownTooltip to show detailed cost/usage information
*/
-import { Badge, BadgeShell } from "@/src/components/design-system/Badge/Badge";
+import { Badge } from "@/src/components/design-system/Badge/Badge";
import {
BreakdownTooltip,
type CostSource,
type PriceSource,
} from "@/src/features/traces/components/BreakdownTooltip";
import { usdFormatter, numberFormatter } from "@/src/utils/numbers";
-import { InfoIcon } from "lucide-react";
export function CostBadge({
totalCost,
@@ -24,7 +23,7 @@ export function CostBadge({
costSource?: CostSource;
}) {
if (!hasBreakdown(costDetails)) {
- return <Badge text={usdFormatter(totalCost)} />;
+ return <Badge color="ghost" text={usdFormatter(totalCost)} />;
}
return (
<BreakdownTooltip
@@ -33,11 +32,7 @@ export function CostBadge({
priceSource={priceSource}
costSource={costSource}
>
- <Badge
- label="cost"
- text={usdFormatter(totalCost)}
- trailingIcon={InfoIcon}
- />
+ <Badge color="ghost" interactive text={usdFormatter(totalCost)} />
</BreakdownTooltip>
);
}
@@ -53,21 +48,15 @@ export function UsageBadge({
totalUsage: number;
usageDetails: Record<string, number>;
}) {
- const tokenText = totalUsage > 0 ? numberFormatter(totalUsage, 0) : undefined;
+ const tokenText = `${numberFormatter(totalUsage, 0)} tokens`;
- if (tokenText && !hasBreakdown(usageDetails)) {
- return <Badge text={tokenText} />;
+ if (!hasBreakdown(usageDetails)) {
+ return <Badge color="ghost" text={tokenText} />;
}
return (
<BreakdownTooltip details={usageDetails} isCost={false}>
- {tokenText ? (
- <Badge label="tokens" text={tokenText} trailingIcon={InfoIcon} />
- ) : (
- <BadgeShell aria-label="View usage breakdown">
- <InfoIcon aria-hidden className="size-3" />
- </BadgeShell>
- )}
+ <Badge color="ghost" interactive text={tokenText} />
</BreakdownTooltip>
);
}
diff --git a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
index cd05c037ef..17e51a5bf9 100644
--- a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
+++ b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
@@ -98,7 +98,10 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
<div className="flex w-full min-w-0 flex-row items-center gap-1">
<ItemBadge type="TRACE" isSmall />
<span
- className={cn("min-w-0 truncate font-bold", isMobile && "flex-1")}
+ className={cn(
+ "min-w-0 truncate text-lg leading-7 font-bold",
+ isMobile && "flex-1",
+ )}
title={trace.name || trace.id}
>
{trace.name || trace.id}
diff --git a/web/src/features/traces/components/TraceHeader.tsx b/web/src/features/traces/components/TraceHeader.tsx
index 4ae8db859a..d248c5aac3 100644
--- a/web/src/features/traces/components/TraceHeader.tsx
+++ b/web/src/features/traces/components/TraceHeader.tsx
@@ -16,12 +16,15 @@ import {
hasBreakdown,
} from "@/src/features/traces/components/ObservationMetadataBadgesTooltip";
import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";
+import { useViewPreferences } from "@/src/features/traces/contexts/ViewPreferencesContext";
import { aggregateTraceMetrics } from "@/src/features/traces/fns/traceAggregation";
+import { cn } from "@/src/utils/tailwind";
const MAX_VISIBLE_TAGS = 3;
export function TraceHeader() {
const { trace, observations, mergedScores } = useTraceData();
+ const { traceContext } = useViewPreferences();
const [showAllTags, setShowAllTags] = useState(false);
const aggregatedMetrics = useMemo(
@@ -40,8 +43,13 @@ export function TraceHeader() {
const hiddenTagCount = trace.tags.length - visibleTags.length;
return (
- <div className="shrink-0 border-b px-3 py-2">
- <div className="flex flex-wrap items-center gap-1.5">
+ <div
+ className={cn(
+ "shrink-0 border-b px-3",
+ traceContext === "fullscreen" ? "pt-0 pb-1.5" : "py-2",
+ )}
+ >
+ <div className="flex flex-wrap items-center gap-6">
<LatencyBadge latencySeconds={trace.latency ?? null} />
{aggregatedMetrics.totalCost != null &&
aggregatedMetrics.costDetails && (
@@ -51,6 +59,7 @@ export function TraceHeader() {
/>
)}
{aggregatedMetrics.hasGenerationLike &&
+ aggregatedMetrics.totalUsage > 0 &&
aggregatedMetrics.usageDetails &&
hasBreakdown(aggregatedMetrics.usageDetails) && (
<UsageBadge
@@ -67,9 +76,11 @@ export function TraceHeader() {
{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">
+ {(traceScores.length > 0 || trace.tags.length > 0) && (
+ <div className="flex min-w-0 flex-wrap items-center gap-1">
+ {traceScores.length > 0 && (
+ <GroupedScoreBadges scores={traceScores} />
+ )}
{visibleTags.map((tag) => (
<TagButton key={tag} tag={tag} loading={false} viewOnly />
))}
diff --git a/web/src/features/traces/components/TraceMetadataBadges.clienttest.tsx b/web/src/features/traces/components/TraceMetadataBadges.clienttest.tsx
index 18efc8e2bb..d48f58c559 100644
--- a/web/src/features/traces/components/TraceMetadataBadges.clienttest.tsx
+++ b/web/src/features/traces/components/TraceMetadataBadges.clienttest.tsx
@@ -7,7 +7,6 @@ import {
TargetTraceBadge,
UserIdBadge,
} from "./TraceMetadataBadges";
-import { UsageBadge } from "./ObservationMetadataBadgesTooltip";
describe("TraceMetadataBadges session replay privacy", () => {
it("blocks trace identifiers from PostHog session recordings", () => {
@@ -31,13 +30,3 @@ describe("TraceMetadataBadges session replay privacy", () => {
);
});
});
-
-describe("UsageBadge", () => {
- it("keeps custom usage details accessible without aggregate token totals", () => {
- render(<UsageBadge totalUsage={0} usageDetails={{ audio_seconds: 12 }} />);
-
- expect(
- screen.getByRole("button", { name: "View usage breakdown" }),
- ).toBeInTheDocument();
- });
-});
diff --git a/web/src/features/traces/components/TraceMetadataBadges.tsx b/web/src/features/traces/components/TraceMetadataBadges.tsx
index b00571e732..b82d2c4eb0 100644
--- a/web/src/features/traces/components/TraceMetadataBadges.tsx
+++ b/web/src/features/traces/components/TraceMetadataBadges.tsx
@@ -21,6 +21,7 @@ export function SessionBadge({
className="ph-no-capture inline-flex"
>
<Badge
+ color="ghost"
text="session"
title={sessionId}
trailingIcon={ArrowUpRight}
@@ -46,6 +47,7 @@ export function UserIdBadge({
className="ph-no-capture inline-flex"
>
<Badge
+ color="ghost"
label={label}
text={text}
trailingIcon={ArrowUpRight}
@@ -71,6 +73,7 @@ export function TargetTraceBadge({
className="ph-no-capture inline-flex"
>
<Badge
+ color="ghost"
label={label}
text={text}
trailingIcon={ArrowUpRight}
@@ -81,13 +84,13 @@ export function TargetTraceBadge({
}
export function EnvironmentBadge({ environment }: { environment: string }) {
- return <Badge label="env" text={environment} />;
+ return <Badge color="ghost" label="env" text={environment} />;
}
export function ReleaseBadge({ release }: { release: string }) {
- return <Badge label="release" text={release} />;
+ return <Badge color="ghost" label="release" text={release} />;
}
export function VersionBadge({ version }: { version: string }) {
- return <Badge label="version" text={version} />;
+ return <Badge color="ghost" label="version" text={version} />;
}