Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
feat(client): add trace-level telemetry view (#1443)
Swapnoneel Saha9329f5d4d077
diff --git a/src/client/src/__tests__/helpers/client/observability-registry.test.ts b/src/client/src/__tests__/helpers/client/observability-registry.test.tsindex 783ca80f..5ee13453 100644--- a/src/client/src/__tests__/helpers/client/observability-registry.test.ts+++ b/src/client/src/__tests__/helpers/client/observability-registry.test.ts@@ -14,13 +14,22 @@ describe("observability signal registry", () => {const traces = getSignalConfig("traces");expect(traces.key).toBe("traces");- expect(traces.listUrl).toBe("/api/telemetry/request");+ expect(traces.listUrl).toBe("/api/telemetry/trace?view=traces");+ expect(traces.summaryUrl).toBe("/api/telemetry/summary/traces?view=traces");expect(traces.getRowId({ spanId: "span-1" })).toBe("span-1");expect(traces.getDetailHref({ spanId: "span-1" }, "/agents/a?tab=monitoring")).toBe("/telemetry/traces/span-1?from=%2Fagents%2Fa%3Ftab%3Dmonitoring");});+ it("keeps the existing span list as a separate signal", () => {+ const spans = getSignalConfig("spans");++ expect(spans.key).toBe("spans");+ expect(spans.listUrl).toBe("/api/telemetry/trace");+ expect(spans.supportGrouping).toBe(true);+ });+it("keeps every signal key unique", () => {const keys = OBSERVABILITY_SIGNALS.map((signal) => signal.key);expect(new Set(keys).size).toBe(keys.length);diff --git a/src/client/src/__tests__/lib/platform/datasource/jaeger-victoria.test.ts b/src/client/src/__tests__/lib/platform/datasource/jaeger-victoria.test.tsindex 24b022d5..e522c1d7 100644--- a/src/client/src/__tests__/lib/platform/datasource/jaeger-victoria.test.ts+++ b/src/client/src/__tests__/lib/platform/datasource/jaeger-victoria.test.ts@@ -337,6 +337,7 @@ describe("JaegerAdapter", () => {serviceName: "svc",durationNs: 12_000_000,cost: 0.003,+ traceSummary: { spanCount: 2, errorCount: 0 },});expect(chat.resourceAttributes["telemetry.sdk.name"]).toBe("openlit");expect(chat.events?.[0]).toMatchObject({diff --git a/src/client/src/__tests__/lib/platform/observability.test.ts b/src/client/src/__tests__/lib/platform/observability.test.tsindex 135dc14c..12365321 100644--- a/src/client/src/__tests__/lib/platform/observability.test.ts+++ b/src/client/src/__tests__/lib/platform/observability.test.ts@@ -143,6 +143,13 @@ describe("observability platform queries", () => {expect(metrics.peak).toBe(4);});+ it("counts unique trace ids for a trace-level summary", async () => {+ await getSignalSummary(params as any, "traces", true);++ const query = (dataCollector as jest.Mock).mock.calls[0][0].query;+ expect(query).toContain("uniqExact(TraceId)");+ });+it("sanitizes log row ids before lookup", async () => {await getLogByRowId("abc123 OR 1=1");diff --git a/src/client/src/__tests__/lib/platform/request/request.test.ts b/src/client/src/__tests__/lib/platform/request/request.test.tsindex 8b6d2399..d725e4c8 100644--- a/src/client/src/__tests__/lib/platform/request/request.test.ts+++ b/src/client/src/__tests__/lib/platform/request/request.test.ts@@ -19,6 +19,8 @@ import {getAverageRequestDuration,getRequestsConfig,getRequests,+ getTraceSummaries,+ getTraceSummarySeries,getRequestViaSpanId,getRequestViaTraceId,getHeirarchyViaSpanId,@@ -259,6 +261,80 @@ describe('getRequests', () => {});});+describe('getTraceSummaries', () => {+ it('counts unique traces and returns one root-oriented row per trace', async () => {+ (dataCollector as jest.Mock)+ .mockResolvedValueOnce({ data: [{ total: 3 }], err: null })+ .mockResolvedValueOnce({+ data: [{ TraceId: 'trace-1', SpanId: 'root-1', SpanCount: 4 }],+ err: null,+ });++ const result = await getTraceSummaries({ ...baseParams, limit: 10, offset: 0 });++ expect(result.total).toBe(3);+ expect(result.records).toEqual([+ { TraceId: 'trace-1', SpanId: 'root-1', SpanCount: 4 },+ ]);+ const countQuery = (dataCollector as jest.Mock).mock.calls[0][0].query;+ const listQuery = (dataCollector as jest.Mock).mock.calls[1][0].query as string;+ expect(countQuery).toContain('uniqExact(TraceId)');+ expect(listQuery).toContain('WITH page AS');+ expect(listQuery).toContain('INNER JOIN page AS p ON t.TraceId = p.TraceId');+ expect(listQuery).toContain("t.ParentSpanId = '0000000000000000'");+ expect(listQuery).toContain('t.SpanId');+ expect(listQuery).toContain('t.Timestamp >= parseDateTimeBestEffort');+ expect(listQuery).toContain('LIMIT 10');+ expect(listQuery).toContain('OFFSET 0');+ expect(listQuery.match(/LIMIT/g)).toHaveLength(1);+ expect(listQuery).not.toContain('argMin(Events');+ expect(listQuery).not.toContain('argMin(Links');+ expect(listQuery).toContain('AS SpanCount');+ expect(listQuery).toContain('AS ErrorCount');+ expect(listQuery).toContain('ORDER BY p.TraceStart DESC');+ });++ it('honors an ascending timestamp sort on the paged trace ids', async () => {+ (dataCollector as jest.Mock)+ .mockResolvedValueOnce({ data: [{ total: 1 }], err: null })+ .mockResolvedValueOnce({ data: [], err: null });++ await getTraceSummaries({+ ...baseParams,+ limit: 10,+ offset: 0,+ sorting: { type: 'Timestamp', direction: 'asc' },+ });++ const listQuery = (dataCollector as jest.Mock).mock.calls[1][0].query as string;+ expect(listQuery).toContain('ORDER BY TraceStart ASC');+ expect(listQuery).toContain('ORDER BY p.TraceStart ASC');+ });++ it('returns the count error without running the list query', async () => {+ (dataCollector as jest.Mock).mockResolvedValueOnce({+ data: null,+ err: 'count failed',+ });++ const result = await getTraceSummaries(baseParams);++ expect(result.err).toBe('count failed');+ expect(dataCollector).toHaveBeenCalledTimes(1);+ });+});++it('counts unique trace IDs in the ClickHouse trace volume series', async () => {+ (dataCollector as jest.Mock).mockResolvedValueOnce({ data: [{ label: '2024/01', count: 2 }], err: null });++ const result = await getTraceSummarySeries(baseParams);++ expect(result.total).toBe(2);+ const query = (dataCollector as jest.Mock).mock.calls[0][0].query as string;+ expect(query).toContain('uniqExact(TraceId)');+ expect(query).toContain('FROM');+});+describe('getRequestViaSpanId', () => {it('queries by SpanId and returns record', async () => {(dataCollector as jest.Mock).mockResolvedValue({diff --git a/src/client/src/__tests__/lib/platform/traces/read.test.ts b/src/client/src/__tests__/lib/platform/traces/read.test.tsindex ec07c66d..c9015b9d 100644--- a/src/client/src/__tests__/lib/platform/traces/read.test.ts+++ b/src/client/src/__tests__/lib/platform/traces/read.test.ts@@ -9,6 +9,8 @@ const mockGetRequestsConfig = jest.fn();const mockGetGroupedRequests = jest.fn();const mockGetAttributeKeys = jest.fn();const mockGetSignalSummary = jest.fn();+const mockGetTraceSummaries = jest.fn();+const mockGetTraceSummarySeries = jest.fn();jest.mock("@/lib/platform/request", () => ({getRequests: (...a: unknown[]) => mockGetRequests(...a),@@ -22,6 +24,8 @@ jest.mock("@/lib/platform/request", () => ({getRequestPerTime: jest.fn(),getAverageRequestDuration: jest.fn(),getRequestExist: jest.fn(),+ getTraceSummaries: (...a: unknown[]) => mockGetTraceSummaries(...a),+ getTraceSummarySeries: (...a: unknown[]) => mockGetTraceSummarySeries(...a),}));jest.mock("@/helpers/server/platform", () => ({@@ -84,6 +88,7 @@ import {getTraceSpanRecord,getTraceTotalRequests,listTraceRecords,+ listTraceSummaries,} from "@/lib/platform/traces/read";import { AdapterError } from "@openplait/adapter-sdk";import { UnsupportedCapabilityError } from "@/lib/platform/connectors/datasource/types";@@ -124,6 +129,95 @@ beforeEach(() => {jest.clearAllMocks();});+describe("listTraceSummaries", () => {+ it("uses the selected ClickHouse source for trace-level SQL", async () => {+ mockResolveDescriptor.mockResolvedValue(builtin);+ mockGetAdapter.mockResolvedValue({});+ mockGetTraceSummaries.mockResolvedValue({ err: null, records: [], total: 0 });++ await listTraceSummaries(params as any);++ expect(mockGetTraceSummaries).toHaveBeenCalledWith(+ expect.objectContaining({ databaseConfigId: "db-1" })+ );+ });++ it("uses a listed trace summary and does not download the tree", async () => {+ mockResolveDescriptor.mockResolvedValue(tempo);+ const getTraceSpans = jest.fn();+ mockGetAdapter.mockResolvedValue({+ listSpans: jest.fn().mockResolvedValue({+ rows: [{+ traceId: "trace-1",+ spanId: "trace-1",+ parentSpanId: "",+ name: "request",+ serviceName: "api",+ timestamp: "2026-07-01T00:00:00.000Z",+ durationNs: 1_000_000_000,+ statusCode: "",+ spanAttributes: {},+ resourceAttributes: {},+ traceSummary: {+ spanCount: 4,+ errorCount: 1,+ durationNs: 2_500_000_000,+ start: "2026-07-01T00:00:00.000Z",+ statusCode: "STATUS_CODE_ERROR",+ },+ }],+ }),+ countTraces: jest.fn().mockResolvedValue({ total: 1, truncated: false }),+ getTraceSpans,+ });++ const result = await listTraceSummaries(params as any);++ expect(getTraceSpans).not.toHaveBeenCalled();+ expect(result).toMatchObject({+ total: 1,+ records: [expect.objectContaining({+ TraceId: "trace-1",+ SpanId: "trace-1",+ SpanCount: 4,+ ErrorCount: 1,+ Duration: "2500000000",+ StatusCode: "STATUS_CODE_ERROR",+ })],+ });+ });++ it("keeps a Tempo search summary without inventing a span count", async () => {+ mockResolveDescriptor.mockResolvedValue(tempo);+ const getTraceSpans = jest.fn();+ mockGetAdapter.mockResolvedValue({+ listSpans: jest.fn().mockResolvedValue({+ rows: [{+ traceId: "trace-1",+ spanId: "trace-1",+ parentSpanId: "",+ name: "request",+ serviceName: "api",+ timestamp: "2026-07-01T00:00:00.000Z",+ durationNs: 1_000_000_000,+ statusCode: "",+ spanAttributes: {},+ resourceAttributes: {},+ }],+ }),+ countTraces: jest.fn().mockResolvedValue({ total: 1, truncated: false }),+ getTraceSpans,+ });++ const result = await listTraceSummaries(params as any);++ expect(getTraceSpans).not.toHaveBeenCalled();+ const record = ((result.records || []) as Record<string, unknown>[])[0];+ expect(record).toMatchObject({ TraceId: "trace-1", SpanId: "trace-1" });+ expect(record).not.toHaveProperty("SpanCount");+ });+});+describe("listTraceRecords", () => {it("uses the same adapter contract for the built-in ClickHouse source", async () => {mockResolveDescriptor.mockResolvedValue(builtin);@@ -840,6 +934,32 @@ describe("getTraceHierarchy", () => {});describe("dashboard graph facades", () => {+ it("uses span volume for the separate spans view", async () => {+ mockResolveDescriptor.mockResolvedValue(tempo);+ const traceTimeSeries = jest.fn();+ const spanTimeSeries = jest.fn().mockResolvedValue({ rows: [{ label: "00:00", count: 3 }] });+ mockGetAdapter.mockResolvedValue({ traceTimeSeries, spanTimeSeries });++ const result = await getTraceSummary(params as any, "traces", false);++ expect(spanTimeSeries).toHaveBeenCalledTimes(1);+ expect(traceTimeSeries).not.toHaveBeenCalled();+ expect(result.total).toBe(3);+ });++ it("uses qualified ClickHouse trace counts for the traces view", async () => {+ mockResolveDescriptor.mockResolvedValue(builtin);+ mockGetAdapter.mockResolvedValue({});+ mockGetTraceSummarySeries.mockResolvedValue({ total: 2, buckets: [], err: null });++ const result = await getTraceSummary(params as any, "traces", true);++ expect(mockGetTraceSummarySeries).toHaveBeenCalledWith(+ expect.objectContaining({ databaseConfigId: "db-1" })+ );+ expect(result.total).toBe(2);+ });+it("uses a backend trace-summary series for the external trace volume", async () => {mockResolveDescriptor.mockResolvedValue(tempo);const traceTimeSeries = jest.fn().mockResolvedValue({diff --git a/src/client/src/app/api/telemetry/summary/[signal]/route.ts b/src/client/src/app/api/telemetry/summary/[signal]/route.tsindex 56a1e0f0..bb537602 100644--- a/src/client/src/app/api/telemetry/summary/[signal]/route.ts+++ b/src/client/src/app/api/telemetry/summary/[signal]/route.ts@@ -23,10 +23,10 @@ const SIGNAL_ACCESS: Record<string, RouteAccessKey> = {};/** Route each signal's summary through its per-signal read facade. */-function summaryForSignal(signal: string, params: MetricParams) {+function summaryForSignal(signal: string, params: MetricParams, aggregateTraces = false) {if (signal === "logs") return getLogsSummary(params);if (signal === "metrics") return getMetricsSummary(params);- return getTraceSummary(params, signal as "traces" | "exceptions");+ return getTraceSummary(params, signal as "traces" | "exceptions", aggregateTraces);}async function POSTHandler(@@ -44,6 +44,7 @@ async function POSTHandler(}const formData = await request.json();+ const { searchParams } = new URL(request.url);const metricParams: MetricParams = {timeLimit: formData.timeLimit as TimeLimit,selectedConfig: formData.selectedConfig || {},@@ -61,7 +62,7 @@ async function POSTHandler(if (!validation.success) return Response.json(validation.err, { status: 400 });try {- return Response.json(await summaryForSignal(params.signal, metricParams));+ return Response.json(await summaryForSignal(params.signal, metricParams, searchParams.get("view") === "traces"));} catch (error) {const message = error instanceof Error ? error.message : String(error);return Response.json(diff --git a/src/client/src/app/api/telemetry/trace/route.ts b/src/client/src/app/api/telemetry/trace/route.tsindex 5921d35f..0709e641 100644--- a/src/client/src/app/api/telemetry/trace/route.ts+++ b/src/client/src/app/api/telemetry/trace/route.ts@@ -2,6 +2,7 @@ import { MetricParams, TimeLimit } from "@/lib/platform/common";import {getTraceFilterConfig,listTraceRecords,+ listTraceSummaries,} from "@/lib/platform/traces/read";import {validateMetricsRequest,@@ -42,9 +43,13 @@ async function POSTHandler(request: Request) {});try {- const res: any = await listTraceRecords(params);-const { searchParams } = new URL(request.url);+ const view = searchParams.get("view") || formData.view;+ const res: any =+ view === "traces"+ ? await listTraceSummaries(params)+ : await listTraceRecords(params);+const includeFilters =searchParams.get("includeFilters") === "true" ||formData.includeFilters === true;diff --git a/src/client/src/components/(playground)/observability/registry.tsx b/src/client/src/components/(playground)/observability/registry.tsxindex d43a67eb..62a21f4b 100644--- a/src/client/src/components/(playground)/observability/registry.tsx+++ b/src/client/src/components/(playground)/observability/registry.tsx@@ -1,5 +1,5 @@import { Columns } from "@/components/data-table/columns";-import { columns as traceColumns } from "@/components/(playground)/request/columns";+import { columns as requestColumns } from "@/components/(playground)/request/columns";import { columns as exceptionColumns } from "@/components/(playground)/exceptions/columns";import {codingUsersColumns,@@ -13,6 +13,7 @@ import {BarChart3,Bot,FileText,+ GitBranch,ShieldAlert,Users,type LucideIcon,@@ -24,8 +25,23 @@ import getMessage from "@/constants/messages";const m = getMessage();+const traceColumns: Columns<any, any> = {+ ...requestColumns,+ id: {+ ...requestColumns.id,+ header: () => m.OBSERVABILITY_TRACE_ID,+ cell: requestColumns.id!.cell!,+ },+ spanId: {+ header: () => m.OBSERVABILITY_SPAN_ID,+ cell: ({ row }) => <div className="truncate font-mono" title={row.spanId}>{row.spanId}</div>,+ enableHiding: true,+ },+};+export type ObservabilitySignal =| "traces"+ | "spans"| "exceptions"| "metrics"| "logs"@@ -68,8 +84,35 @@ export const OBSERVABILITY_SIGNALS: ObservabilitySignalConfig[] = [shortLabel: m.OBSERVABILITY_TRACE_SHORT_LABEL,tone: "text-sky-600 dark:text-sky-400 bg-sky-50 dark:bg-sky-950/40 border-sky-200 dark:border-sky-900",summary: m.OBSERVABILITY_TRACE_SUMMARY,+ icon: GitBranch,+ listUrl: "/api/telemetry/trace?view=traces",+ summaryUrl: "/api/telemetry/summary/traces?view=traces",+ configUrl: "/api/metrics/request/config",+ attributeKeysUrl: "/api/metrics/request/attribute-keys",+ columns: traceColumns,+ pageName: "request",+ visibilityPage: "request",+ includeOnlySorting: ["Timestamp"],+ customAttributeTypes: ["SpanAttributes", "ResourceAttributes", "Field"],+ normalize: (row) => ({+ ...normalizeTrace(row),+ spanCount:+ row.SpanCount == null || row.SpanCount === "" ? null : Number(row.SpanCount),+ errorCount:+ row.ErrorCount == null || row.ErrorCount === "" ? null : Number(row.ErrorCount),+ }),+ getRowId: (row) => row.spanId,+ getDetailHref: (row, from) =>+ `/telemetry/traces/${row.spanId}?from=${encodeURIComponent(from)}`,+ },+ {+ key: "spans",+ label: m.OBSERVABILITY_SPANS,+ shortLabel: m.OBSERVABILITY_SPAN_SHORT_LABEL,+ tone: "text-cyan-600 dark:text-cyan-400 bg-cyan-50 dark:bg-cyan-950/40 border-cyan-200 dark:border-cyan-900",+ summary: m.OBSERVABILITY_SPAN_SUMMARY,icon: Activity,- listUrl: "/api/telemetry/request",+ listUrl: "/api/telemetry/trace",summaryUrl: "/api/telemetry/summary/traces",configUrl: "/api/telemetry/request/config",attributeKeysUrl: "/api/telemetry/request/attribute-keys",diff --git a/src/client/src/components/(playground)/observability/signal-list.tsx b/src/client/src/components/(playground)/observability/signal-list.tsxindex f6e962c6..d655a9d2 100644--- a/src/client/src/components/(playground)/observability/signal-list.tsx+++ b/src/client/src/components/(playground)/observability/signal-list.tsx@@ -241,7 +241,10 @@ export default function ObservabilitySignalList({}, [config, data]);const total = (data as any)?.total || 0;const telemetryError = summaryError || listError;- const isTraceSignal = config.key === "traces" || config.key === "exceptions";+ const isTraceSignal =+ config.key === "traces" ||+ config.key === "spans" ||+ config.key === "exceptions";const isMetricSignal = config.key === "metrics";const isLogSignal = config.key === "logs";// Coding-agent sessions render through the same TraceDetailView used@@ -340,7 +343,7 @@ export default function ObservabilitySignalList({if (isTraceSignal) {skipSelectedHydrationRef.current = false;setPreviewSpanId(row.spanId);- setSelectedInUrl(row.spanId, row.traceId);+ setSelectedInUrl(row.spanId, row.traceId || row.id || null);return;}if (isSessionSignal) {@@ -382,8 +385,20 @@ export default function ObservabilitySignalList({config.key === "exceptions"? "/telemetry/exceptions": "/telemetry/traces";- return `${prefix}/${activeSpanId}?from=${encodeURIComponent(from)}`;- }, [config.key, previewSpanId, selectedParam]);+ const row = rows.find((item: any) => item.spanId === activeSpanId);+ const params = new URLSearchParams();+ params.set("from", from);+ if (+ config.key === "traces" ||+ config.key === "spans" ||+ config.key === "exceptions"+ ) {+ params.set("signal", config.key);+ }+ const traceId = row?.traceId || row?.id;+ if (traceId) params.set("traceId", String(traceId));+ return `${prefix}/${activeSpanId}?${params.toString()}`;+ }, [config.key, previewSpanId, rows, selectedParam]);const metricPreviewHref = useMemo(() => {if (!selectedMetricRow) return "";@@ -540,6 +555,13 @@ export default function ObservabilitySignalList({spanId={previewSpanId}type={config.key === "exceptions" ? "exceptions" : "traces"}variant="sheet"+ listUrl={+ config.key === "traces" ||+ config.key === "spans" ||+ config.key === "exceptions"+ ? config.listUrl+ : undefined+ }onSpanChange={updateTraceSelection}onActiveSpanChange={updateActiveTraceSelection}onNavigationPageChange={updateTraceNavigationPage}diff --git a/src/client/src/components/(playground)/observability/signal-records.tsx b/src/client/src/components/(playground)/observability/signal-records.tsxindex cec10c7a..c5ef359c 100644--- a/src/client/src/components/(playground)/observability/signal-records.tsx+++ b/src/client/src/components/(playground)/observability/signal-records.tsx@@ -173,6 +173,13 @@ function TraceRecord({onOpen: (row: any) => void;}) {const show = (key: string) => visibilityColumns[key] !== false;+ const isTraceSummary = config.key === "traces";+ const spanCount =+ row.spanCount == null || Number.isNaN(Number(row.spanCount))+ ? null+ : Number(row.spanCount);+ const errorCount = Number(row.errorCount || 0);+ const hasErrors = errorCount > 0;const health = classifyFromNormalizedTrace(row);const healthChips: GenerationHealthChip[] = (["truncated", "filtered", "empty", "swapped"] as GenerationHealthChip[]@@ -197,7 +204,7 @@ function TraceRecord({<div className="flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between"><div className="min-w-0"><div className="flex min-w-0 items-center gap-2">- <span className={`h-2 w-2 shrink-0 rounded-full ${config.key === "exceptions" ? "bg-rose-500" : "bg-sky-500"}`} />+ <span className={`h-2 w-2 shrink-0 rounded-full ${config.key === "exceptions" || hasErrors ? "bg-rose-500" : "bg-sky-500"}`} /><h3 className="min-w-0 truncate text-sm font-semibold text-stone-950 dark:text-stone-50">{show("spanName") ? row.spanName || row.id : row.id}</h3>@@ -218,11 +225,14 @@ function TraceRecord({</div><div className="mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-stone-500 dark:text-stone-400">{show("time") && <span>{row.time}</span>}- {show("id") && <span className="font-mono">{row.spanId}</span>}+ {show("id") && <span className="font-mono" title={isTraceSummary ? m.OBSERVABILITY_TRACE_ID : m.OBSERVABILITY_SPAN_ID}>{isTraceSummary ? `${m.OBSERVABILITY_TRACE_ID}: ${row.id}` : `${m.OBSERVABILITY_SPAN_ID}: ${row.spanId}`}</span>}+ {isTraceSummary && row.spanId && <span className="font-mono" title={m.OBSERVABILITY_SPAN_ID}>{m.OBSERVABILITY_SPAN_ID}: {row.spanId}</span>}{show("serviceName") && row.serviceName && <span>{row.serviceName}</span>}</div></div><div className="grid grid-cols-2 gap-1.5 sm:flex sm:flex-wrap sm:justify-end">+ {isTraceSummary && spanCount != null && <MiniMeta icon={<GitBranch className="h-3.5 w-3.5" />} label={m.OBSERVABILITY_SPAN_COUNT_LABEL} value={spanCount} />}+ {isTraceSummary && hasErrors && <MiniMeta icon={<Info className="h-3.5 w-3.5" />} label={m.OBSERVABILITY_ERROR_COUNT_LABEL} value={errorCount} />}{show("requestDuration") && <MiniMeta icon={<Clock className="h-3.5 w-3.5" />} label="duration" value={`${parseFloat(row.requestDuration || "0").toFixed(3)}s`} />}{show("totalTokens") && <MiniMeta icon={<Zap className="h-3.5 w-3.5" />} label="tokens" value={row.totalTokens} />}{show("model") && <MiniMeta icon={<Hash className="h-3.5 w-3.5" />} label="model" value={row.model || row.system} />}diff --git a/src/client/src/components/(playground)/observability/signal-summary.tsx b/src/client/src/components/(playground)/observability/signal-summary.tsxindex 45a04875..e0a00ba0 100644--- a/src/client/src/components/(playground)/observability/signal-summary.tsx+++ b/src/client/src/components/(playground)/observability/signal-summary.tsx@@ -55,13 +55,17 @@ export default function SignalSummary({}) {const buckets = data?.buckets || [];const metricLabel =- config.key === "metrics"- ? m.OBSERVABILITY_METRIC_POINTS- : config.key === "logs"- ? m.OBSERVABILITY_LOG_EVENTS- : config.key === "exceptions"- ? m.OBSERVABILITY_EXCEPTIONS- : m.OBSERVABILITY_TRACES;+ config.key === "traces"+ ? m.OBSERVABILITY_TRACES+ : config.key === "spans"+ ? m.OBSERVABILITY_SPANS+ : config.key === "metrics"+ ? m.OBSERVABILITY_METRIC_POINTS+ : config.key === "logs"+ ? m.OBSERVABILITY_LOG_EVENTS+ : config.key === "exceptions"+ ? m.OBSERVABILITY_EXCEPTIONS+ : m.OBSERVABILITY_TRACES;const freshness = freshnessLabel(data?.freshness);return (diff --git a/src/client/src/components/(playground)/observability/trace-detail-page.tsx b/src/client/src/components/(playground)/observability/trace-detail-page.tsxindex 8aa59b67..4a573ee9 100644--- a/src/client/src/components/(playground)/observability/trace-detail-page.tsx+++ b/src/client/src/components/(playground)/observability/trace-detail-page.tsx@@ -342,6 +342,32 @@ function filterFromSource(from: string | null, offsetOverride?: number): FilterT};}+function tabFromLocation(from: string | null): string | null {+ if (!from) return null;+ try {+ return new URL(from, "http://localhost").searchParams.get("tab");+ } catch {+ return null;+ }+}++function detailListUrl(args: {+ type: "traces" | "exceptions";+ listUrl?: string;+ signal: string | null;+ tab: string | null;+ from: string | null;+}): string {+ if (args.listUrl) return args.listUrl;+ const hinted = args.signal || args.tab || tabFromLocation(args.from);+ if (args.type === "exceptions" || hinted === "exceptions") {+ return "/api/telemetry/exception";+ }+ if (hinted === "traces") return "/api/telemetry/trace?view=traces";+ if (hinted === "spans") return "/api/telemetry/trace";+ return "/api/telemetry/request";+}+function sourceWithOffset(from: string | null, offset: number) {if (!from || typeof window === "undefined") return from;const url = new URL(from, window.location.origin);@@ -361,6 +387,7 @@ export function TraceDetailView({navigationTotal,navigationFilter,onNavigationPageChange,+ listUrl,}: {spanId: string;type: "traces" | "exceptions";@@ -373,6 +400,8 @@ export function TraceDetailView({navigationTotal?: number;navigationFilter?: FilterType;onNavigationPageChange?: (offset: number) => void;+ /** Neighbor-list endpoint. The full-page view falls back to `signal` / `tab`. */+ listUrl?: string;}) {const m = getMessage();const router = useRouter();@@ -427,7 +456,15 @@ export function TraceDetailView({total?: number;} | null>(null);const fromRef = useRef(from);- const listUrlRef = useRef(type === "exceptions" ? "/api/telemetry/exception" : "/api/telemetry/request");+ const listUrlRef = useRef(+ detailListUrl({+ type,+ listUrl,+ signal: searchParams.get("signal"),+ tab: searchParams.get("tab"),+ from: searchParams.get("from"),+ })+ );const detailBasePathRef = useRef(type === "exceptions" ? "/telemetry/exceptions" : "/telemetry/traces");@@ -482,6 +519,8 @@ export function TraceDetailView({const source = fromRef.current;const params = new URLSearchParams();if (source) params.set("from", source);+ const signal = searchParams.get("signal");+ if (signal) params.set("signal", signal);if (nextTraceId) params.set("traceId", nextTraceId);const qs = params.toString() ? `?${params.toString()}` : "";if (variant === "page") {@@ -489,7 +528,7 @@ export function TraceDetailView({}onSpanChange?.(nextSpanId);},- [onSpanChange, router, variant]+ [onSpanChange, router, searchParams, variant]);const selectSpanInCurrentTrace = useCallback(diff --git a/src/client/src/constants/messages/en.ts b/src/client/src/constants/messages/en.tsindex 03c95da5..b47f262d 100644--- a/src/client/src/constants/messages/en.ts+++ b/src/client/src/constants/messages/en.ts@@ -233,10 +233,14 @@ export const OBSERVABILITY_EXCEPTIONS = "Exceptions";export const OBSERVABILITY_METRICS = "Metrics";export const OBSERVABILITY_LOGS = "Logs";export const OBSERVABILITY_TRACE_SHORT_LABEL = "Latency, cost, tokens";+export const OBSERVABILITY_SPAN_SHORT_LABEL = "Individual operations";export const OBSERVABILITY_EXCEPTION_SHORT_LABEL = "Failures and error spans";export const OBSERVABILITY_METRIC_SHORT_LABEL = "Gauges, sums, histograms";export const OBSERVABILITY_LOG_SHORT_LABEL = "Events and correlated context";export const OBSERVABILITY_TRACE_SUMMARY = "Span flow";+export const OBSERVABILITY_SPAN_SUMMARY = "Raw span flow";+export const OBSERVABILITY_SPAN_COUNT_LABEL = "spans";+export const OBSERVABILITY_ERROR_COUNT_LABEL = "errors";export const OBSERVABILITY_EXCEPTION_SUMMARY = "Failure path";export const OBSERVABILITY_METRIC_SUMMARY = "Signal shape";export const OBSERVABILITY_LOG_SUMMARY = "Event stream";diff --git a/src/client/src/helpers/server/platform.ts b/src/client/src/helpers/server/platform.tsindex 419ca046..f00ded10 100644--- a/src/client/src/helpers/server/platform.ts+++ b/src/client/src/helpers/server/platform.ts@@ -211,18 +211,25 @@ export const validateMetricsRequest = (return { success: true };};+/** Time predicate shared by span filters and the trace-summary page scan. */+export function getTimeRangeWhereCondition(filter: {+ timeLimit?: { start?: unknown; end?: unknown };+}): string {+ const { start, end } = filter.timeLimit || {};+ if (start && end) {+ return `Timestamp >= parseDateTimeBestEffort('${start}') AND Timestamp <= parseDateTimeBestEffort('${end}')`;+ }+ return "";+}+export const getFilterWhereCondition = (filter: FilterWhereConditionType,filterSelectedConfig?: boolean) => {const whereArray: string[] = [];try {- const { start, end } = filter.timeLimit || {};- if (start && end) {- whereArray.push(- `Timestamp >= parseDateTimeBestEffort('${start}') AND Timestamp <= parseDateTimeBestEffort('${end}')`- );- }+ const timeWhere = getTimeRangeWhereCondition(filter);+ if (timeWhere) whereArray.push(timeWhere);if (filterSelectedConfig && filter.selectedConfig) {if (filter.selectedConfig.models?.length) {diff --git a/src/client/src/lib/platform/connectors/datasource/clickhouse/normalize.ts b/src/client/src/lib/platform/connectors/datasource/clickhouse/normalize.tsindex 24366121..f3ceb073 100644--- a/src/client/src/lib/platform/connectors/datasource/clickhouse/normalize.ts+++ b/src/client/src/lib/platform/connectors/datasource/clickhouse/normalize.ts@@ -137,6 +137,19 @@ export function denormalizeSpanToTraceRow(Links: [],Cost: span.cost,agentLoop: span.agentLoop,+ ...(span.traceSummary+ ? {+ SpanCount: span.traceSummary.spanCount,+ ErrorCount: span.traceSummary.errorCount,+ ...(span.traceSummary.durationNs != null+ ? { TraceDurationNs: span.traceSummary.durationNs }+ : {}),+ ...(span.traceSummary.start ? { TraceStart: span.traceSummary.start } : {}),+ ...(span.traceSummary.statusCode+ ? { TraceStatusCode: span.traceSummary.statusCode }+ : {}),+ }+ : {}),};}diff --git a/src/client/src/lib/platform/connectors/datasource/graph/sample-fetch.ts b/src/client/src/lib/platform/connectors/datasource/graph/sample-fetch.tsindex 5d02e315..f0249da9 100644--- a/src/client/src/lib/platform/connectors/datasource/graph/sample-fetch.ts+++ b/src/client/src/lib/platform/connectors/datasource/graph/sample-fetch.ts@@ -242,6 +242,38 @@ export function pickRootSpan(spans: NormalizedSpan[]): NormalizedSpan | undefine);}+/** Span count, error count, and wall-clock duration for one already-loaded tree. */+export function summarizeTraceSpans(spans: NormalizedSpan[]): NonNullable<+ NormalizedSpan["traceSummary"]+> {+ let start = Number.POSITIVE_INFINITY;+ let end = Number.NEGATIVE_INFINITY;+ let errorCount = 0;+ for (const span of spans) {+ if (String(span.statusCode || "").toUpperCase().includes("ERROR")) {+ errorCount += 1;+ }+ const startedAt = Date.parse(span.timestamp);+ if (!Number.isFinite(startedAt)) continue;+ const durationMs = Number.isFinite(span.durationNs) ? span.durationNs / 1e6 : 0;+ const endedAt = startedAt + durationMs;+ if (startedAt < start) start = startedAt;+ if (endedAt > end) end = endedAt;+ }+ const hasWindow = Number.isFinite(start) && Number.isFinite(end);+ return {+ spanCount: spans.length,+ errorCount,+ ...(hasWindow+ ? {+ durationNs: Math.max(0, Math.round((end - start) * 1e6)),+ start: new Date(start).toISOString(),+ ...(errorCount ? { statusCode: "STATUS_CODE_ERROR" } : {}),+ }+ : {}),+ };+}+/** Collapse full-trace spans to one root row per trace, newest first. */export function collapseToRootSpans(spans: NormalizedSpan[]): NormalizedSpan[] {const byTrace = new Map<string, NormalizedSpan[]>();diff --git a/src/client/src/lib/platform/connectors/datasource/jaeger/adapter.ts b/src/client/src/lib/platform/connectors/datasource/jaeger/adapter.tsindex 978839eb..b2bdfec2 100644--- a/src/client/src/lib/platform/connectors/datasource/jaeger/adapter.ts+++ b/src/client/src/lib/platform/connectors/datasource/jaeger/adapter.ts@@ -38,6 +38,7 @@ import {SourceResponseError,} from "../http/safe-fetch";import { cacheKey, cachedQuery } from "../http/cache";+import { summarizeTraceSpans } from "../graph/sample-fetch";import { resolveSourceSecret, redactableSecretValues } from "../http/secret";import { spanMatchesAISelector, traceMatchesAISelector } from "../selector-match";import {@@ -575,7 +576,7 @@ export class JaegerAdapter extends BaseExternalAdapter {: offset + pageSize;const traces = await this.collectTraces(query, budget);const rows = traces- .map((trace) => {+ .map((trace): NormalizedSpan | undefined => {const spans = flattenJaegerTraces([trace]).map(toNormalizedSpan);let listed: NormalizedSpan | undefined;if (query.agentLoop) {@@ -590,7 +591,11 @@ export class JaegerAdapter extends BaseExternalAdapter {if (!listed) listed = pickRootSpan(spans);if (!listed) return undefined;const hit = loopHitsByTraceId(spans).get(listed.traceId);- return hit ? { ...listed, agentLoop: hit } : listed;+ return {+ ...listed,+ traceSummary: summarizeTraceSpans(spans),+ ...(hit ? { agentLoop: hit } : {}),+ };}).filter((span): span is NormalizedSpan => !!span);rememberSpans(this.descriptor.id, this.spansFromTraces(traces));diff --git a/src/client/src/lib/platform/connectors/datasource/types.ts b/src/client/src/lib/platform/connectors/datasource/types.tsindex ec1e4bf4..f19f83b6 100644--- a/src/client/src/lib/platform/connectors/datasource/types.ts+++ b/src/client/src/lib/platform/connectors/datasource/types.ts@@ -44,6 +44,21 @@ export interface NormalizedSpan {events?: NormalizedSpanEvent[];/** Optional pre-resolved cost (USD) applied by cost overlay / vendor. */cost?: number;+ /**+ * Trace-level stats already known to the lister (Jaeger has the tree in+ * hand). Absent on search summaries such as Tempo, which do not download+ * child spans for the list.+ */+ traceSummary?: {+ spanCount: number;+ errorCount: number;+ /** End-to-end nanoseconds from the earliest start to the latest end. */+ durationNs?: number;+ /** ISO start of the earliest span. */+ start?: string;+ /** Set when any span in the tree is an error. */+ statusCode?: string;+ };/** Stuck-tool loop on this trace/session, attached by the traces facade. */agentLoop?: {toolName: string;diff --git a/src/client/src/lib/platform/observability.ts b/src/client/src/lib/platform/observability.tsindex 01f3c725..0458a891 100644--- a/src/client/src/lib/platform/observability.ts+++ b/src/client/src/lib/platform/observability.ts@@ -268,7 +268,8 @@ export async function getLogs(params: MetricParams) {export async function getSignalSummary(params: MetricParams,- signal: SummarySignal+ signal: SummarySignal,+ aggregateTraces = false) {const bucket = getSummaryBucket(params);const labelFormat = bucketLabelFormat(bucket);@@ -282,10 +283,14 @@ export async function getSignalSummary(: {}),};const where = getFilterWhereCondition(traceParams, true);+ const countExpression =+ signal === "traces" && aggregateTraces+ ? "uniqExact(TraceId)"+ : "COUNT(*)";query = `SELECTformatDateTime(DATE_TRUNC('${bucket}', Timestamp), '${labelFormat}') AS label,- CAST(COUNT(*) AS INTEGER) AS count,+ CAST(${countExpression} AS INTEGER) AS count,CAST(avg(Duration) * 1e-9 AS FLOAT) AS avgDuration,CAST(SUM(toFloat64OrZero(SpanAttributes['gen_ai.usage.cost'])) AS FLOAT) AS cost,CAST(SUM(toInt64OrZero(SpanAttributes['gen_ai.usage.total_tokens'])) AS INTEGER) AS tokensdiff --git a/src/client/src/lib/platform/request/index.ts b/src/client/src/lib/platform/request/index.tsindex 977ad565..b48a101f 100644--- a/src/client/src/lib/platform/request/index.ts+++ b/src/client/src/lib/platform/request/index.ts@@ -1,4 +1,5 @@import { MetricParams } from "../common";+import { getSummaryBucket } from "../observability";import { queryTracesSql, tracesTableRef } from "../traces/clickhouse-read";import {getTraceMappingKeyFullPath,@@ -11,6 +12,7 @@ import {dateTruncGroupingLogic,getFilterPreviousParams,getFilterWhereCondition,+ getTimeRangeWhereCondition,} from "@/helpers/server/platform";import { hasGenerationHealthFilter } from "@/lib/platform/generation-health/classify";import { hasAgentLoopFilter } from "@/lib/platform/agent-loop/classify";@@ -95,7 +97,7 @@ export async function getTotalRequests(params: MetricParams) {SELECTCOUNT(*) AS total_requests,'${params.timeLimit.start}' as start_date- FROM ${table}+ FROM ${table}WHERE ${getFilterWhereCondition(parameters, true)}`;@@ -227,7 +229,7 @@ export async function getRequestsConfig(params: MetricParams) {`arrayFilter(x -> x != '', ARRAY_AGG(DISTINCT ResourceAttributes['deployment.environment'])) AS environments`);- const query = `SELECT ${select.join(", ")} FROM ${table}+ const query = `SELECT ${select.join(", ")} FROM ${table}WHERE ${getFilterWhereCondition(params, true)}`;return queryTracesSql(query, params.databaseConfigId);@@ -243,7 +245,7 @@ export async function getRequests(params: MetricParams) {? "CAST(uniqExact(TraceId) AS INTEGER)": "CAST(COUNT(*) AS INTEGER)";- const countQuery = `SELECT ${totalExpr} AS total FROM ${table}+ const countQuery = `SELECT ${totalExpr} AS total FROM ${table}WHERE ${getFilterWhereCondition(params, true)}`;const { data: dataTotal, err: errTotal } = await queryTracesSql(@@ -256,7 +258,7 @@ export async function getRequests(params: MetricParams) {};}- const query = `SELECT * FROM ${table}+ const query = `SELECT * FROM ${table}WHERE ${getFilterWhereCondition(params, true)}${params.sorting && params.sorting.type && params.sorting.direction? buildRequestsOrderByClause(params.sorting.type, params.sorting.direction)@@ -274,10 +276,129 @@ export async function getRequests(params: MetricParams) {};}+const TRACE_ERROR_STATUS = "('STATUS_CODE_ERROR', 'Error', 'ERROR')";++function boundedInteger(value: unknown, fallback: number, max: number): number {+ const parsed = Number(value);+ if (!Number.isFinite(parsed)) return fallback;+ return Math.min(max, Math.max(0, Math.trunc(parsed)));+}++function traceSummaryDirection(sorting?: { type?: string; direction?: string }): "ASC" | "DESC" {+ if (sorting?.type === "Timestamp" && sorting.direction === "asc") return "ASC";+ return "DESC";+}++/**+ * Return one representative row for each trace.+ *+ * Page the trace ids that match the active filter first, then aggregate only+ * that page inside the same time window. The root is an empty or all-zero+ * parent, with SpanId as the tie-break. Events and Links are omitted: the+ * table stores them as flattened arrays (`Events.Timestamp`, …), and the+ * detail route loads the chosen span on open.+ */+export async function getTraceSummaries(params: MetricParams) {+ const limit = Math.max(1, boundedInteger(params.limit, 10, 500));+ const offset = boundedInteger(params.offset, 0, 1_000_000);+ const direction = traceSummaryDirection(params.sorting);+ const where = getFilterWhereCondition(params, true) || "1";+ const timeWhere =+ getTimeRangeWhereCondition(params).replaceAll("Timestamp", "t.Timestamp") || "1";+ // Same root rule as pickRootSpan: empty parent, or the 16-zero placeholder.+ const rootRank =+ "if(empty(t.ParentSpanId) OR t.ParentSpanId = '0000000000000000', 0, 1)";+ const rootOrder = `tuple(${rootRank}, t.Timestamp, t.SpanId)`;+ const table = await tracesTableRef(params.databaseConfigId);++ const countQuery = `SELECT CAST(uniqExact(TraceId) AS INTEGER) AS total+ FROM ${table}+ WHERE ${where}`;++ const { data: dataTotal, err: errTotal } = await queryTracesSql(countQuery, params.databaseConfigId);+ if (errTotal) return { err: errTotal };++ const query = `WITH page AS (+ SELECT+ TraceId,+ min(Timestamp) AS TraceStart+ FROM ${table}+ WHERE ${where}+ GROUP BY TraceId+ ORDER BY TraceStart ${direction}+ LIMIT ${limit}+ OFFSET ${offset}+ )+ SELECT+ t.TraceId AS TraceId,+ argMin(t.SpanId, ${rootOrder}) AS SpanId,+ argMin(t.ParentSpanId, ${rootOrder}) AS ParentSpanId,+ argMin(t.TraceState, ${rootOrder}) AS TraceState,+ argMin(t.SpanName, ${rootOrder}) AS SpanName,+ argMin(t.SpanKind, ${rootOrder}) AS SpanKind,+ argMin(t.ServiceName, ${rootOrder}) AS ServiceName,+ argMin(t.ResourceAttributes, ${rootOrder}) AS ResourceAttributes,+ argMin(t.ScopeName, ${rootOrder}) AS ScopeName,+ argMin(t.ScopeVersion, ${rootOrder}) AS ScopeVersion,+ argMin(t.SpanAttributes, ${rootOrder}) AS SpanAttributes,+ min(t.Timestamp) AS Timestamp,+ toString(+ greatest(+ toInt64(0),+ toUnixTimestamp64Nano(max(addNanoseconds(t.Timestamp, toInt64(t.Duration)))) -+ toUnixTimestamp64Nano(min(t.Timestamp))+ )+ ) AS Duration,+ if(countIf(t.StatusCode IN ${TRACE_ERROR_STATUS}) > 0, 'STATUS_CODE_ERROR', argMin(t.StatusCode, ${rootOrder})) AS StatusCode,+ argMaxIf(t.StatusMessage, t.Timestamp, notEmpty(t.StatusMessage)) AS StatusMessage,+ CAST(count() AS INTEGER) AS SpanCount,+ CAST(countIf(t.StatusCode IN ${TRACE_ERROR_STATUS}) AS INTEGER) AS ErrorCount+ FROM ${table} AS t+ INNER JOIN page AS p ON t.TraceId = p.TraceId+ WHERE ${timeWhere}+ GROUP BY t.TraceId, p.TraceStart+ ORDER BY p.TraceStart ${direction}`;++ const { data, err } = await queryTracesSql(query, params.databaseConfigId);+ return {+ err,+ records: data,+ total: (dataTotal as any[])?.[0]?.total || 0,+ };+}++export async function getTraceSummarySeries(params: MetricParams) {+ const bucket = getSummaryBucket(params);+ const labelFormat = bucket === "hour" ? "%m/%d %H:00" : bucket === "month" ? "%Y/%m" : "%Y/%m/%d";+ const table = await tracesTableRef(params.databaseConfigId);+ const where = getFilterWhereCondition(params, true);+ const query = `SELECT+ formatDateTime(DATE_TRUNC('${bucket}', Timestamp), '${labelFormat}') AS label,+ CAST(uniqExact(TraceId) AS INTEGER) AS count,+ CAST(avg(Duration) * 1e-9 AS FLOAT) AS avgDuration,+ CAST(SUM(toFloat64OrZero(SpanAttributes['gen_ai.usage.cost'])) AS FLOAT) AS cost,+ CAST(SUM(toInt64OrZero(SpanAttributes['gen_ai.usage.total_tokens'])) AS INTEGER) AS tokens+ FROM ${table}+ WHERE ${where}+ GROUP BY label+ ORDER BY min(Timestamp)`;+ const { data, err } = await queryTracesSql(query, params.databaseConfigId);+ const buckets = (data as Record<string, unknown>[]) || [];+ return {+ err,+ bucket,+ buckets,+ total: buckets.reduce((sum, row) => sum + Number(row.count || 0), 0),+ peak: buckets.reduce((max, row) => Math.max(max, Number(row.count || 0)), 0),+ freshness: "live" as const,+ truncated: false,+ };+}+export async function getRequestViaSpanId(spanId: string, databaseConfigId?: string) {const table = await tracesTableRef(databaseConfigId);const safeSpanId = escapeClickHouseString(String(spanId ?? ""));- const query = `SELECT * FROM ${table}+ const query = `SELECT * FROM ${table}WHERE SpanId='${safeSpanId}'`;const { data, err } = await queryTracesSql(query, databaseConfigId);diff --git a/src/client/src/lib/platform/traces/read.ts b/src/client/src/lib/platform/traces/read.tsindex ac12e237..5a3c9597 100644--- a/src/client/src/lib/platform/traces/read.ts+++ b/src/client/src/lib/platform/traces/read.ts@@ -46,6 +46,7 @@ import {worstLoop,} from "@/lib/platform/agent-loop/classify";import { mapPool } from "@/lib/platform/connectors/datasource/graph/map-pool";+import { getTraceSummaries, getTraceSummarySeries } from "@/lib/platform/request";async function resolveTracesAdapter(sourceId?: string, environment?: string) {const { adapter, descriptor } = await resolveSignalReadContext("traces", {@@ -397,8 +398,17 @@ function asErrorMessage(err: unknown): string {return typeof err === "string" ? err : getMessage().WIDGET_RUN_FAILED;}-/** List spans for the Telemetry table (same shape as `getRequests`). */-export async function listTraceRecords(params: MetricParams) {+/**+ * List spans for the Telemetry table (same shape as `getRequests`).+ *+ * `hydrateTrees` downloads a Tempo search hit's full trace so loop badges can+ * be attached. The trace-level list turns that off: Tempo summaries are+ * already one row per trace, and a second download belongs on detail open.+ */+export async function listTraceRecords(+ params: MetricParams,+ opts?: { hydrateTrees?: boolean }+) {const { adapter, descriptor } = await resolveTracesAdapter(params.sourceId, params.environment);try {@@ -430,7 +440,7 @@ export async function listTraceRecords(params: MetricParams) {},records);- } else if (spans.some(isTraceSummaryRow)) {+ } else if (opts?.hydrateTrees !== false && spans.some(isTraceSummaryRow)) {const trees = await treesForListedTraces(adapter, spans);records = withLoopHits(records, trees);} else {@@ -468,6 +478,47 @@ export async function listTraceRecords(params: MetricParams) {}}+function applyListedTraceSummary(row: Record<string, unknown>) {+ const next = { ...row };+ if (row.TraceStart) next.Timestamp = row.TraceStart;+ if (row.TraceDurationNs != null) next.Duration = String(row.TraceDurationNs);+ if (row.TraceStatusCode) next.StatusCode = row.TraceStatusCode;+ return next;+}++/**+ * One row per trace, with a representative span for the existing detail route.+ *+ * ClickHouse pages trace ids in SQL. Other sources already list one row per+ * trace (Tempo search summaries, Jaeger roots). Jaeger stamps `traceSummary`+ * from the tree it loaded to pick that root. This does not call+ * `getTraceSpans`: a span-oriented page cannot be re-paginated into traces,+ * and Tempo keeps full trees for the detail open.+ */+export async function listTraceSummaries(params: MetricParams) {+ const { descriptor } = await resolveTracesAdapter(params.sourceId, params.environment);+ if (usesSqlIssueFilters(descriptor)) {+ return getTraceSummaries({+ ...params,+ databaseConfigId: params.databaseConfigId || descriptor.dbConfigId,+ });+ }++ const listed = await listTraceRecords(params, { hydrateTrees: false });+ if (listed.err || !listed.records) return listed;+ const seen = new Set<string>();+ const records: Record<string, unknown>[] = [];+ for (const row of listed.records) {+ const traceId = String(row.TraceId || "");+ if (traceId) {+ if (seen.has(traceId)) continue;+ seen.add(traceId);+ }+ records.push(applyListedTraceSummary(row));+ }+ return { ...listed, records };+}+/*** Tempo list rows reuse `traceId` as `spanId` because search summaries have no* cheap real span id. Treat that sentinel as "open the trace root".@@ -844,14 +895,27 @@ export async function getTraceGrouped(params: MetricParams, groupBy: string) {*/export async function getTraceSummary(params: MetricParams,- signal: "traces" | "exceptions" = "traces"+ signal: "traces" | "exceptions" = "traces",+ /**+ * `true` counts unique traces (the Traces tab). `false` counts spans (the+ * Spans tab). Omitted keeps the previous external default — Tempo and+ * Jaeger trace series — and leaves ClickHouse on span counts so the+ * deprecated observability summary route does not change meaning.+ */+ aggregateTraces?: boolean) {- const { adapter } = await resolveTracesAdapter(params.sourceId, params.environment);+ const { adapter, descriptor } = await resolveTracesAdapter(params.sourceId, params.environment);const bucket = getSummaryBucket(params);const empty = { err: null, bucket, buckets: [], total: 0, peak: 0 };try {+ if (signal === "traces" && aggregateTraces === true && usesSqlIssueFilters(descriptor)) {+ return await getTraceSummarySeries({+ ...params,+ databaseConfigId: params.databaseConfigId || descriptor.dbConfigId,+ });+ }const base = externalTraceQuery(params, { aiSelector: false });const query: OpenLITQuery = {...base,@@ -876,7 +940,7 @@ export async function getTraceSummary(// Trace backends such as Tempo can return lightweight trace summaries// without downloading every span. Prefer that trace-level series when// available so a 200-trace L1 sample is never presented as the volume.- const frame = adapter.traceTimeSeries+ const frame = aggregateTraces !== false && adapter.traceTimeSeries? await adapter.traceTimeSeries(query): await planAndSpanTimeSeries(adapter, query);const buckets = (frame.rows as Record<string, unknown>[]).map((row) => ({