Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(tracing): make traces, spans and operations columns resizable (#91080)

Jimmy Zhu61baca3378e3
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index ea41cd25937d..c78392351885 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5424,6 +5424,26 @@ snapshots:
hash: v1.k794b7964.79b55888f68b8fdecde60eb59f9941838eed95754b51bd361ab65be360277270.lJwqiaG6UTf6bczX7v1jw_bImsnq7LK-tuxsBFZt2F4
products-subscriptions-subscriptions-table--with-pagination--light:
hash: v1.k794b7964.c54c1003b71f29a08808fa1e4e7413ee7c61f514eb1198c924d936cc95c834e5.1PL1n6t2LsJ6X33Z6txXpmifcmqNP6HrVtrLhnMrWMA
+ products-tracing-operationstable--default--dark:
+ hash: v1.k794b7964.58421fb9485687230fc55051bb13eeefff6fec4dbc8cc0eeb9a9a9f3f39a30cd.QacFiUZLBgSAOZZnr3OoUeIP2e-0gBXYobLZf-MTcMM
+ products-tracing-operationstable--default--light:
+ hash: v1.k794b7964.c9a65a8cb017f5d670abd8118677adb369e43f4b23c9606a4c3ad094f297d11d.9yQGoW-Yjz_uW412hLI83uu3CU484MGSEUgoQCEfZPE
+ products-tracing-operationstable--empty--dark:
+ hash: v1.k794b7964.8b62dd81f1477a10a09e32a509a393dfc86c5cf37b0791c60189fdbf46d17f3f.qOdE-5k598paIYulRIAPZ-FpZveKUH5fHKNKdN3M5-I
+ products-tracing-operationstable--empty--light:
+ hash: v1.k794b7964.dd7a89972b74c15592932575b90eb20b0e8ad52f189099151164073143844294.N_5E0cXYptBnG3t3sA6dOdNec6NR_jEXBdWxf6g8Aww
+ products-tracing-operationstable--loading--dark:
+ hash: v1.k794b7964.f7b919b2c420a09ce82ea731390a821c0ec23fea52a26cb7b73c279ff906e2be.kYxfbLWv0vgLI4RPXovyFzobM6K04qFePwZ61e2wkEk
+ products-tracing-operationstable--loading--light:
+ hash: v1.k794b7964.04bcc55cb9522d72f548084a92d35c0aba20ff4995949bd8b2ee8686f96cb6ac.P_KhZ-T4DKSiE8XyxMJSgUEUR9bDfDvgYnGqSOiR860
+ products-tracing-virtualizedspanlist--default--dark:
+ hash: v1.k794b7964.2d26cb574fb8b9011fcf44c766f491adb06c254b9bc1bb70fa1a14bf757eb72d.HK_kiCD_GlyKPWUd6GcCvJJ5tVWaz6t45kZwDWUYg_4
+ products-tracing-virtualizedspanlist--default--light:
+ hash: v1.k794b7964.21b6c26c19954d60a3447075f70b9c9dcfb5f6032f94c85fa223f728ee02bf1c.dAAs5oIhp4WcsPd9uA5wTgaPWyEeuf7PV46c6WFv-9g
+ products-tracing-virtualizedspanlist--empty--dark:
+ hash: v1.k794b7964.5590e8e6497de2fefefa74cf07edd5f814a798deb8f7e5f0102a383f5e8ac6c8.ZvuooUS3qT6kDX8yW2_oQ1iDgO1DwVFMAWM517bhCHw
+ products-tracing-virtualizedspanlist--empty--light:
+ hash: v1.k794b7964.72ff685c9162da170263d416510a2cc5229c999691288c0b8038143000a40f15.ebvPm2A_7cN8QvjEaroudYEO1lp9qFUooW98MMcDBwY
products-workflows-customerioimportmodal--all-steps-completed--dark:
hash: v1.k794b7964.da9d1ebf1836700267307224631511bd8fe3b9fb0906654a383e545e1c6f98f1.lPijIVizKAMxsGEVt28x0Y5izfhcfnbjbPhoHzriWFg
products-workflows-customerioimportmodal--all-steps-completed--light:
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bf5f6ff78e13..e6027d376237 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4601,6 +4601,9 @@ importers:
'@posthog/quill-charts':
specifier: workspace:*
version: link:../../packages/quill/packages/charts
+ '@storybook/react':
+ specifier: 'catalog:'
'@testing-library/react':
specifier: '*'
diff --git a/products/tracing/frontend/OperationsTable.stories.tsx b/products/tracing/frontend/OperationsTable.stories.tsx
new file mode 100644
index 000000000000..7199a8381f0b
--- /dev/null
+++ b/products/tracing/frontend/OperationsTable.stories.tsx
@@ -0,0 +1,78 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { AggregatedSpanRow } from '~/queries/schema/schema-general'
+
+import { OperationsTable } from './OperationsTable'
+
+const ms = (value: number): number => value * 1_000_000
+
+const ROWS: AggregatedSpanRow[] = [
+ {
+ service_name: 'checkout-api',
+ name: 'POST /api/v2/checkout/session/confirm',
+ count: 1_284_004,
+ error_count: 0,
+ p50_duration_nano: ms(372.8),
+ p95_duration_nano: ms(565.6),
+ p99_duration_nano: ms(936.3),
+ p999_duration_nano: ms(1290),
+ total_duration_nano: ms(387_675_574),
+ },
+ {
+ service_name: 'inventory-worker-europe',
+ name: 'reserveStockForOrder',
+ count: 511_222,
+ error_count: 1402,
+ p50_duration_nano: ms(442.2),
+ p95_duration_nano: ms(694.7),
+ p99_duration_nano: ms(903.3),
+ p999_duration_nano: ms(1240),
+ total_duration_nano: ms(232_285_822),
+ },
+ {
+ service_name: 'notifications',
+ name: 'sendEmail',
+ count: 96_310,
+ error_count: 0,
+ p50_duration_nano: ms(89.1),
+ p95_duration_nano: ms(184),
+ p99_duration_nano: ms(195),
+ p999_duration_nano: ms(205),
+ total_duration_nano: ms(9_921_866),
+ },
+] as AggregatedSpanRow[]
+
+const meta: Meta<typeof OperationsTable> = {
+ title: 'Products/Tracing/OperationsTable',
+ component: OperationsTable,
+ tags: ['autodocs'],
+ decorators: [
+ (Story) => (
+ // A definite width, not just height: without one, AutoSizer and Storybook's
+ // shrink-to-fit layout chase each other's size forever.
+ // eslint-disable-next-line react/forbid-dom-props
+ <div style={{ display: 'flex', flexDirection: 'column', width: 1300, height: 400 }}>
+ <Story />
+ </div>
+ ),
+ ],
+}
+export default meta
+
+type Story = StoryObj<typeof OperationsTable>
+
+export const Default: Story = {
+ args: { rows: ROWS, loading: false, windowMs: 3_600_000 },
+}
+
+export const Empty: Story = {
+ args: { rows: [], loading: false, windowMs: 3_600_000 },
+}
+
+export const Loading: Story = {
+ args: { rows: [], loading: true, windowMs: 3_600_000 },
+ parameters: {
+ // The spinner never resolves, so don't wait for it to disappear before snapshotting.
+ testOptions: { waitForLoadersToDisappear: false },
+ },
+}
diff --git a/products/tracing/frontend/OperationsTable.tsx b/products/tracing/frontend/OperationsTable.tsx
index 3a9846486d78..afcc5f1a7bb8 100644
--- a/products/tracing/frontend/OperationsTable.tsx
+++ b/products/tracing/frontend/OperationsTable.tsx
@@ -42,13 +42,15 @@ function buildColumns(windowMs: number): VirtualizedTableColumn<AggregatedSpanRo
{
key: 'service_name',
title: 'Service',
- width: 150,
+ width: 200,
sorter: (a, b) => a.service_name.localeCompare(b.service_name),
render: (row) => <span className="font-mono">{row.service_name}</span>,
},
{
key: 'name',
title: 'Operation',
+ width: 320,
+ grow: true,
sorter: (a, b) => a.name.localeCompare(b.name),
render: (row) => <span className="font-mono">{row.name}</span>,
},
@@ -133,6 +135,10 @@ function buildColumns(windowMs: number): VirtualizedTableColumn<AggregatedSpanRo
]
}
+function operationRowKey(row: AggregatedSpanRow): string {
+ return `${row.service_name}::${row.name}`
+}
+
export interface OperationsTableProps {
rows: AggregatedSpanRow[]
loading: boolean
@@ -145,10 +151,12 @@ export function OperationsTable({ rows, loading, windowMs, onRowClick }: Operati
const columns = useMemo(() => buildColumns(windowMs), [windowMs])
return (
<VirtualizedTable<AggregatedSpanRow>
+ // pinned: identifies stored column widths — renaming resets everyone's widths
+ tableKey="operations"
columns={columns}
dataSource={rows}
loading={loading}
- rowKey={(row) => `${row.service_name}::${row.name}`}
+ rowKey={operationRowKey}
onRowClick={onRowClick}
defaultSort={{ columnKey: 'total_time', order: -1 }}
emptyLabel="No operations found for these filters"
diff --git a/products/tracing/frontend/TraceCompareTable.tsx b/products/tracing/frontend/TraceCompareTable.tsx
index 0b91e1797753..c99eb7b81783 100644
--- a/products/tracing/frontend/TraceCompareTable.tsx
+++ b/products/tracing/frontend/TraceCompareTable.tsx
@@ -12,22 +12,26 @@ import { humanFriendlyNumber } from 'lib/utils/numbers'
import { AggregatedSpanRow } from '~/queries/schema/schema-general'
import { buildRows, changeMagnitude, type CompareRow, type CompareRowStatus, isLowSample } from './compareUtils'
+import { ResizableColumnSpec } from './components/TableColumns/columnWidths'
+import { TableCell } from './components/TableColumns/TableCell'
+import { TableHeaderCell } from './components/TableColumns/TableHeaderCell'
+import { ResizableColumns, useResizableColumns } from './components/TableColumns/useResizableColumns'
import { formatDuration } from './TraceWaterfallView'
const ROW_HEIGHT = 44
const HEADER_HEIGHT = 32
-// Fixed column widths (px). The name column flexes to fill the remaining space.
-const COL_WIDTH = {
- service: 160,
- count: 110,
- p50: 110,
- p95: 110,
- errors: 110,
-} as const
-
-const NAME_MIN_WIDTH = 200
-const MIN_ROW_WIDTH = Object.values(COL_WIDTH).reduce((sum, width) => sum + width, 0) + NAME_MIN_WIDTH
+// Default column widths (px), in render order. Anyone can drag a column wider or narrower from here.
+const COMPARE_COLUMNS: ResizableColumnSpec[] = [
+ { key: 'service_name', width: 200 },
+ { key: 'name', width: 320, grow: true },
+ { key: 'count', width: 110 },
+ { key: 'p50', width: 110 },
+ { key: 'p95', width: 110 },
+ { key: 'errors', width: 110 },
+]
+// pinned: identifies stored column widths — renaming resets everyone's widths
+const TABLE_KEY = 'compare'
// 'change' is the default: biggest p95 movers (both directions) first, so the table answers
// "what changed?" without any clicking. Column header clicks switch to plain value sorts.
@@ -97,40 +101,32 @@ function Delta({ current, previous, higherIsWorse, format }: DeltaProps): JSX.El
)
}
-function Cell({ width, align, children }: { width?: number; align?: 'right'; children: React.ReactNode }): JSX.Element {
- return (
- <div
- className={cn(
- 'shrink-0 truncate px-2 text-xs',
- width === undefined && 'flex-1 min-w-0',
- align === 'right' && 'text-right'
- )}
- // eslint-disable-next-line react/forbid-dom-props
- style={width !== undefined ? { width } : undefined}
- >
- {children}
- </div>
- )
-}
-
interface SortProps {
sortColumn: SortColumn
sortOrder: SortOrder
onSort: (column: SortColumn) => void
}
-function SortableHeaderCell({
+/** Every column here is sortable, so the header cell always carries a sort button. */
+function CompareHeaderCell({
column,
label,
- width,
align,
+ widths,
+ columns,
sortColumn,
sortOrder,
onSort,
-}: { column: SortColumn; label: string; width?: number; align?: 'right' } & SortProps): JSX.Element {
+}: {
+ column: Exclude<SortColumn, 'change'>
+ label: string
+ align?: 'right'
+ widths: Record<string, number>
+ columns: ResizableColumns
+} & SortProps): JSX.Element {
const active = sortColumn === column
return (
- <Cell width={width} align={align}>
+ <TableHeaderCell width={widths[column]} align={align} resize={columns.resizeHandleProps(column, label)}>
<button
type="button"
className={cn(
@@ -144,74 +140,37 @@ function SortableHeaderCell({
<span>{label}</span>
<SortingIndicator order={active ? sortOrder : null} />
</button>
- </Cell>
+ </TableHeaderCell>
)
}
-function CompareRowHeader({ sortColumn, sortOrder, onSort }: SortProps): JSX.Element {
+function CompareRowHeader({
+ widths,
+ columns,
+ sortColumn,
+ sortOrder,
+ onSort,
+}: { widths: Record<string, number>; columns: ResizableColumns } & SortProps): JSX.Element {
+ const shared = { widths, columns, sortColumn, sortOrder, onSort }
return (
<div
className="flex items-center border-b border-border bg-surface-secondary font-medium text-muted"
// eslint-disable-next-line react/forbid-dom-props
style={{ height: HEADER_HEIGHT }}
>
- <SortableHeaderCell
- column="service_name"
- label="Service"
- width={COL_WIDTH.service}
- sortColumn={sortColumn}
- sortOrder={sortOrder}
- onSort={onSort}
- />
- <SortableHeaderCell
- column="name"
- label="Span name"
- sortColumn={sortColumn}
- sortOrder={sortOrder}
- onSort={onSort}
- />
- <SortableHeaderCell
- column="count"
- label="Count"
- width={COL_WIDTH.count}
- align="right"
- sortColumn={sortColumn}
- sortOrder={sortOrder}
- onSort={onSort}
- />
- <SortableHeaderCell
- column="p50"
- label="p50"
- width={COL_WIDTH.p50}
- align="right"
- sortColumn={sortColumn}
- sortOrder={sortOrder}
- onSort={onSort}
- />
- <SortableHeaderCell
- column="p95"
- label="p95"
- width={COL_WIDTH.p95}
- align="right"
- sortColumn={sortColumn}
- sortOrder={sortOrder}
- onSort={onSort}
- />
- <SortableHeaderCell
- column="errors"
- label="Errors"
- width={COL_WIDTH.errors}
- align="right"
- sortColumn={sortColumn}
- sortOrder={sortOrder}
- onSort={onSort}
- />
+ <CompareHeaderCell {...shared} column="service_name" label="Service" />
+ <CompareHeaderCell {...shared} column="name" label="Span name" />
+ <CompareHeaderCell {...shared} column="count" label="Count" align="right" />
+ <CompareHeaderCell {...shared} column="p50" label="p50" align="right" />
+ <CompareHeaderCell {...shared} column="p95" label="p95" align="right" />
+ <CompareHeaderCell {...shared} column="errors" label="Errors" align="right" />
</div>
)
}
interface CompareRowProps {
dataSource: CompareRow[]
+ widths: Record<string, number>
onRowClick?: (row: { service_name: string; name: string }) => void
}
@@ -220,6 +179,7 @@ function CompareListRow({
index,
style,
dataSource,
+ widths,
onRowClick,
}: {
ariaAttributes: { 'aria-posinset': number; 'aria-setsize': number; role: 'listitem' }
@@ -262,10 +222,10 @@ function CompareListRow({
role={onRowClick ? 'button' : undefined}
tabIndex={onRowClick ? 0 : undefined}
>
- <Cell width={COL_WIDTH.service}>
+ <TableCell width={widths.service_name}>
<span className="font-mono">{row.service_name}</span>
- </Cell>
- <Cell>
+ </TableCell>
+ <TableCell width={widths.name}>
<span className="inline-flex items-center gap-1.5 max-w-full">
<span className="font-mono truncate">{row.name}</span>
{statusTag && (
@@ -274,14 +234,14 @@ function CompareListRow({
</LemonTag>
)}
</span>
- </Cell>
- <Cell width={COL_WIDTH.count} align="right">
+ </TableCell>
+ <TableCell width={widths.count} align="right">
<div className="flex flex-col items-end">
<span>{row.current ? humanFriendlyNumber(row.current.count) : '—'}</span>
<Delta current={row.current?.count} previous={row.previous?.count} />
</div>
- </Cell>
- <Cell width={COL_WIDTH.p50} align="right">
+ </TableCell>
+ <TableCell width={widths.p50} align="right">
<div className="flex flex-col items-end">
<span>{row.current ? formatDuration(row.current.p50_duration_nano) : '—'}</span>
<Delta
@@ -291,8 +251,8 @@ function CompareListRow({
format={formatDuration}
/>
</div>
- </Cell>
- <Cell width={COL_WIDTH.p95} align="right">
+ </TableCell>
+ <TableCell width={widths.p95} align="right">
<div className="flex flex-col items-end">
<span>{row.current ? formatDuration(row.current.p95_duration_nano) : '—'}</span>
<Delta
@@ -302,8 +262,8 @@ function CompareListRow({
format={formatDuration}
/>
</div>
- </Cell>
- <Cell width={COL_WIDTH.errors} align="right">
+ </TableCell>
+ <TableCell width={widths.errors} align="right">
<div className="flex flex-col items-end">
<span>{row.current ? humanFriendlyNumber(row.current.error_count) : '—'}</span>
<Delta
@@ -312,7 +272,7 @@ function CompareListRow({
higherIsWorse={judged}
/>
</div>
- </Cell>
+ </TableCell>
</div>
</div>
)
@@ -329,6 +289,7 @@ export function TraceCompareTable({ current, previous, loading, onRowClick }: Tr
const [sortColumn, setSortColumn] = useState<SortColumn>('change')
const [sortOrder, setSortOrder] = useState<SortOrder>(-1)
const [statusFilter, setStatusFilter] = useState<StatusFilter>('all')
+ const columns = useResizableColumns(TABLE_KEY, COMPARE_COLUMNS)
const { allRows, statusCounts } = useMemo(() => {
const built = buildRows(current, previous)
@@ -360,8 +321,6 @@ export function TraceCompareTable({ current, previous, loading, onRowClick }: Tr
}
}
- const rowProps = useMemo((): CompareRowProps => ({ dataSource: rows, onRowClick }), [rows, onRowClick])
-
if (allRows.length === 0) {
return (
<div className="flex items-center justify-center p-8 text-muted border rounded bg-bg-light">
@@ -409,15 +368,22 @@ export function TraceCompareTable({ current, previous, loading, onRowClick }: Tr
if (!width || !height) {
return null
}
- const rowWidth = Math.max(width, MIN_ROW_WIDTH)
+ const { widths, totalWidth } = columns.resolveWidths(width)
+ const rowWidth = Math.max(width, totalWidth)
return (
// The viewport is fixed to the available box; the inner content can be wider
- // (MIN_ROW_WIDTH) so columns scroll horizontally and rows align with the header.
+ // (totalWidth) so columns scroll horizontally and rows align with the header.
// eslint-disable-next-line react/forbid-dom-props
<div className="overflow-x-auto" style={{ width, height }}>
{/* eslint-disable-next-line react/forbid-dom-props */}
<div style={{ width: rowWidth }}>
- <CompareRowHeader sortColumn={sortColumn} sortOrder={sortOrder} onSort={onSort} />
+ <CompareRowHeader
+ widths={widths}
+ columns={columns}
+ sortColumn={sortColumn}
+ sortOrder={sortOrder}
+ onSort={onSort}
+ />
{rows.length === 0 ? (
<div className="flex items-center justify-center p-8 text-muted">
No spans in this bucket
@@ -429,7 +395,7 @@ export function TraceCompareTable({ current, previous, loading, onRowClick }: Tr
rowCount={rows.length}
rowHeight={ROW_HEIGHT}
rowComponent={CompareListRow}
- rowProps={rowProps}
+ rowProps={{ dataSource: rows, widths, onRowClick }}
/>
)}
</div>
diff --git a/products/tracing/frontend/VirtualizedTable.tsx b/products/tracing/frontend/VirtualizedTable.tsx
index 1775dec9638a..e97f969d75a0 100644
--- a/products/tracing/frontend/VirtualizedTable.tsx
+++ b/products/tracing/frontend/VirtualizedTable.tsx
@@ -8,6 +8,10 @@ import { SizeProps } from 'lib/components/AutoSizer/AutoSizer'
import { SortingIndicator } from 'lib/lemon-ui/LemonTable/sorting'
import { cn } from 'lib/utils/css-classes'
+import { TableCell } from './components/TableColumns/TableCell'
+import { TableHeaderCell } from './components/TableColumns/TableHeaderCell'
+import { ResizableColumns, useResizableColumns } from './components/TableColumns/useResizableColumns'
+
// Config-driven virtualized table: owns react-window virtualization, client-side sort, and the
// header/row layout; callers pass column definitions + data. Extracted from TraceCompareTable so
// the compare view and the operations view share one implementation. The column-def contract
@@ -16,16 +20,16 @@ import { cn } from 'lib/utils/css-classes'
const ROW_HEIGHT = 44
const HEADER_HEIGHT = 32
-// Min width a flex (width-less) column reserves when computing the horizontal-scroll row width.
-const FLEX_MIN_WIDTH = 200
export type VirtualizedSortOrder = 1 | -1
export interface VirtualizedTableColumn<T> {
key: string
title: ReactNode
- /** Fixed column width in px. Omit to flex-fill the remaining space. */
- width?: number
+ /** Default column width in px, before anyone resizes it. */
+ width: number
+ /** Takes the space left over in the viewport, up to a cap. At most one column per table. */
+ grow?: boolean
align?: 'right'
/** Header tooltip. */
tooltip?: string
@@ -34,58 +38,44 @@ export interface VirtualizedTableColumn<T> {
sorter?: (a: T, b: T) => number
}
-function Cell({ width, align, children }: { width?: number; align?: 'right'; children: ReactNode }): JSX.Element {
- return (
- <div
- className={cn(
- 'shrink-0 truncate px-2 text-xs',
- width === undefined && 'flex-1 min-w-0',
- align === 'right' && 'text-right'
- )}
- // eslint-disable-next-line react/forbid-dom-props
- style={width !== undefined ? { width } : undefined}
- >
- {children}
- </div>
- )
-}
-
function HeaderCell({
column,
+ width,
+ columns,
sortKey,
sortOrder,
onSort,
}: {
column: VirtualizedTableColumn<any>
+ width: number
+ columns: ResizableColumns
sortKey: string | null
sortOrder: VirtualizedSortOrder
onSort: (key: string) => void
}): JSX.Element {
const label = column.tooltip ? <Tooltip title={column.tooltip}>{column.title}</Tooltip> : column.title
- if (!column.sorter) {
- return (
- <Cell width={column.width} align={column.align}>
- {label}
- </Cell>
- )
- }
+ const resize = columns.resizeHandleProps(column.key, typeof column.title === 'string' ? column.title : column.key)
const active = sortKey === column.key
return (
- <Cell width={column.width} align={column.align}>
- <button
- type="button"
- className={cn(
- 'flex items-center cursor-pointer hover:text-default',
- column.align === 'right' && 'ml-auto',
- active && 'text-default'
- )}
- onClick={() => onSort(column.key)}
- data-attr={`virtualized-table-sort-${column.key}`}
- >
- <span>{label}</span>
- <SortingIndicator order={active ? sortOrder : null} />
- </button>
- </Cell>
+ <TableHeaderCell width={width} align={column.align} resize={resize}>
+ {column.sorter ? (
+ <button
+ type="button"
+ className={cn(
+ 'flex items-center cursor-pointer hover:text-default',
+ column.align === 'right' && 'ml-auto',
+ active && 'text-default'
+ )}
+ onClick={() => onSort(column.key)}
+ data-attr={`virtualized-table-sort-${column.key}`}
+ >
+ <span>{label}</span>
+ <SortingIndicator order={active ? sortOrder : null} />
+ </button>
+ ) : (
+ label
+ )}
+ </TableHeaderCell>
)
}
@@ -93,6 +83,7 @@ function HeaderCell({
// column-definition site (`columns: VirtualizedTableColumn<T>[]`), not inside the row renderer.
interface VirtualizedRowProps {
columns: VirtualizedTableColumn<any>[]
+ widths: Record<string, number>
dataSource: any[]
rowKey: (record: any) => string
onRowClick?: (record: any) => void
@@ -103,6 +94,7 @@ function VirtualizedRow({
index,
style,
columns,
+ widths,
dataSource,
rowKey,
onRowClick,
@@ -142,9 +134,9 @@ function VirtualizedRow({
tabIndex={onRowClick ? 0 : undefined}
>
{columns.map((column) => (
- <Cell key={column.key} width={column.width} align={column.align}>
+ <TableCell key={column.key} width={widths[column.key]} align={column.align}>
{column.render(record)}
- </Cell>
+ </TableCell>
))}
</div>
</div>
@@ -152,6 +144,8 @@ function VirtualizedRow({
}
export interface VirtualizedTableProps<T> {
+ /** Identifies the table's stored column widths. Pinned: renaming resets everyone's widths. */
+ tableKey: string
columns: VirtualizedTableColumn<T>[]
dataSource: T[]
loading: boolean
@@ -163,6 +157,7 @@ export interface VirtualizedTableProps<T> {
}
export function VirtualizedTable<T>({
+ tableKey,
columns,
dataSource,
loading,
@@ -174,11 +169,7 @@ export function VirtualizedTable<T>({
}: VirtualizedTableProps<T>): JSX.Element {
const [sortKey, setSortKey] = useState<string | null>(defaultSort?.columnKey ?? null)
const [sortOrder, setSortOrder] = useState<VirtualizedSortOrder>(defaultSort?.order ?? -1)
-
- const minRowWidth = useMemo(
- () => columns.reduce((sum, column) => sum + (column.width ?? FLEX_MIN_WIDTH), 0),
- [columns]
- )
+ const resizableColumns = useResizableColumns(tableKey, columns)
const rows = useMemo(() => {
const sorter = columns.find((column) => column.key === sortKey)?.sorter
@@ -197,11 +188,6 @@ export function VirtualizedTable<T>({
}
}
- const rowProps = useMemo(
- (): VirtualizedRowProps => ({ columns, dataSource: rows, rowKey, onRowClick }),
- [columns, rows, rowKey, onRowClick]
- )
-
if (rows.length === 0) {
return (
<div className="flex items-center justify-center p-8 text-muted border rounded bg-bg-light">
@@ -217,10 +203,11 @@ export function VirtualizedTable<T>({
if (!width || !height) {
return null
}
- const rowWidth = Math.max(width, minRowWidth)
+ const { widths, totalWidth } = resizableColumns.resolveWidths(width)
+ const rowWidth = Math.max(width, totalWidth)
return (
// The viewport is fixed to the available box; inner content can be wider
- // (minRowWidth) so columns scroll horizontally and rows align with the header.
+ // (totalWidth) so columns scroll horizontally and rows align with the header.
// eslint-disable-next-line react/forbid-dom-props
<div className="overflow-x-auto" style={{ width, height }}>
{/* eslint-disable-next-line react/forbid-dom-props */}
@@ -234,6 +221,8 @@ export function VirtualizedTable<T>({
<HeaderCell
key={column.key}
column={column}
+ width={widths[column.key]}
+ columns={resizableColumns}
sortKey={sortKey}
sortOrder={sortOrder}
onSort={onSort}
@@ -246,7 +235,7 @@ export function VirtualizedTable<T>({
rowCount={rows.length}
rowHeight={ROW_HEIGHT}
rowComponent={VirtualizedRow}
- rowProps={rowProps}
+ rowProps={{ columns, widths, dataSource: rows, rowKey, onRowClick }}
/>
</div>
</div>
diff --git a/products/tracing/frontend/components/TableColumns/ColumnResizeHandle.tsx b/products/tracing/frontend/components/TableColumns/ColumnResizeHandle.tsx
new file mode 100644
index 000000000000..3544a45e584b
--- /dev/null
+++ b/products/tracing/frontend/components/TableColumns/ColumnResizeHandle.tsx
@@ -0,0 +1,51 @@
+import { PointerEvent as ReactPointerEvent } from 'react'
+
+import { MIN_COLUMN_WIDTH } from './columnWidths'
+
+export interface ColumnResizeHandleProps {
+ /** Column heading, so the handle has an accessible name of its own. */
+ columnLabel: string
+ width: number
+ onResizeStart: (event: ReactPointerEvent) => void
+ onNudge: (direction: -1 | 1) => void
+ onReset: () => void
+}
+
+/** Grab bar on the right edge of a header cell. Drag, arrow keys, or double-click to reset. */
+export function ColumnResizeHandle({
+ columnLabel,
+ width,
+ onResizeStart,
+ onNudge,
+ onReset,
+}: ColumnResizeHandleProps): JSX.Element {
+ return (
+ <div
+ role="separator"
+ aria-orientation="vertical"
+ aria-label={`Resize ${columnLabel} column`}
+ aria-valuenow={width}
+ aria-valuemin={MIN_COLUMN_WIDTH}
+ tabIndex={0}
+ // The divider stays visible so the column reads as resizable without hovering it first.
+ className="group absolute inset-y-0 -right-1 z-1 flex w-2 justify-center cursor-col-resize"
+ onPointerDown={onResizeStart}
+ onDoubleClick={onReset}
+ onKeyDown={(event) => {
+ if (event.key === 'ArrowLeft') {
+ event.preventDefault()
+ onNudge(-1)
+ } else if (event.key === 'ArrowRight') {
+ event.preventDefault()
+ onNudge(1)
+ } else if (event.key === 'Enter' || event.key === ' ') {
+ event.preventDefault()
+ onReset()
+ }
+ }}
+ data-attr="tracing-column-resize-handle"
+ >
+ <div className="h-full w-px bg-border group-hover:w-0.5 group-hover:bg-accent group-focus-visible:w-0.5 group-focus-visible:bg-accent" />
+ </div>
+ )
+}
diff --git a/products/tracing/frontend/components/TableColumns/TableCell.tsx b/products/tracing/frontend/components/TableColumns/TableCell.tsx
new file mode 100644
index 000000000000..5c9791ede013
--- /dev/null
+++ b/products/tracing/frontend/components/TableColumns/TableCell.tsx
@@ -0,0 +1,22 @@
+import { ReactNode } from 'react'
+
+import { cn } from 'lib/utils/css-classes'
+
+export interface TableCellProps {
+ width: number
+ align?: 'right'
+ children: ReactNode
+}
+
+/** Body cell of a tracing virtualized table. Width comes from `useResizableColumns`. */
+export function TableCell({ width, align, children }: TableCellProps): JSX.Element {
+ return (
+ <div
+ className={cn('shrink-0 truncate px-2 text-xs', align === 'right' && 'text-right')}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ width }}
+ >
+ {children}
+ </div>
+ )
+}
diff --git a/products/tracing/frontend/components/TableColumns/TableHeaderCell.tsx b/products/tracing/frontend/components/TableColumns/TableHeaderCell.tsx
new file mode 100644
index 000000000000..b135674f8149
--- /dev/null
+++ b/products/tracing/frontend/components/TableColumns/TableHeaderCell.tsx
@@ -0,0 +1,27 @@
+import { ReactNode } from 'react'
+
+import { cn } from 'lib/utils/css-classes'
+
+import { ColumnResizeHandle, ColumnResizeHandleProps } from './ColumnResizeHandle'
+
+export interface TableHeaderCellProps {
+ width: number
+ align?: 'right'
+ /** Omit on the last column, where there is nothing to the right to give or take space. */
+ resize?: Omit<ColumnResizeHandleProps, 'width'>
+ children: ReactNode
+}
+
+/** Header cell of a tracing virtualized table, with the resize grab bar on its right edge. */
+export function TableHeaderCell({ width, align, resize, children }: TableHeaderCellProps): JSX.Element {
+ return (
+ <div
+ className="relative flex h-full shrink-0 items-center"
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ width }}
+ >
+ <div className={cn('w-full truncate px-2 text-xs', align === 'right' && 'text-right')}>{children}</div>
+ {resize && <ColumnResizeHandle width={width} {...resize} />}
+ </div>
+ )
+}
diff --git a/products/tracing/frontend/components/TableColumns/columnWidths.test.ts b/products/tracing/frontend/components/TableColumns/columnWidths.test.ts
new file mode 100644
index 000000000000..c46cc3ec6d29
--- /dev/null
+++ b/products/tracing/frontend/components/TableColumns/columnWidths.test.ts
@@ -0,0 +1,50 @@
+import { MAX_AUTO_GROW_WIDTH, MIN_COLUMN_WIDTH, ResizableColumnSpec, resolveColumnWidths } from './columnWidths'
+
+describe('resolveColumnWidths', () => {
+ const specs: ResizableColumnSpec[] = [
+ { key: 'service', width: 200 },
+ { key: 'name', width: 320, grow: true },
+ { key: 'errors', width: 80 },
+ ]
+
+ it('uses the default widths when nothing is stored', () => {
+ const { widths, totalWidth } = resolveColumnWidths(specs, undefined, null, 600)
+ expect(widths).toEqual({ service: 200, name: 320, errors: 80 })
+ expect(totalWidth).toEqual(600)
+ })
+
+ it('gives leftover space to the growing column', () => {
+ const { widths } = resolveColumnWidths(specs, undefined, null, 700)
+ expect(widths.name).toEqual(420)
+ expect(widths.service).toEqual(200)
+ })
+
+ it('caps how wide the growing column gets on a wide screen', () => {
+ const { widths, totalWidth } = resolveColumnWidths(specs, undefined, null, 2560)
+ expect(widths.name).toEqual(MAX_AUTO_GROW_WIDTH)
+ expect(totalWidth).toBeLessThan(2560)
+ })
+
+ it('stops growing a column once it has a stored width, so a drag is not undone', () => {
+ const { widths } = resolveColumnWidths(specs, { name: 260 }, null, 2560)
+ expect(widths.name).toEqual(260)
+ })
+
+ it('prefers the live drag width over the stored width', () => {
+ const { widths } = resolveColumnWidths(specs, { service: 200 }, { columnKey: 'service', width: 340 }, 2560)
+ expect(widths.service).toEqual(340)
+ })
+
+ it('never renders a column narrower than the minimum', () => {
+ const { widths } = resolveColumnWidths(specs, { service: 10 }, null, 600)
+ expect(widths.service).toEqual(MIN_COLUMN_WIDTH)
+ })
+
+ it.each([NaN, Infinity, undefined as unknown as number])(
+ 'falls back to the default width for a stored %p',
+ (stored) => {
+ const { widths } = resolveColumnWidths(specs, { service: stored }, null, 600)
+ expect(widths.service).toEqual(200)
+ }
+ )
+})
diff --git a/products/tracing/frontend/components/TableColumns/columnWidths.ts b/products/tracing/frontend/components/TableColumns/columnWidths.ts
new file mode 100644
index 000000000000..a51b69c715ba
--- /dev/null
+++ b/products/tracing/frontend/components/TableColumns/columnWidths.ts
@@ -0,0 +1,54 @@
+/** Narrowest a column can be dragged, so a column can never disappear entirely. */
+export const MIN_COLUMN_WIDTH = 56
+/** Widest the growing column gets from leftover space. Dragging past this is still allowed. */
+export const MAX_AUTO_GROW_WIDTH = 520
+
+export interface ResizableColumnSpec {
+ key: string
+ /** Width in px before anyone resizes the column. */
+ width: number
+ /** Takes the space left over in the viewport, up to a cap. At most one column per table. */
+ grow?: boolean
+}
+
+export interface ResolvedColumnWidths {
+ widths: Record<string, number>
+ /** Combined width of every column. The row is never narrower than this. */
+ totalWidth: number
+}
+
+/**
+ * Width of every column for one render, in precedence order: the live drag, then the stored
+ * width, then the default.
+ */
+export function resolveColumnWidths(
+ specs: ResizableColumnSpec[],
+ storedWidths: Record<string, number> | undefined,
+ draggedWidth: { columnKey: string; width: number } | null,
+ availableWidth: number
+): ResolvedColumnWidths {
+ const widths: Record<string, number> = {}
+ let totalWidth = 0
+ for (const spec of specs) {
+ const width =
+ draggedWidth?.columnKey === spec.key ? draggedWidth.width : (storedWidths?.[spec.key] ?? spec.width)
+ // Stored widths outlive the code that wrote them, so a corrupt one falls back to the
+ // default rather than collapsing the column for good.
+ widths[spec.key] = Number.isFinite(width) ? Math.max(MIN_COLUMN_WIDTH, Math.round(width)) : spec.width
+ totalWidth += widths[spec.key]
+ }
+
+ const growSpec = specs.find((spec) => spec.grow)
+ // A column with a width of its own stops growing. If it kept taking the leftover space, that
+ // space would refill after every drag and the column would look stuck.
+ if (growSpec && storedWidths?.[growSpec.key] === undefined && draggedWidth?.columnKey !== growSpec.key) {
+ const extra = Math.min(
+ Math.max(availableWidth - totalWidth, 0),
+ Math.max(MAX_AUTO_GROW_WIDTH - widths[growSpec.key], 0)
+ )
+ widths[growSpec.key] += extra
+ totalWidth += extra
+ }
+
+ return { widths, totalWidth }
+}
diff --git a/products/tracing/frontend/components/TableColumns/useResizableColumns.ts b/products/tracing/frontend/components/TableColumns/useResizableColumns.ts
new file mode 100644
index 000000000000..2c3212732dc4
--- /dev/null
+++ b/products/tracing/frontend/components/TableColumns/useResizableColumns.ts
@@ -0,0 +1,148 @@
+import { useActions, useValues } from 'kea'
+import { PointerEvent as ReactPointerEvent, useCallback, useEffect, useRef, useState } from 'react'
+
+import { tracingConfigLogic } from '../../tracingConfigLogic'
+import { ColumnResizeHandleProps } from './ColumnResizeHandle'
+import { MIN_COLUMN_WIDTH, ResizableColumnSpec, ResolvedColumnWidths, resolveColumnWidths } from './columnWidths'
+
+/** How far one arrow key press moves a resize handle. */
+const KEYBOARD_STEP = 16
+
+export interface ResizableColumns {
+ /** Call during render with the viewport width. The growing column absorbs what is left over. */
+ resolveWidths: (availableWidth: number) => ResolvedColumnWidths
+ startResize: (columnKey: string, event: ReactPointerEvent) => void
+ nudgeWidth: (columnKey: string, direction: -1 | 1) => void
+ resetWidth: (columnKey: string) => void
+ /** False for the last column — it has nothing to its right to give or take space. */
+ isResizable: (columnKey: string) => boolean
+ /** `TableHeaderCell`'s `resize` prop for one column, or undefined if it isn't resizable. */
+ resizeHandleProps: (columnKey: string, columnLabel: string) => Omit<ColumnResizeHandleProps, 'width'> | undefined
+}
+
+/**
+ * Drag-to-resize widths for one table, persisted per person under `tableKey`.
+ *
+ * Widths depend on the viewport, which only `AutoSizer` knows, so the hook hands back
+ * `resolveWidths` for the render prop to call instead of returning widths directly.
+ */
+export function useResizableColumns(tableKey: string, specs: ResizableColumnSpec[]): ResizableColumns {
+ const { columnWidths } = useValues(tracingConfigLogic)
+ const { setColumnWidth, resetColumnWidth } = useActions(tracingConfigLogic)
+ const stored = columnWidths[tableKey]
+
+ // Live width while a handle is held, so the drag stays smooth and only the final width is stored.
+ const [dragged, setDragged] = useState<{ columnKey: string; width: number } | null>(null)
+ const stopDragRef = useRef<(() => void) | null>(null)
+ // The last render's resolved widths — a drag starts from what is on screen, not from the
+ // default — and doubles as a memo cache: reusing the same widths object when none of its
+ // inputs changed means unrelated re-renders (a sort click, a hover) don't hand every
+ // virtualized row a new `widths` reference and force them all to re-render.
+ const lastResolvedRef = useRef<{
+ specs: ResizableColumnSpec[]
+ stored: Record<string, number> | undefined
+ dragged: typeof dragged
+ availableWidth: number
+ result: ResolvedColumnWidths
+ } | null>(null)
+
+ useEffect(() => () => stopDragRef.current?.(), [])
+
+ const resolveWidths = (availableWidth: number): ResolvedColumnWidths => {
+ const last = lastResolvedRef.current
+ if (
+ last &&
+ last.specs === specs &&
+ last.stored === stored &&
+ last.dragged === dragged &&
+ last.availableWidth === availableWidth
+ ) {
+ return last.result
+ }
+ const resolved = resolveColumnWidths(specs, stored, dragged, availableWidth)
+ lastResolvedRef.current = { specs, stored, dragged, availableWidth, result: resolved }
+ return resolved
+ }
+
+ const renderedWidth = (columnKey: string): number =>
+ lastResolvedRef.current?.result.widths[columnKey] ?? MIN_COLUMN_WIDTH
+
+ const isResizable = useCallback((columnKey: string) => specs[specs.length - 1]?.key !== columnKey, [specs])
+
+ const startResize = useCallback(
+ (columnKey: string, event: ReactPointerEvent): void => {
+ event.preventDefault()
+ // A drag cut short by a second pointer (e.g. two-finger touch) leaves its listeners
+ // attached — clear it before starting a new one instead of orphaning it.
+ stopDragRef.current?.()
+ // Keep receiving move/up events even if the pointer leaves the handle, or the
+ // window, before it's released.
+ event.currentTarget.setPointerCapture(event.pointerId)
+
+ const startX = event.clientX
+ const startWidth = renderedWidth(columnKey)
+ const widthAt = (clientX: number): number =>
+ Math.max(MIN_COLUMN_WIDTH, Math.round(startWidth + clientX - startX))
+ // A click with no movement shouldn't pin an auto-growing column to its current width.
+ let moved = false
+
+ const onMove = (moveEvent: PointerEvent): void => {
+ moved = true
+ setDragged({ columnKey, width: widthAt(moveEvent.clientX) })
+ }
+ const onUp = (upEvent: PointerEvent): void => {
+ stopDragRef.current?.()
+ if (moved) {
+ setColumnWidth(tableKey, columnKey, widthAt(upEvent.clientX))
+ }
+ }
+ // A cancelled gesture (e.g. an interrupted touch drag) discards the in-progress width
+ // instead of committing it.
+ const onCancel = (): void => stopDragRef.current?.()
+
+ stopDragRef.current = (): void => {
+ document.removeEventListener('pointermove', onMove)
+ document.removeEventListener('pointerup', onUp)
+ document.removeEventListener('pointercancel', onCancel)
+ document.body.classList.remove('cursor-col-resize', 'select-none')
+ stopDragRef.current = null
+ setDragged(null)
+ }
+ document.addEventListener('pointermove', onMove)
+ document.addEventListener('pointerup', onUp)
+ document.addEventListener('pointercancel', onCancel)
+ // Hold the resize cursor and suppress text selection for the whole drag, not only while
+ // the pointer stays over the handle.
+ document.body.classList.add('cursor-col-resize', 'select-none')
+ },
+ [setColumnWidth, tableKey]
+ )
+
+ const nudgeWidth = useCallback(
+ (columnKey: string, direction: -1 | 1): void => {
+ const current = renderedWidth(columnKey)
+ setColumnWidth(tableKey, columnKey, Math.max(MIN_COLUMN_WIDTH, current + direction * KEYBOARD_STEP))
+ },
+ [setColumnWidth, tableKey]
+ )
+
+ const resetWidth = useCallback(
+ (columnKey: string): void => resetColumnWidth(tableKey, columnKey),
+ [resetColumnWidth, tableKey]
+ )
+
+ const resizeHandleProps = useCallback(
+ (columnKey: string, columnLabel: string): Omit<ColumnResizeHandleProps, 'width'> | undefined =>
+ isResizable(columnKey)
+ ? {
+ columnLabel,
+ onResizeStart: (event) => startResize(columnKey, event),
+ onNudge: (direction) => nudgeWidth(columnKey, direction),
+ onReset: () => resetWidth(columnKey),
+ }
+ : undefined,
+ [isResizable, startResize, nudgeWidth, resetWidth]
+ )
+
+ return { resolveWidths, startResize, nudgeWidth, resetWidth, isResizable, resizeHandleProps }
+}
diff --git a/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.stories.tsx b/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.stories.tsx
new file mode 100644
index 000000000000..1a9279bf47f9
--- /dev/null
+++ b/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.stories.tsx
@@ -0,0 +1,66 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import type { Span } from '../../types'
+import { VirtualizedSpanList } from './VirtualizedSpanList'
+
+const span = (index: number, overrides: Partial<Span> = {}): Span => ({
+ uuid: `span-${index}`,
+ trace_id: '0F3B7C1A5E2D48960B7A1C3E5D9F2048',
+ span_id: `000000000000000${index}`,
+ parent_span_id: '00000000000000ff',
+ name: 'loadCartContents',
+ kind: 3,
+ // Long enough to show that the service column no longer truncates.
+ service_name: 'checkout-orchestrator-europe',
+ status_code: 1,
+ timestamp: '2026-08-28T10:24:27.000Z',
+ end_time: '2026-08-28T10:24:27.000Z',
+ duration_nano: 18_000,
+ is_root_span: false,
+ matched_filter: true,
+ attributes: {},
+ resource_attributes: {},
+ ...overrides,
+})
+
+const SPANS: Span[] = [
+ span(1, { parent_span_id: '', is_root_span: true, name: 'POST /api/v2/checkout/session/confirm' }),
+ span(2, { name: 'validateCoupon' }),
+ span(3, { name: 'reserveStockForOrder', duration_nano: 390_000 }),
+ span(4, { name: 'pricing.quoteFromCache', service_name: 'pricing-api', duration_nano: 4_630_000 }),
+ span(5, { name: 'chargePaymentMethod', status_code: 2, duration_nano: 63_000 }),
+]
+
+const meta: Meta<typeof VirtualizedSpanList> = {
+ title: 'Products/Tracing/VirtualizedSpanList',
+ component: VirtualizedSpanList,
+ tags: ['autodocs'],
+ decorators: [
+ (Story) => (
+ // A definite width, not just height: without one, AutoSizer and Storybook's
+ // shrink-to-fit layout chase each other's size forever.
+ // eslint-disable-next-line react/forbid-dom-props
+ <div style={{ display: 'flex', flexDirection: 'column', width: 1300, height: 400 }}>
+ <Story />
+ </div>
+ ),
+ ],
+ args: {
+ dataSource: SPANS,
+ loading: false,
+ orderBy: 'timestamp',
+ orderDirection: 'DESC',
+ onSort: () => {},
+ onRowClick: () => {},
+ onVisibleRowRangeChange: () => {},
+ },
+}
+export default meta
+
+type Story = StoryObj<typeof VirtualizedSpanList>
+
+export const Default: Story = {}
+
+export const Empty: Story = {
+ args: { dataSource: [] },
+}
diff --git a/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.tsx b/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.tsx
index 57a82a934137..a40ce23bad54 100644
--- a/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.tsx
+++ b/products/tracing/frontend/components/VirtualizedSpanList/VirtualizedSpanList.tsx
@@ -1,4 +1,4 @@
-import { CSSProperties, ReactNode, useCallback, useMemo, useRef } from 'react'
+import { CSSProperties, ReactNode, useCallback, useRef } from 'react'
import { List, useListRef } from 'react-window'
import { LemonTag } from '@posthog/lemon-ui'
@@ -12,6 +12,10 @@ import { formatDuration } from '../../TraceWaterfallView'
import type { TracingOrderBy, TracingOrderDirection } from '../../tracingFiltersLogic'
import { SPAN_KIND_LABELS, STATUS_CODE_LABELS } from '../../types'
import type { Span } from '../../types'
+import { ResizableColumnSpec } from '../TableColumns/columnWidths'
+import { TableCell } from '../TableColumns/TableCell'
+import { TableHeaderCell } from '../TableColumns/TableHeaderCell'
+import { ResizableColumns, useResizableColumns } from '../TableColumns/useResizableColumns'
import { SpanRowActions } from './SpanRowActions'
const ROW_HEIGHT = 36
@@ -19,22 +23,19 @@ const HEADER_HEIGHT = 32
// Trigger the next page once the bottom of the rendered window is within this many rows of the end.
const LOAD_MORE_THRESHOLD = 10
-// Fixed column widths (px). The name column flexes to fill the remaining space.
-const COL_WIDTH = {
- timestamp: 190,
- service: 150,
- kind: 90,
- duration: 90,
- status: 80,
- traceId: 140,
- actions: 130,
-} as const
-
-// Minimum width the flexing name column keeps before the row scrolls horizontally on narrow viewports.
-const NAME_MIN_WIDTH = 160
-// Minimum content width: every fixed column at full width plus a sensible name column. Derived so it
-// can't drift when columns are added or removed.
-const MIN_ROW_WIDTH = Object.values(COL_WIDTH).reduce((sum, width) => sum + width, 0) + NAME_MIN_WIDTH
+// Default column widths (px), in render order. Anyone can drag a column wider or narrower from here.
+const SPAN_COLUMNS: ResizableColumnSpec[] = [
+ { key: 'timestamp', width: 190 },
+ { key: 'name', width: 320, grow: true },
+ { key: 'service', width: 200 },
+ { key: 'kind', width: 90 },
+ { key: 'duration', width: 90 },
+ { key: 'status', width: 80 },
+ { key: 'traceId', width: 140 },
+ { key: 'actions', width: 130 },
+]
+// pinned: identifies stored column widths — renaming resets everyone's widths
+const TABLE_KEY = 'spans'
function isRootSpan(span: Span): boolean {
return !span.parent_span_id
@@ -58,81 +59,94 @@ interface VirtualizedSpanListProps extends SortProps {
interface SpanRowProps {
dataSource: Span[]
+ widths: Record<string, number>
onRowClick: (span: Span) => void
}
-function Cell({ width, children }: { width?: number; children: React.ReactNode }): JSX.Element {
+/** Header cell wired to the shared resize handle. `sort` marks the column as server-sortable. */
+function SpanHeaderCell({
+ columnKey,
+ label,
+ widths,
+ columns,
+ sort,
+}: {
+ columnKey: string
+ /** Omit for a column with no heading, e.g. row actions. */
+ label?: string
+ widths: Record<string, number>
+ columns: ResizableColumns
+ sort?: { column: TracingOrderBy } & SortProps
+}): JSX.Element {
+ const active = sort ? sort.orderBy === sort.column : false
return (
- <div
- className={cn('shrink-0 truncate px-2 text-xs', width === undefined && 'flex-1 min-w-0')}
- // eslint-disable-next-line react/forbid-dom-props
- style={width !== undefined ? { width } : undefined}
- >
- {children}
- </div>
+ <TableHeaderCell width={widths[columnKey]} resize={columns.resizeHandleProps(columnKey, label ?? columnKey)}>
+ {sort ? (
+ <button
+ type="button"
+ className={cn('flex items-center cursor-pointer hover:text-default', active && 'text-default')}
+ onClick={() => sort.onSort(sort.column)}
+ data-attr={`tracing-sort-${sort.column}`}
+ >
+ <span>{label}</span>
+ {/* Neutral icon when inactive (so the column reads as sortable), directional arrow
+ once active — order 1 = ASC, -1 = DESC, matching LemonTable's convention. */}
+ <SortingIndicator order={active ? (sort.orderDirection === 'ASC' ? 1 : -1) : null} />
+ </button>
+ ) : (
+ (label ?? null)
+ )}
+ </TableHeaderCell>
)
}
-function SortableHeaderCell({
- column,
- label,
- width,
+function SpanRowHeader({
+ widths,
+ columns,
orderBy,
orderDirection,
onSort,
-}: { column: TracingOrderBy; label: string; width: number } & SortProps): JSX.Element {
- const active = orderBy === column
- return (
- <Cell width={width}>
- <button
- type="button"
- className={cn('flex items-center cursor-pointer hover:text-default', active && 'text-default')}
- onClick={() => onSort(column)}
- data-attr={`tracing-sort-${column}`}
- >
- <span>{label}</span>
- {/* Neutral icon when inactive (so the column reads as sortable), directional arrow
- once active — order 1 = ASC, -1 = DESC, matching LemonTable's convention. */}
- <SortingIndicator order={active ? (orderDirection === 'ASC' ? 1 : -1) : null} />
- </button>
- </Cell>
- )
-}
-
-function SpanRowHeader({ orderBy, orderDirection, onSort }: SortProps): JSX.Element {
+}: { widths: Record<string, number>; columns: ResizableColumns } & SortProps): JSX.Element {
+ const shared = { widths, columns }
+ const sortProps = { orderBy, orderDirection, onSort }
return (
<div
className="flex items-center border-b border-border bg-surface-secondary font-medium text-muted"
// eslint-disable-next-line react/forbid-dom-props
style={{ height: HEADER_HEIGHT }}
>
- <SortableHeaderCell
- column="timestamp"
+ <SpanHeaderCell
+ {...shared}
+ columnKey="timestamp"
label="Timestamp"
- width={COL_WIDTH.timestamp}
- orderBy={orderBy}
- orderDirection={orderDirection}
- onSort={onSort}
+ sort={{ column: 'timestamp', ...sortProps }}
/>
- <Cell>Name</Cell>
- <Cell width={COL_WIDTH.service}>Service</Cell>
- <Cell width={COL_WIDTH.kind}>Kind</Cell>
- <SortableHeaderCell
- column="duration"
+ <SpanHeaderCell {...shared} columnKey="name" label="Name" />
+ <SpanHeaderCell {...shared} columnKey="service" label="Service" />
+ <SpanHeaderCell {...shared} columnKey="kind" label="Kind" />
+ <SpanHeaderCell
+ {...shared}
+ columnKey="duration"
label="Duration"
- width={COL_WIDTH.duration}
- orderBy={orderBy}
- orderDirection={orderDirection}
- onSort={onSort}
+ sort={{ column: 'duration', ...sortProps }}
/>
- <Cell width={COL_WIDTH.status}>Status</Cell>
- <Cell width={COL_WIDTH.traceId}>Trace ID</Cell>
- <Cell width={COL_WIDTH.actions}> </Cell>
+ <SpanHeaderCell {...shared} columnKey="status" label="Status" />
+ <SpanHeaderCell {...shared} columnKey="traceId" label="Trace ID" />
+ {/* Row actions need no heading. */}
+ <SpanHeaderCell {...shared} columnKey="actions" />
</div>
)
}
-function SpanRow({ span, onClick }: { span: Span; onClick: () => void }): JSX.Element {
+function SpanRow({
+ span,
+ widths,
+ onClick,
+}: {
+ span: Span
+ widths: Record<string, number>
+ onClick: () => void
+}): JSX.Element {
const status = STATUS_CODE_LABELS[span.status_code] ?? { label: String(span.status_code), type: 'default' as const }
return (
@@ -150,8 +164,8 @@ function SpanRow({ span, onClick }: { span: Span; onClick: () => void }): JSX.El
role="button"
tabIndex={0}
>
- <Cell width={COL_WIDTH.timestamp}>{new Date(span.timestamp).toLocaleString()}</Cell>
- <Cell>
+ <TableCell width={widths.timestamp}>{new Date(span.timestamp).toLocaleString()}</TableCell>
+ <TableCell width={widths.name}>
<span className="flex items-center gap-2 truncate">
<span className="truncate">{span.name}</span>
{isRootSpan(span) && (
@@ -160,21 +174,21 @@ function SpanRow({ span, onClick }: { span: Span; onClick: () => void }): JSX.El
</LemonTag>
)}
</span>
- </Cell>
- <Cell width={COL_WIDTH.service}>
+ </TableCell>
+ <TableCell width={widths.service}>
<LemonTag>{span.service_name}</LemonTag>
- </Cell>
- <Cell width={COL_WIDTH.kind}>{SPAN_KIND_LABELS[span.kind] ?? span.kind}</Cell>
- <Cell width={COL_WIDTH.duration}>{formatDuration(span.duration_nano)}</Cell>
- <Cell width={COL_WIDTH.status}>
+ </TableCell>
+ <TableCell width={widths.kind}>{SPAN_KIND_LABELS[span.kind] ?? span.kind}</TableCell>
+ <TableCell width={widths.duration}>{formatDuration(span.duration_nano)}</TableCell>
+ <TableCell width={widths.status}>
<LemonTag type={status.type}>{status.label}</LemonTag>
- </Cell>
- <Cell width={COL_WIDTH.traceId}>
+ </TableCell>
+ <TableCell width={widths.traceId}>
<span className="font-mono">{span.trace_id.substring(0, 16)}...</span>
- </Cell>
- <Cell width={COL_WIDTH.actions}>
+ </TableCell>
+ <TableCell width={widths.actions}>
<SpanRowActions span={span} onViewTrace={onClick} />
- </Cell>
+ </TableCell>
</div>
)
}
@@ -184,6 +198,7 @@ function SpanListRow({
index,
style,
dataSource,
+ widths,
onRowClick,
}: {
ariaAttributes: { 'aria-posinset': number; 'aria-setsize': number; role: 'listitem' }
@@ -195,7 +210,7 @@ function SpanListRow({
return (
// eslint-disable-next-line react/forbid-dom-props
<div {...ariaAttributes} style={style} data-index={index} data-row-key={span.uuid}>
- <SpanRow span={span} onClick={() => onRowClick(span)} />
+ <SpanRow span={span} widths={widths} onClick={() => onRowClick(span)} />
</div>
)
}
@@ -216,6 +231,7 @@ export function VirtualizedSpanList({
const lastVisibleRangeRef = useRef<{ startIndex: number; stopIndex: number } | null>(null)
const listRef = useListRef(null)
+ const columns = useResizableColumns(TABLE_KEY, SPAN_COLUMNS)
const handleRowsRendered = useCallback(
(
@@ -240,8 +256,6 @@ export function VirtualizedSpanList({
[dataSource.length, hasMoreToLoad, loading, onLoadMore, onVisibleRowRangeChange]
)
- const rowProps = useMemo((): SpanRowProps => ({ dataSource, onRowClick }), [dataSource, onRowClick])
-
if (dataSource.length === 0 && !loading) {
return (
<div className="flex items-center justify-center p-8 text-muted border rounded bg-bg-light">
@@ -260,22 +274,29 @@ export function VirtualizedSpanList({
if (!width || !height) {
return null
}
- const rowWidth = Math.max(width, MIN_ROW_WIDTH)
+ const { widths, totalWidth } = columns.resolveWidths(width)
+ const rowWidth = Math.max(width, totalWidth)
return (
// The viewport is fixed to the available box; the inner content can be wider
- // (MIN_ROW_WIDTH) so columns scroll horizontally and rows align with the header.
+ // (totalWidth) so columns scroll horizontally and rows align with the header.
// eslint-disable-next-line react/forbid-dom-props
<div className="overflow-x-auto" style={{ width, height }}>
{/* eslint-disable-next-line react/forbid-dom-props */}
<div style={{ width: rowWidth }}>
- <SpanRowHeader orderBy={orderBy} orderDirection={orderDirection} onSort={onSort} />
+ <SpanRowHeader
+ widths={widths}
+ columns={columns}
+ orderBy={orderBy}
+ orderDirection={orderDirection}
+ onSort={onSort}
+ />
<List<SpanRowProps>
style={{ height: height - HEADER_HEIGHT, width: rowWidth }}
overscanCount={10}
rowCount={dataSource.length}
rowHeight={ROW_HEIGHT}
rowComponent={SpanListRow}
- rowProps={rowProps}
+ rowProps={{ dataSource, widths, onRowClick }}
onRowsRendered={handleRowsRendered}
listRef={listRef}
/>
diff --git a/products/tracing/frontend/tracingConfigLogic.ts b/products/tracing/frontend/tracingConfigLogic.ts
index 208d3f76e151..38a052931cd2 100644
--- a/products/tracing/frontend/tracingConfigLogic.ts
+++ b/products/tracing/frontend/tracingConfigLogic.ts
@@ -1,12 +1,32 @@
import { MakeLogicType, actions, kea, path, reducers } from 'kea'
+/** Column widths a person has dragged, keyed by table then column. */
+export type TracingColumnWidths = Record<string, Record<string, number>>
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface tracingConfigLogicValues {
+ columnWidths: TracingColumnWidths
facetRailCollapsed: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface tracingConfigLogicActions {
+ resetColumnWidth: (
+ tableKey: string,
+ columnKey: string
+ ) => {
+ columnKey: string
+ tableKey: string
+ }
+ setColumnWidth: (
+ tableKey: string,
+ columnKey: string,
+ width: number
+ ) => {
+ columnKey: string
+ tableKey: string
+ width: number
+ }
setFacetRailCollapsed: (facetRailCollapsed: boolean) => {
facetRailCollapsed: boolean
}
@@ -20,6 +40,8 @@ export const tracingConfigLogic = kea<tracingConfigLogicType>([
actions({
setFacetRailCollapsed: (facetRailCollapsed: boolean) => ({ facetRailCollapsed }),
+ setColumnWidth: (tableKey: string, columnKey: string, width: number) => ({ tableKey, columnKey, width }),
+ resetColumnWidth: (tableKey: string, columnKey: string) => ({ tableKey, columnKey }),
}),
reducers({
@@ -30,5 +52,19 @@ export const tracingConfigLogic = kea<tracingConfigLogicType>([
setFacetRailCollapsed: (_, { facetRailCollapsed }) => facetRailCollapsed,
},
],
+ columnWidths: [
+ {} as TracingColumnWidths,
+ { persist: true },
+ {
+ setColumnWidth: (state, { tableKey, columnKey, width }) => ({
+ ...state,
+ [tableKey]: { ...state[tableKey], [columnKey]: width },
+ }),
+ resetColumnWidth: (state, { tableKey, columnKey }) => {
+ const { [columnKey]: _removed, ...rest } = state[tableKey] ?? {}
+ return { ...state, [tableKey]: rest }
+ },
+ },
+ ],
}),
])
diff --git a/products/tracing/package.json b/products/tracing/package.json
index 194a5163fc8c..8a79778a8110 100644
--- a/products/tracing/package.json
+++ b/products/tracing/package.json
@@ -17,6 +17,7 @@
"peerDependencies": {
"@posthog/brand": "catalog:",
"@posthog/icons": "catalog:",
+ "@storybook/react": "catalog:",
"@testing-library/react": "*",
"@types/react": "*",
"clsx": "*",