:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aio): trace view polish sweep (#130027)
Carlos Marchal18bb07446aa4
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 759ab92096e1..78335087f8e6 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -9703,13 +9703,17 @@ snapshots:scenes-app-ai-observability-trace-view-message-part--tool-call-multiline-args--light:hash: v1.k794b7964.9574ac70d0b3fcabc0a60c1fb7b677ceb53a636337094f215b45862c289c8ee8.oELNCo2z_5ClcAdMZJArSx-p3v0tTepDm2JSRpUOC_Yscenes-app-ai-observability-trace-view-node-detail--content-load-error--dark:- hash: v1.k794b7964.5e36d3da09795c3413edf6908a4e90314fceb472621916dbb6de77ac40ac2a48.MayzNXkmRuKZfIU9L-TAGE67PKAPgJcY6R1UaTw1CRY+ hash: v1.k794b7964.2ac522453e68b733e75750b3da8dea28f3a16e86362b80ad1403a6c6081297d5.b3NX05EP1JpbRc4HAjx4TS_hWugqiKPbsGWgLKjJdg4scenes-app-ai-observability-trace-view-node-detail--content-load-error--light:- hash: v1.k794b7964.888a327ae27d5d8ffe6cfde13c9b1871dddf48915a8957787a92f89017fc3ed9._CuQ3SAqbn5iQYF-gsQhWQPCWOjRw5gywJsKBzXZdH0+ hash: v1.k794b7964.c2998582e9784a78692168e260c8c518f8af70e77422aea26acb044763e862b2.XYwKFxB_HgNezn8jLXuaOeRPXTq7wh-QskqInvXzTw8scenes-app-ai-observability-trace-view-node-detail--content-not-found--dark:- hash: v1.k794b7964.aa5f2ea36c16d32009ed51721b09b89687f10d6752c2244c0030240154736b9d.h1bZtLYGaahqQMGZ99NcWY4WezCo324_wg9Qr4sjH3o+ hash: v1.k794b7964.b2589c0e3ad7894b0bb13a739a265942472bc290d9abdceebf69a10461867316.xtro0PP5yevCrKL6BBVy_1n3wtGW7GLvxUgcsBgWegoscenes-app-ai-observability-trace-view-node-detail--content-not-found--light:- hash: v1.k794b7964.d5221fe9b3ba087f1d8715258424d71707ee37b9a2817adef30216272914353b.ZS6oiD8HREwTLnh0qdgNV7IU6TaoG5ryyrBMC6BbDzI+ hash: v1.k794b7964.0c7a7b08444156f34df8d55d2caa2e8d80f5ee24126ea2f174a752854e7c94ff.vNCg78vfcYqSam3X2uuE9ow6_5JT4f81s-tvnMzqILU+ scenes-app-ai-observability-trace-view-node-detail--details-tab-while-loading--dark:+ hash: v1.k794b7964.9e78b87ed85d3835dec2e04debe8b942add81438a7eeb609bc33564719d829be.304zD6AM6cZJ8qE0__O60yltZZPJu5knwA4dkuRJ_j8+ scenes-app-ai-observability-trace-view-node-detail--details-tab-while-loading--light:+ hash: v1.k794b7964.7bc83300ba9538ccb94f0386cd80d02873e89d53889a57e8f79d4c70f36387dd.fSeBh4fc9ubvTc5lilDeHP0eL6J5rqbZXJM1VYgNOpMscenes-app-ai-observability-trace-view-node-detail--evals-load-error--dark:hash: v1.k794b7964.8e974f8628c9cc06a2f376f029a8d4d1e5e6755bfc4e15cf1425d50ac27d5507.8xlC3RbKsMdoSiqaBI0oIq7qF844Mjm5g4b4yhjjEKAscenes-app-ai-observability-trace-view-node-detail--evals-load-error--light:@@ -9750,10 +9754,6 @@ snapshots:hash: v1.k794b7964.472d15736611ee2c67d9817d282e742382d32a363e86ec5ff0c469759378b2da.d81wvewvsO-BZ7FgxJ1ag5UqUty-N2KUiB9074hIcHkscenes-app-ai-observability-trace-view-node-detail--nothing-captured--light:hash: v1.k794b7964.d1068fff97081a2779188f47f3776dc01a24c0def7d1d6e5a8c940e51db7080b.fT-Iw09kOJ7sQfP43yB3bkDAnG12YZpvX69mMwTEz8s- scenes-app-ai-observability-trace-view-node-detail--raw-tab-while-loading--dark:- hash: v1.k794b7964.18cf781434dc68c49196fc46b7b7e741d8bbaf988f969e87cddba444dda970dc.JlcKvloACxrmr1NHcJP1U9fCvsgwg0WzigUF25xx0BM- scenes-app-ai-observability-trace-view-node-detail--raw-tab-while-loading--light:- hash: v1.k794b7964.963ea7f1028cf1cac01798ba8a9666073a119fb9a80500e9f0f8138e030f9ac0.faMrLWo2r8TFBrRAi_DApZcAJ4r6AwhCiSt_GZEsXxYscenes-app-ai-observability-trace-view-node-detail--span-details-tab--dark:hash: v1.k794b7964.c8765f600847c62e2d29705c6833a4e43707668a4c53f57e918e8c958e25d401.KDRSsssfGhhPMk88hskuIT4xCo_HEmeHTjs17yqXbaMscenes-app-ai-observability-trace-view-node-detail--span-details-tab--light:diff --git a/products/ai_observability/backend/facade/api.py b/products/ai_observability/backend/facade/api.pyindex 0942c7770c9f..623255c14ba2 100644--- a/products/ai_observability/backend/facade/api.py+++ b/products/ai_observability/backend/facade/api.py@@ -287,9 +287,9 @@ def mentions_evaluation_pass_markers(text: str) -> bool:def get_trace_evaluation_results(team: Team, user: User | None, trace_id: str) -> contracts.TraceEvaluationResults:rows = load_evaluation_results(team, user, trace_id)- configs = load_output_configs(team, user, {row.evaluation_id for row in rows if row.evaluation_id})+ configs = load_output_configs(team, user, {row.evaluation_uuid for row in rows if row.evaluation_uuid})results = [- EvaluationResult.from_row(row, trace_id=trace_id, output_config=configs.get(row.evaluation_id or "", {}))+ EvaluationResult.from_row(row, trace_id=trace_id, output_config=configs.get(row.evaluation_uuid or "", {}))for row in rows]return contracts.TraceEvaluationResults(diff --git a/products/ai_observability/backend/logic/traces/evaluation_result.py b/products/ai_observability/backend/logic/traces/evaluation_result.pyindex 471a350ab955..005a29bf1c3c 100644--- a/products/ai_observability/backend/logic/traces/evaluation_result.py+++ b/products/ai_observability/backend/logic/traces/evaluation_result.py@@ -1,6 +1,7 @@import jsonfrom collections.abc import Mappingfrom datetime import UTC, datetime+from decimal import ROUND_HALF_UP, Context, Decimalfrom typing import Selffrom posthog.dataclasses import frozen@@ -9,7 +10,7 @@ from ...facade.contracts import EvaluationOutcomefrom ...models.evaluation_configs import OutputTypefrom ...models.evaluation_outcomes import EvaluationReportOutcomeDefinition, get_outcome_definitionfrom .evaluation_result_queries import EvaluationResultRow-from .trace_queries import canonical_uuid, read_flag, read_number, read_text+from .trace_queries import read_flag, read_number, read_text_SENTIMENT_OUTCOMES: dict[str, EvaluationOutcome] = {"positive": "pass", "neutral": "unrated", "negative": "fail"}UNKNOWN_EVALUATION_NAME = "Unknown evaluation"@@ -48,7 +49,10 @@ def _graded(passed: bool | None, label: str) -> _Display:def _format_score(score: float) -> str:- rounded = float(f"{score:.2f}") if abs(score) >= 1 else float(f"{score:.2g}")+ # Ties round away from zero, like `toFixed` and `toPrecision` in the evaluation pages.+ exact = Decimal(score)+ significant_digits = exact.adjusted() + 3 if abs(score) >= 1 else 2+ rounded = float(Context(prec=significant_digits, rounding=ROUND_HALF_UP).plus(exact))return str(int(rounded)) if rounded.is_integer() else repr(rounded)@@ -171,7 +175,7 @@ class EvaluationResult:display = raw.display(_outcome_definition(raw.result_type, output_config))return cls(id=row.uuid,- evaluation_id=row.evaluation_id if row.evaluation_id and canonical_uuid(row.evaluation_id) else None,+ evaluation_id=row.evaluation_id if row.evaluation_uuid else None,name=read_text(row.evaluation_name) or UNKNOWN_EVALUATION_NAME,target_node_id=read_text(row.target_event_id) or trace_id,outcome=display.outcome,diff --git a/products/ai_observability/backend/logic/traces/evaluation_result_queries.py b/products/ai_observability/backend/logic/traces/evaluation_result_queries.pyindex 6c73093b6bee..0a29d989812b 100644--- a/products/ai_observability/backend/logic/traces/evaluation_result_queries.py+++ b/products/ai_observability/backend/logic/traces/evaluation_result_queries.py@@ -40,6 +40,11 @@ class EvaluationResultRow:backfill_id: str | Nonestart_time: str | None+ @property+ def evaluation_uuid(self) -> str | None:+ # Results can come from outside PostHog with any id, and a malformed UUID in the lookup raises.+ return canonical_uuid(self.evaluation_id) if self.evaluation_id else None+_PROPERTY_COLUMNS = {"evaluation_id": "$ai_evaluation_id",@@ -116,15 +121,14 @@ def load_evaluation_results(team: Team, user: User | None, trace_id: str) -> tupdef load_output_configs(- team: Team, user: User | None, evaluation_ids: Iterable[str]+ team: Team, user: User | None, evaluation_uuids: Iterable[str]) -> dict[str, Mapping[str, object]]:- """Keyed by each id as given, not by its canonical UUID form."""- # Results can come from outside PostHog with any id, and a malformed UUID in the lookup raises.- ids_by_uuid = {uuid: evaluation_id for evaluation_id in evaluation_ids if (uuid := canonical_uuid(evaluation_id))}- if not ids_by_uuid:+ """Keyed by canonical UUID, like `EvaluationResultRow.evaluation_uuid`."""+ uuids = set(evaluation_uuids)+ if not uuids:return {}# A deleted detector's results still read as a detector's, so deleted evaluations stay in.- evaluations: QuerySet[Evaluation] = Evaluation.objects.filter(team_id=team.pk, id__in=ids_by_uuid)+ evaluations: QuerySet[Evaluation] = Evaluation.objects.filter(team_id=team.pk, id__in=uuids)if user is not None:# Evaluations have their own access control, apart from the llm_analytics access that opens the trace.evaluations = UserAccessControl(user=user, team=team).filter_queryset_by_access_level(@@ -132,7 +136,5 @@ def load_output_configs()rows = evaluations.values_list("id", "output_config")return {- ids_by_uuid[str(evaluation_id)]: output_config- for evaluation_id, output_config in rows- if isinstance(output_config, Mapping)+ str(evaluation_id): output_config for evaluation_id, output_config in rows if isinstance(output_config, Mapping)}diff --git a/products/ai_observability/backend/tests/logic/traces/test_evaluation_result.py b/products/ai_observability/backend/tests/logic/traces/test_evaluation_result.pyindex 663b364dceb6..d3289adeab6e 100644--- a/products/ai_observability/backend/tests/logic/traces/test_evaluation_result.py+++ b/products/ai_observability/backend/tests/logic/traces/test_evaluation_result.py@@ -48,6 +48,15 @@ def evaluation_result(overrides: dict[str, Any], output_config: dict[str, Any] |"12.35",),("a whole score", {"result_type": "numeric", "score": "3"}, {}, "unrated", "3"),+ ("a tie rounded up to two places", {"result_type": "numeric", "score": "2.125"}, {}, "unrated", "2.13"),+ ("a tie rounded up to two digits", {"result_type": "numeric", "score": "0.125"}, {}, "unrated", "0.13"),+ (+ "a score past the default decimal precision",+ {"result_type": "numeric", "score": "1e30"},+ {},+ "unrated",+ "1000000000000000019884624838656",+ ),("a score whose rounding would flip the verdict",{"result_type": "numeric", "score": "0.6999"},diff --git a/products/ai_observability/backend/tests/test_facade_api.py b/products/ai_observability/backend/tests/test_facade_api.pyindex 5315ab622b28..6b9200f723f4 100644--- a/products/ai_observability/backend/tests/test_facade_api.py+++ b/products/ai_observability/backend/tests/test_facade_api.py@@ -298,6 +298,24 @@ class TestGetTraceEvaluationResults(ClickhouseTestMixin, BaseTest):assert result.outcome == outcome+ def test_applies_the_stored_output_config_to_every_spelling_of_its_id(self) -> None:+ evaluation_id = self._detector()+ bulk_create_events(+ [+ make_evaluation_result_event(+ uuid=f"00000000-0000-0000-0000-00000000000{index}",+ team=self.team,+ timestamp=T0 + timedelta(seconds=index),+ properties={"$ai_evaluation_id": spelling},+ )+ for index, spelling in enumerate((evaluation_id, evaluation_id.upper()), start=1)+ ]+ )++ results = api.get_trace_evaluation_results(self.team, self.user, "trace-1").results++ assert [result.outcome for result in results] == ["fail", "fail"]+def test_reads_a_registered_boolean_property_like_its_ingested_value(self) -> None:PropertyDefinition.objects.create(team=self.team,diff --git a/products/ai_observability/frontend/redesign/trace/components/AttachmentImage.test.tsx b/products/ai_observability/frontend/redesign/trace/adapter/AttachmentImage.test.tsxsimilarity index 100%rename from products/ai_observability/frontend/redesign/trace/components/AttachmentImage.test.tsxrename to products/ai_observability/frontend/redesign/trace/adapter/AttachmentImage.test.tsxdiff --git a/products/ai_observability/frontend/redesign/trace/components/AttachmentImage.tsx b/products/ai_observability/frontend/redesign/trace/adapter/AttachmentImage.tsxsimilarity index 87%rename from products/ai_observability/frontend/redesign/trace/components/AttachmentImage.tsxrename to products/ai_observability/frontend/redesign/trace/adapter/AttachmentImage.tsxindex d97631f333ad..962019ccf030 100644--- a/products/ai_observability/frontend/redesign/trace/components/AttachmentImage.tsx+++ b/products/ai_observability/frontend/redesign/trace/adapter/AttachmentImage.tsx@@ -1,6 +1,6 @@import { AIImage } from '../../../components/AIImage'-import { AttachmentLink } from './AttachmentLink'-import { classifyAttachmentUrl } from './attachmentUrl'+import { AttachmentLink } from '../components/AttachmentLink'+import { classifyAttachmentUrl } from '../components/attachmentUrl'export interface AttachmentImageProps {url: stringdiff --git a/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.ts b/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.tsindex 5048caf01eea..bbba0253daed 100644--- a/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.ts+++ b/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.ts@@ -122,7 +122,15 @@ export function makeTraceResource(overrides: Partial<TraceApi> = {}): TraceApi {})),},],- timeline: [],+ timeline: childIds.map((id) => ({+ id,+ kind: id.startsWith('gen') ? 'generation' : 'span',+ name: id,+ depth: 0,+ startMs: 0,+ durationMs: null,+ hasError: false,+ })),totalMs: 0,threadNodeIds: ['gen-2'],defaultNodeId: 'trace-1',diff --git a/products/ai_observability/frontend/redesign/trace/adapter/toNodeDetail.test.ts b/products/ai_observability/frontend/redesign/trace/adapter/toNodeDetail.test.tsindex 0b606e25e7a3..239299aa740e 100644--- a/products/ai_observability/frontend/redesign/trace/adapter/toNodeDetail.test.ts+++ b/products/ai_observability/frontend/redesign/trace/adapter/toNodeDetail.test.ts@@ -1,9 +1,9 @@-import type { TraceNodeApi } from '../../../generated/api.schemas'-import { EvalResult, EvalsState, NodeLoad } from '../types'+import type { TraceEvaluationResultApi, TraceNodeApi, TraceNodeDetailApi } from '../../../generated/api.schemas'+import { EvalResult, EvalsState, NodeContent, NodeLoad } from '../types'import { makeEvaluationResult, makeNodeDetail } from './testFixtures'import { toNodeDetail } from './toNodeDetail'-const node = (id: string, kind: 'trace' | 'span' | 'generation'): TraceNodeApi => ({+const node = (id: string, kind: TraceNodeApi['kind']): TraceNodeApi => ({id,kind,name: id,@@ -20,7 +20,7 @@ const node = (id: string, kind: 'trace' | 'span' | 'generation'): TraceNodeApi =},})-const result = (overrides: Parameters<typeof makeEvaluationResult>[0] = {}): ReturnType<typeof makeEvaluationResult> =>+const result = (overrides: Partial<TraceEvaluationResultApi> = {}): TraceEvaluationResultApi =>makeEvaluationResult({ targetNodeId: 'gen-1', ...overrides })function readyResults(evals: EvalsState): EvalResult[] {@@ -30,7 +30,7 @@ function readyResults(evals: EvalsState): EvalResult[] {return evals.results}-const ready = (detail: ReturnType<typeof makeNodeDetail>): NodeLoad => ({ status: 'ready', node: detail })+const ready = (detail: TraceNodeDetailApi): NodeLoad => ({ status: 'ready', node: detail })describe('toNodeDetail', () => {const base = {@@ -42,7 +42,7 @@ describe('toNodeDetail', () => {trace: { createdAt: '2026-09-01T10:15:00Z', sessionId: 'sess-1' },}- it.each<[string, NodeLoad, unknown]>([+ it.each<[string, NodeLoad, NodeContent]>([['loading', { status: 'loading' }, { kind: 'loading' }],['not found',diff --git a/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsx b/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsxindex 2a655f8d49ff..891183bb17e3 100644--- a/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsx+++ b/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsx@@ -17,6 +17,7 @@ import { AccessControlLevel, AccessControlResourceType } from '~/types'import { aiObservabilityTraceLogic } from '../../../aiObservabilityTraceLogic'import { saveToDatasetButtonLogic } from '../../../datasets/saveToDatasetButtonLogic'import type { TraceClusterApi } from '../../../generated/api.schemas'+import { queryEvaluationRuns } from '../../../utils'import { traceReviewLogic } from '../traceReviewLogic'import { TraceScene } from '../TraceScene'import {@@ -165,7 +166,7 @@ describe('TraceScene', () => {})})- it('opens on the default node without the legacy trace or neighbours queries', async () => {+ it('opens on the default node without the legacy trace, neighbours or evaluation runs queries', async () => {const apiQuery = jest.spyOn(api, 'query').mockResolvedValue({ results: [] })const { findAllByText, findByText } = renderNewView({ [TRACE_NAVIGATION_FLAG]: true })@@ -174,6 +175,7 @@ describe('TraceScene', () => {await expectLogic(aiObservabilityTraceLogic).toFinishAllListeners()expect(jest.mocked(performQuery).mock.calls.some(([query]) => query.kind === 'TraceQuery')).toBe(false)expect(apiQuery.mock.calls.some(([query]) => query.kind === 'TraceNeighborsQuery')).toBe(false)+ expect(queryEvaluationRuns).not.toHaveBeenCalled()apiQuery.mockRestore()})diff --git a/products/ai_observability/frontend/redesign/trace/components/AttachmentPart.tsx b/products/ai_observability/frontend/redesign/trace/components/AttachmentPart.tsxindex 6dd8847d2d2f..bef7b874128c 100644--- a/products/ai_observability/frontend/redesign/trace/components/AttachmentPart.tsx+++ b/products/ai_observability/frontend/redesign/trace/components/AttachmentPart.tsx@@ -1,6 +1,6 @@+import { AttachmentImage } from '../adapter/AttachmentImage'import { AttachmentMediaType } from '../types'import { AttachmentChip } from './AttachmentChip'-import { AttachmentImage } from './AttachmentImage'import { classifyAttachmentUrl } from './attachmentUrl'export interface AttachmentPartProps {diff --git a/products/ai_observability/frontend/redesign/trace/components/NodeContentGate.tsx b/products/ai_observability/frontend/redesign/trace/components/NodeContentGate.tsxnew file mode 100644index 000000000000..2ffb6ae71c84--- /dev/null+++ b/products/ai_observability/frontend/redesign/trace/components/NodeContentGate.tsx@@ -0,0 +1,21 @@+import { ReactNode } from 'react'++import { LemonSkeleton } from '@posthog/lemon-ui'++import { LoadedNodeContent, NodeContent } from '../types'+import { ErrorCallout } from './ErrorCallout'++export interface NodeContentGateProps {+ content: NodeContent+ children: (content: LoadedNodeContent) => ReactNode+}++export function NodeContentGate({ content, children }: NodeContentGateProps): JSX.Element {+ if (content.kind === 'loading') {+ return <LemonSkeleton repeat={3} className="h-16" />+ }+ if (content.kind === 'error') {+ return <ErrorCallout message={content.message} />+ }+ return <>{children(content)}</>+}diff --git a/products/ai_observability/frontend/redesign/trace/components/NodeDetail.stories.tsx b/products/ai_observability/frontend/redesign/trace/components/NodeDetail.stories.tsxindex 654daa0902dc..018d98c8d880 100644--- a/products/ai_observability/frontend/redesign/trace/components/NodeDetail.stories.tsx+++ b/products/ai_observability/frontend/redesign/trace/components/NodeDetail.stories.tsx@@ -93,8 +93,8 @@ export const ContentNotFound: Story = {},},}-export const RawTabWhileLoading: Story = {- args: { ...base, content: { kind: 'loading' }, initialTab: 'raw' },+export const DetailsTabWhileLoading: Story = {+ args: { ...base, content: { kind: 'loading' }, initialTab: 'details' },parameters: { testOptions: { waitForLoadersToDisappear: false } },}export const WithError: Story = {diff --git a/products/ai_observability/frontend/redesign/trace/components/NodeDetail.tsx b/products/ai_observability/frontend/redesign/trace/components/NodeDetail.tsxindex 3816420195b2..c8ca6a8b7f42 100644--- a/products/ai_observability/frontend/redesign/trace/components/NodeDetail.tsx+++ b/products/ai_observability/frontend/redesign/trace/components/NodeDetail.tsx@@ -1,11 +1,11 @@import { ReactNode } from 'react'-import { LemonSkeleton, LemonTabs } from '@posthog/lemon-ui'+import { LemonTabs } from '@posthog/lemon-ui'import type { TraceNodeApi } from '../../../generated/api.schemas'import { EvalsState, MessagesOpening, NodeContent, NodeDetailTab, NodeProperties } from '../types'-import { ErrorCallout } from './ErrorCallout'import { EvalResultList } from './EvalResultList'+import { NodeContentGate } from './NodeContentGate'import { NodeDetailHeader } from './NodeDetailHeader'import { NodeMessagesTab } from './NodeMessagesTab'import { NodePropertyList } from './NodePropertyList'@@ -34,6 +34,7 @@ export interface NodeDetailProps {export function NodeDetail(props: NodeDetailProps): JSX.Element {const highlightRef = useSearchHighlight(props.highlightQuery ?? null, props.matchStepCount)+ const propertyList = <NodePropertyList node={props.node} properties={props.properties} />return (<div className="flex min-w-0 flex-col gap-2" ref={highlightRef}><NodeDetailHeader node={props.node} actions={props.actions} stepFeedback={props.stepFeedback} />@@ -63,7 +64,13 @@ export function NodeDetail(props: NodeDetailProps): JSX.Element {key: 'details',label: 'Details','data-attr': 'trace-view-detail-tab-details',- content: <NodePropertyList node={props.node} properties={props.properties} />,+ // The root's properties come from the trace, so they do not wait for its step read.+ content:+ props.node.kind === 'trace' ? (+ propertyList+ ) : (+ <NodeContentGate content={props.content}>{() => propertyList}</NodeContentGate>+ ),},{key: 'evals',@@ -75,14 +82,11 @@ export function NodeDetail(props: NodeDetailProps): JSX.Element {key: 'raw',label: 'Raw','data-attr': 'trace-view-detail-tab-raw',- content:- props.content.kind === 'loading' ? (- <LemonSkeleton repeat={3} className="h-16" />- ) : props.content.kind === 'error' ? (- <ErrorCallout message={props.content.message} />- ) : (- <NodeRawTab raw={props.raw} />- ),+ content: (+ <NodeContentGate content={props.content}>+ {() => <NodeRawTab raw={props.raw} />}+ </NodeContentGate>+ ),},]}/>diff --git a/products/ai_observability/frontend/redesign/trace/components/NodeMessagesTab.tsx b/products/ai_observability/frontend/redesign/trace/components/NodeMessagesTab.tsxindex 53d97b64889c..f4429d0748ae 100644--- a/products/ai_observability/frontend/redesign/trace/components/NodeMessagesTab.tsx+++ b/products/ai_observability/frontend/redesign/trace/components/NodeMessagesTab.tsx@@ -1,13 +1,14 @@import { useEffect, useRef, useState } from 'react'import { IconMessage } from '@posthog/icons'-import { LemonButton, LemonSegmentedButton, LemonSkeleton } from '@posthog/lemon-ui'+import { LemonButton, LemonSegmentedButton } from '@posthog/lemon-ui'import { MessagesOpening, NodeContent } from '../types'import { ErrorCallout } from './ErrorCallout'import { firstOpenIndex } from './firstOpenIndex'import { IOPanel } from './IOPanel'import { MessageSection } from './MessageSection'+import { NodeContentGate } from './NodeContentGate'import { revealFirstOpenMessage } from './revealFirstOpenMessage'export interface NodeMessagesTabProps {@@ -64,67 +65,72 @@ export function NodeMessagesTab({return (<div className="flex flex-col gap-3" ref={containerRef}>{error ? <ErrorCallout message={error} /> : null}- {content.kind === 'loading' ? (- <LemonSkeleton repeat={3} className="h-16" />- ) : content.kind === 'error' ? (- <ErrorCallout message={content.message} />- ) : content.kind === 'messages' ? (- <>- <div className="flex justify-end">- <LemonSegmentedButton- size="xsmall"- value={opening}- onChange={selectOpening}- data-attr="trace-view-messages-opening"- options={[- {- value: 'lastTurn',- label: 'Last turn',- tooltip: tooltip('lastTurn', 'Open messages from the last user message on'),- 'data-attr': 'trace-view-messages-opening-last-turn',- },- {- value: 'everything',- label: 'Everything',- tooltip: tooltip('everything', 'Open every message'),- 'data-attr': 'trace-view-messages-opening-everything',- },- ]}- />- </div>- {/* A new key remounts the messages, which drops what was opened or closed by hand. */}- <div key={listKey} className="flex flex-col gap-3">- <MessageSection- title="Input"- messages={content.input}- emptyText="No input captured."- openFrom={firstOpenIndex(content.input, opening)}- highlightQuery={highlightQuery}- />- <MessageSection- title="Output"- messages={content.output}- emptyText="No output captured."- openFrom={0}- highlightQuery={highlightQuery}- />- </div>- </>- ) : (- <IOPanel input={content.input} output={content.output} />- )}- {onViewInThread && content.kind !== 'loading' ? (- <LemonButton- type="secondary"- size="small"- icon={<IconMessage />}- className="self-start"- onClick={onViewInThread}- data-attr="trace-view-view-in-thread"- >- View in thread- </LemonButton>- ) : null}+ <NodeContentGate content={content}>+ {(loaded) => (+ <>+ {loaded.kind === 'messages' ? (+ <>+ <div className="flex justify-end">+ <LemonSegmentedButton+ size="xsmall"+ value={opening}+ onChange={selectOpening}+ data-attr="trace-view-messages-opening"+ options={[+ {+ value: 'lastTurn',+ label: 'Last turn',+ tooltip: tooltip(+ 'lastTurn',+ 'Open messages from the last user message on'+ ),+ 'data-attr': 'trace-view-messages-opening-last-turn',+ },+ {+ value: 'everything',+ label: 'Everything',+ tooltip: tooltip('everything', 'Open every message'),+ 'data-attr': 'trace-view-messages-opening-everything',+ },+ ]}+ />+ </div>+ {/* A new key remounts the messages, which drops what was opened or closed by hand. */}+ <div key={listKey} className="flex flex-col gap-3">+ <MessageSection+ title="Input"+ messages={loaded.input}+ emptyText="No input captured."+ openFrom={firstOpenIndex(loaded.input, opening)}+ highlightQuery={highlightQuery}+ />+ <MessageSection+ title="Output"+ messages={loaded.output}+ emptyText="No output captured."+ openFrom={0}+ highlightQuery={highlightQuery}+ />+ </div>+ </>+ ) : (+ <IOPanel input={loaded.input} output={loaded.output} />+ )}+ {onViewInThread ? (+ <LemonButton+ type="secondary"+ size="small"+ icon={<IconMessage />}+ className="self-start"+ onClick={onViewInThread}+ data-attr="trace-view-view-in-thread"+ >+ View in thread+ </LemonButton>+ ) : null}+ </>+ )}+ </NodeContentGate></div>)}diff --git a/products/ai_observability/frontend/redesign/trace/traceViewLogic.test.ts b/products/ai_observability/frontend/redesign/trace/traceViewLogic.test.tsindex bd85e0b0dd81..ae1a672dd29c 100644--- a/products/ai_observability/frontend/redesign/trace/traceViewLogic.test.ts+++ b/products/ai_observability/frontend/redesign/trace/traceViewLogic.test.ts@@ -214,17 +214,23 @@ describe('traceViewLogic', () => {)it.each([- [404, 'not_found'],- [500, 'failed'],- ])('a node read answered with %s fails as %s', async (status, failure) => {- const logic = await mountedLogic()- nodeStatus = status+ [404, 'not_found', false],+ [500, 'failed', true],+ [503, 'failed', false],+ ])(+ 'a node read answered with %s fails as %s, reported to error tracking: %s',+ async (status, failure, reported) => {+ const report = jest.spyOn(posthog, 'captureException')+ const logic = await mountedLogic()+ nodeStatus = status- logic.actions.loadNode('span-1', 'selection')- await expectLogic(logic).toFinishAllListeners()+ logic.actions.loadNode('span-1', 'selection')+ await expectLogic(logic).toFinishAllListeners()- expect(logic.values.nodes['span-1']).toEqual({ status: 'error', failure })- })+ expect(logic.values.nodes['span-1']).toEqual({ status: 'error', failure })+ expect(report).toHaveBeenCalledTimes(reported ? 1 : 0)+ }+ )it.each(['selection', 'navigation'] as const)('retries a failed node on a %s but not on a prefetch',@@ -277,7 +283,7 @@ describe('traceViewLogic', () => {expect(capture).toHaveBeenCalledWith('llma trace view loaded', {trace_load_ms: expect.any(Number),- node_count: 0,+ node_count: 4,})expect(capture).toHaveBeenCalledWith('llma trace node loaded', {load_ms: expect.any(Number),diff --git a/products/ai_observability/frontend/redesign/trace/traceViewLogic.ts b/products/ai_observability/frontend/redesign/trace/traceViewLogic.tsindex 3808c28b1754..a121a305e8a4 100644--- a/products/ai_observability/frontend/redesign/trace/traceViewLogic.ts+++ b/products/ai_observability/frontend/redesign/trace/traceViewLogic.ts@@ -3,6 +3,7 @@ import { loaders } from 'kea-loaders'import posthog from 'posthog-js'import { ApiConfig, ApiError } from 'lib/api'+import { shouldReportApiFailure } from 'lib/api-error'import { urls } from 'scenes/urls'import {@@ -159,6 +160,13 @@ function toLoadFailure(error: unknown): LoadFailure {return error instanceof ApiError && error.status === 404 ? 'not_found' : 'failed'}+function needsRead(current: NodeLoad | undefined, trigger: NodeLoadTrigger): boolean {+ if (!current) {+ return true+ }+ return current.status === 'error' && (trigger === 'selection' || trigger === 'navigation')+}+export function elapsedMs(since: number): number {return Math.round(performance.now() - since)}@@ -298,7 +306,8 @@ export const traceViewLogic = kea<traceViewLogicType>([loadTraceSuccess: ({ trace }) => {posthog.capture('llma trace view loaded', {trace_load_ms: elapsedMs(cache.traceRequestedAt),- node_count: trace.timeline.length,+ // The timeline lists every step but the root.+ node_count: trace.timeline.length + 1,})for (const nodeId of trace.threadNodeIds) {actions.loadNode(nodeId, 'thread')@@ -309,10 +318,7 @@ export const traceViewLogic = kea<traceViewLogicType>([if (trigger === 'selection' && current?.status !== 'ready') {selectedAt()[nodeId] ??= performance.now()}- if (current?.status === 'loading' || current?.status === 'ready') {- return- }- if (current?.status === 'error' && trigger !== 'selection' && trigger !== 'navigation') {+ if (!needsRead(current, trigger)) {return}if (trigger === 'prefetch') {@@ -335,7 +341,13 @@ export const traceViewLogic = kea<traceViewLogicType>([hint ? { timestamp_hint: hint } : undefined).then((node: TraceNodeDetailApi) => ({ node }),- (error: unknown) => ({ failure: toLoadFailure(error) })+ (error: unknown) => {+ const failure = toLoadFailure(error)+ if (failure === 'failed' && shouldReportApiFailure(error)) {+ posthog.captureException(error)+ }+ return { failure }+ })// A read can answer after the view closed, and a reopened view of the trace shares its actions.if (cache.disposables.isDisposed) {diff --git a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.tsindex 5ed2cc3e178e..dbd2d8259823 100644--- a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts+++ b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.test.ts@@ -205,7 +205,6 @@ describe('traceViewModelLogic', () => {releaseTrace = resolve})mountAt()- await waitFor(() => expect(nodeRequests).toEqual(['trace-1']))host.actions.requestStep('next-trace-step', 'trace-2')releaseTrace()@@ -221,7 +220,6 @@ describe('traceViewModelLogic', () => {})mountAt()- await waitFor(() => expect(nodeRequests).toEqual(['trace-1']))expect(clusterRequests).toEqual([])expect(logic.values.clustersChip).toBeNull()@@ -242,6 +240,17 @@ describe('traceViewModelLogic', () => {expect(toast).not.toHaveBeenCalled()})+ it.each([+ ['a root without state', 'gen-1'],+ ['a root with state', 'trace-1'],+ ])('reads only the default step and the thread when the trace opens on %s', async (_name, defaultNodeId) => {+ traceResource = makeTraceResource({ defaultNodeId })+ mountAt()+ await expectLogic(logic).toFinishAllListeners()++ expect([...nodeRequests].sort()).toEqual([defaultNodeId, 'gen-2'].sort())+ })+it('reports the reads that open the view as navigation and a click on an unread step as a selection', async () => {const capture = jest.spyOn(posthog, 'capture')traceResource = makeTraceResource({ defaultNodeId: 'gen-1' })diff --git a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.tsindex cb1579ee35f3..4202c36a2a45 100644--- a/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts+++ b/products/ai_observability/frontend/redesign/trace/traceViewModelLogic.ts@@ -125,6 +125,7 @@ export interface traceViewModelLogicValues {highlightQuery: string | nullmatchStepCount: numbermatchingNodeIds: ReadonlySet<string> | null+ nodeIdToRead: string | nullreadySearchResults: TraceSearchResultsApi | nullsearchBox: TraceSearchBoxDataselectedNodeId: string@@ -248,6 +249,7 @@ export interface traceViewModelLogicMeta {nodeIdsByAlias: Record<string, string>,traceId: string) => string+ nodeIdToRead: (status: TraceViewStatus, requestedStepId: string | null, selectedNodeId: string) => string | nullselectedTreeNode: (tree: TraceNodeApi[], selectedNodeId: string) => TraceNodeApi | nullselectedNodeLoad: (selectedNodeId: string, nodes: Record<string, NodeLoad>) => NodeLoadthreadNodeLoad: (threadNodeIds: string[], nodes: Record<string, NodeLoad>) => NodeLoad | null@@ -450,6 +452,12 @@ export const traceViewModelLogic = kea<traceViewModelLogicType>([return nodeIdsByAlias[requestedStepId] ?? traceId},],+ // Until the trace names its default step, only a step the URL asks for is worth reading.+ nodeIdToRead: [+ (s) => [s.status, s.requestedStepId, s.selectedNodeId],+ (status: TraceViewStatus, requestedStepId: string | null, selectedNodeId: string): string | null =>+ status === 'ready' || requestedStepId ? selectedNodeId : null,+ ],selectedTreeNode: [(s) => [s.tree, s.selectedNodeId],(tree: TraceNodeApi[], selectedNodeId: string): TraceNodeApi | null => findTreeNode(tree, selectedNodeId),@@ -637,7 +645,7 @@ export const traceViewModelLogic = kea<traceViewModelLogicType>([],}),listeners(({ actions, values, props }) => {- // The click's read starts before the selection moves, so the selectedNodeId subscription's navigation read+ // The click's read starts before the selection moves, so the nodeIdToRead subscription's navigation read// for the same id is deduped and the load event reports a click. Selecting the node that is already// selected changes no value and the subscription does not fire, so this read also retries a failed node.const select = ({ id }: { id: string }): void => {@@ -715,12 +723,15 @@ export const traceViewModelLogic = kea<traceViewModelLogicType>([}}),subscriptions(({ actions, props, values }) => ({- selectedNodeId: (selectedNodeId: string) => {+ nodeIdToRead: (nodeIdToRead: string | null) => {// 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) {+ if (+ nodeIdToRead === null ||+ (values.requestedTraceId !== null && values.requestedTraceId !== props.traceId)+ ) {return}- actions.loadNode(selectedNodeId, 'navigation')+ actions.loadNode(nodeIdToRead, 'navigation')},mode: (mode: TraceMode) => {if (mode === 'summary' && !values.summaryIsOpen) {diff --git a/products/ai_observability/frontend/redesign/trace/types.ts b/products/ai_observability/frontend/redesign/trace/types.tsindex 5ab5119c6e41..f2f32949eec8 100644--- a/products/ai_observability/frontend/redesign/trace/types.ts+++ b/products/ai_observability/frontend/redesign/trace/types.ts@@ -75,6 +75,8 @@ export type NodeContent =| { kind: 'loading' }| { kind: 'error'; message: string }+export type LoadedNodeContent = Extract<NodeContent, { kind: 'messages' | 'io' }>+export interface NodeProperties {timestamp: string | nullprovider: string | null