: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(error-tracking): use canonical exception properties (#73940)
Hugues Pouillot01cb1fc4725b
diff --git a/products/conversations/backend/ai/suggest.py b/products/conversations/backend/ai/suggest.pyindex d8c3e709fd61..7242305345d7 100644--- a/products/conversations/backend/ai/suggest.py+++ b/products/conversations/backend/ai/suggest.py@@ -129,6 +129,8 @@ def _fetch_session_exceptions(team: Team, session_id: str, ticket_created_at: stselect=["event","timestamp",+ "properties.$exception_values",+ "properties.$exception_types","properties.$exception_message","properties.$exception_type","properties.$current_url",@@ -153,6 +155,14 @@ def _fetch_session_exceptions(team: Team, session_id: str, ticket_created_at: streturn exceptions+def _first_string(value: object) -> str | None:+ if isinstance(value, str):+ return value+ if isinstance(value, list) and value and isinstance(value[0], str):+ return value[0]+ return None++def _format_enhanced_context(conversation_text: str,events: list[dict],@@ -164,8 +174,20 @@ def _format_enhanced_context(if exceptions:parts.append("\n\nRecent exceptions from the user's session:")for exc in exceptions[-MAX_EXCEPTIONS_CONTEXT:]:- exc_type = exc.get("properties.$exception_type") or exc.get("$exception_type") or "Unknown"- exc_msg = exc.get("properties.$exception_message") or exc.get("$exception_message") or "No message"+ exc_type = (+ _first_string(exc.get("properties.$exception_types"))+ or _first_string(exc.get("$exception_types"))+ or _first_string(exc.get("properties.$exception_type"))+ or _first_string(exc.get("$exception_type"))+ or "Unknown"+ )+ exc_msg = (+ _first_string(exc.get("properties.$exception_values"))+ or _first_string(exc.get("$exception_values"))+ or _first_string(exc.get("properties.$exception_message"))+ or _first_string(exc.get("$exception_message"))+ or "No message"+ )url = exc.get("properties.$current_url") or exc.get("$current_url") or ""ts = exc.get("timestamp", "")parts.append(f"- [{ts}] {exc_type}: {exc_msg} (on {url})")diff --git a/products/conversations/backend/ai/test_suggest.py b/products/conversations/backend/ai/test_suggest.pynew file mode 100644index 000000000000..39a1b4ae1827--- /dev/null+++ b/products/conversations/backend/ai/test_suggest.py@@ -0,0 +1,24 @@+from django.test import SimpleTestCase++from parameterized import parameterized++from products.conversations.backend.ai.suggest import _format_enhanced_context+++class TestFormatEnhancedContext(SimpleTestCase):+ @parameterized.expand(+ [+ (+ "canonical array properties",+ {"properties.$exception_types": ["TypeError"], "properties.$exception_values": ["Bad call"]},+ ),+ (+ "legacy scalar properties",+ {"properties.$exception_type": "TypeError", "properties.$exception_message": "Bad call"},+ ),+ ]+ )+ def test_formats_exception_type_and_message(self, _name: str, exception: dict[str, object]) -> None:+ context = _format_enhanced_context("Conversation", [], [exception])++ assert "TypeError: Bad call" in contextdiff --git a/products/error_tracking/backend/prompts.py b/products/error_tracking/backend/prompts.pyindex cc3c083b0709..5e28613cae63 100644--- a/products/error_tracking/backend/prompts.py+++ b/products/error_tracking/backend/prompts.py@@ -163,7 +163,7 @@ Choose appropriate operators based on the query intent:**Exception-related (event type)**:- `$exception_types`: Type of exception (e.g., "TypeError", "ReferenceError") as a list of strings- `$exception_values`: Error message text as a list of strings-- `$exception_stack_trace`: Stack trace information+- `$exception_list`: Normalized exception chain, including stack trace frames- `$exception_sources`: Source file paths where error occurred as a list of strings**Context Properties (event type)**:diff --git a/products/error_tracking/mcp/apps/ErrorDetailsView.test.tsx b/products/error_tracking/mcp/apps/ErrorDetailsView.test.tsxnew file mode 100644index 000000000000..1bda5c967b2e--- /dev/null+++ b/products/error_tracking/mcp/apps/ErrorDetailsView.test.tsx@@ -0,0 +1,57 @@+import { cleanup, render, screen } from '@testing-library/react'+import { type ReactElement } from 'react'++import { ErrorDetailsView } from './ErrorDetailsView'++jest.mock(+ '@posthog/mcp-ui',+ () => ({+ DescriptionList: (): null => null,+ formatDate: (value: string): string => value,+ }),+ { virtual: true }+)++jest.mock(+ '@posthog/quill',+ () => ({+ Badge: ({ children }: { children: ReactElement }): ReactElement => <span>{children}</span>,+ Card: ({ children }: { children: ReactElement }): ReactElement => <div>{children}</div>,+ CardContent: ({ children }: { children: ReactElement }): ReactElement => <div>{children}</div>,+ Empty: ({ children }: { children: ReactElement }): ReactElement => <div>{children}</div>,+ EmptyDescription: ({ children }: { children: ReactElement }): ReactElement => <div>{children}</div>,+ EmptyHeader: ({ children }: { children: ReactElement }): ReactElement => <div>{children}</div>,+ EmptyTitle: ({ children }: { children: ReactElement }): ReactElement => <div>{children}</div>,+ }),+ { virtual: true }+)++jest.mock('./StackTraceView', () => ({ StackTraceView: (): null => null }))++describe('ErrorDetailsView', () => {+ afterEach(cleanup)++ it('shows synthetic exceptions from the canonical exception list', () => {+ render(+ <ErrorDetailsView+ data={{+ results: [+ {+ properties: {+ $exception_list: [+ {+ type: 'TypeError',+ value: 'Bad call',+ mechanism: { synthetic: true },+ },+ ],+ },+ },+ ],+ }}+ />+ )++ expect(screen.getByText('Synthetic')).toBeTruthy()+ })+})diff --git a/products/error_tracking/mcp/apps/ErrorDetailsView.tsx b/products/error_tracking/mcp/apps/ErrorDetailsView.tsxindex c579b31cfcbd..0b2b842ccefa 100644--- a/products/error_tracking/mcp/apps/ErrorDetailsView.tsx+++ b/products/error_tracking/mcp/apps/ErrorDetailsView.tsx@@ -66,6 +66,8 @@ export function ErrorDetailsView({ data }: { data: ErrorDetailsData }): ReactEleconst exceptionType = firstString(properties.$exception_types) ?? exceptions[0]?.type ?? 'Error'const exceptionMessage = firstString(properties.$exception_values) ?? exceptions[0]?.value ?? ''+ const isSynthetic =+ properties.$exception_synthetic === true || exceptions.some((exception) => exception.mechanism?.synthetic)return (<div className="p-4">@@ -73,7 +75,7 @@ export function ErrorDetailsView({ data }: { data: ErrorDetailsData }): ReactEle<div className="flex flex-col gap-1"><div className="flex items-center gap-2 flex-wrap"><Badge variant="destructive">{exceptionType}</Badge>- {properties.$exception_synthetic && <Badge>Synthetic</Badge>}+ {isSynthetic && <Badge>Synthetic</Badge>}</div><span className="text-sm">{exceptionMessage}</span></div>diff --git a/products/error_tracking/mcp/apps/StackTraceView.tsx b/products/error_tracking/mcp/apps/StackTraceView.tsxindex cbdf7edb6722..3a5f29fcee33 100644--- a/products/error_tracking/mcp/apps/StackTraceView.tsx+++ b/products/error_tracking/mcp/apps/StackTraceView.tsx@@ -23,7 +23,7 @@ export interface ExceptionData {type: stringvalue: stringmodule?: string- mechanism?: { handled?: boolean; type?: string }+ mechanism?: { handled?: boolean; synthetic?: boolean; type?: string }stacktrace?: {type?: stringframes?: StackFrame[]diff --git a/products/mcp_analytics/backend/management/commands/seed_mcp_sessions.py b/products/mcp_analytics/backend/management/commands/seed_mcp_sessions.pyindex dc1ed45cc7df..76234f0bec10 100644--- a/products/mcp_analytics/backend/management/commands/seed_mcp_sessions.py+++ b/products/mcp_analytics/backend/management/commands/seed_mcp_sessions.py@@ -407,6 +407,7 @@ class Command(BaseCommand):# Pair some failures with an $exception event so the tool detail# "Failures" table (which reads $exception events) has data.if is_error and rng.random() < EXCEPTION_PAIR_PROBABILITY:+ exception_message = rng.choice(EXCEPTION_MESSAGES)create_event(event_uuid=uuid.uuid4(),event="$exception",@@ -420,7 +421,15 @@ class Command(BaseCommand):"$session_id": session_id,"$mcp_tool_name": tool_name,"$mcp_client_name": client_name,- "$exception_message": rng.choice(EXCEPTION_MESSAGES),+ "$exception_types": ["MCPToolError"],+ "$exception_values": [exception_message],+ "$exception_list": [+ {+ "type": "MCPToolError",+ "value": exception_message,+ "mechanism": {"handled": True},+ }+ ],},)total_events += 1diff --git a/products/posthog_ai/skills/querying-posthog-data/references/models-error-tracking.md b/products/posthog_ai/skills/querying-posthog-data/references/models-error-tracking.mdindex 51e056c32614..b6aed57adbc1 100644--- a/products/posthog_ai/skills/querying-posthog-data/references/models-error-tracking.md+++ b/products/posthog_ai/skills/querying-posthog-data/references/models-error-tracking.md@@ -116,9 +116,9 @@ ORDER BY count DESC```sqlSELECTtimestamp,- properties.$exception_type AS exception_type,- properties.$exception_message AS exception_message,- properties.$exception_source AS source,+ properties.$exception_types[1] AS exception_type,+ properties.$exception_values[1] AS exception_message,+ properties.$exception_sources[1] AS source,person.id AS user_idFROM eventsWHERE event = '$exception'diff --git a/products/replay/skills/investigating-replay/SKILL.md b/products/replay/skills/investigating-replay/SKILL.mdindex 7fb856c2956a..1ae92c0b7ee2 100644--- a/products/replay/skills/investigating-replay/SKILL.md+++ b/products/replay/skills/investigating-replay/SKILL.md@@ -82,8 +82,8 @@ SELECTtimestamp,event,properties.$current_url AS url,- if(event = '$exception', properties.$exception_message, null) AS exception_message,- if(event = '$exception', properties.$exception_type, null) AS exception_type+ if(event = '$exception', properties.$exception_values[1], null) AS exception_message,+ if(event = '$exception', properties.$exception_types[1], null) AS exception_typeFROM eventsWHERE $session_id = '<session_id>'AND event IN ('$pageview', '$pageleave', '$autocapture', '$exception', '$rageclick')@@ -99,8 +99,8 @@ If the recording has console errors or exceptions, find related error tracking iposthog:execute-sqlSELECT DISTINCTproperties.$exception_fingerprint AS fingerprint,- properties.$exception_type AS type,- properties.$exception_message AS message,+ properties.$exception_types[1] AS type,+ properties.$exception_values[1] AS message,count() AS occurrencesFROM eventsWHERE $session_id = '<session_id>'