: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aio): stop one bad row blanking the traces list (#98961)
posthog[bot]b05031a64245
diff --git a/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx b/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsxindex 72fffa21b5be..11b50ec708c7 100644--- a/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx+++ b/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx@@ -5,6 +5,8 @@ import { Link } from 'lib/lemon-ui/Link'import { newInternalTab } from 'lib/utils/newInternalTab'import { urls } from 'scenes/urls'+import { DataTableNode } from '~/queries/schema/schema-general'+import { QueryContextColumnComponent } from '~/queries/types'import { initKeaTests } from '~/test/init'import { useTracesQueryContext } from './AIObservabilityTracesScene'@@ -34,62 +36,114 @@ function renderRow(record: unknown): { plainCell: HTMLElement; linkCell: HTMLElereturn { 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)+function renderCell(columnName: string, record: unknown): string {+ const { result } = renderHook(() => useTracesQueryContext())+ const Column = result.current.columns?.[columnName]?.render as QueryContextColumnComponent+ const { container } = render(+ <Column+ record={record}+ columnName={columnName}+ value={undefined}+ query={{} as DataTableNode}+ recordIndex={0}+ rowCount={1}+ />+ )+ return container.textContent ?? ''+}- expect(router.values.location.pathname).toContain(LINK_CELL_PATH)- expect(newInternalTab).not.toHaveBeenCalled()+describe('useTracesQueryContext', () => {+ describe('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([+ ['has no createdAt', { id: 'trace-1', events: [] }],+ ['has an unparseable createdAt', { id: 'trace-1', createdAt: 'not a date', events: [] }],+ ])('leaves the timestamp out of the trace detail url when the row %s', (_name, result) => {+ const { plainCell } = renderRow({ result })++ fireEvent.click(plainCell)++ expect(router.values.location.pathname).toContain(TRACE_PATH)+ expect(router.values.searchParams).not.toHaveProperty('timestamp')+ })++ 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()+ })})- 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()+ // A row the response returned without a field `LLMTrace` types as present used to throw+ // in the cell renderer, which reaches the scene error boundary and blanks the whole list.+ describe('malformed cells', () => {+ beforeEach(() => {+ cleanup()+ initKeaTests()+ })++ it.each([+ ['id', { createdAt: '2026-01-01T12:00:00Z', events: [] }],+ ['createdAt', { id: 'trace-1', events: [] }],+ ['promptVersion', { id: 'trace-1', createdAt: '2026-01-01T12:00:00Z' }],+ ['promptVersionId', { id: 'trace-1', createdAt: '2026-01-01T12:00:00Z' }],+ ])('renders the %s cell as a dash instead of throwing', (columnName, record) => {+ expect(renderCell(columnName, record)).toBe('–')+ })++ it('renders the trace name as plain text when the row has no id', () => {+ expect(renderCell('traceName', { traceName: 'my trace' })).toBe('my trace')+ })})})diff --git a/products/ai_observability/frontend/AIObservabilityTracesScene.tsx b/products/ai_observability/frontend/AIObservabilityTracesScene.tsxindex 0be236e526b2..76f332a92d0c 100644--- a/products/ai_observability/frontend/AIObservabilityTracesScene.tsx+++ b/products/ai_observability/frontend/AIObservabilityTracesScene.tsx@@ -6,6 +6,7 @@ import { IconGear } from '@posthog/icons'import { LemonButton, LemonDropdown, LemonSwitch, LemonTag } from '@posthog/lemon-ui'import { TZLabel } from 'lib/components/TZLabel'+import { dayjs } from 'lib/dayjs'import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'import { Link } from 'lib/lemon-ui/Link'import { Tooltip } from 'lib/lemon-ui/Tooltip'@@ -141,7 +142,10 @@ function buildTraceDetailUrl(row: LLMTrace, searchParams: Record<string, unknownreturn combineUrl(urls.aiObservabilityTrace(row.id), {...nonTraceSearchParams,back_to: 'traces',- timestamp: getTraceTimestamp(row.createdAt),+ // An omitted timestamp makes the detail view use its wide default date range. A timestamp+ // built from a missing or unparseable `createdAt` would instead point the lookup at a+ // ten-minute window around the present, where an older trace is not found.+ timestamp: row.createdAt && dayjs(row.createdAt).isValid() ? getTraceTimestamp(row.createdAt) : undefined,}).url}@@ -256,9 +260,20 @@ export const useTracesQueryContext = (): QueryContext<DataTableNode> => {}}+// DataTable passes each renderer the row the response actually returned, which can+// lack fields `LLMTrace` declares as present. A throw in a cell reaches the scene's+// error boundary and blanks the whole traces list, so every renderer below degrades+// to a dash instead.+function traceEvents(row: LLMTrace): LLMTrace['events'] {+ return Array.isArray(row.events) ? row.events : []+}+const IDColumn: QueryContextColumnComponent = ({ record }) => {const row = record as LLMTraceconst { searchParams } = useValues(router)+ if (!row.id) {+ return <>–</>+ }return (<strong><Tooltip title={row.id}>@@ -273,12 +288,17 @@ const IDColumn: QueryContextColumnComponent = ({ record }) => {const TraceNameColumn: QueryContextColumnComponent = ({ record }) => {const row = record as LLMTraceconst { searchParams } = useValues(router)+ const name = row.traceName || '–'return (<div className="flex items-center gap-2"><strong>- <Link to={buildTraceDetailUrl(row, searchParams)} data-attr="trace-name-link">- {row.traceName || '–'}- </Link>+ {row.id ? (+ <Link to={buildTraceDetailUrl(row, searchParams)} data-attr="trace-name-link">+ {name}+ </Link>+ ) : (+ name+ )}</strong>{row.isSupportTrace && <LemonTag type="muted">Support</LemonTag>}</div>@@ -287,6 +307,9 @@ const TraceNameColumn: QueryContextColumnComponent = ({ record }) => {const TimestampColumn: QueryContextColumnComponent = ({ record }) => {const row = record as LLMTrace+ if (!row.createdAt) {+ return <>–</>+ }return <TZLabel time={row.createdAt} />}TimestampColumn.displayName = 'TimestampColumn'@@ -295,7 +318,7 @@ const PromptVersionColumn: QueryContextColumnComponent = ({ record }) => {const row = record as LLMTraceconst promptVersions = Array.from(new Set(- row.events+ traceEvents(row).map((event) => event.properties?.['$ai_prompt_version']).filter((value): value is string | number => typeof value === 'string' || typeof value === 'number').map((value) => String(value))@@ -321,7 +344,7 @@ const PromptVersionIdColumn: QueryContextColumnComponent = ({ record }) => {const row = record as LLMTraceconst promptVersionIds = Array.from(new Set(- row.events+ traceEvents(row).map((event) => event.properties?.['$ai_prompt_version_id']).filter((value): value is string => typeof value === 'string' && value.length > 0))@@ -386,7 +409,7 @@ function useTraceMessagesForRow(row: LLMTrace): TraceMessages | null | undefinedensureTraceMessagesLoaded([{ id: row.id, createdAt: row.createdAt ?? null }])}}, [row.id, row.createdAt, ensureTraceMessagesLoaded])- return getTraceMessages(row.id)+ return row.id ? getTraceMessages(row.id) : null}const InputMessageColumn: QueryContextColumnComponent = ({ record }) => {@@ -411,9 +434,7 @@ const OutputMessageColumn: QueryContextColumnComponent = ({ record }) => {const row = record as LLMTraceconst messages = useTraceMessagesForRow(row)- const errorEventFound = Array.isArray(row.events)- ? row.events.find((e) => e.properties?.$ai_error || e.properties?.$ai_is_error)- : false+ const errorEventFound = traceEvents(row).find((e) => e.properties?.$ai_error || e.properties?.$ai_is_error)if (errorEventFound) {return (<LemonTag type="danger" className="font-mono max-w-50 truncate">