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.

perf(aio): load the global column renderers on first use (#110095)

Paul D'Ambra5a330d6f4441
diff --git a/frontend/src/queries/nodes/DataTable/renderColumn.tsx b/frontend/src/queries/nodes/DataTable/renderColumn.tsx
index 7893528d0335..322f65b4685a 100644
--- a/frontend/src/queries/nodes/DataTable/renderColumn.tsx
+++ b/frontend/src/queries/nodes/DataTable/renderColumn.tsx
@@ -42,7 +42,7 @@ import {
} from '~/queries/utils'
import { AnyPropertyFilter, EventType, PersonType, PropertyFilterType, PropertyOperator } from '~/types'
-import { aiObservabilityGlobalColumnRenderers } from 'products/ai_observability/frontend/aiObservabilityColumnRenderers'
+import { aiObservabilityGlobalColumnRenderers } from 'products/ai_observability/frontend/aiObservabilityGlobalColumns'
import { GroupActorDisplay } from 'products/persons/frontend/components/GroupActorDisplay'
import { PersonDisplay, PersonDisplayProps } from 'products/persons/frontend/components/PersonDisplay'
import { pickBestPersonDistinctId } from 'products/persons/frontend/person-utils'
diff --git a/products/ai_observability/frontend/AIObservabilityGlobalColumnCell.tsx b/products/ai_observability/frontend/AIObservabilityGlobalColumnCell.tsx
new file mode 100644
index 000000000000..8a7b90ec9fde
--- /dev/null
+++ b/products/ai_observability/frontend/AIObservabilityGlobalColumnCell.tsx
@@ -0,0 +1,29 @@
+import { ComponentProps, Suspense } from 'react'
+
+import { Spinner } from 'lib/lemon-ui/Spinner/Spinner'
+import { lazyWithRetry } from 'lib/utils/retryImport'
+import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'
+
+import { QueryContextColumnComponent } from '~/queries/types'
+
+type CellProps = ComponentProps<QueryContextColumnComponent> & { rendererKey: string }
+
+const RendererCell = lazyWithRetry(() =>
+ import('./aiObservabilityColumnRenderers').then(({ aiObservabilityColumnRenderers }) => ({
+ default: function RendererCell({ rendererKey, ...props }: CellProps): JSX.Element | null {
+ const Render = aiObservabilityColumnRenderers[rendererKey]?.render
+ return Render ? <Render {...props} /> : null
+ },
+ }))
+)
+
+export function AIObservabilityGlobalColumnCell(props: CellProps): JSX.Element {
+ return (
+ // The query's own ErrorBoundary is nearer than the scene's, so without this a stale chunk never reloads.
+ <ChunkLoadErrorBoundary>
+ <Suspense fallback={<Spinner />}>
+ <RendererCell {...props} />
+ </Suspense>
+ </ChunkLoadErrorBoundary>
+ )
+}
diff --git a/products/ai_observability/frontend/aiObservabilityColumnRenderers.test.ts b/products/ai_observability/frontend/aiObservabilityColumnRenderers.test.ts
index c88f9bf876f2..f9535b19b455 100644
--- a/products/ai_observability/frontend/aiObservabilityColumnRenderers.test.ts
+++ b/products/ai_observability/frontend/aiObservabilityColumnRenderers.test.ts
@@ -4,13 +4,26 @@ import { PropertyFilterType, PropertyOperator } from '~/types'
import {
FilterIdentifier,
PersonData,
+ aiObservabilityColumnRenderers,
createPersonFilter,
getEventData,
getFilterIdentifier,
getTracesUrlWithPersonFilter,
} from './aiObservabilityColumnRenderers'
+import { aiObservabilityGlobalColumnRenderers } from './aiObservabilityGlobalColumns'
describe('aiObservabilityColumnRenderers', () => {
+ describe('aiObservabilityGlobalColumnRenderers', () => {
+ // The global keys are listed by hand so that tables can skip the renderer module. A namespaced
+ // renderer missing from that list would stop applying outside the AI observability scenes.
+ it('lists every namespaced renderer', () => {
+ const namespacedKeys = Object.keys(aiObservabilityColumnRenderers).filter(
+ (key) => key.startsWith('properties.$ai_') || key.startsWith('__llm_')
+ )
+ expect(Object.keys(aiObservabilityGlobalColumnRenderers).sort()).toEqual(namespacedKeys.sort())
+ })
+ })
+
describe('getEventData', () => {
// Regression: without traceId + timestamp, useAIData can never fetch stripped heavy props,
// so Input/Output cells fall back to empty instead of loading the full payload.
diff --git a/products/ai_observability/frontend/aiObservabilityColumnRenderers.tsx b/products/ai_observability/frontend/aiObservabilityColumnRenderers.tsx
index 9d215568d642..5bf82c424c3d 100644
--- a/products/ai_observability/frontend/aiObservabilityColumnRenderers.tsx
+++ b/products/ai_observability/frontend/aiObservabilityColumnRenderers.tsx
@@ -536,14 +536,3 @@ export const aiObservabilityColumnRenderers: Record<string, QueryContextColumn>
},
},
}
-
-// The subset that `renderColumn` applies to every DataTable in the app. A key here wins over the
-// core renderer for that column name everywhere, so only namespaced keys belong: a `$ai_` property,
-// or a name carrying the `__llm_` prefix. A plain name such as `person` would take the column over
-// in the events table and the persons list too. Scenes opt into the rest through their own
-// QueryContext, the way AIObservabilityTracesScene does.
-export const aiObservabilityGlobalColumnRenderers: Record<string, QueryContextColumn> = Object.fromEntries(
- Object.entries(aiObservabilityColumnRenderers).filter(
- ([key]) => key.startsWith('properties.$ai_') || key.startsWith('__llm_')
- )
-)
diff --git a/products/ai_observability/frontend/aiObservabilityGlobalColumns.tsx b/products/ai_observability/frontend/aiObservabilityGlobalColumns.tsx
new file mode 100644
index 000000000000..e3744632ccf4
--- /dev/null
+++ b/products/ai_observability/frontend/aiObservabilityGlobalColumns.tsx
@@ -0,0 +1,31 @@
+import { QueryContextColumn } from '~/queries/types'
+
+import { AIObservabilityGlobalColumnCell } from './AIObservabilityGlobalColumnCell'
+
+// Each entry names its own renderer, so the cell does not depend on the column name it is given.
+function globalColumn(rendererKey: string): QueryContextColumn {
+ return {
+ render: function AIObservabilityGlobalColumn(props) {
+ return <AIObservabilityGlobalColumnCell {...props} rendererKey={rendererKey} />
+ },
+ }
+}
+
+// The renderers that `renderColumn` applies to every DataTable in the app. A key here wins over the
+// core renderer for that column name everywhere, so only namespaced keys belong: a `$ai_` property,
+// or a name carrying the `__llm_` prefix. A plain name such as `person` would take the column over
+// in the events table and the persons list too. Scenes opt into the rest through their own
+// QueryContext, the way AIObservabilityTracesScene does.
+// The cell loads the renderers on first use, so a table without these columns skips that module.
+export const aiObservabilityGlobalColumnRenderers: Record<string, QueryContextColumn> = Object.fromEntries(
+ [
+ 'properties.$ai_input[-1]',
+ 'properties.$ai_input',
+ 'properties.$ai_output_choices',
+ 'properties.$ai_trace_id',
+ 'properties.$ai_tools_called',
+ '__llm_sentiment',
+ '__llm_tools',
+ '__llm_person',
+ ].map((rendererKey) => [rendererKey, globalColumn(rendererKey)])
+)