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.

fix(aio): make traces table rows clickable (#83478)

posthog[bot]afdd2d0b673b
diff --git a/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx b/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx
new file mode 100644
index 000000000000..72fffa21b5be
--- /dev/null
+++ b/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx
@@ -0,0 +1,95 @@
+import { cleanup, fireEvent, render, renderHook } from '@testing-library/react'
+import { router } from 'kea-router'
+
+import { Link } from 'lib/lemon-ui/Link'
+import { newInternalTab } from 'lib/utils/newInternalTab'
+import { urls } from 'scenes/urls'
+
+import { initKeaTests } from '~/test/init'
+
+import { useTracesQueryContext } from './AIObservabilityTracesScene'
+
+jest.mock('lib/utils/newInternalTab')
+
+const TRACE_RECORD = { result: { id: 'trace-1', createdAt: '2026-01-01T12:00:00Z', events: [] } }
+const TRACE_PATH = urls.aiObservabilityTrace('trace-1')
+const LINK_CELL_PATH = urls.aiObservabilitySessions()
+
+function renderRow(record: unknown): { plainCell: HTMLElement; linkCell: HTMLElement } {
+ const { result } = renderHook(() => useTracesQueryContext())
+ const { getByTestId } = render(
+ <table>
+ <tbody>
+ <tr {...(result.current.rowProps?.(record) ?? {})}>
+ <td data-attr="plain-cell">plain</td>
+ <td>
+ <Link to={LINK_CELL_PATH} data-attr="link-cell">
+ link
+ </Link>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ )
+ return { plainCell: getByTestId('plain-cell'), linkCell: getByTestId('link-cell') }
+}
+
+describe('useTracesQueryContext row navigation', () => {
+ let pathnameBeforeClick: string
+
+ beforeEach(() => {
+ cleanup()
+ initKeaTests()
+ jest.mocked(newInternalTab).mockClear()
+ pathnameBeforeClick = router.values.location.pathname
+ })
+
+ it('navigates to the trace detail view when a plain cell is clicked', () => {
+ const { plainCell } = renderRow(TRACE_RECORD)
+
+ fireEvent.click(plainCell)
+
+ expect(router.values.location.pathname).toContain(TRACE_PATH)
+ expect(router.values.searchParams).toMatchObject({ back_to: 'traces', timestamp: '2026-01-01T11:55:00Z' })
+ expect(newInternalTab).not.toHaveBeenCalled()
+ })
+
+ it.each([
+ ['meta-click', (cell: HTMLElement): boolean => fireEvent.click(cell, { metaKey: true })],
+ ['ctrl-click', (cell: HTMLElement): boolean => fireEvent.click(cell, { ctrlKey: true })],
+ [
+ 'middle click',
+ (cell: HTMLElement): boolean =>
+ fireEvent(cell, new MouseEvent('auxclick', { bubbles: true, cancelable: true, button: 1 })),
+ ],
+ ])('opens the trace detail view in a new tab on %s', (_name, clickCell) => {
+ const { plainCell } = renderRow(TRACE_RECORD)
+
+ clickCell(plainCell)
+
+ expect(router.values.location.pathname).toBe(pathnameBeforeClick)
+ expect(newInternalTab).toHaveBeenCalledWith(expect.stringContaining(TRACE_PATH))
+ })
+
+ it('leaves a cell with its own link to handle its click', () => {
+ const { linkCell } = renderRow(TRACE_RECORD)
+
+ fireEvent.click(linkCell)
+
+ expect(router.values.location.pathname).toContain(LINK_CELL_PATH)
+ expect(newInternalTab).not.toHaveBeenCalled()
+ })
+
+ it.each([
+ ['a label row', { label: 'January 1' }],
+ ['an array result', { result: ['trace-1'] }],
+ ['a result without an id', { result: { createdAt: '2026-01-01T12:00:00Z' } }],
+ ])('does not make the row clickable for %s', (_name, record) => {
+ const { plainCell } = renderRow(record)
+
+ fireEvent.click(plainCell)
+
+ expect(router.values.location.pathname).toBe(pathnameBeforeClick)
+ expect(newInternalTab).not.toHaveBeenCalled()
+ })
+})
diff --git a/products/ai_observability/frontend/AIObservabilityTracesScene.tsx b/products/ai_observability/frontend/AIObservabilityTracesScene.tsx
index 0b94b43fb354..291d01c278c0 100644
--- a/products/ai_observability/frontend/AIObservabilityTracesScene.tsx
+++ b/products/ai_observability/frontend/AIObservabilityTracesScene.tsx
@@ -1,6 +1,6 @@
import { useActions, useMountedLogic, useValues } from 'kea'
import { combineUrl, router } from 'kea-router'
-import { useEffect } from 'react'
+import { useCallback, useEffect } from 'react'
import { IconGear } from '@posthog/icons'
import { LemonButton, LemonDropdown, LemonSwitch, LemonTag } from '@posthog/lemon-ui'
@@ -9,6 +9,7 @@ import { TZLabel } from 'lib/components/TZLabel'
import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
import { Link } from 'lib/lemon-ui/Link'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { newInternalTab } from 'lib/utils/newInternalTab'
import { urls } from 'scenes/urls'
import { DataTable } from '~/queries/nodes/DataTable/DataTable'
@@ -135,11 +136,69 @@ function TracesOptionsMenu(): JSX.Element | null {
)
}
+function buildTraceDetailUrl(row: LLMTrace, searchParams: Record<string, unknown>): string {
+ const nonTraceSearchParams = sanitizeTraceUrlSearchParams(searchParams, { removeSearch: true })
+ return combineUrl(urls.aiObservabilityTrace(row.id), {
+ ...nonTraceSearchParams,
+ back_to: 'traces',
+ timestamp: getTraceTimestamp(row.createdAt),
+ }).url
+}
+
+function getTraceFromRow(record: unknown): LLMTrace | null {
+ if (typeof record !== 'object' || !record || !('result' in record)) {
+ return null
+ }
+ const result = record.result
+ if (typeof result !== 'object' || !result || Array.isArray(result) || !('id' in result) || !result.id) {
+ return null
+ }
+ return result as LLMTrace
+}
+
+// Cells with their own link or button (ID, trace name, person) handle their own clicks.
+function hasOwnClickHandler(target: EventTarget | null): boolean {
+ return target instanceof Element && !!target.closest('button, a, [role="button"]')
+}
+
export const useTracesQueryContext = (): QueryContext<DataTableNode> => {
+ const { searchParams } = useValues(router)
+ const { push } = useActions(router)
+ // Stable identity so DataTable's `onRow` useCallback holds and rows are not re-rendered each poll cycle.
+ const rowProps = useCallback<NonNullable<QueryContext['rowProps']>>(
+ (record) => {
+ const row = getTraceFromRow(record)
+ if (!row) {
+ return {}
+ }
+ const url = buildTraceDetailUrl(row, searchParams)
+ return {
+ onClick: (event) => {
+ if (hasOwnClickHandler(event.target)) {
+ return
+ }
+ if (event.metaKey || event.ctrlKey) {
+ newInternalTab(url)
+ } else {
+ push(url)
+ }
+ },
+ onAuxClick: (event) => {
+ if (event.button !== 1 || hasOwnClickHandler(event.target)) {
+ return
+ }
+ event.preventDefault()
+ newInternalTab(url)
+ },
+ }
+ },
+ [push, searchParams]
+ )
return {
emptyStateHeading: 'There were no traces in this period',
emptyStateDetail: 'Try changing the date range or filters.',
dataTableMaxPaginationLimit: LLM_TRACES_PAGE_SIZE,
+ rowProps,
columns: {
id: {
title: 'ID',
@@ -200,20 +259,10 @@ export const useTracesQueryContext = (): QueryContext<DataTableNode> => {
const IDColumn: QueryContextColumnComponent = ({ record }) => {
const row = record as LLMTrace
const { searchParams } = useValues(router)
- const nonTraceSearchParams = sanitizeTraceUrlSearchParams(searchParams, { removeSearch: true })
return (
<strong>
<Tooltip title={row.id}>
- <Link
- to={
- combineUrl(urls.aiObservabilityTrace(row.id), {
- ...nonTraceSearchParams,
- back_to: 'traces',
- timestamp: getTraceTimestamp(row.createdAt),
- }).url
- }
- data-attr="trace-id-link"
- >
+ <Link to={buildTraceDetailUrl(row, searchParams)} data-attr="trace-id-link">
{row.id.slice(0, 4)}...{row.id.slice(-4)}
</Link>
</Tooltip>
@@ -224,20 +273,10 @@ const IDColumn: QueryContextColumnComponent = ({ record }) => {
const TraceNameColumn: QueryContextColumnComponent = ({ record }) => {
const row = record as LLMTrace
const { searchParams } = useValues(router)
- const nonTraceSearchParams = sanitizeTraceUrlSearchParams(searchParams, { removeSearch: true })
return (
<div className="flex items-center gap-2">
<strong>
- <Link
- to={
- combineUrl(urls.aiObservabilityTrace(row.id), {
- ...nonTraceSearchParams,
- back_to: 'traces',
- timestamp: getTraceTimestamp(row.createdAt),
- }).url
- }
- data-attr="trace-name-link"
- >
+ <Link to={buildTraceDetailUrl(row, searchParams)} data-attr="trace-name-link">
{row.traceName || '–'}
</Link>
</strong>
diff --git a/products/ai_observability/frontend/aiObservabilityLogic.test.ts b/products/ai_observability/frontend/aiObservabilityLogic.test.ts
index cfd4c568a643..7d58afa845a3 100644
--- a/products/ai_observability/frontend/aiObservabilityLogic.test.ts
+++ b/products/ai_observability/frontend/aiObservabilityLogic.test.ts
@@ -223,6 +223,17 @@ describe('aiObservabilitySharedLogic', () => {
})
})
+ it('does not move the dashboard date range when the events tabs change dates', () => {
+ logic.actions.setDates('-30d', '-1d')
+
+ expectLogic(logic).toMatchValues({
+ dateFilter: { dateFrom: '-30d', dateTo: '-1d' },
+ dashboardDateFilter: { dateFrom: '-7d', dateTo: null },
+ dashboardDateOverride: false,
+ dashboardExternalDateFilters: { date_from: undefined, date_to: undefined },
+ })
+ })
+
it('keeps dashboard dates while restoring shared filters from the URL', () => {
router.actions.push(urls.aiObservabilityDashboard(), {
date_from: '-30d',
diff --git a/products/ai_observability/frontend/aiObservabilitySharedLogic.ts b/products/ai_observability/frontend/aiObservabilitySharedLogic.ts
index f39615f17000..49a119a1d105 100644
--- a/products/ai_observability/frontend/aiObservabilitySharedLogic.ts
+++ b/products/ai_observability/frontend/aiObservabilitySharedLogic.ts
@@ -342,7 +342,9 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([
dateTo: INITIAL_DATE_TO,
},
{
- setDates: (_, { dateFrom, dateTo }) => ({ dateFrom, dateTo }),
+ // `setDates` (the events tabs' picker) is deliberately absent: it would move the
+ // dashboard picker without setting `dashboardDateOverride`, which gates the range
+ // the tiles actually run on.
setDashboardDates: (_, { dateFrom, dateTo }) => ({ dateFrom, dateTo }),
applyDashboardUrlDates: (_, { dateFrom, dateTo }) => ({ dateFrom, dateTo }),
restoreSavedDashboardDates: (_, { dateFrom, dateTo }) => ({ dateFrom, dateTo }),