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(aio): open traces in the drawer from every trace list (#128163)

Carlos Marchal2e93a35ebb52
diff --git a/frontend/src/initKea.ts b/frontend/src/initKea.ts
index 3b80f83f3249..eb09178f5003 100644
--- a/frontend/src/initKea.ts
+++ b/frontend/src/initKea.ts
@@ -136,6 +136,7 @@ const ERROR_FILTER_ALLOW_LIST_BY_LOGIC_PATH: Record<string, string> = {
createProviderKey: 'products.ai_observability.settings.llmProviderKeysLogic',
updateProviderKey: 'products.ai_observability.settings.llmProviderKeysLogic',
deleteProviderKey: 'products.ai_observability.settings.llmProviderKeysLogic',
+ loadTrace: 'products.ai_observability.frontend.redesign.trace.traceViewLogic', // The trace view shows the error in its panel
loadEvaluationResults: 'products.ai_observability.frontend.redesign.trace.traceViewLogic', // The trace view's Evals tab shows the error
loadClusters: 'products.ai_observability.frontend.redesign.trace.traceClustersLogic', // The trace view hides the clusters chip
loadTraceFeedback: 'products.ai_observability.frontend.redesign.trace.traceFeedbackLogic', // The trace view's Feedback mode shows the error
diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx
index 087b25b19d4f..ca5c1e387cce 100644
--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx
@@ -200,6 +200,27 @@ describe('LemonTable', () => {
}
)
+ it('reports the rows in sorted order, and again only when they change', () => {
+ const onSortedRowsChange = jest.fn()
+ const table = (dataSource: Row[]): JSX.Element => (
+ <LemonTable
+ rowKey="id"
+ dataSource={dataSource}
+ columns={[...COLUMNS]}
+ defaultSorting={{ columnKey: 'value', order: 1 }}
+ onSortedRowsChange={onSortedRowsChange}
+ />
+ )
+ const { rerender } = render(table(DATA))
+ expect(onSortedRowsChange.mock.calls).toEqual([[[DATA[1], DATA[2], DATA[0]]]])
+
+ rerender(table(DATA))
+ expect(onSortedRowsChange).toHaveBeenCalledTimes(1)
+
+ rerender(table([DATA[0]]))
+ expect(onSortedRowsChange).toHaveBeenLastCalledWith([DATA[0]])
+ })
+
it('does not rerender retained virtualized cells when scrolling', () => {
const height = jest
.spyOn(HTMLElement.prototype, 'offsetHeight', 'get')
diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx
index 5afe3c52ce7d..e8d1f4ce59d0 100644
--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx
+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx
@@ -110,6 +110,8 @@ export interface LemonTableProps<T extends Record<string, any>, K extends BulkSe
sorting?: Sorting | null
/** Sorting change handler for controlled sort order. */
onSort?: (newSorting: Sorting | null) => void
+ /** Called with every row in display order, on mount and whenever those rows change. */
+ onSortedRowsChange?: (rows: T[]) => void
/** Defaults to true. Used if you don't want to use the URL to store sort order **/
useURLForSorting?: boolean
/** How many skeleton rows should be used for the empty loading state. The default value is 1. */
@@ -191,6 +193,7 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio
defaultSorting = null,
sorting,
onSort,
+ onSortedRowsChange,
useURLForSorting = true,
loadingSkeletonRows = 1,
emptyState,
@@ -316,6 +319,20 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio
return dataSource
}, [dataSource, currentSorting, baseColumns])
+ // Inline columns give sortedDataSource a new identity on each render, so compare the rows themselves. Otherwise a
+ // parent that stores them would render again and report again without end.
+ const reportedRowsRef = useRef<T[] | null>(null)
+ useEffect(() => {
+ const reported = reportedRowsRef.current
+ const isUnchanged =
+ reported?.length === sortedDataSource.length &&
+ sortedDataSource.every((row, index) => row === reported[index])
+ if (onSortedRowsChange && !isUnchanged) {
+ reportedRowsRef.current = sortedDataSource
+ onSortedRowsChange(sortedDataSource)
+ }
+ }, [sortedDataSource, onSortedRowsChange])
+
const paginationState = usePagination(sortedDataSource, pagination, id)
const virtualizeRows = virtualized && allowContentScroll && !expandable
const scrollMargin = tableRef.current?.tHead?.offsetHeight ?? 0
diff --git a/products/ai_observability/frontend/AIObservabilityScene.test.tsx b/products/ai_observability/frontend/AIObservabilityScene.test.tsx
new file mode 100644
index 000000000000..54a6e7cfa55c
--- /dev/null
+++ b/products/ai_observability/frontend/AIObservabilityScene.test.tsx
@@ -0,0 +1,153 @@
+import { RenderResult, act, cleanup, fireEvent, render, waitFor } from '@testing-library/react'
+import { combineUrl, router } from 'kea-router'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
+
+import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'
+import { performQuery } from '~/queries/query'
+import { NodeKind } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+
+import { AIObservabilityGenerations, AIObservabilityScene } from './AIObservabilityScene'
+import { traceDrawerLogic } from './redesign/trace/traceDrawerLogic'
+
+jest.mock('./AIObservabilityTracesScene', () => ({ AIObservabilityTraces: () => null }))
+jest.mock('./AIObservabilitySessionsPlaylist', () => ({ AIObservabilitySessionsPlaylist: () => null }))
+jest.mock('~/queries/query', () => ({ ...jest.requireActual('~/queries/query'), performQuery: jest.fn() }))
+
+const GENERATIONS_PATH = urls.aiObservabilityGenerations()
+const DRAWER_TIMESTAMP = '2026-01-01T11:55:00Z'
+const PERSON = { uuid: 'person-1', distinct_id: 'user-1', properties: {} }
+
+function generationRow(uuid: string | null, traceId: string): unknown[] {
+ return [uuid, traceId, PERSON, 'gpt-4', null, '', '1 s', '1 → 1 (∑ 2)', '$0.1', '2026-01-01T12:00:00Z']
+}
+
+async function renderGenerations({ flag = true, url = GENERATIONS_PATH } = {}): Promise<RenderResult> {
+ initKeaTests()
+ localStorage.clear()
+ jest.mocked(performQuery).mockReset()
+ jest.mocked(performQuery).mockImplementation(async (query) =>
+ query.kind === NodeKind.EventsQuery
+ ? { results: [generationRow('gen-1', 'trace-1'), generationRow(null, 'trace-2')] }
+ : { results: [] }
+ )
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN], {
+ [FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN]: flag,
+ })
+ panelLayoutLogic.mount()
+ router.actions.push(url)
+ const view = render(<AIObservabilityGenerations />)
+ await waitFor(() => expect(view.container.querySelector('[data-attr="generation-id-link"]')).not.toBeNull())
+ return view
+}
+
+function element(view: RenderResult, selector: string): Element {
+ const found = view.container.querySelector(selector)
+ if (!found) {
+ throw new Error(`No ${selector}`)
+ }
+ return found
+}
+
+function row(view: RenderResult): Element {
+ const found = element(view, '[data-attr="generation-id-link"]').closest('tr')
+ if (!found) {
+ throw new Error('No row')
+ }
+ return found
+}
+
+describe('AIObservabilityScene', () => {
+ afterEach(cleanup)
+
+ it('leaves the trace drawer params out of the tab links and keeps the filters', () => {
+ initKeaTests()
+ router.actions.push(`${urls.aiObservabilityTraces()}?date_from=-7d&trace=a&ts=2026&step=x`)
+
+ const { container } = render(<AIObservabilityScene />)
+
+ const href = container.querySelector('[data-attr="generations-tab"]')?.closest('a')?.getAttribute('href')
+ expect(href).toContain(`${urls.aiObservabilityGenerations()}?date_from=-7d`)
+ expect(href).not.toMatch(/trace=|ts=|step=/)
+ })
+
+ describe('opening the trace drawer from generations', () => {
+ it.each([
+ ['the row', (view: RenderResult): Element => row(view).querySelectorAll('td')[3]],
+ ['the ID link', (view: RenderResult): Element => element(view, '[data-attr="generation-id-link"]')],
+ ['the trace link', (view: RenderResult): Element => element(view, '[data-attr="generation-trace-link"]')],
+ ])('opens on the generation from a plain click on %s', async (_name, target) => {
+ const view = await renderGenerations()
+
+ fireEvent.click(target(view))
+
+ expect(router.values.location.pathname).toContain(GENERATIONS_PATH)
+ expect(router.values.searchParams).toMatchObject({
+ trace: 'trace-1',
+ ts: DRAWER_TIMESTAMP,
+ step: 'gen-1',
+ })
+ })
+
+ it('gives the drawer the rows that have ids', async () => {
+ await renderGenerations()
+ const logic = traceDrawerLogic({ listId: 'generations' })
+
+ await waitFor(() =>
+ expect(logic.values.rows).toEqual([
+ { traceId: 'trace-1', timestamp: DRAWER_TIMESTAMP, stepId: 'gen-1' },
+ ])
+ )
+ })
+
+ it('expands a row without opening the drawer', async () => {
+ const view = await renderGenerations()
+ const expander = row(view).querySelector('button')
+ if (!expander) {
+ throw new Error('No expander')
+ }
+
+ fireEvent.click(expander)
+
+ expect(router.values.searchParams).not.toHaveProperty('trace')
+ })
+
+ // A remounted link cannot take focus back when the drawer closes.
+ it('keeps the same ID link in the document when the drawer writes the URL', async () => {
+ const view = await renderGenerations()
+ const link = element(view, '[data-attr="generation-id-link"]')
+
+ act(() => router.actions.push(GENERATIONS_PATH, { trace: 'trace-1' }))
+
+ expect(element(view, '[data-attr="generation-id-link"]')).toBe(link)
+ expect(link.isConnected).toBe(true)
+ })
+
+ it('leaves the drawer params out of the ID link', async () => {
+ const view = await renderGenerations({
+ url: combineUrl(GENERATIONS_PATH, { trace: 'trace-2', ts: DRAWER_TIMESTAMP, step: 'gen-2' }).url,
+ })
+
+ const link = element(view, '[data-attr="generation-id-link"]').getAttribute('href') ?? ''
+
+ expect(combineUrl(link).searchParams).toMatchObject({ back_to: 'generations', event: 'gen-1' })
+ expect(combineUrl(link).searchParams).not.toHaveProperty('trace')
+ expect(combineUrl(link).searchParams).not.toHaveProperty('step')
+ })
+
+ it('keeps the row and its links as they were when the drawer is disabled', async () => {
+ const view = await renderGenerations({ flag: false })
+
+ fireEvent.click(row(view).querySelectorAll('td')[3])
+ expect(router.values.location.pathname).toContain(GENERATIONS_PATH)
+
+ fireEvent.click(element(view, '[data-attr="generation-trace-link"]'))
+ expect(router.values.location.pathname).toContain(urls.aiObservabilityTrace('trace-1'))
+ expect(router.values.searchParams).not.toHaveProperty('trace')
+ })
+ })
+})
diff --git a/products/ai_observability/frontend/AIObservabilityScene.tsx b/products/ai_observability/frontend/AIObservabilityScene.tsx
index 165e01cd4ed0..3cc40f951fec 100644
--- a/products/ai_observability/frontend/AIObservabilityScene.tsx
+++ b/products/ai_observability/frontend/AIObservabilityScene.tsx
@@ -1,6 +1,6 @@
import { BindLogic, useActions, useValues } from 'kea'
import { combineUrl, router } from 'kea-router'
-import React from 'react'
+import React, { useCallback } from 'react'
import { LemonButton, LemonTab, LemonTabs, LemonTag, Link, Spinner } from '@posthog/lemon-ui'
import { Button } from '@posthog/quill'
@@ -35,6 +35,7 @@ import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollec
import { DataTable } from '~/queries/nodes/DataTable/DataTable'
import { DataTableRow } from '~/queries/nodes/DataTable/dataTableLogic'
import { ProductKey } from '~/queries/schema/schema-general'
+import { QueryContext } from '~/queries/types'
import { isEventsQuery } from '~/queries/utils'
import { AccessControlLevel, AccessControlResourceType, DashboardPlacement, EventType } from '~/types'
@@ -54,6 +55,11 @@ import { aiObservabilityEmptyState } from './emptyState/aiObservabilityEmptyStat
import { useSortableColumns } from './hooks/useSortableColumns'
import { InstrumentationChecklistCard } from './instrumentationChecklist/InstrumentationChecklistCard'
import { llmPersonsLazyLoaderLogic } from './llmPersonsLazyLoaderLogic'
+import { toFullPageListParams } from './redesign/trace/adapter/toBackLink'
+import { TraceDrawerQueryHost } from './redesign/trace/TraceDrawerQueryHost'
+import { withoutTraceDrawerParams } from './redesign/trace/traceDrawerRows'
+import { useTraceDrawerRows } from './redesign/trace/TraceDrawerRowsHost'
+import { TraceListRow } from './redesign/trace/traceListRows'
import { AIObservabilitySelfDriving } from './selfDriving/AIObservabilitySelfDriving'
import { aiObservabilityDashboardLogic } from './tabs/aiObservabilityDashboardLogic'
import { aiObservabilityErrorsLogic } from './tabs/aiObservabilityErrorsLogic'
@@ -65,7 +71,7 @@ import { aiObservabilityToolsLogic } from './tabs/aiObservabilityToolsLogic'
import { aiObservabilityTracesTabLogic } from './tabs/aiObservabilityTracesTabLogic'
import { aiObservabilityUsersLogic } from './tabs/aiObservabilityUsersLogic'
import { AIObservabilityHumanReviews } from './traceReviews/AIObservabilityHumanReviews'
-import { getTraceTimestamp, sanitizeTraceUrlSearchParams, truncateValue } from './utils'
+import { getTraceTimestamp, truncateValue } from './utils'
export const scene: SceneExport = {
component: AIObservabilityScene,
@@ -200,10 +206,67 @@ function AIObservabilityDashboard(): JSX.Element {
)
}
-function AIObservabilityGenerations(): JSX.Element {
+const GENERATIONS_LIST_ID = 'generations'
+const GENERATIONS_DATA_NODE_KEY = 'llm-analytics-generations'
+const GENERATION_LINKS = '[data-attr="generation-id-link"], [data-attr="generation-trace-link"]'
+
+interface GenerationRowIds {
+ uuid: string
+ traceId: string
+ traceTimestamp?: string
+}
+
+function useGenerationRowIds(): (result: unknown) => GenerationRowIds | null {
+ const { generationsQuery } = useValues(aiObservabilityGenerationsLogic)
+
+ return useCallback(
+ (result: unknown): GenerationRowIds | null =>
+ isEventsQuery(generationsQuery.source)
+ ? toGenerationRowIds(result, generationsQuery.source.select || getDefaultGenerationsColumns())
+ : null,
+ [generationsQuery.source]
+ )
+}
+
+// The data table uses a column's `render` as a component type, so an inline render remounts every cell on each render
+// of the scene, and a focused link in the cell loses focus.
+function GenerationIdCell({ record, value }: { record: unknown; value: unknown }): JSX.Element | null {
+ const { searchParams } = useValues(router)
+ const getRowIds = useGenerationRowIds()
+
+ if (!value || typeof value !== 'string') {
+ return null
+ }
+
+ const ids = getRowIds(record)
+ const visualValue = truncateValue(value)
+
+ return !ids ? (
+ <strong>{visualValue}</strong>
+ ) : (
+ <strong>
+ <Tooltip title={value}>
+ <Link
+ to={
+ combineUrl(urls.aiObservabilityTrace(ids.traceId), {
+ ...toFullPageListParams(searchParams),
+ event: value,
+ timestamp: ids.traceTimestamp,
+ back_to: 'generations',
+ }).url
+ }
+ data-attr="generation-id-link"
+ >
+ {visualValue}
+ </Link>
+ </Tooltip>
+ </strong>
+ )
+}
+
+export function AIObservabilityGenerations(): JSX.Element {
const { applyUrlState } = useActions(aiObservabilitySharedLogic)
const { dateFilter, propertyFilters: currentPropertyFilters } = useValues(aiObservabilitySharedLogic)
- const { searchParams } = useValues(router)
const { setGenerationsColumns, toggleGenerationExpanded, setGenerationsSort } = useActions(
aiObservabilityGenerationsLogic
)
@@ -214,206 +277,199 @@ function AIObservabilityGenerations(): JSX.Element {
const { renderSortableColumnTitle } = useSortableColumns(generationsSort, setGenerationsSort)
// Helper to safely extract uuid and traceId from a result row based on current column configuration
- const getRowIds = (result: unknown): { uuid: string; traceId: string; traceTimestamp?: string } | null => {
- if (!Array.isArray(result) || !isEventsQuery(generationsQuery.source)) {
- return null
- }
-
- const columns = generationsQuery.source.select || getDefaultGenerationsColumns()
+ const getRowIds = useGenerationRowIds()
+ const toDrawerRow = useCallback(
+ (result: unknown): TraceListRow | null => {
+ const ids = getRowIds(result)
+ return ids && { traceId: ids.traceId, timestamp: ids.traceTimestamp ?? null, stepId: ids.uuid }
+ },
+ [getRowIds]
+ )
+ const { rowProps: toDrawerRowProps } = useTraceDrawerRows(GENERATIONS_LIST_ID, GENERATION_LINKS)
+ const rowProps = useCallback<NonNullable<QueryContext['rowProps']>>(
+ (record) => {
+ const result = typeof record === 'object' && record && 'result' in record ? record.result : null
+ return toDrawerRowProps(toDrawerRow(result))
+ },
+ [toDrawerRow, toDrawerRowProps]
+ )
- const uuidIndex = columns.findIndex((col) => col === 'uuid')
- const traceIdIndex = columns.findIndex((col) => col === 'properties.$ai_trace_id')
- const timestampIndex = columns.findIndex((col) => col === 'timestamp')
+ return (
+ <>
+ <DataTable
+ attachTo={aiObservabilitySharedLogic}
+ query={{
+ ...generationsQuery,
+ showSavedFilters: true,
+ defaultColumns: getDefaultGenerationsColumns(),
+ }}
+ setQuery={(query) => {
+ if (!isEventsQuery(query.source)) {
+ throw new Error('Invalid query')
+ }
+ applyUrlState(
+ buildApplyUrlStatePayload({
+ dateFrom: query.source.after || null,
+ dateTo: query.source.before || null,
+ shouldFilterTestAccounts: query.source.filterTestAccounts || false,
+ propertyFilters: query.source.properties || [],
+ currentDateFilter: dateFilter,
+ currentPropertyFilters,
+ })
+ )
- if (uuidIndex < 0 || traceIdIndex < 0) {
- return null
- }
+ if (query.source.select) {
+ setGenerationsColumns(query.source.select)
+ }
+ }}
+ context={{
+ dataNodeLogicKey: GENERATIONS_DATA_NODE_KEY,
+ rowProps,
+ emptyStateHeading: 'There were no generations in this period',
+ emptyStateDetail: 'Try changing the date range or filters.',
+ columns: {
+ uuid: {
+ title: 'ID',
+ render: GenerationIdCell,
+ },
+ 'properties.$ai_input[-1]': {
+ ...aiObservabilityColumnRenderers['properties.$ai_input[-1]'],
+ renderTitle: () => (
+ <Tooltip title="The last message in the input array sent to the LLM for this generation.">
+ <span>Input</span>
+ </Tooltip>
+ ),
+ },
+ 'properties.$ai_output_choices': {
+ ...aiObservabilityColumnRenderers['properties.$ai_output_choices'],
+ renderTitle: () => (
+ <Tooltip title="The LLM's response for this generation.">
+ <span>Output</span>
+ </Tooltip>
+ ),
+ },
+ person: aiObservabilityColumnRenderers.person,
+ 'properties.$ai_tools_called': aiObservabilityColumnRenderers['properties.$ai_tools_called'],
+ "f'{properties.$ai_model}' -- Model": {
+ renderTitle: () => renderSortableColumnTitle('properties.$ai_model', 'Model'),
+ },
+ "f'{round(toFloat(properties.$ai_latency), 2)} s' -- Latency": {
+ renderTitle: () => renderSortableColumnTitle('properties.$ai_latency', 'Latency'),
+ },
+ "f'${round(toFloat(properties.$ai_total_cost_usd), 6)}' -- Cost": {
+ renderTitle: () => (
+ <Tooltip title="Cost of this generation">
+ {renderSortableColumnTitle('properties.$ai_total_cost_usd', 'Cost')}
+ </Tooltip>
+ ),
+ },
+ timestamp: {
+ renderTitle: () => renderSortableColumnTitle('timestamp', 'Time'),
+ },
+ },
+ expandable: {
+ expandedRowRender: function renderExpandedGeneration({ result }: DataTableRow) {
+ const ids = getRowIds(result)
+
+ if (!ids) {
+ return (
+ <div className="p-4 text-danger">
+ Cannot expand: required columns (uuid, properties.$ai_trace_id) are missing.
+ Please reset your column configuration.
+ </div>
+ )
+ }
- const uuid = result[uuidIndex]
- const traceId = result[traceIdIndex]
- const timestampValue = timestampIndex >= 0 ? result[timestampIndex] : null
+ const trace = loadedTraces[ids.traceId]
+ const event = trace?.events.find((e) => e.id === ids.uuid)
- if (typeof uuid === 'string' && typeof traceId === 'string') {
- const parsedTimestamp =
- timestampValue != null && dayjs(String(timestampValue)).isValid()
- ? getTraceTimestamp(String(timestampValue))
- : undefined
- return { uuid, traceId, traceTimestamp: parsedTimestamp }
- }
+ if (!trace) {
+ return (
+ <div className="p-4">
+ <Spinner />
+ </div>
+ )
+ }
- return null
- }
+ if (!event) {
+ return <div className="p-4">Event not found in trace</div>
+ }
- return (
- <DataTable
- attachTo={aiObservabilitySharedLogic}
- query={{
- ...generationsQuery,
- showSavedFilters: true,
- defaultColumns: getDefaultGenerationsColumns(),
- }}
- setQuery={(query) => {
- if (!isEventsQuery(query.source)) {
- throw new Error('Invalid query')
- }
- applyUrlState(
- buildApplyUrlStatePayload({
- dateFrom: query.source.after || null,
- dateTo: query.source.before || null,
- shouldFilterTestAccounts: query.source.filterTestAccounts || false,
- propertyFilters: query.source.properties || [],
- currentDateFilter: dateFilter,
- currentPropertyFilters,
- })
- )
-
- if (query.source.select) {
- setGenerationsColumns(query.source.select)
- }
- }}
- context={{
- emptyStateHeading: 'There were no generations in this period',
- emptyStateDetail: 'Try changing the date range or filters.',
- columns: {
- uuid: {
- title: 'ID',
- render: ({ record, value }) => {
- if (!value || typeof value !== 'string') {
- return null
+ // Convert LLMTraceEvent to EventType format for EventDetails
+ const eventForDetails: EventType = {
+ id: event.id,
+ uuid: event.id,
+ distinct_id: '',
+ properties: event.properties,
+ event: event.event,
+ timestamp: event.createdAt,
+ elements: [],
}
- const ids = getRowIds(record)
- const visualValue = truncateValue(value)
- const nonTraceSearchParams = sanitizeTraceUrlSearchParams(searchParams, {
- removeSearch: true,
- })
-
- return !ids ? (
- <strong>{visualValue}</strong>
- ) : (
- <strong>
- <Tooltip title={value}>
- <Link
- to={
- combineUrl(urls.aiObservabilityTrace(ids.traceId), {
- ...nonTraceSearchParams,
- event: value,
- timestamp: ids.traceTimestamp,
- back_to: 'generations',
- }).url
- }
- data-attr="generation-id-link"
- >
- {visualValue}
- </Link>
- </Tooltip>
- </strong>
+ return (
+ <div className="pt-2 px-4 pb-4">
+ <EventDetails event={eventForDetails} />
+ </div>
)
},
+ rowExpandable: ({ result }: DataTableRow) => !!getRowIds(result),
+ isRowExpanded: ({ result }: DataTableRow) => {
+ const ids = getRowIds(result)
+ return !!ids && expandedGenerationIds.has(ids.uuid)
+ },
+ onRowExpand: ({ result }: DataTableRow) => {
+ const ids = getRowIds(result)
+ if (ids) {
+ toggleGenerationExpanded(ids.uuid, ids.traceId)
+ }
+ },
+ onRowCollapse: ({ result }: DataTableRow) => {
+ const ids = getRowIds(result)
+ if (ids) {
+ toggleGenerationExpanded(ids.uuid, ids.traceId)
+ }
+ },
+ noIndent: true,
},
- 'properties.$ai_input[-1]': {
- ...aiObservabilityColumnRenderers['properties.$ai_input[-1]'],
- renderTitle: () => (
- <Tooltip title="The last message in the input array sent to the LLM for this generation.">
- <span>Input</span>
- </Tooltip>
- ),
- },
- 'properties.$ai_output_choices': {
- ...aiObservabilityColumnRenderers['properties.$ai_output_choices'],
- renderTitle: () => (
- <Tooltip title="The LLM's response for this generation.">
- <span>Output</span>
- </Tooltip>
- ),
- },
- person: aiObservabilityColumnRenderers.person,
- 'properties.$ai_tools_called': aiObservabilityColumnRenderers['properties.$ai_tools_called'],
- "f'{properties.$ai_model}' -- Model": {
- renderTitle: () => renderSortableColumnTitle('properties.$ai_model', 'Model'),
- },
- "f'{round(toFloat(properties.$ai_latency), 2)} s' -- Latency": {
- renderTitle: () => renderSortableColumnTitle('properties.$ai_latency', 'Latency'),
- },
- "f'${round(toFloat(properties.$ai_total_cost_usd), 6)}' -- Cost": {
- renderTitle: () => (
- <Tooltip title="Cost of this generation">
- {renderSortableColumnTitle('properties.$ai_total_cost_usd', 'Cost')}
- </Tooltip>
- ),
- },
- timestamp: {
- renderTitle: () => renderSortableColumnTitle('timestamp', 'Time'),
- },
- },
- expandable: {
- expandedRowRender: function renderExpandedGeneration({ result }: DataTableRow) {
- const ids = getRowIds(result)
+ }}
+ uniqueKey={GENERATIONS_DATA_NODE_KEY}
+ />
+ <TraceDrawerQueryHost
+ listId={GENERATIONS_LIST_ID}
+ dataNodeKey={GENERATIONS_DATA_NODE_KEY}
+ query={generationsQuery.source}
+ toRow={toDrawerRow}
+ />
+ </>
+ )
+}
- if (!ids) {
- return (
- <div className="p-4 text-danger">
- Cannot expand: required columns (uuid, properties.$ai_trace_id) are missing. Please
- reset your column configuration.
- </div>
- )
- }
+function toGenerationRowIds(result: unknown, columns: string[]): GenerationRowIds | null {
+ if (!Array.isArray(result)) {
+ return null
+ }
- const trace = loadedTraces[ids.traceId]
- const event = trace?.events.find((e) => e.id === ids.uuid)
+ const uuidIndex = columns.findIndex((col) => col === 'uuid')
+ const traceIdIndex = columns.findIndex((col) => col === 'properties.$ai_trace_id')
+ const timestampIndex = columns.findIndex((col) => col === 'timestamp')
- if (!trace) {
- return (
- <div className="p-4">
- <Spinner />
- </div>
- )
- }
-
- if (!event) {
- return <div className="p-4">Event not found in trace</div>
- }
-
- // Convert LLMTraceEvent to EventType format for EventDetails
- const eventForDetails: EventType = {
- id: event.id,
- uuid: event.id,
- distinct_id: '',
- properties: event.properties,
- event: event.event,
- timestamp: event.createdAt,
- elements: [],
- }
-
- return (
- <div className="pt-2 px-4 pb-4">
- <EventDetails event={eventForDetails} />
- </div>
- )
- },
- rowExpandable: ({ result }: DataTableRow) => !!getRowIds(result),
- isRowExpanded: ({ result }: DataTableRow) => {
- const ids = getRowIds(result)
- return !!ids && expandedGenerationIds.has(ids.uuid)
- },
- onRowExpand: ({ result }: DataTableRow) => {
- const ids = getRowIds(result)
- if (ids) {
- toggleGenerationExpanded(ids.uuid, ids.traceId)
- }
- },
- onRowCollapse: ({ result }: DataTableRow) => {
- const ids = getRowIds(result)
- if (ids) {
- toggleGenerationExpanded(ids.uuid, ids.traceId)
- }
- },
- noIndent: true,
- },
- }}
- uniqueKey="llm-analytics-generations"
- />
- )
+ if (uuidIndex < 0 || traceIdIndex < 0) {
+ return null
+ }
+
+ const uuid = result[uuidIndex]
+ const traceId = result[traceIdIndex]
+ const timestampValue = timestampIndex >= 0 ? result[timestampIndex] : null
+
+ if (typeof uuid === 'string' && typeof traceId === 'string') {
+ const parsedTimestamp =
+ timestampValue != null && dayjs(String(timestampValue)).isValid()
+ ? getTraceTimestamp(String(timestampValue))
+ : undefined
+ return { uuid, traceId, traceTimestamp: parsedTimestamp }
+ }
+
+ return null
}
const DEFAULT_DOCS_URL = 'https://posthog.com/docs/ai-observability/installation'
@@ -476,6 +532,7 @@ export function AIObservabilityScene(): JSX.Element {
function AIObservabilitySceneContent(): JSX.Element {
const { activeTab, featureFlags } = useValues(aiObservabilitySharedLogic)
const { searchParams } = useValues(router)
+ const tabParams = withoutTraceDrawerParams(searchParams)
const { push } = useActions(router)
const selfDrivingEnabled = Boolean(featureFlags[FEATURE_FLAGS.AI_OBSERVABILITY_SELF_DRIVING])
@@ -487,7 +544,7 @@ function AIObservabilitySceneContent(): JSX.Element {
keybind: [keyBinds.tab1],
intent: 'Go to Dashboard',
interaction: 'function',
- callback: () => push(combineUrl(urls.aiObservabilityDashboard(), searchParams).url),
+ callback: () => push(combineUrl(urls.aiObservabilityDashboard(), tabParams).url),
scope: Scene.AIObservability,
})
useShortcut({
@@ -495,7 +552,7 @@ function AIObservabilitySceneContent(): JSX.Element {
keybind: [keyBinds.tab2],
intent: 'Go to Traces',
interaction: 'function',
- callback: () => push(combineUrl(urls.aiObservabilityTraces(), searchParams).url),
+ callback: () => push(combineUrl(urls.aiObservabilityTraces(), tabParams).url),
scope: Scene.AIObservability,
})
useShortcut({
@@ -507,7 +564,7 @@ function AIObservabilitySceneContent(): JSX.Element {
push(
combineUrl(
selfDrivingEnabled ? urls.aiObservabilitySelfDriving() : urls.aiObservabilityGenerations(),
- searchParams
+ tabParams
).url
),
scope: Scene.AIObservability,
@@ -521,7 +578,7 @@ function AIObservabilitySceneContent(): JSX.Element {
push(
combineUrl(
selfDrivingEnabled ? urls.aiObservabilityGenerations() : urls.aiObservabilityUsers(),
- searchParams
+ tabParams
).url
),
scope: Scene.AIObservability,
@@ -535,7 +592,7 @@ function AIObservabilitySceneContent(): JSX.Element {
push(
combineUrl(
selfDrivingEnabled ? urls.aiObservabilitySessions() : urls.aiObservabilityErrors(),
- searchParams
+ tabParams
).url
),
scope: Scene.AIObservability,
@@ -550,28 +607,28 @@ function AIObservabilitySceneContent(): JSX.Element {
key: 'dashboard',
label: 'Dashboard',
content: <AIObservabilityDashboard />,
- link: combineUrl(urls.aiObservabilityDashboard(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityDashboard(), tabParams).url,
'data-attr': 'dashboard-tab',
},
{
key: 'traces',
label: 'Traces',
content: <AIObservabilityTraces />,
- link: combineUrl(urls.aiObservabilityTraces(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityTraces(), tabParams).url,
'data-attr': 'traces-tab',
},
{
key: 'generations',
label: 'Generations',
content: <AIObservabilityGenerations />,
- link: combineUrl(urls.aiObservabilityGenerations(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityGenerations(), tabParams).url,
'data-attr': 'generations-tab',
},
{
key: 'users',
label: 'Users',
content: <AIObservabilityUsers />,
- link: combineUrl(urls.aiObservabilityUsers(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityUsers(), tabParams).url,
'data-attr': 'users-tab',
},
]
@@ -588,7 +645,7 @@ function AIObservabilitySceneContent(): JSX.Element {
</>
),
content: <AIObservabilitySelfDriving />,
- link: combineUrl(urls.aiObservabilitySelfDriving(), searchParams).url,
+ link: combineUrl(urls.aiObservabilitySelfDriving(), tabParams).url,
'data-attr': 'self-driving-tab',
})
}
@@ -597,7 +654,7 @@ function AIObservabilitySceneContent(): JSX.Element {
key: 'errors',
label: 'Errors',
content: <AIObservabilityErrors />,
- link: combineUrl(urls.aiObservabilityErrors(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityErrors(), tabParams).url,
'data-attr': 'errors-tab',
})
@@ -605,7 +662,7 @@ function AIObservabilitySceneContent(): JSX.Element {
key: 'tools',
label: 'Tools',
content: <AIObservabilityTools />,
- link: combineUrl(urls.aiObservabilityTools(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityTools(), tabParams).url,
'data-attr': 'tools-tab',
})
@@ -619,7 +676,7 @@ function AIObservabilitySceneContent(): JSX.Element {
<AIObservabilitySentiment />
</>
),
- link: combineUrl(urls.aiObservabilitySentiment(), searchParams).url,
+ link: combineUrl(urls.aiObservabilitySentiment(), tabParams).url,
'data-attr': 'llma-sentiment-tab',
})
@@ -632,7 +689,7 @@ function AIObservabilitySceneContent(): JSX.Element {
<AIObservabilitySessionsPlaylist />
</>
),
- link: combineUrl(urls.aiObservabilitySessions(), searchParams).url,
+ link: combineUrl(urls.aiObservabilitySessions(), tabParams).url,
'data-attr': 'sessions-tab',
})
@@ -640,7 +697,7 @@ function AIObservabilitySceneContent(): JSX.Element {
key: 'reviews',
label: 'Reviews',
content: <AIObservabilityHumanReviews />,
- link: combineUrl(urls.aiObservabilityReviews(), searchParams).url,
+ link: combineUrl(urls.aiObservabilityReviews(), tabParams).url,
'data-attr': 'llma-reviews-tab',
})
diff --git a/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx b/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx
index 0bad04966c2a..cb78bb23a94e 100644
--- a/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx
+++ b/products/ai_observability/frontend/AIObservabilityTracesScene.test.tsx
@@ -351,7 +351,7 @@ describe('AIObservabilityTracesScene', () => {
const view = await renderTraces()
fireEvent.click(firstCell(view))
- act(() => traceDrawerLogic({ listId: 'traces' }).actions.requestStep('gen-1'))
+ act(() => traceDrawerLogic({ listId: 'traces' }).actions.requestStep('gen-1', 'trace-1'))
expect(tracesRequests()).toBe(1)
diff --git a/products/ai_observability/frontend/AIObservabilityTracesScene.tsx b/products/ai_observability/frontend/AIObservabilityTracesScene.tsx
index cc49148f36c0..6549056b3a09 100644
--- a/products/ai_observability/frontend/AIObservabilityTracesScene.tsx
+++ b/products/ai_observability/frontend/AIObservabilityTracesScene.tsx
@@ -1,7 +1,7 @@
import clsx from 'clsx'
import { useActions, useMountedLogic, useValues } from 'kea'
import { combineUrl, router } from 'kea-router'
-import { MouseEvent, useCallback, useEffect, useMemo } from 'react'
+import { useCallback, useEffect } from 'react'
import { IconGear } from '@posthog/icons'
import { LemonButton, LemonDropdown, LemonSwitch, LemonTag } from '@posthog/lemon-ui'
@@ -14,7 +14,6 @@ import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { newInternalTab } from 'lib/utils/newInternalTab'
import { urls } from 'scenes/urls'
-import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { DataTable } from '~/queries/nodes/DataTable/DataTable'
import { DataTableNode, LLMTrace } from '~/queries/schema/schema-general'
import { QueryContext, QueryContextColumnComponent } from '~/queries/types'
@@ -25,8 +24,10 @@ import { buildApplyUrlStatePayload, aiObservabilitySharedLogic } from './aiObser
import { LLMMessageDisplay } from './ConversationDisplay/ConversationMessagesDisplay'
import { normalizeMessages } from './messageNormalization'
import { toFullPageListParams } from './redesign/trace/adapter/toBackLink'
-import { TraceDrawerHost } from './redesign/trace/TraceDrawerHost'
-import { traceDrawerLogic } from './redesign/trace/traceDrawerLogic'
+import { TRACE_DRAWER_LISTS, TraceDrawerListId } from './redesign/trace/traceDrawerLists'
+import { TraceDrawerQueryHost } from './redesign/trace/TraceDrawerQueryHost'
+import { hasOwnClickHandler } from './redesign/trace/traceDrawerRows'
+import { useTraceDrawerRows } from './redesign/trace/TraceDrawerRowsHost'
import { TraceListRow } from './redesign/trace/traceListRows'
import { aiObservabilityTracesTabLogic } from './tabs/aiObservabilityTracesTabLogic'
import { TraceMessages, traceMessagesLazyLoaderLogic } from './traceMessagesLazyLoaderLogic'
@@ -46,7 +47,6 @@ import {
const TRACES_DATA_NODE_KEY = 'llm-analytics-traces'
const TRACE_DRAWER_LIST_ID = 'traces'
-const OPEN_ROW_CLASS = 'LemonTable__row--status-highlighted'
const TRACE_LINKS = '[data-attr="trace-id-link"], [data-attr="trace-name-link"]'
export function AIObservabilityTraces(): JSX.Element {
@@ -58,38 +58,9 @@ export function AIObservabilityTraces(): JSX.Element {
const { tracesQuery } = useValues(aiObservabilityTracesTabLogic)
const appliedSearchTerm = isTracesQuery(tracesQuery.source) ? tracesQuery.source.searchTerm : undefined
- const baseContext = useTracesQueryContext()
- const { rowProps: baseRowProps } = baseContext
- const logic = traceDrawerLogic({ listId: TRACE_DRAWER_LIST_ID })
- const { isEnabled, openTraceId } = useValues(logic)
- const { openRow } = useActions(logic)
- const drawerRowProps = useCallback<NonNullable<QueryContext['rowProps']>>(
- (record) => {
- const baseProps = baseRowProps?.(record) ?? {}
- const trace = getTraceFromRow(record)
- if (!trace) {
- return baseProps
- }
- return {
- ...baseProps,
- className: clsx(baseProps.className, trace.id === openTraceId && OPEN_ROW_CLASS),
- onClickCapture: (event) => {
- if (opensTraceDrawer(event)) {
- event.preventDefault()
- event.stopPropagation()
- // A row cannot take focus, and the panel gives focus back to what held it on opening.
- event.currentTarget.querySelector<HTMLElement>(TRACE_LINKS)?.focus({ preventScroll: true })
- openRow(toTraceListRow(trace))
- }
- },
- }
- },
- [baseRowProps, openRow, openTraceId]
- )
+ const drawerContext = useTracesDrawerContext(TRACE_DRAWER_LIST_ID, TRACES_DATA_NODE_KEY)
const context: QueryContext<DataTableNode> = {
- ...baseContext,
- dataNodeLogicKey: TRACES_DATA_NODE_KEY,
- rowProps: isEnabled ? drawerRowProps : baseRowProps,
+ ...drawerContext,
...(appliedSearchTerm
? {
emptyStateHeading: 'No traces matched your search',
@@ -130,26 +101,16 @@ export function AIObservabilityTraces(): JSX.Element {
context={context}
uniqueKey={TRACES_DATA_NODE_KEY}
/>
- {isEnabled ? <TraceDrawerRows query={tracesQuery.source} /> : null}
- <TraceDrawerHost listId={TRACE_DRAWER_LIST_ID} />
+ <TraceDrawerQueryHost
+ listId={TRACE_DRAWER_LIST_ID}
+ dataNodeKey={TRACES_DATA_NODE_KEY}
+ query={tracesQuery.source}
+ toRow={toTraceDrawerRow}
+ />
</div>
)
}
-// A sibling after DataTable, so that DataTable builds the logic with its full props. Subscribing in
-// AIObservabilityTraces would also rebuild the table context on each poll and re-render every row.
-function TraceDrawerRows({ query }: { query: DataTableNode['source'] }): null {
- const { response } = useValues(dataNodeLogic({ key: TRACES_DATA_NODE_KEY, query }))
- const { setRows } = useActions(traceDrawerLogic({ listId: TRACE_DRAWER_LIST_ID }))
- const rows = useMemo(() => toTraceListRows(response), [response])
-
- useEffect(() => {
- setRows(rows)
- }, [rows, setRows])
-
- return null
-}
-
function TracesOptionsMenu(): JSX.Element | null {
const { showInputOutputColumns, showSentimentColumn } = useValues(aiObservabilityTracesTabLogic)
const { setShowInputOutputColumns, setShowSentimentColumn } = useActions(aiObservabilityTracesTabLogic)
@@ -203,21 +164,15 @@ function toTraceListRow(trace: LLMTrace): TraceListRow {
return { traceId: trace.id, timestamp: getTraceLookupTimestamp(trace) ?? null, stepId: null }
}
-function toTraceListRows(response: unknown): TraceListRow[] {
- const results = typeof response === 'object' && response && 'results' in response ? response.results : null
- if (!Array.isArray(results)) {
- return []
- }
- return results.flatMap((result) => {
- const trace = getTraceFromRow({ result })
- return trace ? [toTraceListRow(trace)] : []
- })
+export function toTraceDrawerRow(result: unknown): TraceListRow | null {
+ const trace = getTraceFromRow({ result })
+ return trace && toTraceListRow(trace)
}
function buildTraceDetailUrl(row: LLMTrace, searchParams: Record<string, unknown>): string {
return combineUrl(urls.aiObservabilityTrace(row.id), {
...toFullPageListParams(searchParams),
- back_to: 'traces',
+ back_to: TRACE_DRAWER_LISTS[TRACE_DRAWER_LIST_ID].backTo,
timestamp: getTraceLookupTimestamp(row),
}).url
}
@@ -233,17 +188,20 @@ function getTraceFromRow(record: unknown): LLMTrace | 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"]')
-}
-
-function opensTraceDrawer({ target, currentTarget, button, metaKey, ctrlKey, shiftKey, altKey }: MouseEvent): boolean {
- // React capture also reaches the row from a portal, so an overlay opened from a cell would lose its own clicks.
- const isInsideRow = target instanceof Node && currentTarget.contains(target)
- const isPlainClick = button === 0 && !metaKey && !ctrlKey && !shiftKey && !altKey
- const isTraceLink = target instanceof Element && !!target.closest(TRACE_LINKS)
- return isInsideRow && isPlainClick && (isTraceLink || !hasOwnClickHandler(target))
+export function useTracesDrawerContext(listId: TraceDrawerListId, dataNodeKey: string): QueryContext<DataTableNode> {
+ const baseContext = useTracesQueryContext()
+ const { rowProps: baseRowProps } = baseContext
+ const { isEnabled, rowProps: toDrawerRowProps } = useTraceDrawerRows(listId, TRACE_LINKS)
+ const drawerRowProps = useCallback<NonNullable<QueryContext['rowProps']>>(
+ (record) => {
+ const baseProps = baseRowProps?.(record) ?? {}
+ const trace = getTraceFromRow(record)
+ const rowProps = toDrawerRowProps(trace && toTraceListRow(trace))
+ return { ...baseProps, ...rowProps, className: clsx(baseProps.className, rowProps.className) }
+ },
+ [baseRowProps, toDrawerRowProps]
+ )
+ return { ...baseContext, dataNodeLogicKey: dataNodeKey, rowProps: isEnabled ? drawerRowProps : baseRowProps }
}
export const useTracesQueryContext = (): QueryContext<DataTableNode> => {
diff --git a/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.test.tsx b/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.test.tsx
new file mode 100644
index 000000000000..21ed4e1d2d88
--- /dev/null
+++ b/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.test.tsx
@@ -0,0 +1,108 @@
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { BindLogic } from 'kea'
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { teamLogic } from 'scenes/teamLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { traceDrawerLogic } from '../redesign/trace/traceDrawerLogic'
+import { traceViewHostLogic } from '../redesign/trace/traceViewHostLogic'
+import { AIObservabilityClusterScene } from './AIObservabilityClusterScene'
+import { clusterDetailLogic } from './clusterDetailLogic'
+import { Cluster } from './types'
+
+const FLAG = FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN
+const RUN_ID = 'team_2025-01-05'
+const PROPS = { runId: RUN_ID, clusterId: 0 }
+
+function clusterAtLevel(level: string): { cluster: Cluster } {
+ const info = (traceId: string, timestamp: string, generationId?: string): Cluster['traces'][string] => ({
+ distance_to_centroid: 0.1,
+ rank: 0,
+ x: 0,
+ y: 0,
+ timestamp,
+ trace_id: traceId,
+ generation_id: generationId,
+ })
+ return {
+ cluster: {
+ cluster_id: 0,
+ size: 2,
+ title: 'Cluster',
+ description: '',
+ centroid: [1],
+ centroid_x: 0,
+ centroid_y: 0,
+ traces: {
+ 'key-1': info('trace-1', '2025-01-05T10:00:00Z', level === 'generation' ? 'gen-1' : undefined),
+ 'key-2': info('trace-2', '2025-01-05T11:00:00Z', level === 'generation' ? 'gen-2' : undefined),
+ },
+ },
+ }
+}
+
+describe('AIObservabilityClusterScene', () => {
+ let logic: ReturnType<typeof clusterDetailLogic.build>
+
+ async function mountScene(level: string): Promise<void> {
+ const { cluster } = clusterAtLevel(level)
+ initKeaTests()
+ localStorage.clear()
+ jest.spyOn(api, 'queryHogQL').mockImplementation(async (query) =>
+ String(query).includes('$ai_clusters')
+ ? { results: [[RUN_ID, 'a', 'b', JSON.stringify([cluster]), '2025-01-05T00:00:00Z', level]] }
+ : { results: [] }
+ )
+ teamLogic.mount()
+ await expectLogic(teamLogic).toFinishAllListeners()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FLAG], { [FLAG]: true })
+ router.actions.push('/ai-observability/clusters/' + RUN_ID + '/0')
+ logic = clusterDetailLogic(PROPS)
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ render(
+ <BindLogic logic={clusterDetailLogic} props={PROPS}>
+ <AIObservabilityClusterScene />
+ </BindLogic>
+ )
+ await waitFor(() => expect(screen.getAllByText(/^View (trace|generation) →$/)).toHaveLength(2))
+ }
+
+ afterEach(async () => {
+ await expectLogic(teamLogic).toFinishAllListeners()
+ cleanup()
+ logic.unmount()
+ jest.restoreAllMocks()
+ })
+
+ it('opens a trace-level member on its trace, and steps through the page rows', async () => {
+ await mountScene('trace')
+
+ fireEvent.click(screen.getAllByText('View trace →')[0])
+
+ expect(router.values.searchParams).toEqual({ trace: 'key-1', ts: '2025-01-05T10:00:00.000Z' })
+ const host = traceViewHostLogic({ hostId: traceDrawerLogic({ listId: 'cluster-traces' }).values.hostId })
+ expect(host.values.openingMode).toBe('summary')
+ expect(traceDrawerLogic({ listId: 'cluster-traces' }).values.rows.map((row) => row.traceId)).toEqual([
+ 'key-1',
+ 'key-2',
+ ])
+ })
+
+ it('opens a generation-level member on its step', async () => {
+ await mountScene('generation')
+
+ fireEvent.click(screen.getAllByText('View generation →')[1])
+
+ expect(router.values.searchParams).toEqual({ trace: 'trace-2', ts: '2025-01-05T11:00:00.000Z', step: 'gen-2' })
+ const host = traceViewHostLogic({ hostId: traceDrawerLogic({ listId: 'cluster-traces' }).values.hostId })
+ expect(host.values.requestedStepId).toBe('gen-2')
+ })
+})
diff --git a/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.tsx b/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.tsx
index 060de6b7f832..493ac4a33adf 100644
--- a/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.tsx
+++ b/products/ai_observability/frontend/clusters/AIObservabilityClusterScene.tsx
@@ -1,5 +1,6 @@
+import clsx from 'clsx'
import { useActions, useValues } from 'kea'
-import { useState } from 'react'
+import { useMemo, useState } from 'react'
import { IconChevronDown, IconChevronLeft, IconChevronRight } from '@posthog/icons'
import { LemonButton, LemonSkeleton, LemonTag, Link, Spinner, Tooltip } from '@posthog/lemon-ui'
@@ -20,10 +21,13 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { groupsModel } from '~/models/groupsModel'
import { ProductKey } from '~/queries/schema/schema-general'
+import { TraceDrawerHost } from '../redesign/trace/TraceDrawerHost'
+import { TraceDrawerRowProps, TraceDrawerRowsSync, useTraceDrawerRows } from '../redesign/trace/TraceDrawerRowsHost'
import { formatErrorRate, formatLLMCost, formatLLMLatency, formatTokens } from '../utils'
import { BulletList, ClusterDescription, parseBullets } from './ClusterDescriptionComponents'
import { ClusterDetailLogicProps, clusterDetailLogic } from './clusterDetailLogic'
import { ClusterDetailScatterPlot } from './ClusterDetailScatterPlot'
+import { toClusterTraceDrawerRow } from './clusterTraceDrawerRow'
import { TRACES_PER_PAGE } from './constants'
import { formatEvalTitle } from './traceSummaryLoader'
import { ClusterItemInfo, ClusterMetrics, ClusteringLevel, TraceSummary } from './types'
@@ -38,6 +42,9 @@ export const scene: SceneExport<ClusterDetailLogicProps> = {
}),
}
+const TRACE_DRAWER_LIST_ID = 'cluster-traces'
+const TRACE_LINK = '[data-attr="clusters-view-trace-link"]'
+
export function AIObservabilityClusterScene(): JSX.Element {
const {
cluster,
@@ -62,6 +69,12 @@ export function AIObservabilityClusterScene(): JSX.Element {
const { setPage, setPropertyFilters, setShouldFilterTestAccounts } = useActions(clusterDetailLogic)
const { groupsTaxonomicTypes } = useValues(groupsModel)
const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+ const { rowProps: toDrawerRowProps, openTraceId } = useTraceDrawerRows(TRACE_DRAWER_LIST_ID, TRACE_LINK)
+ const drawerRows = useMemo(
+ () => paginatedTracesWithSummaries.map((item) => toClusterTraceDrawerRow(item, clusteringLevel)),
+ [paginatedTracesWithSummaries, clusteringLevel]
+ )
+ const syncedDrawerRows = useMemo(() => drawerRows.filter((row) => row !== null), [drawerRows])
if (clusterDataLoading) {
return (
@@ -241,12 +254,17 @@ export function AIObservabilityClusterScene(): JSX.Element {
summary={summary}
displayRank={(currentPage - 1) * TRACES_PER_PAGE + index + 1}
clusteringLevel={clusteringLevel}
+ drawerRowProps={toDrawerRowProps(drawerRows[index])}
+ isDrawerOpen={drawerRows[index]?.traceId === openTraceId}
/>
)
)
)}
</div>
+ <TraceDrawerRowsSync listId={TRACE_DRAWER_LIST_ID} rows={syncedDrawerRows} />
+ <TraceDrawerHost listId={TRACE_DRAWER_LIST_ID} />
+
{/* Pagination controls at bottom */}
{totalPages > 1 && (
<div className="flex justify-center mt-4">
@@ -431,12 +449,16 @@ function TraceListItem({
summary,
displayRank,
clusteringLevel = 'trace',
+ drawerRowProps,
+ isDrawerOpen,
}: {
traceId: string
traceInfo: ClusterItemInfo
summary?: TraceSummary
displayRank: number
clusteringLevel?: ClusteringLevel
+ drawerRowProps: TraceDrawerRowProps
+ isDrawerOpen: boolean
}): JSX.Element {
const [showFlow, setShowFlow] = useState(false)
const [showBullets, setShowBullets] = useState(false)
@@ -482,7 +504,13 @@ function TraceListItem({
: 'muted'
return (
- <div className="p-4 hover:bg-surface-secondary transition-colors">
+ <div
+ className={clsx(
+ 'p-4 transition-colors',
+ isDrawerOpen ? 'bg-accent-highlight-secondary' : 'hover:bg-surface-secondary'
+ )}
+ onClickCapture={drawerRowProps.onClickCapture}
+ >
{/* Header row with rank, title, and link */}
<div className="flex items-center gap-2 mb-2">
<LemonTag type="muted" size="small">
diff --git a/products/ai_observability/frontend/clusters/clusterTraceDrawerRow.test.ts b/products/ai_observability/frontend/clusters/clusterTraceDrawerRow.test.ts
new file mode 100644
index 000000000000..2f18a213d358
--- /dev/null
+++ b/products/ai_observability/frontend/clusters/clusterTraceDrawerRow.test.ts
@@ -0,0 +1,60 @@
+import type { TraceWithSummary } from './clusterDetailLogic'
+import { toClusterTraceDrawerRow } from './clusterTraceDrawerRow'
+import type { ClusterItemInfo, TraceSummary } from './types'
+
+function member(info: Partial<ClusterItemInfo> = {}, summary?: Partial<TraceSummary>): TraceWithSummary {
+ return {
+ traceId: 'item-key',
+ traceInfo: {
+ distance_to_centroid: 0,
+ rank: 1,
+ x: 0,
+ y: 0,
+ timestamp: '2024-01-01T00:00:00+00:00',
+ trace_id: 'trace-1',
+ ...info,
+ },
+ summary: summary && {
+ traceId: 'summary-trace',
+ title: '',
+ flowDiagram: '',
+ bullets: '',
+ interestingNotes: '',
+ timestamp: '',
+ ...summary,
+ },
+ }
+}
+
+describe('toClusterTraceDrawerRow', () => {
+ it.each([
+ [
+ 'a trace opens the trace',
+ 'trace',
+ member(),
+ { traceId: 'item-key', timestamp: '2024-01-01T00:00:00.000Z', stepId: null },
+ ],
+ [
+ 'a generation opens its step in its trace',
+ 'generation',
+ member({ generation_id: 'gen-1' }),
+ { traceId: 'trace-1', timestamp: '2024-01-01T00:00:00.000Z', stepId: 'gen-1' },
+ ],
+ [
+ 'a generation with no timestamp has none',
+ 'generation',
+ member({ timestamp: '' }),
+ { traceId: 'trace-1', timestamp: null, stepId: null },
+ ],
+ [
+ 'an evaluation opens the generation it judged, never its own uuid',
+ 'evaluation',
+ member({ trace_id: 'eval-uuid' }, { traceId: 'trace-2', generationId: 'gen-2' }),
+ { traceId: 'trace-2', timestamp: null, stepId: 'gen-2' },
+ ],
+ ['an evaluation with no summary has no row', 'evaluation', member(), null],
+ ['an evaluation whose summary has no trace has no row', 'evaluation', member({}, { traceId: '' }), null],
+ ] as const)('maps %s', (_name, level, item, expected) => {
+ expect(toClusterTraceDrawerRow(item, level)).toEqual(expected)
+ })
+})
diff --git a/products/ai_observability/frontend/clusters/clusterTraceDrawerRow.ts b/products/ai_observability/frontend/clusters/clusterTraceDrawerRow.ts
new file mode 100644
index 000000000000..ffc1676b21de
--- /dev/null
+++ b/products/ai_observability/frontend/clusters/clusterTraceDrawerRow.ts
@@ -0,0 +1,22 @@
+import { dayjs } from 'lib/dayjs'
+
+import type { TraceListRow } from '../redesign/trace/traceListRows'
+import type { TraceWithSummary } from './clusterDetailLogic'
+import type { ClusteringLevel } from './types'
+
+export function toClusterTraceDrawerRow(
+ { traceId, traceInfo, summary }: TraceWithSummary,
+ clusteringLevel: ClusteringLevel
+): TraceListRow | null {
+ if (clusteringLevel === 'evaluation') {
+ // `traceInfo.trace_id` is the evaluation's own uuid when its metadata could not be resolved.
+ return summary?.traceId
+ ? { traceId: summary.traceId, timestamp: null, stepId: summary.generationId ?? null }
+ : null
+ }
+ const timestamp = traceInfo.timestamp ? dayjs.utc(traceInfo.timestamp).toISOString() : null
+ if (clusteringLevel === 'generation') {
+ return { traceId: traceInfo.trace_id, timestamp, stepId: traceInfo.generation_id ?? null }
+ }
+ return { traceId, timestamp, stepId: null }
+}
diff --git a/products/ai_observability/frontend/clusters/traceSummaryLoader.test.ts b/products/ai_observability/frontend/clusters/traceSummaryLoader.test.ts
index 054197585f53..8597ac7512b5 100644
--- a/products/ai_observability/frontend/clusters/traceSummaryLoader.test.ts
+++ b/products/ai_observability/frontend/clusters/traceSummaryLoader.test.ts
@@ -1,18 +1,34 @@
import { deriveVerdict } from './traceSummaryLoader'
describe('deriveVerdict', () => {
- it('reads a true result as a pass for a normal evaluation', () => {
- expect(deriveVerdict('true', null, false)).toBe('pass')
- expect(deriveVerdict('false', null, false)).toBe('fail')
+ it.each([
+ ['true', 'false'],
+ ['TRUE', 'FALSE'],
+ [true, false],
+ ])('reads %s as a pass and %s as a fail for a normal evaluation', (passing, failing) => {
+ expect(deriveVerdict(passing, null, false)).toBe('pass')
+ expect(deriveVerdict(failing, null, false)).toBe('fail')
})
- it('reads a true result as a fail for a detector', () => {
- expect(deriveVerdict('true', null, true)).toBe('fail')
- expect(deriveVerdict('false', null, true)).toBe('pass')
+ it.each([
+ ['true', 'false'],
+ [true, false],
+ ])('reads %s as a fail and %s as a pass for a detector', (failing, passing) => {
+ expect(deriveVerdict(failing, null, true)).toBe('fail')
+ expect(deriveVerdict(passing, null, true)).toBe('pass')
})
- it.each([false, true])('reports a non-applicable result as n/a (detector: %s)', (trueIsFailure) => {
- expect(deriveVerdict('true', 'false', trueIsFailure)).toBe('n/a')
+ it.each([
+ ['true', 'false', false],
+ ['true', 'false', true],
+ [true, false, false],
+ [true, false, true],
+ ])('reports %s as n/a when applicable is %s (detector: %s)', (result, applicable, trueIsFailure) => {
+ expect(deriveVerdict(result, applicable, trueIsFailure)).toBe('n/a')
+ })
+
+ it('keeps a boolean true applicable from hiding the verdict', () => {
+ expect(deriveVerdict(true, true, false)).toBe('pass')
})
it.each([false, true])('reports an unreadable result as unknown (detector: %s)', (trueIsFailure) => {
diff --git a/products/ai_observability/frontend/clusters/traceSummaryLoader.ts b/products/ai_observability/frontend/clusters/traceSummaryLoader.ts
index ad7ac3f8d3b3..56f3e4b41067 100644
--- a/products/ai_observability/frontend/clusters/traceSummaryLoader.ts
+++ b/products/ai_observability/frontend/clusters/traceSummaryLoader.ts
@@ -227,16 +227,20 @@ export function formatEvalTitle(summary: TraceSummary | undefined, maxReasoningC
return `${name} — ${preview}`
}
+// HogQL returns these properties as text or as booleans, depending on how the column is typed.
+function toVerdictText(value: string | boolean | null): string {
+ return String(value ?? '').toLowerCase()
+}
+
export function deriveVerdict(
- result: string | null,
- applicable: string | null,
+ result: string | boolean | null,
+ applicable: string | boolean | null,
trueIsFailure: boolean
): 'pass' | 'fail' | 'n/a' | 'unknown' {
- const a = (applicable || '').toLowerCase()
- if (a === 'false') {
+ if (toVerdictText(applicable) === 'false') {
return 'n/a'
}
- const v = (result || '').toLowerCase()
+ const v = toVerdictText(result)
if (v !== 'true' && v !== 'false') {
return 'unknown'
}
diff --git a/products/ai_observability/frontend/components/EvaluationRunTargetCell.tsx b/products/ai_observability/frontend/components/EvaluationRunTargetCell.tsx
index 6f5323c5b9af..131dca211beb 100644
--- a/products/ai_observability/frontend/components/EvaluationRunTargetCell.tsx
+++ b/products/ai_observability/frontend/components/EvaluationRunTargetCell.tsx
@@ -6,6 +6,7 @@ import { Link } from '@posthog/lemon-ui'
import { urls } from 'scenes/urls'
import { EvaluationRun } from '../evaluations/types'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { sanitizeTraceUrlSearchParams } from '../utils'
// Generation-target runs link to the specific event in the trace; trace-target
@@ -31,7 +32,7 @@ export function EvaluationRunTargetCell({ run }: { run: EvaluationRun }): JSX.El
// (debounce window, manual re-runs), and without one the trace query scans from the
// beginning, which always finds the trace.
const to = combineUrl(urls.aiObservabilityTrace(run.trace_id), {
- ...sanitizeTraceUrlSearchParams(searchParams, { removeSearch: true }),
+ ...sanitizeTraceUrlSearchParams(withoutTraceDrawerParams(searchParams), { removeSearch: true }),
tab: 'evals',
...(run.generation_id ? { event: run.generation_id } : {}),
}).url
@@ -39,7 +40,7 @@ export function EvaluationRunTargetCell({ run }: { run: EvaluationRun }): JSX.El
return (
<div className="font-mono text-sm">
- <Link to={to} className="text-primary">
+ <Link to={to} className="text-primary" data-attr="llma-eval-run-target-link">
{label}
</Link>
</div>
diff --git a/products/ai_observability/frontend/datasets/DatasetItems.test.tsx b/products/ai_observability/frontend/datasets/DatasetItems.test.tsx
new file mode 100644
index 000000000000..067ae3493acb
--- /dev/null
+++ b/products/ai_observability/frontend/datasets/DatasetItems.test.tsx
@@ -0,0 +1,166 @@
+import { cleanup, fireEvent, render, waitFor, within } from '@testing-library/react'
+import { BindLogic } from 'kea'
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
+
+import { initKeaTests } from '~/test/init'
+
+import type { DatasetItemReadApi as DatasetItem, DatasetReadApi as Dataset } from '../generated/api.schemas'
+import { traceDrawerLogic } from '../redesign/trace/traceDrawerLogic'
+import { aiObservabilityDatasetLogic } from './aiObservabilityDatasetLogic'
+import { DatasetItems } from './DatasetItems'
+import { datasetsApi } from './datasetsApi'
+
+jest.mock('./datasetsApi', () => ({
+ datasetsApi: {
+ getDataset: jest.fn(),
+ getItem: jest.fn(),
+ listDatasets: jest.fn(),
+ listItems: jest.fn(),
+ listRevisions: jest.fn(),
+ },
+}))
+
+const FLAG = FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN
+const DATASET_ID = 'dataset-1'
+const TIMESTAMP = '2024-01-01T00:00:00Z'
+const TRACE_LINK = '[data-attr="dataset-item-trace-link"]'
+
+const DATASET: Dataset = {
+ tags: [],
+ id: DATASET_ID,
+ name: 'Dataset',
+ description: '',
+ metadata: {},
+ team_id: 997,
+ created_at: TIMESTAMP,
+ updated_at: TIMESTAMP,
+ created_by: null,
+ archived: false,
+ current_revision: null,
+ current_revision_id: null,
+ user_access_level: 'editor',
+}
+
+const ITEM_WITHOUT_TRACE: DatasetItem = {
+ id: 'item-1',
+ dataset: DATASET_ID,
+ client_item_id: null,
+ version: 1,
+ version_id: 'version-1',
+ dataset_revision: 1,
+ dataset_revision_id: 'revision-1',
+ archived: false,
+ input: {},
+ expected_output: {},
+ source_output: null,
+ metadata: {},
+ source_trace_id: null,
+ source_timestamp: null,
+ source_event_id: null,
+ created_by: null,
+ created_at: TIMESTAMP,
+ updated_at: TIMESTAMP,
+ version_created_at: TIMESTAMP,
+ version_created_by: null,
+ team_id: 997,
+}
+
+const ITEM_WITH_TRACE: DatasetItem = {
+ ...ITEM_WITHOUT_TRACE,
+ id: 'item-2',
+ source_trace_id: 'trace-1',
+ source_timestamp: TIMESTAMP,
+ source_event_id: 'event-1',
+}
+
+const ITEM_WITHOUT_TIMESTAMP: DatasetItem = {
+ ...ITEM_WITH_TRACE,
+ id: 'item-3',
+ source_trace_id: 'trace-2',
+ source_timestamp: null,
+}
+
+describe('DatasetItems', () => {
+ let logic: ReturnType<typeof aiObservabilityDatasetLogic.build>
+
+ const traceLink = (): Element => {
+ const link = document.querySelector(TRACE_LINK)
+ if (!link) {
+ throw new Error('No trace link')
+ }
+ return link
+ }
+
+ beforeEach(async () => {
+ initKeaTests()
+ localStorage.clear()
+ const mockDatasetsApi = jest.mocked(datasetsApi)
+ mockDatasetsApi.getDataset.mockResolvedValue(DATASET)
+ mockDatasetsApi.getItem.mockResolvedValue(ITEM_WITH_TRACE)
+ mockDatasetsApi.listDatasets.mockResolvedValue({ results: [], count: 0 })
+ mockDatasetsApi.listItems.mockResolvedValue({
+ results: [ITEM_WITHOUT_TRACE, ITEM_WITH_TRACE, ITEM_WITHOUT_TIMESTAMP],
+ count: 3,
+ })
+ mockDatasetsApi.listRevisions.mockResolvedValue({ results: [], count: 0 })
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FLAG], { [FLAG]: true })
+ router.actions.push(urls.aiObservabilityDataset(DATASET_ID))
+ logic = aiObservabilityDatasetLogic({ datasetId: DATASET_ID })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ render(
+ <BindLogic logic={aiObservabilityDatasetLogic} props={{ datasetId: DATASET_ID }}>
+ <DatasetItems dataset={DATASET} />
+ </BindLogic>
+ )
+ await waitFor(() => expect(document.querySelector(TRACE_LINK)).not.toBeNull())
+ })
+
+ afterEach(() => {
+ cleanup()
+ logic.unmount()
+ })
+
+ it('opens the drawer on the source event from the trace link', () => {
+ fireEvent.click(traceLink())
+
+ expect(router.values.location.pathname).toContain(urls.aiObservabilityDataset(DATASET_ID))
+ expect(router.values.searchParams).toEqual({ trace: 'trace-1', ts: TIMESTAMP, step: 'event-1' })
+ })
+
+ it('does nothing on a click elsewhere in the row', () => {
+ const row = traceLink().closest('tr')
+ if (!row) {
+ throw new Error('No row')
+ }
+
+ fireEvent.click(within(row).getByText('Active'))
+
+ expect(router.values.location.pathname).toContain(urls.aiObservabilityDataset(DATASET_ID))
+ expect(router.values.searchParams).toEqual({})
+ })
+
+ it('gives the drawer only the rows that show a trace link', () => {
+ expect(traceDrawerLogic({ listId: 'dataset-items' }).values.rows).toEqual([
+ { traceId: 'trace-1', timestamp: TIMESTAMP, stepId: 'event-1' },
+ ])
+ })
+
+ it('still opens the item modal from the ID link', () => {
+ const idLink = document.querySelector('[data-attr="dataset-item-open"]')
+ if (!idLink) {
+ throw new Error('No ID link')
+ }
+
+ fireEvent.click(idLink)
+
+ expect(router.values.searchParams).toMatchObject({ item: ITEM_WITHOUT_TRACE.id })
+ expect(logic.values.isDatasetItemModalOpen).toBe(true)
+ })
+})
diff --git a/products/ai_observability/frontend/datasets/DatasetItems.tsx b/products/ai_observability/frontend/datasets/DatasetItems.tsx
index f755edf0251c..f10ca02fb321 100644
--- a/products/ai_observability/frontend/datasets/DatasetItems.tsx
+++ b/products/ai_observability/frontend/datasets/DatasetItems.tsx
@@ -20,11 +20,23 @@ import { urls } from 'scenes/urls'
import { UserBasicType } from '~/types'
import type { DatasetItemReadApi as DatasetItem, DatasetReadApi as Dataset } from '../generated/api.schemas'
+import { TraceDrawerHost } from '../redesign/trace/TraceDrawerHost'
+import { useTraceDrawerTable } from '../redesign/trace/TraceDrawerRowsHost'
+import { TraceListRow } from '../redesign/trace/traceListRows'
import { truncateValue } from '../utils'
import { aiObservabilityDatasetLogic } from './aiObservabilityDatasetLogic'
import { JSONColumn } from './JSONColumn'
import { RefreshButton } from './RefreshButton'
+const TRACE_DRAWER_LIST_ID = 'dataset-items'
+const TRACE_LINK = '[data-attr="dataset-item-trace-link"]'
+
+function toTraceDrawerRow(item: DatasetItem): TraceListRow | null {
+ return item.source_trace_id && item.source_timestamp
+ ? { traceId: item.source_trace_id, timestamp: item.source_timestamp, stepId: item.source_event_id }
+ : null
+}
+
export function DatasetItems({ dataset }: { dataset: Dataset }): JSX.Element {
const {
archivingDatasetItemId,
@@ -57,6 +69,7 @@ export function DatasetItems({ dataset }: { dataset: Dataset }): JSX.Element {
} = useActions(aiObservabilityDatasetLogic)
const { searchParams } = useValues(router)
const canChangeDatasetStatus = canManageDataset && !isHistoricalRevision
+ const drawerTableProps = useTraceDrawerTable(TRACE_DRAWER_LIST_ID, TRACE_LINK, toTraceDrawerRow)
const columns: LemonTableColumns<DatasetItem> = [
{
@@ -91,6 +104,7 @@ export function DatasetItems({ dataset }: { dataset: Dataset }): JSX.Element {
event: item.source_event_id ?? undefined,
timestamp: item.source_timestamp,
})}
+ data-attr="dataset-item-trace-link"
>
{truncateValue(item.source_trace_id)}
</Link>
@@ -294,7 +308,9 @@ export function DatasetItems({ dataset }: { dataset: Dataset }): JSX.Element {
pagination={pagination}
nouns={['dataset item', 'dataset items']}
emptyState="No items in this dataset yet."
+ {...drawerTableProps}
/>
+ <TraceDrawerHost listId={TRACE_DRAWER_LIST_ID} />
</div>
)
}
diff --git a/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.test.ts b/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.test.ts
index 8bd6d7e26529..311bd009e18c 100644
--- a/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.test.ts
+++ b/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.test.ts
@@ -1182,6 +1182,19 @@ describe('aiObservabilityDatasetLogic', () => {
})
})
+ it('keeps the dataset id in the URL when mounting on filters before the dataset loads', () => {
+ logic.unmount()
+ const datasetUrl = urls.aiObservabilityDataset(mockDataset.id)
+ router.actions.push(datasetUrl, { page: '2' })
+
+ logic = aiObservabilityDatasetLogic({ datasetId: mockDataset.id })
+ logic.mount()
+
+ expect(logic.values.dataset).toBeNull()
+ expect(logic.values.filters.page).toBe(2)
+ expect(router.values.location.pathname).toContain(datasetUrl)
+ })
+
it('loads an exact revision and archived items from URL state', async () => {
const datasetUrl = urls.aiObservabilityDataset(mockDataset.id)
@@ -1222,6 +1235,7 @@ describe('aiObservabilityDatasetLogic', () => {
expect(router.values.hashParams).toEqual({ section: 'items' })
expect(logic.values.activeTab).toBe('items')
+ router.actions.replace(datasetUrl, { search: 'quality', trace: 'a', ts: '2026', step: 'x' })
await expectLogic(logic, () => {
logic.actions.setActiveTab(DatasetTab.Metadata)
}).toFinishAllListeners()
@@ -1229,10 +1243,11 @@ describe('aiObservabilityDatasetLogic', () => {
expect(router.values.searchParams).toEqual({ search: 'quality', tab: 'metadata' })
await expectLogic(logic, () => {
- router.actions.push(datasetUrl, { search: 'quality' })
+ router.actions.push(datasetUrl, { search: 'quality', trace: 'a' })
}).toFinishAllListeners()
expect(logic.values.activeTab).toBe('items')
+ expect(router.values.searchParams).toEqual({ search: 'quality', trace: 'a' })
expect(mockDatasetsApi.listItems).not.toHaveBeenCalled()
})
diff --git a/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.ts b/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.ts
index bfa8c68116ed..4e018875b096 100644
--- a/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.ts
+++ b/products/ai_observability/frontend/datasets/aiObservabilityDatasetLogic.ts
@@ -40,6 +40,7 @@ import type {
PaginatedDatasetItemReadListApi,
PaginatedDatasetRevisionReadListApi,
} from '../generated/api.schemas'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { truncateValue } from '../utils'
import { aiObservabilityDatasetsLogic, getDatasetDetailUrl, getDatasetListUrl } from './aiObservabilityDatasetsLogic'
import { datasetsApi } from './datasetsApi'
@@ -1281,15 +1282,19 @@ export const aiObservabilityDatasetLogic = kea<aiObservabilityDatasetLogicType>(
},
})),
- trackedActionToUrl(({ values }) => ({
- setActiveTab: () => [
- router.values.location.pathname,
- {
- ...router.values.searchParams,
- tab: values.activeTab === DatasetTab.Metadata ? DatasetTab.Metadata : undefined,
- },
- router.values.hashParams,
- ],
+ trackedActionToUrl(({ props, values }) => ({
+ setActiveTab: () => {
+ const tab = values.activeTab === DatasetTab.Metadata ? DatasetTab.Metadata : undefined
+ // urlToAction also syncs the tab from a URL the person went back to, and that URL must keep its open trace.
+ if ((router.values.searchParams.tab === DatasetTab.Metadata ? DatasetTab.Metadata : undefined) === tab) {
+ return
+ }
+ return [
+ router.values.location.pathname,
+ { ...withoutTraceDrawerParams(router.values.searchParams), tab },
+ router.values.hashParams,
+ ]
+ },
setFilters: () => {
const nextSearchParams = {
...router.values.searchParams,
@@ -1299,7 +1304,7 @@ export const aiObservabilityDatasetLogic = kea<aiObservabilityDatasetLogicType>(
revision: values.filters.revision ?? undefined,
}
return [
- urls.aiObservabilityDataset(isDataset(values.dataset) ? values.dataset.id : 'new'),
+ urls.aiObservabilityDataset(isDataset(values.dataset) ? values.dataset.id : props.datasetId),
nextSearchParams,
{},
{ replace: true },
@@ -1308,7 +1313,7 @@ export const aiObservabilityDatasetLogic = kea<aiObservabilityDatasetLogicType>(
closeModalAndRefetchDatasetItems: () => {
const nextSearchParams = { ...router.values.searchParams, item: undefined }
return [
- urls.aiObservabilityDataset(isDataset(values.dataset) ? values.dataset.id : 'new'),
+ urls.aiObservabilityDataset(isDataset(values.dataset) ? values.dataset.id : props.datasetId),
nextSearchParams,
{},
{ replace: false },
diff --git a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx
index aeaa825ea34b..fdcaa5dbccc5 100644
--- a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx
+++ b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx
@@ -18,6 +18,7 @@ import { AccessControlLevel, AccessControlResourceType } from '~/types'
import { useAttachedContext } from 'products/posthog_ai/frontend/api/logics'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { providerKeyStateIssueDescription, providerLabel } from '../settings/providerKeyStateUtils'
import { EvaluationBackfillsTab } from './components/EvaluationBackfillsTab'
import { EvaluationFirstResultStatus } from './components/EvaluationFirstResultStatus'
@@ -76,7 +77,10 @@ export function AIObservabilityEvaluation(): JSX.Element {
const unsaved = hasUnsavedChanges || (!isNewEvaluation && reportConfigDirty)
const { saveEvaluation, resetEvaluation, setActiveTab, setFormStep } = useActions(llmEvaluationLogic)
const { push } = useActions(router)
- const settingsUrl = combineUrl(urls.aiObservabilityEvaluations(), { ...searchParams, tab: 'settings' }).url
+ const settingsUrl = combineUrl(urls.aiObservabilityEvaluations(), {
+ ...withoutTraceDrawerParams(searchParams),
+ tab: 'settings',
+ }).url
useAttachedContext(
evaluation ? [{ type: 'evaluation', key: evaluation.id || 'new', label: evaluation.name ?? undefined }] : null
diff --git a/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.test.tsx b/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.test.tsx
index 73711c8e3668..901caa7b6df7 100644
--- a/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.test.tsx
+++ b/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.test.tsx
@@ -1,15 +1,21 @@
import '@testing-library/jest-dom'
-import { cleanup, render, screen } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { BindLogic, Provider } from 'kea'
+import { combineUrl, router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
import api from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { getEvaluationResultDisplay } from '../../components/EvaluationResultTag'
+import { traceDrawerLogic } from '../../redesign/trace/traceDrawerLogic'
+import { traceViewHostLogic } from '../../redesign/trace/traceViewHostLogic'
import { llmEvaluationLogic } from '../llmEvaluationLogic'
import { EvaluationConfig, EvaluationRun } from '../types'
import { EvaluationRunsTable } from './EvaluationRunsTable'
@@ -124,4 +130,114 @@ describe('EvaluationRunsTable', () => {
expect(screen.getByText('No evaluation runs found')).toBeInTheDocument()
})
+
+ describe('opening the trace drawer', () => {
+ const FLAG = FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN
+ const PATH = urls.aiObservabilityEvaluation('eval-123')
+ const olderRun: EvaluationRun = {
+ ...passingRun,
+ id: 'run-2',
+ generation_id: null,
+ trace_id: 'trace-2',
+ timestamp: '2023-01-01T10:00:00Z',
+ }
+ const sessionRun: EvaluationRun = {
+ ...passingRun,
+ id: 'run-3',
+ generation_id: null,
+ trace_id: '',
+ session_id: 'session-1',
+ reasoning: 'Session verdict',
+ }
+
+ function renderRuns(url: string = PATH): void {
+ localStorage.clear()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FLAG], { [FLAG]: true })
+ router.actions.push(url)
+ logic.actions.loadEvaluationRunsSuccess([olderRun, passingRun, sessionRun])
+ renderTable()
+ }
+
+ const targetLink = (traceId: string = 'trace-1'): Element => {
+ const link = document.querySelector(`[data-attr="llma-eval-run-target-link"][href*="${traceId}"]`)
+ if (!link) {
+ throw new Error('No target link')
+ }
+ return link
+ }
+
+ it.each([
+ ['the row', (): Element | null => targetLink().closest('tr')?.querySelector('td') ?? null],
+ ['the target link', (): Element => targetLink()],
+ ])('opens from %s on the Evals tab with the generation selected', (_name, target) => {
+ renderRuns()
+ const clicked = target()
+ if (!clicked) {
+ throw new Error('No click target')
+ }
+
+ fireEvent.click(clicked)
+
+ expect(router.values.location.pathname).toContain(PATH)
+ expect(router.values.searchParams).toEqual({ trace: 'trace-1', step: 'gen-1' })
+ const { hostId } = traceDrawerLogic({ listId: 'evaluation-runs' }).values
+ expect(traceViewHostLogic({ hostId }).values.detailTab).toBe('evals')
+ })
+
+ it.each([
+ ['from the list', PATH],
+ ['with that trace open on a step', combineUrl(PATH, { trace: 'trace-2', step: 'gen-2' }).url],
+ ])('opens a trace-level run on the root of its trace %s', (_name, url) => {
+ renderRuns(url)
+ const linkParams = combineUrl(targetLink('trace-2').getAttribute('href') ?? '').searchParams
+
+ fireEvent.click(targetLink('trace-2'))
+
+ expect(linkParams).toMatchObject({ tab: 'evals' })
+ expect(linkParams).not.toHaveProperty('event')
+ expect(router.values.searchParams).toEqual({ trace: 'trace-2', step: 'trace-2' })
+ const { fullPageHref } = traceDrawerLogic({ listId: 'evaluation-runs' }).values
+ expect(combineUrl(fullPageHref ?? '').searchParams).toMatchObject({ event: 'trace-2' })
+ })
+
+ it('leaves a session run to its session link', () => {
+ renderRuns()
+ const sessionLink = screen.getByText(/session session-1/)
+ const sessionRow = sessionLink.closest('tr')
+ if (!sessionRow) {
+ throw new Error('No session row')
+ }
+
+ fireEvent.click(sessionRow)
+ expect(router.values.searchParams).not.toHaveProperty('trace')
+
+ fireEvent.click(sessionLink)
+ expect(router.values.location.pathname).toContain(urls.aiObservabilitySession('session-1'))
+ })
+
+ it('gives the drawer the rows with a trace in the order on screen', () => {
+ renderRuns()
+ const drawer = traceDrawerLogic({ listId: 'evaluation-runs' })
+ expect(drawer.values.rows).toEqual([
+ { traceId: 'trace-2', timestamp: null, stepId: 'trace-2' },
+ { traceId: 'trace-1', timestamp: null, stepId: 'gen-1' },
+ ])
+
+ fireEvent.click(screen.getByText('Timestamp'))
+
+ expect(drawer.values.rows.map(({ traceId }) => traceId)).toEqual(['trace-1', 'trace-2'])
+ })
+
+ it('leaves the drawer params out of the target link', () => {
+ renderRuns(combineUrl(PATH, { trace: 'trace-2', ts: '2024-01-01T00:00:00Z', step: 'gen-2' }).url)
+
+ const params = combineUrl(targetLink().getAttribute('href') ?? '').searchParams
+
+ expect(params).toMatchObject({ tab: 'evals', event: 'gen-1' })
+ expect(params).not.toHaveProperty('trace')
+ expect(params).not.toHaveProperty('ts')
+ expect(params).not.toHaveProperty('step')
+ })
+ })
})
diff --git a/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.tsx b/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.tsx
index 7d4f52f8cf3a..3323a73d1785 100644
--- a/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.tsx
+++ b/products/ai_observability/frontend/evaluations/components/EvaluationRunsTable.tsx
@@ -10,6 +10,9 @@ import { EvaluationExplanation } from '../../components/EvaluationExplanation'
import { EvaluationResultTag, compareEvaluationResults } from '../../components/EvaluationResultTag'
import { EvaluationRunTargetCell } from '../../components/EvaluationRunTargetCell'
import { EvaluationRunTimestampCell } from '../../components/EvaluationRunTimestampCell'
+import { TraceDrawerHost } from '../../redesign/trace/TraceDrawerHost'
+import { useTraceDrawerTable } from '../../redesign/trace/TraceDrawerRowsHost'
+import { TraceListRow } from '../../redesign/trace/traceListRows'
import { evaluationIsDetector } from '../constants'
import { evaluationSupportsRunOutcomes } from '../evaluationCapabilities'
import { llmEvaluationLogic } from '../llmEvaluationLogic'
@@ -23,6 +26,15 @@ const SENTIMENT_FILTER_OPTIONS: { value: SentimentEvaluationRunsFilter; label: s
{ value: 'all', label: 'All' },
]
+const TRACE_DRAWER_LIST_ID = 'evaluation-runs'
+const TRACE_LINK = '[data-attr="llma-eval-run-target-link"]'
+
+// A run's timestamp can be long after its trace, so it makes a poor lookup hint.
+// A trace-level run shows on the root only, and with no step the view can open on a generation instead.
+function toTraceDrawerRow(run: EvaluationRun): TraceListRow | null {
+ return run.trace_id ? { traceId: run.trace_id, timestamp: null, stepId: run.generation_id || run.trace_id } : null
+}
+
function SentimentEvaluationRunsFilters(): JSX.Element {
const { evaluationRunsFilter } = useValues(llmEvaluationLogic)
const { setEvaluationRunsFilter } = useActions(llmEvaluationLogic)
@@ -54,6 +66,7 @@ export function EvaluationRunsTable(): JSX.Element {
runsSummary,
} = useValues(llmEvaluationLogic)
const { refreshEvaluationRuns, setRunsDates, loadOlderEvaluationRuns } = useActions(llmEvaluationLogic)
+ const drawerTableProps = useTraceDrawerTable(TRACE_DRAWER_LIST_ID, TRACE_LINK, toTraceDrawerRow)
const showOutcomeFilters =
evaluation?.output_type === 'numeric' ||
evaluation?.output_type === 'categorical' ||
@@ -151,84 +164,88 @@ export function EvaluationRunsTable(): JSX.Element {
]
return (
- <div className="space-y-4">
- <div className="flex flex-wrap gap-2 justify-between items-center">
- <div className="flex flex-wrap items-center gap-2">
- {!runsBackfillId && (
- <DateFilter
- dateFrom={runsDateRange.date_from}
- dateTo={runsDateRange.date_to}
- onChange={setRunsDates}
+ <>
+ <div className="space-y-4">
+ <div className="flex flex-wrap gap-2 justify-between items-center">
+ <div className="flex flex-wrap items-center gap-2">
+ {!runsBackfillId && (
+ <DateFilter
+ dateFrom={runsDateRange.date_from}
+ dateTo={runsDateRange.date_to}
+ onChange={setRunsDates}
+ size="small"
+ />
+ )}
+ {showOutcomeFilters ? (
+ <EvaluationRunsFilters />
+ ) : showSentimentFilters ? (
+ <SentimentEvaluationRunsFilters />
+ ) : null}
+ </div>
+ <div className="flex flex-wrap items-center gap-2">
+ {evaluationRuns.length > 0 && !evaluationRunsError && (
+ <>
+ <span className="text-muted text-sm">
+ {!evaluationRunsHasMore
+ ? evaluationRuns.length === 1
+ ? 'Showing 1 run.'
+ : `Showing all ${evaluationRuns.length.toLocaleString()} runs.`
+ : matchingRunsTotal && matchingRunsTotal > evaluationRuns.length
+ ? `Showing the latest ${evaluationRuns.length.toLocaleString()} of ${matchingRunsTotal.toLocaleString()} runs.`
+ : `Showing the latest ${evaluationRuns.length.toLocaleString()} runs.`}
+ </span>
+ {evaluationRunsHasMore && (
+ <LemonButton
+ type="secondary"
+ size="small"
+ onClick={() => loadOlderEvaluationRuns()}
+ loading={evaluationRunsLoading}
+ data-attr="llma-evaluation-runs-load-older"
+ >
+ Load older runs
+ </LemonButton>
+ )}
+ </>
+ )}
+ <LemonButton
+ type="secondary"
+ icon={<IconRefresh />}
+ onClick={refreshEvaluationRuns}
+ loading={evaluationRunsLoading}
size="small"
- />
- )}
- {showOutcomeFilters ? (
- <EvaluationRunsFilters />
- ) : showSentimentFilters ? (
- <SentimentEvaluationRunsFilters />
- ) : null}
+ data-attr="llma-evaluation-refresh-runs"
+ >
+ Refresh
+ </LemonButton>
+ </div>
</div>
- <div className="flex flex-wrap items-center gap-2">
- {evaluationRuns.length > 0 && !evaluationRunsError && (
- <>
- <span className="text-muted text-sm">
- {!evaluationRunsHasMore
- ? evaluationRuns.length === 1
- ? 'Showing 1 run.'
- : `Showing all ${evaluationRuns.length.toLocaleString()} runs.`
- : matchingRunsTotal && matchingRunsTotal > evaluationRuns.length
- ? `Showing the latest ${evaluationRuns.length.toLocaleString()} of ${matchingRunsTotal.toLocaleString()} runs.`
- : `Showing the latest ${evaluationRuns.length.toLocaleString()} runs.`}
- </span>
- {evaluationRunsHasMore && (
- <LemonButton
- type="secondary"
- size="small"
- onClick={() => loadOlderEvaluationRuns()}
- loading={evaluationRunsLoading}
- data-attr="llma-evaluation-runs-load-older"
- >
- Load older runs
- </LemonButton>
- )}
- </>
- )}
- <LemonButton
- type="secondary"
- icon={<IconRefresh />}
- onClick={refreshEvaluationRuns}
- loading={evaluationRunsLoading}
- size="small"
- data-attr="llma-evaluation-refresh-runs"
+
+ {showStaleRunsBanner && (
+ <LemonBanner
+ type="error"
+ action={{
+ children: 'Try again',
+ onClick: refreshEvaluationRuns,
+ 'data-attr': 'llma-evaluation-runs-stale-retry',
+ }}
>
- Refresh
- </LemonButton>
- </div>
- </div>
+ We couldn't refresh the evaluation runs. The runs below may be out of date.
+ </LemonBanner>
+ )}
- {showStaleRunsBanner && (
- <LemonBanner
- type="error"
- action={{
- children: 'Try again',
- onClick: refreshEvaluationRuns,
- 'data-attr': 'llma-evaluation-runs-stale-retry',
+ <LemonTable
+ columns={columns}
+ dataSource={filteredEvaluationRuns}
+ loading={evaluationRunsLoading}
+ rowKey="id"
+ pagination={{
+ pageSize: 50,
}}
- >
- We couldn't refresh the evaluation runs. The runs below may be out of date.
- </LemonBanner>
- )}
-
- <LemonTable
- columns={columns}
- dataSource={filteredEvaluationRuns}
- loading={evaluationRunsLoading}
- rowKey="id"
- pagination={{
- pageSize: 50,
- }}
- emptyState={emptyState}
- />
- </div>
+ emptyState={emptyState}
+ {...drawerTableProps}
+ />
+ </div>
+ <TraceDrawerHost listId={TRACE_DRAWER_LIST_ID} />
+ </>
)
}
diff --git a/products/ai_observability/frontend/evaluations/evaluationNavigation.test.ts b/products/ai_observability/frontend/evaluations/evaluationNavigation.test.ts
index 8f3c0359b99d..74fb69b9c5da 100644
--- a/products/ai_observability/frontend/evaluations/evaluationNavigation.test.ts
+++ b/products/ai_observability/frontend/evaluations/evaluationNavigation.test.ts
@@ -57,6 +57,13 @@ describe('evaluation navigation', () => {
'Evaluations',
`${urls.aiObservabilityEvaluations()}?tab=settings`,
],
+ [
+ 'evaluation runs with the trace drawer open',
+ false,
+ { tab: 'settings', trace: 'trace-id', ts: '2024-01-01T00:00:00Z', step: 'step-id' },
+ 'Evaluations',
+ `${urls.aiObservabilityEvaluations()}?tab=settings`,
+ ],
])('returns a draft opened from the %s to its origin', (_origin, isNew, searchParams, name, path) => {
expect(getEvaluationBackTarget(isNew, searchParams)).toMatchObject({ name, path })
})
diff --git a/products/ai_observability/frontend/evaluations/evaluationNavigation.ts b/products/ai_observability/frontend/evaluations/evaluationNavigation.ts
index 0c97f63e32d9..555667801631 100644
--- a/products/ai_observability/frontend/evaluations/evaluationNavigation.ts
+++ b/products/ai_observability/frontend/evaluations/evaluationNavigation.ts
@@ -2,6 +2,8 @@ import { combineUrl } from 'kea-router'
import { urls } from 'scenes/urls'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
+
export interface EvaluationBackTarget {
name: 'Evaluations' | 'Templates' | 'Sentiment' | 'Trace'
path: string
@@ -16,7 +18,7 @@ function searchParamsWithoutEvaluationSource(searchParams: Record<string, any>):
template: _template,
type: _type,
...remainingSearchParams
- } = searchParams
+ } = withoutTraceDrawerParams(searchParams)
return remainingSearchParams
}
diff --git a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts
index a845be03ad44..2a6f607f5635 100644
--- a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts
+++ b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts
@@ -1230,6 +1230,17 @@ return result`,
expect(router.values.searchParams.evaluation_tab).toBeUndefined()
})
+
+ it('leaves the trace drawer params behind on a tab change', async () => {
+ router.actions.push(combineUrl(urls.aiObservabilityEvaluation('eval-123'), { trace: 'a', step: 'b' }).url)
+ logic = llmEvaluationLogic({ evaluationId: 'eval-123' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadEvaluationSuccess'])
+
+ logic.actions.setActiveTab('configuration')
+
+ expect(router.values.searchParams).toEqual({ evaluation_tab: 'configuration' })
+ })
})
describe('async flows', () => {
diff --git a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts
index 6d79fd4ae147..e04ad0e18f37 100644
--- a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts
+++ b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts
@@ -26,6 +26,7 @@ import type { EvaluationBackfillApi, TestHogRequestApi, TestHogResultItemApi } f
import type { EvaluationApiOutputConfig } from '../generated/api.schemas'
import { parsePlaygroundProviderKeyId } from '../ModelPicker'
import { modelPickerLogic, type ModelOption, type ProviderModelGroup } from '../modelPickerLogic'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { LLMProviderKey, llmProviderKeysLogic, toLLMProvider } from '../settings/llmProviderKeysLogic'
import type { EvaluationConfig as TeamEvaluationConfig } from '../settings/llmProviderKeysLogic'
import { getUnhealthyProviderKey } from '../settings/providerKeyStateUtils'
@@ -2059,7 +2060,7 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([
return [
router.values.location.pathname,
- { ...router.values.searchParams, evaluation_tab: evaluationTab },
+ { ...withoutTraceDrawerParams(router.values.searchParams), evaluation_tab: evaluationTab },
router.values.hashParams,
{ replace: true },
]
diff --git a/products/ai_observability/frontend/prompts/LLMPromptScene.tsx b/products/ai_observability/frontend/prompts/LLMPromptScene.tsx
index e068d1c0ea6e..a013e44659bb 100644
--- a/products/ai_observability/frontend/prompts/LLMPromptScene.tsx
+++ b/products/ai_observability/frontend/prompts/LLMPromptScene.tsx
@@ -19,6 +19,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { ProductKey } from '~/queries/schema/schema-general'
import { AccessControlLevel, AccessControlResourceType, ActivityScope } from '~/types'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { PromptLogicProps, PromptMode, isPrompt, llmPromptLogic } from './llmPromptLogic'
import {
PromptCode,
@@ -206,7 +207,7 @@ export function LLMPromptScene(): JSX.Element {
onChange={(tab) =>
router.actions.replace(urls.aiObservabilityPrompt(prompt.name), {
...cleanPromptSearchParams(
- currentSearchParams,
+ withoutTraceDrawerParams(currentSearchParams),
prompt.is_latest ? null : prompt.version
),
tab,
diff --git a/products/ai_observability/frontend/prompts/llmPromptLogic.test.ts b/products/ai_observability/frontend/prompts/llmPromptLogic.test.ts
index 1d61a6f046da..94440ed524a4 100644
--- a/products/ai_observability/frontend/prompts/llmPromptLogic.test.ts
+++ b/products/ai_observability/frontend/prompts/llmPromptLogic.test.ts
@@ -1,6 +1,6 @@
import { MOCK_DEFAULT_TEAM } from '~/lib/api.mock'
-import { router } from 'kea-router'
+import { decodeParams, router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
@@ -331,6 +331,63 @@ describe('llmPromptLogic', () => {
logic.unmount()
})
+ describe('with the trace drawer open on the related traces', () => {
+ const PATH = '/prompt-management/prompts/my-test-prompt'
+ const LIST_PARAMS = { tab: 'usage', version: 1 }
+
+ async function mountWithEdits(): Promise<ReturnType<typeof llmPromptLogic.build>> {
+ const { versions, has_more, ...promptFields } = mockPrompt
+ mockResolve.mockResolvedValue({
+ prompt: promptFields,
+ versions,
+ has_more,
+ } as unknown as LLMPromptResolveResponseApi)
+ router.actions.push(PATH, LIST_PARAMS)
+ const logic = llmPromptLogic({ promptName: 'my-test-prompt' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadPromptSuccess'])
+ logic.actions.setPromptFormValue('prompt', 'edited')
+ mockResolve.mockClear()
+ return logic
+ }
+
+ function goBackTo(search: string): void {
+ router.actions.locationChanged({
+ method: 'POP',
+ pathname: router.values.location.pathname,
+ search,
+ searchParams: decodeParams(search, '?'),
+ hash: '',
+ hashParams: {},
+ url: `${router.values.location.pathname}${search}`,
+ })
+ }
+
+ it('does not reload the prompt or reset the form on open, step, close and back', async () => {
+ const logic = await mountWithEdits()
+
+ router.actions.push(PATH, { ...LIST_PARAMS, trace: 'a', ts: '2026' })
+ router.actions.push(PATH, { ...LIST_PARAMS, trace: 'b', step: 'gen-1' })
+ goBackTo('?tab=usage&version=1&trace=a&ts=2026')
+ router.actions.push(PATH, LIST_PARAMS)
+
+ expect(mockResolve).not.toHaveBeenCalled()
+ expect(logic.values.promptForm.prompt).toBe('edited')
+ logic.unmount()
+ })
+
+ it('still reloads when a list param changes with the drawer params', async () => {
+ const logic = await mountWithEdits()
+ router.actions.push(PATH, { ...LIST_PARAMS, trace: 'a' })
+
+ router.actions.push(PATH, { ...LIST_PARAMS, version: 2, trace: 'b' })
+
+ await expectLogic(logic).toDispatchActions(['loadPromptSuccess'])
+ expect(mockResolve).toHaveBeenCalledTimes(1)
+ logic.unmount()
+ })
+ })
+
it('discards a stale resolved-preview response once a newer load started', async () => {
const { versions, has_more, ...promptFields } = mockPrompt
mockResolve.mockResolvedValue({
diff --git a/products/ai_observability/frontend/prompts/llmPromptLogic.ts b/products/ai_observability/frontend/prompts/llmPromptLogic.ts
index cdcdff9e49af..374bd1253a65 100644
--- a/products/ai_observability/frontend/prompts/llmPromptLogic.ts
+++ b/products/ai_observability/frontend/prompts/llmPromptLogic.ts
@@ -51,6 +51,7 @@ import type {
LLMPromptResolveResponseApi,
} from '../generated/api.schemas'
import { buildAiObservabilityStorageConfig } from '../preferenceStorage'
+import { changedOnlyTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { llmPromptsLogic } from './llmPromptsLogic'
import { LLM_PROMPTS_FORCE_RELOAD_PARAM } from './llmPromptsLogic'
import { LLMPrompt, LLMPromptVersionSummary } from './types'
@@ -1616,13 +1617,18 @@ export const llmPromptLogic = kea<llmPromptLogicType>([
})),
urlToAction(({ actions, values }) => ({
- '/prompt-management/prompts/:name': (_, __, ___, { method }) => {
+ '/prompt-management/prompts/:name': (_, __, ___, { method, pathname, searchParams }, previousLocation) => {
if (method === 'PUSH' && values.isNewPrompt) {
actions.setPrompt(DEFAULT_PROMPT_FORM_VALUES)
actions.resetPromptForm(DEFAULT_PROMPT_FORM_VALUES)
return
}
+ // The trace drawer pushes each step, and opening or stepping it should not reload the prompt.
+ if (changedOnlyTraceDrawerParams(previousLocation, { pathname, searchParams })) {
+ return
+ }
+
// POP included: back/forward between versions lands on the same logic
// instance, so the selected version must be re-resolved from the URL.
if ((method === 'PUSH' || method === 'POP') && !values.isNewPrompt) {
diff --git a/products/ai_observability/frontend/prompts/promptSceneComponents.test.tsx b/products/ai_observability/frontend/prompts/promptSceneComponents.test.tsx
new file mode 100644
index 000000000000..3768cbf48a7e
--- /dev/null
+++ b/products/ai_observability/frontend/prompts/promptSceneComponents.test.tsx
@@ -0,0 +1,112 @@
+import { RenderResult, act, cleanup, fireEvent, render, waitFor } from '@testing-library/react'
+import { BindLogic } from 'kea'
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'
+import { performQuery } from '~/queries/query'
+import { NodeKind } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+
+import { llmPromptsResolveNameRetrieve } from '../generated/api'
+import type { LLMPromptResolveResponseApi } from '../generated/api.schemas'
+import { llmPromptLogic } from './llmPromptLogic'
+import { PromptRelatedTraces } from './promptSceneComponents'
+
+jest.mock('../generated/api', () => ({ llmPromptsResolveNameRetrieve: jest.fn() }))
+jest.mock('~/queries/query', () => ({ ...jest.requireActual('~/queries/query'), performQuery: jest.fn() }))
+
+const PROMPT_NAME = 'my-test-prompt'
+const PATH = `/prompt-management/prompts/${PROMPT_NAME}`
+const TRACES = [
+ { id: 'trace-1', createdAt: '2026-01-01T12:00:00Z', events: [], traceName: 'first' },
+ { id: 'trace-2', createdAt: '2026-01-01T13:00:00Z', events: [], traceName: 'second' },
+]
+
+function tracesRequests(): number {
+ return jest.mocked(performQuery).mock.calls.filter(([query]) => query.kind === NodeKind.TracesQuery).length
+}
+
+describe('PromptRelatedTraces', () => {
+ let logic: ReturnType<typeof llmPromptLogic.build>
+
+ async function renderList(): Promise<RenderResult> {
+ initKeaTests()
+ localStorage.clear()
+ jest.mocked(llmPromptsResolveNameRetrieve).mockResolvedValue({
+ prompt: {
+ id: 'prompt-1',
+ name: PROMPT_NAME,
+ prompt: 'You are a helpful assistant.',
+ version: 2,
+ latest_version: 2,
+ version_count: 1,
+ is_latest: true,
+ deleted: false,
+ created_at: '2024-01-02T00:00:00Z',
+ updated_at: '2024-01-02T00:00:00Z',
+ },
+ versions: [],
+ has_more: false,
+ } as unknown as LLMPromptResolveResponseApi)
+ jest.mocked(performQuery).mockReset()
+ jest.mocked(performQuery).mockImplementation(async (query) =>
+ query.kind === NodeKind.TracesQuery ? { results: TRACES } : { results: [] }
+ )
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN], {
+ [FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN]: true,
+ })
+ panelLayoutLogic.mount()
+ router.actions.push(PATH, { tab: 'usage' })
+ logic = llmPromptLogic({ promptName: PROMPT_NAME })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadPromptSuccess'])
+ const view = render(
+ <BindLogic logic={llmPromptLogic} props={{ promptName: PROMPT_NAME }}>
+ <PromptRelatedTraces />
+ </BindLogic>
+ )
+ await waitFor(() => expect(view.container.querySelector('[data-attr="trace-id-link"]')).not.toBeNull())
+ return view
+ }
+
+ afterEach(() => {
+ cleanup()
+ logic.unmount()
+ })
+
+ it.each([
+ ['the row', (view: RenderResult): Element | null => view.getByText('first').closest('tr')?.children[1] ?? null],
+ [
+ 'the ID link',
+ (view: RenderResult): Element | null => view.container.querySelector('[data-attr="trace-id-link"]'),
+ ],
+ ])('opens the drawer from %s and stays on the usage tab', async (_name, target) => {
+ const view = await renderList()
+ const clicked = target(view)
+ if (!clicked) {
+ throw new Error('No click target')
+ }
+
+ fireEvent.click(clicked)
+
+ expect(router.values.location.pathname).toContain(PATH)
+ expect(router.values.searchParams).toMatchObject({ tab: 'usage', trace: 'trace-1' })
+ })
+
+ it('does not refetch the traces when the prompt reloads', async () => {
+ await renderList()
+ expect(tracesRequests()).toBe(1)
+
+ await act(async () => {
+ logic.actions.loadPrompt()
+ await expectLogic(logic).toDispatchActions(['loadPromptSuccess'])
+ })
+
+ expect(tracesRequests()).toBe(1)
+ })
+})
diff --git a/products/ai_observability/frontend/prompts/promptSceneComponents.tsx b/products/ai_observability/frontend/prompts/promptSceneComponents.tsx
index d1553042250c..d12adf5d3a3d 100644
--- a/products/ai_observability/frontend/prompts/promptSceneComponents.tsx
+++ b/products/ai_observability/frontend/prompts/promptSceneComponents.tsx
@@ -34,8 +34,9 @@ import { Query } from '~/queries/Query/Query'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
import type { ExperimentBasicApi } from '../../../experiments/frontend/generated/api.schemas'
-import { useTracesQueryContext } from '../AIObservabilityTracesScene'
+import { toTraceDrawerRow, useTracesDrawerContext } from '../AIObservabilityTracesScene'
import { MarkdownOutline } from '../components/MarkdownOutline'
+import { TraceDrawerQueryHost } from '../redesign/trace/TraceDrawerQueryHost'
import { CreatePromptExperimentModal } from './CreatePromptExperimentModal'
import { createPromptExperimentModalLogic } from './createPromptExperimentModalLogic'
import { InsertPromptReferenceButton } from './InsertPromptReferenceButton'
@@ -512,10 +513,13 @@ function PromptDiffView(): JSX.Element {
)
}
+const PROMPT_TRACES_LIST_ID = 'prompt-traces'
+const PROMPT_TRACES_DATA_NODE_KEY = 'llm-analytics-prompt-traces'
+
export function PromptRelatedTraces(): JSX.Element {
const { prompt, relatedTracesQuery, viewAllTracesUrl, analyticsScope } = useValues(llmPromptLogic)
const { setRelatedTracesQuery } = useActions(llmPromptLogic)
- const tracesQueryContext = useTracesQueryContext()
+ const tracesQueryContext = useTracesDrawerContext(PROMPT_TRACES_LIST_ID, PROMPT_TRACES_DATA_NODE_KEY)
if (!prompt || !isPrompt(prompt)) {
return <></>
@@ -551,13 +555,21 @@ export function PromptRelatedTraces(): JSX.Element {
</div>
{relatedTracesQuery && (
- <DataTable
- query={relatedTracesQuery}
- setQuery={setRelatedTracesQuery}
- context={tracesQueryContext}
- uniqueKey="prompt-related-traces"
- attachTo={llmPromptLogic}
- />
+ <>
+ <DataTable
+ query={relatedTracesQuery}
+ setQuery={setRelatedTracesQuery}
+ context={tracesQueryContext}
+ uniqueKey="prompt-related-traces"
+ attachTo={llmPromptLogic}
+ />
+ <TraceDrawerQueryHost
+ listId={PROMPT_TRACES_LIST_ID}
+ dataNodeKey={PROMPT_TRACES_DATA_NODE_KEY}
+ query={relatedTracesQuery.source}
+ toRow={toTraceDrawerRow}
+ />
+ </>
)}
</div>
)
diff --git a/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.test.tsx b/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.test.tsx
index e93dd0bbe73d..28df6141414f 100644
--- a/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.test.tsx
+++ b/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.test.tsx
@@ -10,6 +10,7 @@ import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import { aiObservabilityTracesNodesRetrieve } from '../../generated/api'
import {
decodeIdSegment,
makeEvaluationResults,
@@ -18,11 +19,19 @@ import {
makeTraceResource,
} from './adapter/testFixtures'
import { TraceDrawerHost } from './TraceDrawerHost'
+import type { TraceDrawerListId } from './traceDrawerLists'
import { traceDrawerLogic } from './traceDrawerLogic'
import { TraceListRow } from './traceListRows'
import { traceViewHostLogic } from './traceViewHostLogic'
jest.mock('~/queries/query', () => ({ ...jest.requireActual('~/queries/query'), performQuery: jest.fn() }))
+jest.mock('../../generated/api', () => {
+ const actual = jest.requireActual('../../generated/api')
+ return {
+ ...actual,
+ aiObservabilityTracesNodesRetrieve: jest.fn(actual.aiObservabilityTracesNodesRetrieve),
+ }
+})
jest.mock('../../utils', () => ({
...jest.requireActual('../../utils'),
queryEvaluationRuns: jest.fn().mockResolvedValue([]),
@@ -30,7 +39,7 @@ jest.mock('../../utils', () => ({
const TRACE_BASE_URL = '/api/projects/:team_id/ai_observability/traces/:id'
const LIST_PATH = urls.aiObservabilityTraces()
-const LIST_ID = 'traces'
+const LIST_ID: TraceDrawerListId = 'traces'
const ROW_A: TraceListRow = { traceId: 'a', timestamp: '2026-09-01T10:15:00Z', stepId: null }
const ROW_B: TraceListRow = { traceId: 'b', timestamp: '2026-09-01T10:20:00Z', stepId: null }
@@ -54,6 +63,7 @@ function useTraceMocks(firstTraceReply: TraceReply): void {
[`${TRACE_BASE_URL}/evaluations/`]: () => [200, makeEvaluationResults()],
[`${TRACE_BASE_URL}/clusters/`]: () => [200, { clusters: [] }],
[`${TRACE_BASE_URL}/feedback/`]: () => [200, makeFeedback({ scores: [], responses: [] })],
+ [`${TRACE_BASE_URL}/summary/`]: () => [404, { detail: 'No summary yet.' }],
},
})
}
@@ -70,15 +80,15 @@ function setUp(url: string, sceneRect: Partial<DOMRect> = {}): void {
router.actions.push(url)
}
-function drawerUrl({ traceId, timestamp }: TraceListRow): string {
- return combineUrl(LIST_PATH, { trace: traceId, ts: timestamp ?? undefined }).url
+function drawerUrl({ traceId, timestamp }: TraceListRow, listPath: string = LIST_PATH): string {
+ return combineUrl(listPath, { trace: traceId, ts: timestamp ?? undefined }).url
}
-function renderHost(rows: TraceListRow[]): RenderResult {
- const logic = traceDrawerLogic({ listId: LIST_ID })
+function renderHost(rows: TraceListRow[], listId: TraceDrawerListId = LIST_ID): RenderResult {
+ const logic = traceDrawerLogic({ listId })
logic.mount()
logic.actions.setRows(rows)
- return render(<TraceDrawerHost listId={LIST_ID} />)
+ return render(<TraceDrawerHost listId={listId} />)
}
function attr(container: Element, name: string): HTMLElement {
@@ -150,6 +160,38 @@ describe('TraceDrawerHost', () => {
release()
})
+ it.each(['spans', 'summary'] as const)(
+ 'applies the opening of the list once, so stepping from %s stays there',
+ async (mode) => {
+ silenceKeaLoadersErrors()
+ useTraceMocks(answerTrace('a'))
+ setUp(drawerUrl(ROW_A, urls.aiObservabilityCluster('run-1', 3)))
+ const view = renderHost([ROW_A, ROW_B], 'cluster-traces')
+ const host = traceViewHostLogic({ hostId: traceDrawerLogic({ listId: 'cluster-traces' }).values.hostId })
+ await waitFor(() => expect(host.values.mode).toBe('summary'))
+ act(() => host.actions.setMode(mode))
+
+ fireEvent.click(attr(view.container, 'trace-drawer-next'))
+
+ await view.findAllByText('answer-b')
+ expect(host.values.mode).toBe(mode)
+ }
+ )
+
+ it('reads no node when it closes on a step other than the default', async () => {
+ useTraceMocks(answerTrace('a'))
+ setUp(combineUrl(LIST_PATH, { trace: 'a', ts: ROW_A.timestamp ?? undefined, step: 'span-1' }).url)
+ const view = renderHost([ROW_A])
+ await view.findAllByText('answer-a')
+ await waitFor(() => expect(aiObservabilityTracesNodesRetrieve).toHaveBeenCalled())
+ jest.mocked(aiObservabilityTracesNodesRetrieve).mockClear()
+
+ fireEvent.click(attr(view.container, 'trace-drawer-close'))
+
+ expect(router.values.searchParams.trace).toBeUndefined()
+ expect(aiObservabilityTracesNodesRetrieve).not.toHaveBeenCalled()
+ })
+
it('writes a clicked step to the list URL and stays on the list', async () => {
useTraceMocks(answerTrace('a'))
setUp(drawerUrl(ROW_A))
diff --git a/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.tsx b/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.tsx
index f41e421eb8ff..9bc25b918abf 100644
--- a/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.tsx
+++ b/products/ai_observability/frontend/redesign/trace/TraceDrawerHost.tsx
@@ -9,10 +9,11 @@ import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'
import { DetailPanel, isDetailPanelFullWidth } from '../shared/components/DetailPanel'
import { TraceViewContainer } from './adapter/TraceViewContainer'
import { TraceDrawerToolbar } from './components/TraceDrawerToolbar'
+import type { TraceDrawerListId } from './traceDrawerLists'
import { traceDrawerLogic } from './traceDrawerLogic'
export interface TraceDrawerHostProps {
- listId: string
+ listId: TraceDrawerListId
}
export function TraceDrawerHost({ listId }: TraceDrawerHostProps): JSX.Element | null {
diff --git a/products/ai_observability/frontend/redesign/trace/TraceDrawerQueryHost.tsx b/products/ai_observability/frontend/redesign/trace/TraceDrawerQueryHost.tsx
new file mode 100644
index 000000000000..291f7813b283
--- /dev/null
+++ b/products/ai_observability/frontend/redesign/trace/TraceDrawerQueryHost.tsx
@@ -0,0 +1,50 @@
+import { useValues } from 'kea'
+import { useMemo } from 'react'
+
+import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
+import { DataTableNode } from '~/queries/schema/schema-general'
+
+import { TraceDrawerHost } from './TraceDrawerHost'
+import type { TraceDrawerListId } from './traceDrawerLists'
+import { traceDrawerLogic } from './traceDrawerLogic'
+import { TraceDrawerRowsSync } from './TraceDrawerRowsHost'
+import { TraceListRow } from './traceListRows'
+
+export interface TraceDrawerQueryHostProps {
+ listId: TraceDrawerListId
+ dataNodeKey: string
+ query: DataTableNode['source']
+ /** Needs a stable identity, because a new function maps every row again. */
+ toRow: (result: unknown) => TraceListRow | null
+}
+
+function toRows(response: unknown, toRow: TraceDrawerQueryHostProps['toRow']): TraceListRow[] {
+ const results = typeof response === 'object' && response && 'results' in response ? response.results : null
+ if (!Array.isArray(results)) {
+ return []
+ }
+ return results.flatMap((result) => {
+ const row = toRow(result)
+ return row ? [row] : []
+ })
+}
+
+function TraceDrawerQueryRows({ listId, dataNodeKey, query, toRow }: TraceDrawerQueryHostProps): JSX.Element {
+ const { response } = useValues(dataNodeLogic({ key: dataNodeKey, query }))
+ const rows = useMemo(() => toRows(response, toRow), [response, toRow])
+
+ return <TraceDrawerRowsSync listId={listId} rows={rows} />
+}
+
+// Render this as a sibling after DataTable, so that DataTable builds the logic with its full props. Subscribing in the
+// list component would also rebuild the table context on each poll and re-render every row.
+export function TraceDrawerQueryHost(props: TraceDrawerQueryHostProps): JSX.Element {
+ const { isEnabled } = useValues(traceDrawerLogic({ listId: props.listId }))
+
+ return (
+ <>
+ {isEnabled ? <TraceDrawerQueryRows {...props} /> : null}
+ <TraceDrawerHost listId={props.listId} />
+ </>
+ )
+}
diff --git a/products/ai_observability/frontend/redesign/trace/TraceDrawerRowsHost.test.tsx b/products/ai_observability/frontend/redesign/trace/TraceDrawerRowsHost.test.tsx
new file mode 100644
index 000000000000..b034ddb852b1
--- /dev/null
+++ b/products/ai_observability/frontend/redesign/trace/TraceDrawerRowsHost.test.tsx
@@ -0,0 +1,42 @@
+import { renderHook } from '@testing-library/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { useTraceDrawerRows } from './TraceDrawerRowsHost'
+import { TraceListRow } from './traceListRows'
+
+const FLAG = FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN
+const ROW: TraceListRow = { traceId: 'a', timestamp: null, stepId: null }
+
+describe('useTraceDrawerRows', () => {
+ function setUp(flag: boolean): ReturnType<typeof useTraceDrawerRows> {
+ initKeaTests()
+ localStorage.clear()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FLAG], { [FLAG]: flag })
+ return renderHook(() => useTraceDrawerRows('traces', 'a')).result.current
+ }
+
+ it.each([
+ ['a row with no trace', true, null],
+ ['a list with the drawer disabled', false, ROW],
+ ])('adds nothing for %s', (_name, flag, row) => {
+ expect(setUp(flag).rowProps(row)).toEqual({})
+ })
+
+ it.each([
+ ['traces', true],
+ ['dataset-items', false],
+ ] as const)('marks %s rows as clickable only when the row opens the drawer: %s', (listId, clickable) => {
+ initKeaTests()
+ localStorage.clear()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FLAG], { [FLAG]: true })
+ const { rowProps } = renderHook(() => useTraceDrawerRows(listId, 'a')).result.current
+
+ expect(rowProps(ROW).className?.includes('cursor-pointer')).toBe(clickable)
+ })
+})
diff --git a/products/ai_observability/frontend/redesign/trace/TraceDrawerRowsHost.tsx b/products/ai_observability/frontend/redesign/trace/TraceDrawerRowsHost.tsx
new file mode 100644
index 000000000000..cadd919e006c
--- /dev/null
+++ b/products/ai_observability/frontend/redesign/trace/TraceDrawerRowsHost.tsx
@@ -0,0 +1,90 @@
+import clsx from 'clsx'
+import { useActions, useValues } from 'kea'
+import { MouseEventHandler, useCallback, useEffect } from 'react'
+
+import { TRACE_DRAWER_LISTS, TraceDrawerListId } from './traceDrawerLists'
+import { traceDrawerLogic } from './traceDrawerLogic'
+import { TRACE_DRAWER_OPEN_ROW_CLASS, opensTraceDrawer } from './traceDrawerRows'
+import { TraceListRow } from './traceListRows'
+
+export interface TraceDrawerRowProps {
+ className?: string
+ onClickCapture?: MouseEventHandler<HTMLElement>
+}
+
+export interface TraceDrawerRows {
+ isEnabled: boolean
+ openTraceId: string | null
+ rowProps: (row: TraceListRow | null) => TraceDrawerRowProps
+}
+
+export function useTraceDrawerRows(listId: TraceDrawerListId, linkSelector: string): TraceDrawerRows {
+ const logic = traceDrawerLogic({ listId })
+ const { isEnabled, openTraceId } = useValues(logic)
+ const { openRow } = useActions(logic)
+ const { rowClick } = TRACE_DRAWER_LISTS[listId]
+
+ const rowProps = useCallback(
+ (row: TraceListRow | null): TraceDrawerRowProps => {
+ if (!row || !isEnabled) {
+ return {}
+ }
+ return {
+ className: clsx(
+ rowClick && 'cursor-pointer',
+ row.traceId === openTraceId && TRACE_DRAWER_OPEN_ROW_CLASS
+ ),
+ onClickCapture: (event) => {
+ if (opensTraceDrawer(event, linkSelector, rowClick)) {
+ event.preventDefault()
+ event.stopPropagation()
+ // A row cannot take focus, and the panel gives focus back to what held it on opening.
+ event.currentTarget.querySelector<HTMLElement>(linkSelector)?.focus({ preventScroll: true })
+ openRow(row)
+ }
+ },
+ }
+ },
+ [isEnabled, linkSelector, openRow, openTraceId, rowClick]
+ )
+
+ return { isEnabled, openTraceId, rowProps }
+}
+
+export interface TraceDrawerTableProps<T> {
+ onRow: (record: T) => TraceDrawerRowProps
+ onSortedRowsChange: (records: T[]) => void
+}
+
+/** Props for a `LemonTable`. `toRow` needs a stable identity, and returns null for a record with no trace. */
+export function useTraceDrawerTable<T>(
+ listId: TraceDrawerListId,
+ linkSelector: string,
+ toRow: (record: T) => TraceListRow | null
+): TraceDrawerTableProps<T> {
+ const { rowProps } = useTraceDrawerRows(listId, linkSelector)
+ const { setRows } = useActions(traceDrawerLogic({ listId }))
+
+ const onRow = useCallback((record: T): TraceDrawerRowProps => rowProps(toRow(record)), [rowProps, toRow])
+ const onSortedRowsChange = useCallback(
+ (records: T[]): void => setRows(records.map(toRow).filter((row) => row !== null)),
+ [setRows, toRow]
+ )
+
+ return { onRow, onSortedRowsChange }
+}
+
+export interface TraceDrawerRowsSyncProps {
+ listId: TraceDrawerListId
+ rows: TraceListRow[]
+}
+
+export function TraceDrawerRowsSync({ listId, rows }: TraceDrawerRowsSyncProps): null {
+ const { setRows } = useActions(traceDrawerLogic({ listId }))
+
+ useEffect(() => {
+ setRows(rows)
+ }, [rows, setRows])
+
+ return null
+}
diff --git a/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.test.ts b/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.test.ts
index 746d101951d8..36cf870c75a1 100644
--- a/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.test.ts
+++ b/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.test.ts
@@ -25,4 +25,44 @@ describe('toBackLink', () => {
])('goes back to %s', (_name, searchParams, expected) => {
expect(toBackLink(searchParams).href).toBe(expected)
})
+
+ it.each([
+ ['evaluation', 'Back to evaluation'],
+ ['prompt', 'Back to prompt'],
+ ['constructor', 'Back'],
+ [undefined, 'Back'],
+ ])('follows an internal back_url with back_to %s', (backTo, label) => {
+ const backUrl = '/prompt-management/prompts/p1?tab=usage&search=invoice'
+
+ expect(toBackLink({ back_to: backTo, back_url: backUrl })).toEqual({ label, href: backUrl })
+ })
+
+ it('follows a back_url under a project prefix', () => {
+ const backUrl = '/project/1/ai-evals/evaluations/e1'
+
+ expect(toBackLink({ back_url: backUrl }).href).toBe(backUrl)
+ })
+
+ it.each([
+ 'https://x',
+ '//x',
+ '/\\x',
+ '/x\\y',
+ '/\t/x',
+ 'x',
+ '',
+ 5,
+ '/api/integrations/authorize?next=/x',
+ '/x/../api/y',
+ '/logout',
+ '/ai-observability/../logout',
+ '/ai-observabilityx/traces',
+ '/project/1/dashboard',
+ '/%2e%2e/api/y',
+ ])('ignores the back_url %s', (backUrl) => {
+ expect(toBackLink({ back_to: 'generations', back_url: backUrl, date_from: '-7d' })).toEqual({
+ label: 'Back to generations',
+ href: '/ai-observability/generations?date_from=-7d',
+ })
+ })
})
diff --git a/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.ts b/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.ts
index 78f101cc1086..7261cbb3d9cd 100644
--- a/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.ts
+++ b/products/ai_observability/frontend/redesign/trace/adapter/toBackLink.ts
@@ -1,20 +1,26 @@
import { combineUrl } from 'kea-router'
+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { urls } from 'scenes/urls'
import { sanitizeTraceUrlSearchParams } from '../../../utils'
+import { traceDrawerBackLabel } from '../traceDrawerLists'
+import { withoutTraceDrawerParams } from '../traceDrawerRows'
import { LabeledLink } from '../types'
type SearchParams = Record<string, unknown>
+// A second `/`, a backslash, or a tab or newline that browsers drop from a URL would leave the site.
+const INTERNAL_PATH = /^\/(?!\/)[^\\\s]*$/
+const BACK_URL_PATH_PREFIXES = ['/ai-observability/', '/ai-evals/', '/prompt-management/']
+
// The lists read `search` as their own search term.
function listParams(searchParams: SearchParams): SearchParams {
return sanitizeTraceUrlSearchParams(searchParams, { removeSearch: true })
}
export function toFullPageListParams(searchParams: SearchParams): SearchParams {
- const { trace: _trace, ts: _ts, step: _step, ...params } = listParams(searchParams)
- return params
+ return withoutTraceDrawerParams(listParams(searchParams))
}
// Matches the legacy scene: a link opened from a review queue returns to that queue, other links to the reviews tab.
@@ -26,15 +32,32 @@ function reviewsBackHref(searchParams: SearchParams): string {
}).url
}
+// An API path reaches the browser as a download, and an integration's authorize URL redirects off the site. The check
+// reads the resolved path, because `/x/../api/` reaches the same URL.
+function isInternalPath(url: unknown): url is string {
+ if (typeof url !== 'string' || !INTERNAL_PATH.test(url)) {
+ return false
+ }
+ const path = removeProjectIdIfPresent(new URL(url, window.location.origin).pathname)
+ return BACK_URL_PATH_PREFIXES.some((prefix) => path.startsWith(prefix))
+}
+
export function toBackLink(searchParams: SearchParams): LabeledLink {
- if (searchParams.back_to === 'reviews') {
- return { label: 'Back to reviews', href: reviewsBackHref(searchParams) }
+ const { back_to: backTo, back_url: backUrl } = searchParams
+ if (isInternalPath(backUrl)) {
+ return { label: traceDrawerBackLabel(backTo), href: backUrl }
+ }
+ if (backTo === 'reviews') {
+ return { label: traceDrawerBackLabel(backTo), href: reviewsBackHref(searchParams) }
}
- if (searchParams.back_to === 'generations') {
+ if (backTo === 'generations') {
return {
- label: 'Back to generations',
+ label: traceDrawerBackLabel(backTo),
href: combineUrl(urls.aiObservabilityGenerations(), listParams(searchParams)).url,
}
}
- return { label: 'Back to traces', href: combineUrl(urls.aiObservabilityTraces(), listParams(searchParams)).url }
+ return {
+ label: traceDrawerBackLabel('traces'),
+ href: combineUrl(urls.aiObservabilityTraces(), listParams(searchParams)).url,
+ }
}
diff --git a/products/ai_observability/frontend/redesign/trace/traceDrawerLists.ts b/products/ai_observability/frontend/redesign/trace/traceDrawerLists.ts
new file mode 100644
index 000000000000..920aa6bf3316
--- /dev/null
+++ b/products/ai_observability/frontend/redesign/trace/traceDrawerLists.ts
@@ -0,0 +1,77 @@
+import type { NodeDetailTab, TraceOpeningMode } from './types'
+
+// List ids are the `list` property of `llma trace drawer opened`, so renaming one breaks the event history.
+export type TraceDrawerListId =
+ | 'traces'
+ | 'generations'
+ | 'prompt-traces'
+ | 'reviews'
+ | 'evaluation-runs'
+ | 'dataset-items'
+ | 'cluster-traces'
+
+export interface TraceDrawerListConfig {
+ // Tested against the path without its project prefix. Other products use `trace` for their own ids, and on browser
+ // back the outgoing list is still mounted on the next list's URL, so a list reads `trace` on its own path only.
+ pathMatcher: RegExp
+ backTo: string
+ backLabel: string
+ openingMode?: TraceOpeningMode
+ detailTab?: NodeDetailTab
+ rowClick: boolean
+}
+
+export const TRACE_DRAWER_LISTS: Record<TraceDrawerListId, TraceDrawerListConfig> = {
+ traces: {
+ pathMatcher: /^\/ai-observability\/traces$/,
+ backTo: 'traces',
+ backLabel: 'Back to traces',
+ rowClick: true,
+ },
+ generations: {
+ pathMatcher: /^\/ai-observability\/generations$/,
+ backTo: 'generations',
+ backLabel: 'Back to generations',
+ rowClick: true,
+ },
+ 'prompt-traces': {
+ pathMatcher: /^\/prompt-management\/prompts\/[^/]+$/,
+ backTo: 'prompt',
+ backLabel: 'Back to prompt',
+ rowClick: true,
+ },
+ reviews: {
+ pathMatcher: /^\/ai-observability\/reviews$/,
+ backTo: 'reviews',
+ backLabel: 'Back to reviews',
+ rowClick: true,
+ },
+ 'evaluation-runs': {
+ pathMatcher: /^\/ai-evals\/evaluations\/(?!(?:templates|offline|scorers)$)[^/]+$/,
+ backTo: 'evaluation',
+ backLabel: 'Back to evaluation',
+ detailTab: 'evals',
+ rowClick: true,
+ },
+ 'dataset-items': {
+ pathMatcher: /^\/ai-evals\/evaluations\/offline\/datasets\/[^/]+$/,
+ backTo: 'dataset',
+ backLabel: 'Back to dataset',
+ rowClick: false,
+ },
+ 'cluster-traces': {
+ pathMatcher: /^\/ai-observability\/clusters\/[^/]+\/[^/]+$/,
+ backTo: 'cluster',
+ backLabel: 'Back to cluster',
+ openingMode: 'summary',
+ rowClick: false,
+ },
+}
+
+const BACK_LABELS: ReadonlyMap<unknown, string> = new Map(
+ Object.values(TRACE_DRAWER_LISTS).map(({ backTo, backLabel }) => [backTo, backLabel])
+)
+
+export function traceDrawerBackLabel(backTo: unknown): string {
+ return BACK_LABELS.get(backTo) ?? 'Back'
+}
diff --git a/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.test.ts b/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.test.ts
index 17a8fe74dc3f..6325dfbee093 100644
--- a/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.test.ts
+++ b/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.test.ts
@@ -1,4 +1,4 @@
-import { decodeParams, router } from 'kea-router'
+import { combineUrl, decodeParams, router } from 'kea-router'
import { getRouterContext } from 'kea-router/lib/router'
import posthog from 'posthog-js'
@@ -11,7 +11,9 @@ import { urls } from 'scenes/urls'
import { ProductIntentContext, ProductKey } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
+import type { TraceDrawerListId } from './traceDrawerLists'
import { traceDrawerLogic } from './traceDrawerLogic'
+import { withoutTraceDrawerParams } from './traceDrawerRows'
import { TraceListRow } from './traceListRows'
import { traceViewHostLogic } from './traceViewHostLogic'
import { traceViewPreferenceLogic } from './traceViewPreferenceLogic'
@@ -66,14 +68,18 @@ describe('traceDrawerLogic', () => {
goTo(browserHistory[browserHistory.length - 1])
}
- function mountDrawer(): void {
- logic = traceDrawerLogic({ listId: 'traces' })
+ function mountDrawer(listId: TraceDrawerListId = 'traces'): void {
+ logic = traceDrawerLogic({ listId })
logic.mount()
host = traceViewHostLogic({ hostId: logic.values.hostId })
host.mount()
}
- function setUp({ url = LIST_PATH, flag = true }: { url?: string; flag?: boolean } = {}): void {
+ function setUp({
+ url = LIST_PATH,
+ flag = true,
+ listId,
+ }: { url?: string; flag?: boolean; listId?: TraceDrawerListId } = {}): void {
initKeaTests()
localStorage.clear()
featureFlagLogic.mount()
@@ -89,7 +95,7 @@ describe('traceDrawerLogic', () => {
}
capture = jest.spyOn(posthog, 'capture')
- mountDrawer()
+ mountDrawer(listId)
}
afterEach(() => {
@@ -166,7 +172,7 @@ describe('traceDrawerLogic', () => {
it('keeps the selected step when a row with no step targets the open trace', () => {
setUp()
logic.actions.openRow(A)
- host.actions.requestStep('y')
+ host.actions.requestStep('y', 'a')
const url = browserHistory[browserHistory.length - 1]
logic.actions.openRow({ ...A, stepId: null })
@@ -191,12 +197,39 @@ describe('traceDrawerLogic', () => {
expect(host.values).toMatchObject({ mode: 'spans', detailTab: 'messages' })
})
+ it.each<[TraceDrawerListId, string, Record<string, unknown>]>([
+ ['traces', LIST_PATH, { mode: 'spans', detailTab: 'messages', openingMode: null }],
+ [
+ 'evaluation-runs',
+ urls.aiObservabilityEvaluation('e1'),
+ { mode: 'spans', detailTab: 'evals', openingMode: null },
+ ],
+ [
+ 'cluster-traces',
+ urls.aiObservabilityCluster('run-1', 3),
+ { mode: 'spans', detailTab: 'messages', openingMode: 'summary' },
+ ],
+ ])('opens %s with its own opening, and keeps what the person changed when stepping', (listId, url, opening) => {
+ setUp({ url, listId })
+ host.actions.setMode('thread')
+ host.actions.setDetailTab('raw')
+ logic.actions.setRows([A, B])
+
+ logic.actions.openRow(A)
+ expect(host.values).toMatchObject(opening)
+
+ host.actions.setMode('thread')
+ host.actions.setDetailTab('raw')
+ logic.actions.stepTo('next')
+ expect(host.values).toMatchObject({ mode: 'thread', detailTab: 'raw', openingMode: null })
+ })
+
it('goes back through each trace it stepped through, and back to the list', () => {
setUp()
logic.actions.setRows([A, B, C])
logic.actions.openRow(A)
logic.actions.stepTo('next')
- host.actions.requestStep('b-step')
+ host.actions.requestStep('b-step', 'b')
logic.actions.stepTo('next')
goBack()
@@ -266,25 +299,30 @@ describe('traceDrawerLogic', () => {
it.each([
['opening', (): void => logic.actions.openRow(B)],
['stepping', (): void => logic.actions.stepTo('next')],
- ['a requested step', (): void => host.actions.requestStep('gen-2')],
+ ['a requested step', (): void => host.actions.requestStep('gen-2', '1.50')],
['closing', (): void => logic.actions.close()],
])('keeps the other params and the hash when %s', (_name, write) => {
- setUp({ url: `${LIST_PATH}?trace_search=1.50&date_from=-7d&trace=1.50&ts=2.50&step=3.50#panel=discussion` })
+ setUp({
+ url: `${LIST_PATH}?trace_search=1.50&review_search=007&on=TRUE&filters=[{"a":1}]&date_from=-7d&trace=1.50&ts=2.50&step=3.50#panel=discussion`,
+ })
logic.actions.setRows([{ traceId: '1.50', timestamp: '2.50', stepId: '3.50' }, B])
write()
expect(param('trace_search')).toBe('1.50')
+ expect(param('review_search')).toBe('007')
+ expect(param('on')).toBe('TRUE')
+ expect(router.values.searchParams.filters).toEqual([{ a: 1 }])
expect(param('date_from')).toBe('-7d')
expect(router.values.hashParams).toEqual({ panel: 'discussion' })
})
- it('keeps the raw open trace when a step is written', () => {
- setUp({ url: `${LIST_PATH}?trace=1.50&ts=2.50` })
+ it.each(['1.50', '{"a": 1}'])('keeps the raw open trace %s when a step is written', (traceId) => {
+ setUp({ url: combineUrl(LIST_PATH, { trace: traceId, ts: '2.50' }).url })
- host.actions.requestStep('gen-2')
+ host.actions.requestStep('gen-2', traceId)
- expect(logic.values.openRef).toEqual({ traceId: '1.50', timestamp: '2.50', stepId: 'gen-2' })
+ expect(logic.values.openRef).toEqual({ traceId, timestamp: '2.50', stepId: 'gen-2' })
expect(browserHistory).toHaveLength(1)
})
@@ -292,7 +330,7 @@ describe('traceDrawerLogic', () => {
setUp({ url: `${LIST_PATH}?trace=a&step=1.50` })
const replaceState = jest.spyOn(routerHistory(), 'replaceState')
- host.actions.requestStep('1.50')
+ host.actions.requestStep('1.50', 'a')
expect(replaceState).not.toHaveBeenCalled()
})
@@ -300,7 +338,7 @@ describe('traceDrawerLogic', () => {
it('leaves the list URL alone for a step requested while closed', () => {
setUp()
- host.actions.requestStep('gen-2')
+ host.actions.requestStep('gen-2', 'a')
expect(param('step')).toBeNull()
})
@@ -310,10 +348,10 @@ describe('traceDrawerLogic', () => {
logic.actions.setRows([A, B])
logic.actions.openRow(A)
- expect(host.values.requestedStepId).toBe('x')
+ expect(host.values).toMatchObject({ requestedStepId: 'x', requestedTraceId: 'a' })
logic.actions.stepTo('next')
- expect(host.values.requestedStepId).toBeNull()
+ expect(host.values).toMatchObject({ requestedStepId: null, requestedTraceId: 'b' })
})
it.each([
@@ -329,34 +367,108 @@ describe('traceDrawerLogic', () => {
expect(logic.values.isEnabled).toBe(false)
expect(router.values.location.pathname).toContain(urls.aiObservabilityTrace('a/b'))
- expect(router.values.searchParams).toEqual({ timestamp: '2026-01-01', event: 'gen-1' })
+ expect(router.values.searchParams).toEqual({
+ date_from: '-7d',
+ timestamp: '2026-01-01',
+ event: 'gen-1',
+ back_to: 'traces',
+ back_url: `${LIST_PATH}?date_from=-7d`,
+ })
expect(capturedEvents()).toEqual([])
expect(addProductIntent).not.toHaveBeenCalled()
})
- it('strips its params on unmount, so changing tab closes the drawer', () => {
+ it('sends a trace-level link to the trace page with no event, because that page is the legacy scene', () => {
+ const path = urls.aiObservabilityEvaluation('e1')
+
+ setUp({ url: `${path}?trace=a`, flag: false, listId: 'evaluation-runs' })
+
+ expect(router.values.location.pathname).toContain(urls.aiObservabilityTrace('a'))
+ expect(router.values.searchParams).toEqual({ tab: 'evals', back_to: 'evaluation', back_url: path })
+ })
+
+ it('keeps its params on unmount, so a list that remounts while it loads reopens the trace', () => {
setUp({ url: `${LIST_PATH}?trace_search=1.50&trace=a&ts=2026&step=x` })
logic.actions.setRows([A, B])
logic.actions.stepTo('next')
+ const search = router.values.location.search
host.unmount()
logic.unmount()
- expect(router.values.location.search).toBe('?trace_search=1.50')
+ expect(router.values.location.search).toBe(search)
expect(capturedEvents()).toContainEqual(['llma trace drawer closed', { steps: 1 }])
+
+ mountDrawer()
+ expect(logic.values.openTraceId).toBe(B.traceId)
})
- it.each(['/ai-observability/generations', '/project/1/ai-observability/generations'])(
- 'still strips its params from the tab %s',
- (tabPath) => {
- setUp()
- goTo(`${tabPath}?date_from=-7d&trace=a&ts=2026&step=x`)
+ it('stays open when the browser goes back to a list with an open drawer', () => {
+ const openSearch = '?date_from=-7d&trace=a&ts=2026&step=x'
+ setUp({ url: urls.aiObservabilityGenerations(), listId: 'generations' })
- logic.unmount()
+ goTo(`${LIST_PATH}${openSearch}`)
+ const previousList = traceDrawerLogic({ listId: 'traces' })
+ const unmountPreviousList = previousList.mount()
+ logic.unmount()
- expect(router.values.location.search).toBe('?date_from=-7d')
- }
- )
+ expect(previousList.values.openTraceId).toBe('a')
+ expect(router.values.location.search).toBe(openSearch)
+ expect(capturedEvents()).toEqual([['llma trace drawer opened', { list: 'traces' }]])
+ unmountPreviousList()
+ })
+
+ it('leaves the next list closed when a tab link drops the drawer params', () => {
+ setUp({ url: `${LIST_PATH}?date_from=-7d&trace=a&ts=2026&step=x` })
+
+ router.actions.push(
+ combineUrl(urls.aiObservabilityGenerations(), withoutTraceDrawerParams(router.values.searchParams)).url
+ )
+ const nextList = traceDrawerLogic({ listId: 'generations' })
+ const unmountNextList = nextList.mount()
+ logic.unmount()
+
+ expect(nextList.values.openRef).toBeNull()
+ expect(param('date_from')).toBe('-7d')
+ expect(capturedEvents()).toEqual([
+ ['llma trace drawer opened', { list: 'traces' }],
+ ['llma trace drawer closed', { steps: 0 }],
+ ])
+ unmountNextList()
+ })
+
+ it.each<[TraceDrawerListId, string]>([
+ ['traces', urls.aiObservabilityTraces()],
+ ['generations', urls.aiObservabilityGenerations()],
+ ['prompt-traces', urls.aiObservabilityPrompt('p1')],
+ ['reviews', urls.aiObservabilityReviews()],
+ ['evaluation-runs', urls.aiObservabilityEvaluation('e1')],
+ ['evaluation-runs', `/project/1${urls.aiObservabilityEvaluation('e1')}`],
+ ['dataset-items', urls.aiObservabilityDataset('d1')],
+ ['cluster-traces', urls.aiObservabilityCluster('run:1', 3)],
+ ])('opens %s at %s', (listId, path) => {
+ setUp({ url: `${path}?trace=a`, listId })
+
+ expect(logic.values.openTraceId).toBe('a')
+ })
+
+ it.each<[TraceDrawerListId, string]>([
+ ['traces', urls.aiObservabilityTrace('a')],
+ ['traces', urls.aiObservabilityGenerations()],
+ ['prompt-traces', urls.aiObservabilityPrompts()],
+ ['evaluation-runs', urls.aiObservabilityEvaluations()],
+ ['evaluation-runs', urls.aiObservabilityEvaluationTemplates()],
+ ['evaluation-runs', urls.aiObservabilityScorers()],
+ ['evaluation-runs', '/ai-evals/evaluations/offline'],
+ ['evaluation-runs', urls.aiObservabilityDataset('d1')],
+ ['dataset-items', urls.aiObservabilityEvaluation('e1')],
+ ['cluster-traces', urls.aiObservabilityClusters('run:1')],
+ ])('leaves %s closed at %s', (listId, path) => {
+ setUp({ url: `${path}?trace=a`, listId })
+
+ expect(logic.values.openTraceId).toBeNull()
+ expect(capturedEvents()).toEqual([])
+ })
it.each([
['enabled', true],
@@ -455,7 +567,7 @@ describe('traceDrawerLogic', () => {
it('links to the full page with the selected step and the list params', () => {
setUp({ url: `${LIST_PATH}?trace_search=1.50&date_from=-7d&trace=a%2Fb%23c&ts=2026-01-01&step=gen-1` })
- host.actions.requestStep('gen-2')
+ host.actions.requestStep('gen-2', 'a/b#c')
const href = logic.values.fullPageHref ?? ''
@@ -466,6 +578,30 @@ describe('traceDrawerLogic', () => {
timestamp: '2026-01-01',
event: 'gen-2',
back_to: 'traces',
+ back_url: `${LIST_PATH}?trace_search=1.50&date_from=-7d`,
+ })
+ })
+
+ it.each<[TraceDrawerListId, string, string]>([
+ ['evaluation-runs', urls.aiObservabilityEvaluation('e1'), 'evals'],
+ ['cluster-traces', urls.aiObservabilityCluster('run-1', 3), 'summary'],
+ ])('links to the full page of %s on the view it opened', (listId, path, tab) => {
+ setUp({ url: `${path}?tab=stale&trace=a&step=x`, listId })
+
+ expect(combineUrl(logic.values.fullPageHref ?? '').searchParams).toMatchObject({ tab, event: 'x' })
+ })
+
+ it('links to the full page with the back target of its own list, without the project prefix', () => {
+ setUp({
+ url: '/project/1/prompt-management/prompts/p1?tab=usage&trace=a&ts=2026&step=x',
+ listId: 'prompt-traces',
+ })
+
+ const { searchParams } = combineUrl(logic.values.fullPageHref ?? '')
+
+ expect(searchParams).toMatchObject({
+ back_to: 'prompt',
+ back_url: '/prompt-management/prompts/p1?tab=usage',
})
})
diff --git a/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.ts b/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.ts
index d547d7d75ab3..f0fced988765 100644
--- a/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.ts
+++ b/products/ai_observability/frontend/redesign/trace/traceDrawerLogic.ts
@@ -25,13 +25,15 @@ import { ProductIntentContext, ProductKey } from '~/queries/schema/schema-genera
import { toFullPageListParams } from './adapter/toBackLink'
import { rawSearchParam } from './rawSearchParam'
import { shouldCloseOnEscape } from './shouldCloseOnEscape'
+import { TRACE_DRAWER_LISTS, TraceDrawerListConfig, TraceDrawerListId } from './traceDrawerLists'
+import { TRACE_DRAWER_PARAMS, withoutTraceDrawerParams } from './traceDrawerRows'
import { TraceListRow, uniqueTraces } from './traceListRows'
import { traceViewHostLogic } from './traceViewHostLogic'
import { traceViewPreferenceLogic } from './traceViewPreferenceLogic'
import type { TraceViewChoice } from './types'
export interface TraceDrawerLogicProps {
- listId: string
+ listId: TraceDrawerListId
}
export type TraceStepDirection = 'previous' | 'next'
@@ -43,22 +45,24 @@ export interface TraceDrawerPosition {
const CLOSE_ON_ESCAPE_DISPOSABLE = 'closeOnEscape'
-const AI_OBSERVABILITY_PATH_PREFIX = '/ai-observability/'
-
-const TEXT_PARAMS = ['trace_search', 'trace', 'ts', 'step']
-
function traceDrawerHostId(listId: string): string {
return `trace-drawer-${listId}`
}
-// Other products use `trace` for their own ids, and tab links carry the drawer params across this product's paths.
-function isAIObservabilityPath(pathname: string): boolean {
- return removeProjectIdIfPresent(pathname).startsWith(AI_OBSERVABILITY_PATH_PREFIX)
+// kea-router loses the text of a number or boolean, so a typed `1.50` must stay raw. A JSON param such as `filters` must
+// stay parsed, because kea-router pads a string shaped like JSON and reads it back as a string. The drawer's own params
+// are ids, so they stay raw whatever their shape.
+function keepsRawText(name: string, value: unknown): boolean {
+ return TRACE_DRAWER_PARAMS.includes(name) || typeof value === 'number' || typeof value === 'boolean'
}
-function withTextParams(searchParams: Record<string, unknown>, search: string): Record<string, unknown> {
- const textParams = TEXT_PARAMS.map((name) => [name, rawSearchParam(search, name) ?? undefined])
- return { ...searchParams, ...Object.fromEntries(textParams) }
+function withRawParams(searchParams: Record<string, unknown>, search: string): Record<string, unknown> {
+ return Object.fromEntries(
+ Object.entries(searchParams).map(([name, value]) => [
+ name,
+ keepsRawText(name, value) ? (rawSearchParam(search, name) ?? value) : value,
+ ])
+ )
}
function toDrawerParams(row: TraceListRow | null): Record<string, string | undefined> {
@@ -73,7 +77,7 @@ function writeUrlParams(method: 'push' | 'replace', changes: Record<string, stri
try {
router.actions[method](
pathname,
- { ...withTextParams(router.values.searchParams, search), ...changes },
+ { ...withRawParams(router.values.searchParams, search), ...changes },
router.values.hashParams
)
} finally {
@@ -97,6 +101,24 @@ function isNumberRewriteOf(current: TraceListRow, previous: TraceListRow): boole
)
}
+function toFullPageUrl(
+ { traceId, timestamp }: TraceListRow,
+ stepId: string | null,
+ { backTo, openingMode, detailTab }: TraceDrawerListConfig,
+ { pathname, search }: { pathname: string; search: string },
+ searchParams: Record<string, unknown>
+): string {
+ const listParams = withRawParams(searchParams, search)
+ return combineUrl(urls.aiObservabilityTrace(traceId), {
+ ...toFullPageListParams(listParams),
+ timestamp: timestamp ?? undefined,
+ event: stepId ?? undefined,
+ tab: openingMode ?? detailTab,
+ back_to: backTo,
+ back_url: combineUrl(removeProjectIdIfPresent(pathname), withoutTraceDrawerParams(listParams)).url,
+ }).url
+}
+
function trackDrawerClosed(cache: Record<string, any>): void {
if (cache.stepsTaken === undefined) {
return
@@ -125,8 +147,12 @@ export interface traceDrawerLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface traceDrawerLogicActions {
- requestStep: (stepId: string | null) => {
+ requestStep: (
+ stepId: string | null,
+ traceId: string | null
+ ) => {
stepId: string | null
+ traceId: string | null
} // traceViewHostLogic
setDetailTab: (tab: import('./types').NodeDetailTab) => {
tab: import('./types').NodeDetailTab
@@ -134,6 +160,9 @@ export interface traceDrawerLogicActions {
setMode: (mode: import('./types').TraceMode) => {
mode: import('./types').TraceMode
} // traceViewHostLogic
+ setOpeningMode: (mode: import('./types').TraceOpeningMode) => {
+ mode: import('./types').TraceOpeningMode
+ } // traceViewHostLogic
close: () => {
value: true
}
@@ -150,11 +179,18 @@ export interface traceDrawerLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface traceDrawerLogicMeta {
- key: string
+ key: TraceDrawerListId
__keaTypeGenInternalSelectorTypes: {
- hostId: (listId: string) => string
+ hostId: (listId: TraceDrawerListId) => string
isEnabled: (activeView: TraceViewChoice) => boolean
- openRef: (location: { hash: string; pathname: string; search: string }) => TraceListRow | null
+ openRef: (
+ location: {
+ hash: string
+ pathname: string
+ search: string
+ },
+ listId: TraceDrawerListId
+ ) => TraceListRow | null
openTraceId: (openRef: TraceListRow | null) => string | null
traces: (rows: TraceListRow[]) => TraceListRow[]
openIndex: (traces: TraceListRow[], openTraceId: string | null) => number
@@ -164,12 +200,13 @@ export interface traceDrawerLogicMeta {
fullPageHref: (
openRef: TraceListRow | null,
requestedStepId: string | null,
- searchParams: Record<string, any>,
+ listId: TraceDrawerListId,
location: {
hash: string
pathname: string
search: string
- }
+ },
+ searchParams: Record<string, any>
) => string | null
}
}
@@ -194,7 +231,7 @@ export const traceDrawerLogic = kea<traceDrawerLogicType>([
],
actions: [
traceViewHostLogic({ hostId: traceDrawerHostId(props.listId) }),
- ['requestStep', 'setMode', 'setDetailTab'],
+ ['requestStep', 'setMode', 'setDetailTab', 'setOpeningMode'],
],
})),
actions({
@@ -215,9 +252,13 @@ export const traceDrawerLogic = kea<traceDrawerLogicType>([
hostId: [(_, p) => [p.listId], (listId: string): string => traceDrawerHostId(listId)],
isEnabled: [(s) => [s.activeView], (activeView: TraceViewChoice): boolean => activeView === 'new'],
openRef: [
- () => [router.selectors.location],
- ({ pathname, search }: { pathname: string; search: string }): TraceListRow | null => {
- const traceId = isAIObservabilityPath(pathname) ? rawSearchParam(search, 'trace') : null
+ (_, p) => [router.selectors.location, p.listId],
+ (
+ { pathname, search }: { pathname: string; search: string },
+ listId: TraceDrawerListId
+ ): TraceListRow | null => {
+ const isOwnPath = TRACE_DRAWER_LISTS[listId].pathMatcher.test(removeProjectIdIfPresent(pathname))
+ const traceId = isOwnPath ? rawSearchParam(search, 'trace') : null
return traceId
? { traceId, timestamp: rawSearchParam(search, 'ts'), stepId: rawSearchParam(search, 'step') }
: null
@@ -246,20 +287,21 @@ export const traceDrawerLogic = kea<traceDrawerLogicType>([
openIndex < 0 ? null : (traces[openIndex + 1] ?? null),
],
fullPageHref: [
- (s) => [s.openRef, s.requestedStepId, router.selectors.searchParams, router.selectors.location],
+ (s, p) => [
+ s.openRef,
+ s.requestedStepId,
+ p.listId,
+ router.selectors.location,
+ router.selectors.searchParams,
+ ],
(
openRef: TraceListRow | null,
requestedStepId: string | null,
- searchParams: Record<string, unknown>,
- { search }: { search: string }
+ listId: TraceDrawerListId,
+ location: { pathname: string; search: string },
+ searchParams: Record<string, unknown>
): string | null =>
- openRef &&
- combineUrl(urls.aiObservabilityTrace(openRef.traceId), {
- ...toFullPageListParams(withTextParams(searchParams, search)),
- timestamp: openRef.timestamp ?? undefined,
- event: requestedStepId ?? undefined,
- back_to: 'traces',
- }).url,
+ openRef && toFullPageUrl(openRef, requestedStepId, TRACE_DRAWER_LISTS[listId], location, searchParams),
],
}),
listeners(({ actions, cache, values }) => ({
@@ -268,7 +310,7 @@ export const traceDrawerLogic = kea<traceDrawerLogicType>([
writeUrlParams('push', toDrawerParams(row))
} else if (row.stepId !== null) {
// A row with no step of its own would otherwise clear the selected step.
- actions.requestStep(row.stepId)
+ actions.requestStep(row.stepId, row.traceId)
}
},
stepTo: ({ direction }) => {
@@ -294,20 +336,20 @@ export const traceDrawerLogic = kea<traceDrawerLogicType>([
writeUrlParams('replace', toDrawerParams(previousRef))
return
}
- actions.requestStep(openRef?.stepId ?? null)
if (!openRef) {
trackDrawerClosed(cache)
- } else if (!values.isEnabled) {
- router.actions.replace(
- urls.aiObservabilityTrace(openRef.traceId, {
- timestamp: openRef.timestamp ?? undefined,
- event: openRef.stepId ?? undefined,
- })
- )
+ return
+ }
+ const config = TRACE_DRAWER_LISTS[props.listId]
+ actions.requestStep(openRef.stepId, openRef.traceId)
+ if (!values.isEnabled) {
+ const { location, searchParams } = router.values
+ router.actions.replace(toFullPageUrl(openRef, openRef.stepId, config, location, searchParams))
} else if (cache.stepsTaken === undefined) {
cache.stepsTaken = 0
+ actions.setOpeningMode(config.openingMode ?? null)
actions.setMode('spans')
- actions.setDetailTab('messages')
+ actions.setDetailTab(config.detailTab ?? 'messages')
posthog.capture('llma trace drawer opened', { list: props.listId })
void addProductIntent({
product_type: ProductKey.AI_OBSERVABILITY,
@@ -326,13 +368,16 @@ export const traceDrawerLogic = kea<traceDrawerLogicType>([
document.addEventListener('keydown', closeOnEscape)
return () => document.removeEventListener('keydown', closeOnEscape)
}, CLOSE_ON_ESCAPE_DISPOSABLE)
+ } else if (openRef.traceId !== previousRef?.traceId) {
+ // The view applies an opening on each trace it loads, which would undo the mode the person chose.
+ actions.setOpeningMode(null)
}
},
})),
beforeUnmount(({ cache, values }) => {
+ // A list remounts behind its loading state on browser back, and the URL must still hold its trace.
if (values.openRef) {
trackDrawerClosed(cache)
- writeUrlParams('replace', toDrawerParams(null))
}
}),
])
diff --git a/products/ai_observability/frontend/redesign/trace/traceDrawerRows.test.ts b/products/ai_observability/frontend/redesign/trace/traceDrawerRows.test.ts
new file mode 100644
index 000000000000..1e78d33e04d0
--- /dev/null
+++ b/products/ai_observability/frontend/redesign/trace/traceDrawerRows.test.ts
@@ -0,0 +1,56 @@
+import { changedOnlyTraceDrawerParams, opensTraceDrawer } from './traceDrawerRows'
+
+type DrawerClick = Parameters<typeof opensTraceDrawer>[0]
+
+const LINK = '[data-attr="trace-link"]'
+
+function click(target: EventTarget, row: Element, modifiers: { metaKey?: boolean } = {}): DrawerClick {
+ return {
+ target,
+ currentTarget: row,
+ button: 0,
+ metaKey: false,
+ ctrlKey: false,
+ shiftKey: false,
+ altKey: false,
+ ...modifiers,
+ }
+}
+
+describe('changedOnlyTraceDrawerParams', () => {
+ const list = { pathname: '/list', searchParams: { tab: 'usage', trace: 'a' } }
+
+ it.each([
+ ['another trace', { ...list, searchParams: { tab: 'usage', trace: 'b' } }, true],
+ ['a closed drawer', { ...list, searchParams: { tab: 'usage' } }, true],
+ ['the same location', list, false],
+ ['another list param as well', { ...list, searchParams: { tab: 'code', trace: 'b' } }, false],
+ ['another path as well', { pathname: '/other', searchParams: { tab: 'usage', trace: 'b' } }, false],
+ ])('for %s', (_name, next, expected) => {
+ expect(changedOnlyTraceDrawerParams(list, next)).toBe(expected)
+ })
+})
+
+describe('opensTraceDrawer', () => {
+ const row = document.createElement('tr')
+ row.innerHTML =
+ '<td data-attr="cell">cell</td><td><a data-attr="trace-link">trace</a><a data-attr="other-link">other</a></td>'
+ const part = (name: string): Element => row.querySelector(`[data-attr="${name}"]`) ?? row
+
+ it.each([
+ ['a plain cell on a list that opens from the row', 'cell', true, true],
+ ['a plain cell on a list that opens from its links only', 'cell', false, false],
+ ['the trace link on a list that opens from its links only', 'trace-link', false, true],
+ ['another link', 'other-link', true, false],
+ ])('on %s', (_name, target, rowClick, expected) => {
+ expect(opensTraceDrawer(click(part(target), row), LINK, rowClick)).toBe(expected)
+ })
+
+ it('leaves a Cmd-click to the browser', () => {
+ expect(opensTraceDrawer(click(part('trace-link'), row, { metaKey: true }), LINK, true)).toBe(false)
+ })
+
+ it('ignores a click from a portal outside the row', () => {
+ expect(opensTraceDrawer(click(document.createElement('div'), row), LINK, true)).toBe(false)
+ })
+})
diff --git a/products/ai_observability/frontend/redesign/trace/traceDrawerRows.ts b/products/ai_observability/frontend/redesign/trace/traceDrawerRows.ts
new file mode 100644
index 000000000000..5b57b5516d5c
--- /dev/null
+++ b/products/ai_observability/frontend/redesign/trace/traceDrawerRows.ts
@@ -0,0 +1,46 @@
+import type { MouseEvent } from 'react'
+
+import { objectsEqual } from 'lib/utils/objects'
+
+export const TRACE_DRAWER_OPEN_ROW_CLASS = 'LemonTable__row--status-highlighted'
+
+export const TRACE_DRAWER_PARAMS = ['trace', 'ts', 'step']
+
+export function withoutTraceDrawerParams<T>(params: Record<string, T>): Record<string, T> {
+ return Object.fromEntries(Object.entries(params).filter(([name]) => !TRACE_DRAWER_PARAMS.includes(name)))
+}
+
+interface ListLocation {
+ pathname: string
+ searchParams: Record<string, unknown>
+}
+
+export function changedOnlyTraceDrawerParams(previous: ListLocation, next: ListLocation): boolean {
+ return (
+ previous.pathname === next.pathname &&
+ TRACE_DRAWER_PARAMS.some((name) => previous.searchParams[name] !== next.searchParams[name]) &&
+ objectsEqual(withoutTraceDrawerParams(previous.searchParams), withoutTraceDrawerParams(next.searchParams))
+ )
+}
+
+// Cells with their own link or button (ID, trace name, person) handle their own clicks.
+export function hasOwnClickHandler(target: EventTarget | null): boolean {
+ return target instanceof Element && !!target.closest('button, a, [role="button"]')
+}
+
+type DrawerClick = Pick<
+ MouseEvent,
+ 'target' | 'currentTarget' | 'button' | 'metaKey' | 'ctrlKey' | 'shiftKey' | 'altKey'
+>
+
+function isPlainLeftClick({ button, metaKey, ctrlKey, shiftKey, altKey }: DrawerClick): boolean {
+ return button === 0 && !metaKey && !ctrlKey && !shiftKey && !altKey
+}
+
+export function opensTraceDrawer(click: DrawerClick, linkSelector: string, rowClick: boolean): boolean {
+ const { target, currentTarget } = click
+ // React capture also reaches the row from a portal, so an overlay opened from a cell would lose its own clicks.
+ const isInsideRow = target instanceof Node && currentTarget.contains(target)
+ const isTraceLink = target instanceof Element && !!target.closest(linkSelector)
+ return isInsideRow && isPlainLeftClick(click) && (isTraceLink || (rowClick && !hasOwnClickHandler(target)))
+}
diff --git a/products/ai_observability/frontend/redesign/trace/tracePageLogic.test.ts b/products/ai_observability/frontend/redesign/trace/tracePageLogic.test.ts
index 3b9511d95f9b..5a46b56118c0 100644
--- a/products/ai_observability/frontend/redesign/trace/tracePageLogic.test.ts
+++ b/products/ai_observability/frontend/redesign/trace/tracePageLogic.test.ts
@@ -36,8 +36,14 @@ describe('tracePageLogic', () => {
it.each([
['event', '?event=gen-1', { requestedStepId: 'gen-1', openingMode: null }],
- ['tab=summary', '?tab=summary', { requestedStepId: null, openingMode: 'summary' }],
- ['another tab', '?tab=conversation', { requestedStepId: null, openingMode: null }],
+ ['tab=summary', '?tab=summary', { requestedStepId: null, openingMode: 'summary', detailTab: 'messages' }],
+ [
+ 'tab=evals with no event',
+ '?tab=evals',
+ { requestedStepId: 'trace-1', openingMode: null, detailTab: 'evals' },
+ ],
+ ['tab=evals with an event', '?tab=evals&event=gen-1', { requestedStepId: 'gen-1', detailTab: 'evals' }],
+ ['another tab', '?tab=conversation', { requestedStepId: null, openingMode: null, detailTab: 'messages' }],
['search', '?search=refund', { seedQuery: 'refund' }],
['a numeric search keeps its text', '?search=1.50', { seedQuery: '1.50' }],
])('reads %s from the URL', (_name, search, expected) => {
@@ -88,8 +94,20 @@ describe('tracePageLogic', () => {
expect(host.values).toMatchObject({ mode: 'spans', detailTab: 'messages' })
})
+ it('opens another trace on tab=evals, and keeps the tab the person picks when a step writes the URL', () => {
+ open('')
+ open('?tab=evals', 'trace-2')
+ expect(host.values.detailTab).toBe('evals')
+
+ host.actions.setDetailTab('raw')
+ host.actions.requestStep('gen-2', 'trace-2')
+
+ expect(router.values.searchParams).toMatchObject({ tab: 'evals', event: 'gen-2' })
+ expect(host.values.detailTab).toBe('raw')
+ })
+
it.each([
- ['a requested step', (): void => host.actions.requestStep('gen-2'), { event: 'gen-2' }],
+ ['a requested step', (): void => host.actions.requestStep('gen-2', 'trace-1'), { event: 'gen-2' }],
['a published query', (): void => host.actions.publishQuery('x'), { search: 'x' }],
])('writes %s to the URL and keeps the other params and the hash', (_name, write, expected) => {
open('?back_to=generations')
@@ -104,14 +122,14 @@ describe('tracePageLogic', () => {
it.each(['1.50', '2e3'])('keeps the raw search %s when a step is written', (query) => {
open(`?search=${query}`)
- host.actions.requestStep('gen-2')
+ host.actions.requestStep('gen-2', 'trace-1')
expect(new URLSearchParams(router.values.location.search).get('search')).toBe(query)
expect(host.values.seedQuery).toBe(query)
})
it.each([
- ['a step the URL already omits', '', (): void => host.actions.requestStep(null)],
+ ['a step the URL already omits', '', (): void => host.actions.requestStep(null, 'trace-1')],
['a query the URL already holds', '?search=1.50', (): void => host.actions.publishQuery('1.50')],
])('does not write the URL for %s', (_name, search, write) => {
open(search)
diff --git a/products/ai_observability/frontend/redesign/trace/tracePageLogic.ts b/products/ai_observability/frontend/redesign/trace/tracePageLogic.ts
index 84440706bb93..6839295eeb27 100644
--- a/products/ai_observability/frontend/redesign/trace/tracePageLogic.ts
+++ b/products/ai_observability/frontend/redesign/trace/tracePageLogic.ts
@@ -70,8 +70,12 @@ export interface tracePageLogicActions {
publishQuery: (query: string) => {
query: string
} // traceViewHostLogic
- requestStep: (stepId: string | null) => {
+ requestStep: (
+ stepId: string | null,
+ traceId: string | null
+ ) => {
stepId: string | null
+ traceId: string | null
} // traceViewHostLogic
setDetailTab: (tab: import('./types').NodeDetailTab) => {
tab: import('./types').NodeDetailTab
@@ -107,6 +111,17 @@ export type tracePageLogicType = MakeLogicType<
tracePageLogicMeta
>
+function toTimestampHint(timestamp?: string, exceptionTimestamp?: string): string | null {
+ const dateFrom = timestamp ? parseUrlDate(timestamp) : null
+ if (dateFrom) {
+ return dateFrom
+ }
+ const exceptionDate = exceptionTimestamp ? parseUrlDate(exceptionTimestamp) : null
+ return exceptionDate
+ ? dayjs(exceptionDate).subtract(EXCEPTION_LOOKUP_WINDOW_MINUTES, 'minutes').toISOString()
+ : null
+}
+
export const tracePageLogic = kea<tracePageLogicType>([
path(['products', 'ai_observability', 'frontend', 'redesign', 'trace', 'tracePageLogic']),
connect(() => ({
@@ -162,20 +177,18 @@ export const tracePageLogic = kea<tracePageLogicType>([
actions.setMode('spans')
actions.setDetailTab('messages')
}
+ // The page writes its URL on each step, so a later pass here would undo the tab the person picked.
+ if (isNewTrace && tab === 'evals') {
+ actions.setDetailTab('evals')
+ }
actions.setTraceId(traceId)
- actions.requestStep(event || null)
+ // An eval link with no event comes from a trace-level run, and only the root shows that run.
+ actions.requestStep(event || (tab === 'evals' ? traceId : null), traceId)
actions.setOpeningMode(tab === 'summary' ? 'summary' : null)
actions.setSeedQuery(searchParamFromUrl())
- const dateFrom = timestamp ? parseUrlDate(timestamp) : null
- const exceptionDate = exception_ts ? parseUrlDate(exception_ts) : null
- if (dateFrom) {
- actions.setTimestampHint(dateFrom)
- } else if (exceptionDate) {
- actions.setTimestampHint(
- dayjs(exceptionDate).subtract(EXCEPTION_LOOKUP_WINDOW_MINUTES, 'minutes').toISOString()
- )
- } else if (isNewTrace) {
- actions.setTimestampHint(null)
+ const timestampHint = toTimestampHint(timestamp, exception_ts)
+ if (timestampHint || isNewTrace) {
+ actions.setTimestampHint(timestampHint)
}
},
})),
diff --git a/products/ai_observability/frontend/redesign/trace/traceViewHostLogic.ts b/products/ai_observability/frontend/redesign/trace/traceViewHostLogic.ts
index 256b22a8c581..4ed6b6919357 100644
--- a/products/ai_observability/frontend/redesign/trace/traceViewHostLogic.ts
+++ b/products/ai_observability/frontend/redesign/trace/traceViewHostLogic.ts
@@ -12,6 +12,7 @@ export interface traceViewHostLogicValues {
mode: TraceMode
openingMode: TraceOpeningMode
requestedStepId: string | null
+ requestedTraceId: string | null
seedQuery: string
}
@@ -20,8 +21,12 @@ export interface traceViewHostLogicActions {
publishQuery: (query: string) => {
query: string
}
- requestStep: (stepId: string | null) => {
+ requestStep: (
+ stepId: string | null,
+ traceId: string | null
+ ) => {
stepId: string | null
+ traceId: string | null
}
setDetailTab: (tab: NodeDetailTab) => {
tab: NodeDetailTab
@@ -56,7 +61,7 @@ export const traceViewHostLogic = kea<traceViewHostLogicType>([
actions({
setMode: (mode: TraceMode) => ({ mode }),
setDetailTab: (tab: NodeDetailTab) => ({ tab }),
- requestStep: (stepId: string | null) => ({ stepId }),
+ requestStep: (stepId: string | null, traceId: string | null) => ({ stepId, traceId }),
setOpeningMode: (mode: TraceOpeningMode) => ({ mode }),
setSeedQuery: (query: string) => ({ query }),
publishQuery: (query: string) => ({ query }),
@@ -80,6 +85,12 @@ export const traceViewHostLogic = kea<traceViewHostLogicType>([
requestStep: (_, { stepId }) => stepId,
},
],
+ requestedTraceId: [
+ null as string | null,
+ {
+ requestStep: (_, { traceId }) => traceId,
+ },
+ ],
openingMode: [
null as TraceOpeningMode,
{
diff --git a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts
index 91d7df37dbd4..5ed2cc3e178e 100644
--- a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts
+++ b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts
@@ -67,7 +67,7 @@ describe('traceViewModelLogic', () => {
function mountAt({ requestedStepId, openingMode, seedQuery }: HostState = {}): void {
host = traceViewHostLogic({ hostId: HOST_ID })
host.mount()
- host.actions.requestStep(requestedStepId ?? null)
+ host.actions.requestStep(requestedStepId ?? null, null)
host.actions.setOpeningMode(openingMode ?? null)
host.actions.setSeedQuery(seedQuery ?? '')
logic = traceViewModelLogic({ hostId: HOST_ID, traceId: 'trace-1', timestampHint: null })
@@ -176,6 +176,7 @@ describe('traceViewModelLogic', () => {
['a node in the tree', { requestedStepId: 'span-1' }, 'span-1'],
['an SDK id through its alias', { requestedStepId: 'sdk-gen-1' }, 'gen-1'],
['a stale id as the root', { requestedStepId: 'missing' }, 'trace-1'],
+ ['the trace itself as the root, not the default node', { requestedStepId: 'trace-1' }, 'trace-1'],
['no id as the default node', {}, 'gen-1'],
['a trace-level link as the root', { openingMode: 'summary' }, 'trace-1'],
] as const)('selects %s', async (_name, state: HostState, expected) => {
@@ -186,6 +187,33 @@ describe('traceViewModelLogic', () => {
expect(logic.values.detailData?.content.kind).not.toBe('error')
})
+ it('reads no root node for a step requested for the next trace', async () => {
+ mountAt({ requestedStepId: 'span-1' })
+ await expectLogic(logic).toFinishAllListeners().toMatchValues({ status: 'ready', selectedNodeId: 'span-1' })
+ nodeRequests.length = 0
+
+ host.actions.requestStep('next-trace-step', 'trace-2')
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.selectedNodeId).toBe('trace-1')
+ expect(nodeRequests).toEqual([])
+ })
+
+ it('does not read the next trace step under this trace while this trace loads', async () => {
+ let releaseTrace = (): void => {}
+ traceGate = new Promise<void>((resolve) => {
+ releaseTrace = resolve
+ })
+ mountAt()
+ await waitFor(() => expect(nodeRequests).toEqual(['trace-1']))
+
+ host.actions.requestStep('next-trace-step', 'trace-2')
+ releaseTrace()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(nodeRequests).not.toContain('next-trace-step')
+ })
+
it('asks for the clusters with the trace start once the trace arrives', async () => {
let releaseTrace = (): void => {}
traceGate = new Promise<void>((resolve) => {
diff --git a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts
index 971ad1bc05c6..a9b74479bb97 100644
--- a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts
+++ b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts
@@ -86,6 +86,7 @@ export interface traceViewModelLogicValues {
mode: TraceMode // traceViewHostLogic
openingMode: TraceOpeningMode // traceViewHostLogic
requestedStepId: string | null // traceViewHostLogic
+ requestedTraceId: string | null // traceViewHostLogic
seedQuery: string // traceViewHostLogic
createdAt: string | null // traceViewLogic
defaultNodeId: string // traceViewLogic
@@ -157,8 +158,12 @@ export interface traceViewModelLogicActions {
publishQuery: (query: string) => {
query: string
} // traceViewHostLogic
- requestStep: (stepId: string | null) => {
+ requestStep: (
+ stepId: string | null,
+ traceId: string | null
+ ) => {
stepId: string | null
+ traceId: string | null
} // traceViewHostLogic
setHostDetailTab: (tab: NodeDetailTab) => {
tab: NodeDetailTab
@@ -345,7 +350,7 @@ export const traceViewModelLogic = kea<traceViewModelLogicType>([
'trace',
],
traceViewHostLogic({ hostId: props.hostId }),
- ['mode', 'detailTab', 'requestedStepId', 'openingMode', 'seedQuery'],
+ ['mode', 'detailTab', 'requestedStepId', 'requestedTraceId', 'openingMode', 'seedQuery'],
teamLogic,
['currentTeamId'],
featureFlagLogic,
@@ -633,7 +638,7 @@ export const traceViewModelLogic = kea<traceViewModelLogicType>([
// selected changes no value and the subscription does not fire, so this read also retries a failed node.
const select = ({ id }: { id: string }): void => {
actions.loadNode(id, 'selection')
- actions.requestStep(id)
+ actions.requestStep(id, props.traceId)
}
const captureFeedbackViewed = (entry: FeedbackEntry | 'tab'): void => {
posthog.capture('llma trace view feedback viewed', {
@@ -705,8 +710,14 @@ export const traceViewModelLogic = kea<traceViewModelLogicType>([
setDetailTab: ({ tab }) => actions.setHostDetailTab(tab),
}
}),
- subscriptions(({ actions, values }) => ({
- selectedNodeId: (selectedNodeId: string) => actions.loadNode(selectedNodeId, 'navigation'),
+ subscriptions(({ actions, props, values }) => ({
+ selectedNodeId: (selectedNodeId: string) => {
+ // A drawer requests the next trace's step before this view unmounts. That step is not a node of this trace.
+ if (values.requestedTraceId !== null && values.requestedTraceId !== props.traceId) {
+ return
+ }
+ actions.loadNode(selectedNodeId, 'navigation')
+ },
mode: (mode: TraceMode) => {
if (mode === 'summary' && !values.summaryIsOpen) {
actions.openSummary('tab')
diff --git a/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.test.ts b/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.test.ts
new file mode 100644
index 000000000000..6268e1bee17a
--- /dev/null
+++ b/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.test.ts
@@ -0,0 +1,24 @@
+import { router } from 'kea-router'
+
+import { urls } from 'scenes/urls'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { aiObservabilitySessionsViewLogic } from './aiObservabilitySessionsViewLogic'
+
+describe('aiObservabilitySessionsViewLogic', () => {
+ it('leaves the trace drawer params behind when selecting a session', () => {
+ useMocks({ post: { '/api/environments/:team_id/query/:kind/': () => [200, { results: [] }] } })
+ initKeaTests()
+ router.actions.push(`${urls.aiObservabilitySessions()}?date_from=-7d&trace=a&ts=2026&step=x`)
+ const logic = aiObservabilitySessionsViewLogic()
+ logic.mount()
+
+ logic.actions.selectSession('session-1')
+
+ expect(router.values.location.pathname).toContain(urls.aiObservabilitySession('session-1'))
+ expect(router.values.searchParams).toEqual({ date_from: '-7d' })
+ logic.unmount()
+ })
+})
diff --git a/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.ts b/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.ts
index 8154293e6394..d5593ff48f37 100644
--- a/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.ts
+++ b/products/ai_observability/frontend/tabs/aiObservabilitySessionsViewLogic.ts
@@ -15,6 +15,7 @@ import type { SortDirection, SortState } from '../aiObservabilitySharedLogic'
import { aiObservabilitySharedLogic } from '../aiObservabilitySharedLogic'
import type { AIObservabilityTabId } from '../aiObservabilitySharedLogic'
import { llmSessionTitleLazyLoaderLogic } from '../llmSessionTitleLazyLoaderLogic'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import type { DateRangeFilter } from '../types'
export type AIObservabilitySessionsViewLogicProps = Record<string, never>
@@ -377,7 +378,7 @@ export const aiObservabilitySessionsViewLogic = kea<aiObservabilitySessionsViewL
actionToUrl(() => ({
selectSession: ({ sessionId }) => {
- const search = router.values.searchParams
+ const search = withoutTraceDrawerParams(router.values.searchParams)
return sessionId
? combineUrl(urls.aiObservabilitySession(sessionId), search).url
: combineUrl(urls.aiObservabilitySessions(), search).url
diff --git a/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.test.tsx b/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.test.tsx
new file mode 100644
index 000000000000..d250b997ae08
--- /dev/null
+++ b/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.test.tsx
@@ -0,0 +1,29 @@
+import { cleanup, render } from '@testing-library/react'
+import { router } from 'kea-router'
+
+import { urls } from 'scenes/urls'
+
+import { initKeaTests } from '~/test/init'
+
+import { AIObservabilityHumanReviews } from './AIObservabilityHumanReviews'
+
+jest.mock('../reviewQueues/AIObservabilityReviewQueues', () => ({ AIObservabilityReviewQueues: () => null }))
+jest.mock('./AIObservabilityReviews', () => ({ AIObservabilityReviews: () => null }))
+
+describe('AIObservabilityHumanReviews', () => {
+ afterEach(cleanup)
+
+ it.each(['llma-review-queues-tab', 'llma-trace-reviews-tab'])(
+ 'leaves the trace drawer params out of the %s link and keeps the filters',
+ (tab) => {
+ initKeaTests()
+ router.actions.push(`${urls.aiObservabilityReviews()}?date_from=-7d&trace=a&ts=2026&step=x`)
+
+ const { container } = render(<AIObservabilityHumanReviews />)
+
+ const href = container.querySelector(`[data-attr="${tab}"]`)?.closest('a')?.getAttribute('href')
+ expect(href).toContain('date_from=-7d')
+ expect(href).not.toMatch(/trace=|ts=|step=/)
+ }
+ )
+})
diff --git a/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.tsx b/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.tsx
index bf0ca53052b4..f67b5323fa70 100644
--- a/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.tsx
+++ b/products/ai_observability/frontend/traceReviews/AIObservabilityHumanReviews.tsx
@@ -5,6 +5,7 @@ import { LemonTab, LemonTabs } from '@posthog/lemon-ui'
import { urls } from '~/scenes/urls'
+import { withoutTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { AIObservabilityReviewQueues } from '../reviewQueues/AIObservabilityReviewQueues'
import { AIObservabilityReviews } from './AIObservabilityReviews'
@@ -13,6 +14,7 @@ const HUMAN_REVIEWS_TAB_PARAM = 'human_reviews_tab'
export function AIObservabilityHumanReviews(): JSX.Element {
const { searchParams } = useValues(router)
const { push } = useActions(router)
+ const tabParams = withoutTraceDrawerParams(searchParams)
const activeHumanReviewsTab =
searchParams[HUMAN_REVIEWS_TAB_PARAM] === 'reviews'
@@ -27,7 +29,7 @@ export function AIObservabilityHumanReviews(): JSX.Element {
label: 'Queues',
content: <AIObservabilityReviewQueues />,
link: combineUrl(urls.aiObservabilityReviews(), {
- ...searchParams,
+ ...tabParams,
[HUMAN_REVIEWS_TAB_PARAM]: undefined,
}).url,
'data-attr': 'llma-review-queues-tab',
@@ -37,7 +39,7 @@ export function AIObservabilityHumanReviews(): JSX.Element {
label: 'Reviews',
content: <AIObservabilityReviews />,
link: combineUrl(urls.aiObservabilityReviews(), {
- ...searchParams,
+ ...tabParams,
[HUMAN_REVIEWS_TAB_PARAM]: 'reviews',
}).url,
'data-attr': 'llma-trace-reviews-tab',
@@ -61,7 +63,7 @@ export function AIObservabilityHumanReviews(): JSX.Element {
tab === 'scorers'
? urls.aiObservabilityScorers()
: combineUrl(urls.aiObservabilityReviews(), {
- ...searchParams,
+ ...tabParams,
[HUMAN_REVIEWS_TAB_PARAM]: tab === 'reviews' ? 'reviews' : undefined,
}).url
)
diff --git a/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.test.tsx b/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.test.tsx
index ffc3937fbb13..71f591694608 100644
--- a/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.test.tsx
+++ b/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.test.tsx
@@ -1,10 +1,13 @@
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'
import { router } from 'kea-router'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { urls } from 'scenes/urls'
import { initKeaTests } from '~/test/init'
+import { traceDrawerLogic } from '../redesign/trace/traceDrawerLogic'
import { AIObservabilityReviews } from './AIObservabilityReviews'
import { TRACE_REVIEWS_PER_PAGE } from './aiObservabilityReviewsLogic'
import { traceReviewsApi } from './traceReviewsApi'
@@ -82,4 +85,41 @@ describe('AIObservabilityReviews', () => {
)
expect(router.values.searchParams.review_order_by).toBe('updated_at')
})
+
+ describe('opening the trace drawer', () => {
+ const FLAG = FEATURE_FLAGS.AI_OBSERVABILITY_TRACE_REDESIGN
+
+ async function renderReviews(): Promise<HTMLElement> {
+ localStorage.clear()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FLAG], { [FLAG]: true })
+ router.actions.push(urls.aiObservabilityReviews(), { human_reviews_tab: 'reviews' })
+ const { findByText } = render(<AIObservabilityReviews />)
+ return await findByText('trace-0')
+ }
+
+ it.each([
+ ['the row', (link: HTMLElement): Element | null => link.closest('tr')?.querySelector('td + td') ?? null],
+ ['the trace link', (link: HTMLElement): Element => link],
+ ])('opens from %s with no timestamp or step', async (_name, target) => {
+ const clicked = target(await renderReviews())
+ if (!clicked) {
+ throw new Error('No click target')
+ }
+
+ fireEvent.click(clicked)
+
+ expect(router.values.location.pathname).toContain(urls.aiObservabilityReviews())
+ expect(router.values.searchParams).toEqual({ human_reviews_tab: 'reviews', trace: 'trace-0' })
+ })
+
+ it('gives the drawer the rows in table order', async () => {
+ await renderReviews()
+
+ expect(traceDrawerLogic({ listId: 'reviews' }).values.rows.slice(0, 2)).toEqual([
+ { traceId: 'trace-0', timestamp: null, stepId: null },
+ { traceId: 'trace-1', timestamp: null, stepId: null },
+ ])
+ })
+ })
})
diff --git a/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.tsx b/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.tsx
index 499ca73c1b2d..07441d329a5d 100644
--- a/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.tsx
+++ b/products/ai_observability/frontend/traceReviews/AIObservabilityReviews.tsx
@@ -21,14 +21,25 @@ import { updatedAtColumn } from '~/lib/lemon-ui/LemonTable/columnUtils'
import { urls } from '~/scenes/urls'
import { AccessControlLevel, AccessControlResourceType, ExporterFormat } from '~/types'
+import { TraceDrawerHost } from '../redesign/trace/TraceDrawerHost'
+import { useTraceDrawerTable } from '../redesign/trace/TraceDrawerRowsHost'
+import { TraceListRow } from '../redesign/trace/traceListRows'
import { aiObservabilityReviewsLogic, TRACE_REVIEWS_PER_PAGE } from './aiObservabilityReviewsLogic'
import { TraceReviewValue } from './TraceReviewValue'
import type { TraceReview } from './types'
+const TRACE_DRAWER_LIST_ID = 'reviews'
+const TRACE_LINK = '[data-attr="llma-trace-review-trace-link"]'
+
function formatTraceId(traceId: string): string {
return traceId.length > 12 ? `${traceId.slice(0, 4)}...${traceId.slice(-4)}` : traceId
}
+// `created_at` is when the review happened, which says nothing about when the trace did, so no timestamp.
+function toTraceDrawerRow(review: TraceReview): TraceListRow | null {
+ return review.trace_id ? { traceId: review.trace_id, timestamp: null, stepId: null } : null
+}
+
export function AIObservabilityReviews(): JSX.Element {
const logic = useMountedLogic(aiObservabilityReviewsLogic())
const { setFilters, copyReviewsToClipboard } = useActions(logic)
@@ -44,6 +55,7 @@ export function AIObservabilityReviews(): JSX.Element {
scoreDefinitionOptions,
scoreDefinitionOptionsLoading,
} = useValues(logic)
+ const drawerTableProps = useTraceDrawerTable(TRACE_DRAWER_LIST_ID, TRACE_LINK, toTraceDrawerRow)
const triggerFileExport = (format: ExporterFormat, extension: 'csv' | 'xlsx'): void => {
startExport({
@@ -136,107 +148,111 @@ export function AIObservabilityReviews(): JSX.Element {
]
return (
- <div className="space-y-4">
- <div className="flex gap-x-4 gap-y-2 items-center flex-wrap py-4 -mt-4 mb-4 border-b justify-between">
- <div className="flex gap-2 items-center flex-wrap">
- <LemonInput
- type="search"
- placeholder="Search reviews..."
- value={filters.search}
- onChange={(value) => setFilters({ search: value })}
- className="max-w-md"
- data-attr="llma-trace-reviews-search-input"
- />
- <LemonSelect
- value={filters.definition_id || undefined}
- onChange={(value) => setFilters({ definition_id: value ? String(value) : '' })}
- options={[
- { label: 'All scorers', value: '' },
- ...scoreDefinitionOptions.map((definition) => ({
- label: definition.name,
- value: definition.id,
- })),
- ]}
- placeholder="Filter by scorer"
- loading={scoreDefinitionOptionsLoading}
- className="min-w-60"
- data-attr="llma-trace-reviews-definition-filter"
- />
- </div>
- <div className="flex gap-2 items-center">
- <span className="text-muted-alt">{reviewCountLabel}</span>
- <LemonMenu
- items={[
- {
- label: 'Export current columns',
- items: [
- {
- label: 'CSV',
- onClick: () => triggerFileExport(ExporterFormat.CSV, 'csv'),
- disabledReason: fileExportDisabledReason,
- },
- {
- label: 'XLSX',
- onClick: () => triggerFileExport(ExporterFormat.XLSX, 'xlsx'),
- disabledReason: fileExportDisabledReason,
- },
- ],
- },
- {
- label: 'Copy to clipboard',
- items: [
- {
- label: 'CSV',
- onClick: () => copyReviewsToClipboard('csv'),
- 'data-attr': 'copy-csv-to-clipboard',
- },
- {
- label: 'JSON',
- onClick: () => copyReviewsToClipboard('json'),
- 'data-attr': 'copy-json-to-clipboard',
- },
- {
- label: 'Excel',
- onClick: () => copyReviewsToClipboard('tsv'),
- 'data-attr': 'copy-excel-to-clipboard',
- },
- ],
- },
- ]}
- >
- <LemonButton
- type="secondary"
- icon={<IconDownload />}
- size="small"
- disabledReason={exportDisabledReason}
- data-attr="llma-trace-reviews-export-menu"
+ <>
+ <div className="space-y-4">
+ <div className="flex gap-x-4 gap-y-2 items-center flex-wrap py-4 -mt-4 mb-4 border-b justify-between">
+ <div className="flex gap-2 items-center flex-wrap">
+ <LemonInput
+ type="search"
+ placeholder="Search reviews..."
+ value={filters.search}
+ onChange={(value) => setFilters({ search: value })}
+ className="max-w-md"
+ data-attr="llma-trace-reviews-search-input"
+ />
+ <LemonSelect
+ value={filters.definition_id || undefined}
+ onChange={(value) => setFilters({ definition_id: value ? String(value) : '' })}
+ options={[
+ { label: 'All scorers', value: '' },
+ ...scoreDefinitionOptions.map((definition) => ({
+ label: definition.name,
+ value: definition.id,
+ })),
+ ]}
+ placeholder="Filter by scorer"
+ loading={scoreDefinitionOptionsLoading}
+ className="min-w-60"
+ data-attr="llma-trace-reviews-definition-filter"
+ />
+ </div>
+ <div className="flex gap-2 items-center">
+ <span className="text-muted-alt">{reviewCountLabel}</span>
+ <LemonMenu
+ items={[
+ {
+ label: 'Export current columns',
+ items: [
+ {
+ label: 'CSV',
+ onClick: () => triggerFileExport(ExporterFormat.CSV, 'csv'),
+ disabledReason: fileExportDisabledReason,
+ },
+ {
+ label: 'XLSX',
+ onClick: () => triggerFileExport(ExporterFormat.XLSX, 'xlsx'),
+ disabledReason: fileExportDisabledReason,
+ },
+ ],
+ },
+ {
+ label: 'Copy to clipboard',
+ items: [
+ {
+ label: 'CSV',
+ onClick: () => copyReviewsToClipboard('csv'),
+ 'data-attr': 'copy-csv-to-clipboard',
+ },
+ {
+ label: 'JSON',
+ onClick: () => copyReviewsToClipboard('json'),
+ 'data-attr': 'copy-json-to-clipboard',
+ },
+ {
+ label: 'Excel',
+ onClick: () => copyReviewsToClipboard('tsv'),
+ 'data-attr': 'copy-excel-to-clipboard',
+ },
+ ],
+ },
+ ]}
>
- Export
- </LemonButton>
- </LemonMenu>
+ <LemonButton
+ type="secondary"
+ icon={<IconDownload />}
+ size="small"
+ disabledReason={exportDisabledReason}
+ data-attr="llma-trace-reviews-export-menu"
+ >
+ Export
+ </LemonButton>
+ </LemonMenu>
+ </div>
</div>
- </div>
- <LemonTable
- id="review"
- loading={reviewsLoading}
- columns={columns}
- dataSource={reviews.results}
- pagination={pagination}
- noSortingCancellation
- sorting={sorting}
- useURLForSorting={false}
- onSort={(newSorting) =>
- setFilters({
- order_by: newSorting
- ? `${newSorting.order === -1 ? '-' : ''}${newSorting.columnKey}`
- : undefined,
- })
- }
- rowKey="id"
- loadingSkeletonRows={TRACE_REVIEWS_PER_PAGE}
- nouns={['review', 'reviews']}
- />
- </div>
+ <LemonTable
+ id="review"
+ loading={reviewsLoading}
+ columns={columns}
+ dataSource={reviews.results}
+ pagination={pagination}
+ noSortingCancellation
+ sorting={sorting}
+ useURLForSorting={false}
+ onSort={(newSorting) =>
+ setFilters({
+ order_by: newSorting
+ ? `${newSorting.order === -1 ? '-' : ''}${newSorting.columnKey}`
+ : undefined,
+ })
+ }
+ rowKey="id"
+ loadingSkeletonRows={TRACE_REVIEWS_PER_PAGE}
+ nouns={['review', 'reviews']}
+ {...drawerTableProps}
+ />
+ </div>
+ <TraceDrawerHost listId={TRACE_DRAWER_LIST_ID} />
+ </>
)
}
diff --git a/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.test.ts b/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.test.ts
index 8eda095fc4a4..34e62ef19e59 100644
--- a/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.test.ts
+++ b/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.test.ts
@@ -153,6 +153,20 @@ describe('aiObservabilityReviewsLogic.copyReviewsToClipboard', () => {
expect(router.values.searchParams.search).toBe('from-scorers')
})
+ it.each([
+ ['does not reload', 'the trace drawer steps to another trace', 'trace-2', 0],
+ ['reloads', 'the same location is pushed again', 'trace-1', 1],
+ ])('%s the reviews when %s', async (_outcome, _name, trace, expectedLoads) => {
+ router.actions.push(urls.aiObservabilityReviews(), { human_reviews_tab: 'reviews', trace: 'trace-1' })
+ await expectLogic(logic).toFinishAllListeners()
+ mockTraceReviewsList.mockClear()
+
+ router.actions.push(urls.aiObservabilityReviews(), { human_reviews_tab: 'reviews', trace })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockTraceReviewsList).toHaveBeenCalledTimes(expectedLoads)
+ })
+
it('cancels an earlier invocation when called twice in quick succession', async () => {
mockTraceReviewsList.mockReset()
let resolveFirst: ((value: { results: TraceReview[]; count: number }) => void) | undefined
diff --git a/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.ts b/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.ts
index 2e580dcdb73a..d42a3c50be82 100644
--- a/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.ts
+++ b/products/ai_observability/frontend/traceReviews/aiObservabilityReviewsLogic.ts
@@ -19,6 +19,7 @@ import { urls } from '~/scenes/urls'
import { llmAnalyticsScoreDefinitionsList as aiObservabilityScoreDefinitionsList } from '../generated/api'
import type { ScoreDefinitionApi } from '../generated/api.schemas'
+import { changedOnlyTraceDrawerParams } from '../redesign/trace/traceDrawerRows'
import { buildTraceReviewsListUrl, traceReviewListParamsFromFilters, traceReviewsApi } from './traceReviewsApi'
import { fetchAllReviewsForExport, formatReviewsForClipboard, type ReviewClipboardFormat } from './traceReviewsExport'
import type { TraceReview } from './types'
@@ -346,12 +347,15 @@ export const aiObservabilityReviewsLogic = kea<aiObservabilityReviewsLogicType>(
})),
urlToAction(({ actions, values }) => ({
- [urls.aiObservabilityReviews()]: (_, searchParams, __, { method }) => {
+ [urls.aiObservabilityReviews()]: (_, searchParams, __, { method, pathname }, previousLocation) => {
const newFilters = filtersFromUrl(searchParams)
if (!objectsEqual(values.filters, newFilters)) {
actions.setFilters(newFilters, false)
- } else if (method !== 'REPLACE') {
+ } else if (
+ method !== 'REPLACE' &&
+ !changedOnlyTraceDrawerParams(previousLocation, { pathname, searchParams })
+ ) {
actions.loadReviews(false)
}
},
diff --git a/products/ai_observability/frontend/utils.test.ts b/products/ai_observability/frontend/utils.test.ts
index 62c48f393632..d266220c3281 100644
--- a/products/ai_observability/frontend/utils.test.ts
+++ b/products/ai_observability/frontend/utils.test.ts
@@ -251,6 +251,7 @@ describe('AI observability utils', () => {
line: '5',
tab: 'conversation',
back_to: 'traces',
+ back_url: '/ai-observability/traces',
filters: [{ key: '$ai_model', value: ['gpt-4o'] }],
search: 'foo',
},
diff --git a/products/ai_observability/frontend/utils.ts b/products/ai_observability/frontend/utils.ts
index f2ccf8849a1e..dd749e558eeb 100644
--- a/products/ai_observability/frontend/utils.ts
+++ b/products/ai_observability/frontend/utils.ts
@@ -88,6 +88,7 @@ export function sanitizeTraceUrlSearchParams(
delete sanitizedSearchParams.line
delete sanitizedSearchParams.tab
delete sanitizedSearchParams.back_to
+ delete sanitizedSearchParams.back_url
delete sanitizedSearchParams.msg
if (options.removeSearch) {