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(insights): restore insight error message telemetry (#69174)

Thomas Obermüller43bd31e4331a
diff --git a/frontend/src/queries/query.test.ts b/frontend/src/queries/query.test.ts
index 98ea92e633f7..cc9633ec3d66 100644
--- a/frontend/src/queries/query.test.ts
+++ b/frontend/src/queries/query.test.ts
@@ -152,7 +152,14 @@ describe('query', () => {
const queryFailedCalls = captureSpy.mock.calls.filter((call) => call[0] === 'query failed')
expect(queryFailedCalls).toHaveLength(1)
- expect(queryFailedCalls[0][1]).toMatchObject({ query: q, duration: expect.any(Number) })
+ expect(queryFailedCalls[0][1]).toMatchObject({
+ query: q,
+ duration: expect.any(Number),
+ error_status: 500,
+ error_code: null,
+ })
+ // Raw error text must stay out of telemetry
+ expect(queryFailedCalls[0][1]).not.toHaveProperty('error_message')
})
describe('waitForPageVisible', () => {
diff --git a/frontend/src/queries/query.ts b/frontend/src/queries/query.ts
index bbdea3f168f9..0b3f35f1bd77 100644
--- a/frontend/src/queries/query.ts
+++ b/frontend/src/queries/query.ts
@@ -273,10 +273,14 @@ export async function performQuery<N extends DataNode>(
})
return response
} catch (e) {
+ // Raw error detail/message can echo query fragments, so telemetry only gets status and code
+ const error = e as (Error & { status?: number; code?: string | null }) | null
posthog.capture('query failed', {
query: queryNode,
queryId,
duration: performance.now() - startTime,
+ error_status: error?.status ?? null,
+ error_code: error?.code ?? null,
...logParams,
})
throw e
diff --git a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx
index 5952f9a5ee33..577f86a6260c 100644
--- a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx
+++ b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx
@@ -15,11 +15,13 @@ import { MCPUseCaseCard } from 'lib/components/MCPHint/MCPUseCaseCard'
import { supportLogic } from 'lib/components/Support/supportLogic'
import { dayjs } from 'lib/dayjs'
import { holidaysMatcher, isChristmas } from 'lib/holidays'
+import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { usePageVisibility } from 'lib/hooks/usePageVisibility'
import { IconChristmasOrnament, IconErrorOutline, IconOpenInNew } from 'lib/lemon-ui/icons'
import { LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu/LemonMenu'
import { Link } from 'lib/lemon-ui/Link'
import { LoadingBar } from 'lib/lemon-ui/LoadingBar'
+import posthog from 'lib/posthog-typed'
import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
import { humanFriendlyNumber, humanizeBytes } from 'lib/utils/numbers'
import { isTrustedPostHogUrl } from 'lib/utils/trustedUrl'
@@ -547,6 +549,12 @@ export function renderDetailWithLinks(detail: string): (string | JSX.Element)[]
)
}
+/** Kind of the query that errored, unwrapping InsightVizNode/DataTableNode wrappers to the source query. */
+function queryKindForReporting(query: Record<string, any> | Node | null | undefined): string | null {
+ const record = query as Record<string, any> | null | undefined
+ return record?.source?.kind ?? record?.kind ?? null
+}
+
export function InsightValidationError({
detail,
validationErrorCode,
@@ -566,6 +574,15 @@ export function InsightValidationError({
const defaultCta =
cta ?? (onRetry ? <RetryButton onRetry={onRetry} query={query} /> : <QueryDebuggerButton query={query} />)
+ // Raw error detail can echo query fragments, so telemetry only gets the code and coarse metadata
+ useOnMountEffect(() => {
+ posthog.capture('insight error message shown', {
+ error_type: 'validation',
+ code: validationErrorCode ?? null,
+ query_kind: queryKindForReporting(query),
+ })
+ })
+
return (
<div
data-attr="insight-empty-state"
@@ -646,6 +663,16 @@ export function InsightErrorState({
const { preflight } = useValues(preflightLogic)
const { openSupportForm } = useActions(supportLogic)
+ // Raw error detail can echo query fragments, so telemetry only gets coarse metadata;
+ // query_id lets staff look the actual error up server-side
+ useOnMountEffect(() => {
+ posthog.capture('insight error message shown', {
+ error_type: 'server',
+ query_kind: queryKindForReporting(query),
+ query_id: queryId ?? null,
+ })
+ })
+
if (!preflight?.cloud) {
excludeDetail = true // We don't provide support for self-hosted instances
}
diff --git a/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsx b/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsx
new file mode 100644
index 000000000000..e0538fd499d1
--- /dev/null
+++ b/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsx
@@ -0,0 +1,53 @@
+import { cleanup, render } from '@testing-library/react'
+import posthog from 'posthog-js'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { InsightErrorState, InsightValidationError } from './EmptyStates'
+
+describe('insight error states', () => {
+ let captureSpy: jest.SpyInstance
+
+ beforeEach(() => {
+ useMocks({})
+ initKeaTests()
+ captureSpy = jest.spyOn(posthog, 'capture')
+ captureSpy.mockClear()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('reports "insight error message shown" when a validation error renders', () => {
+ render(
+ <InsightValidationError
+ detail="Funnels require at least two steps."
+ validationErrorCode="funnels_require_at_least_two_steps"
+ query={{ kind: 'InsightVizNode', source: { kind: 'FunnelsQuery' } }}
+ />
+ )
+
+ const shownCalls = captureSpy.mock.calls.filter((call) => call[0] === 'insight error message shown')
+ expect(shownCalls).toHaveLength(1)
+ // Exact match: raw error detail must stay out of telemetry
+ expect(shownCalls[0][1]).toEqual({
+ error_type: 'validation',
+ code: 'funnels_require_at_least_two_steps',
+ query_kind: 'FunnelsQuery',
+ })
+ })
+
+ it('reports "insight error message shown" when a server error renders', () => {
+ render(<InsightErrorState title="A server error occurred." queryId="test-query-id" />)
+
+ const shownCalls = captureSpy.mock.calls.filter((call) => call[0] === 'insight error message shown')
+ expect(shownCalls).toHaveLength(1)
+ expect(shownCalls[0][1]).toEqual({
+ error_type: 'server',
+ query_kind: null,
+ query_id: 'test-query-id',
+ })
+ })
+})