: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(replay): stop toasting transient failures in recordings list properties (#76437)
posthog[bot]e53b75e5fa4b
diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.tsindex 8c114c2b74d9..3d50dafca107 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.ts@@ -270,4 +270,30 @@ describe('sessionRecordingsListPropertiesLogic', () => {expect(issuedQueries[issuedQueries.length - 1]).toContain('$entry_utm_medium')expect(logic.values.recordingPropertiesById['s2']).toMatchObject({ $entry_utm_medium: 'paid' })})++ it('resolves instead of throwing when the base query fails with no pins to fall back on', async () => {+ useQueryMocks(() => [500, { detail: 'ClickHouse is unavailable' }])++ await expectLogic(logic, () => {+ logic.actions.loadPropertiesForSessions(mockSessons)+ })+ .toDispatchActions(['loadPropertiesForSessionsSuccess'])+ .toNotHaveDispatchedActions(['loadPropertiesForSessionsFailure'])++ expect(logic.values.recordingPropertiesById).toEqual({})+ })++ it('resolves instead of throwing when both the wide and fallback queries fail', async () => {+ useQueryMocks(() => [500, { detail: 'ClickHouse is unavailable' }])+ sessionRecordingPinnedPropertiesLogic.actions.setPinnedProperties(['$entry_utm_medium'])++ await expectLogic(logic, () => {+ logic.actions.loadPropertiesForSessions(mockSessons)+ })+ .toDispatchActions(['loadPropertiesForSessionsSuccess'])+ .toNotHaveDispatchedActions(['loadPropertiesForSessionsFailure'])++ // an outage on both queries isn't a 400, so the pin set isn't blacklisted (it's retried next batch)+ expect(logic.values.unqueryableExtraProperties).toBeNull()+ })})diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.tsindex c4d5a2ab703b..d521ab32eb56 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.ts@@ -1,5 +1,6 @@import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'+import posthog from 'posthog-js'import api, { ApiError } from 'lib/api'import { dayjs } from 'lib/dayjs'@@ -166,12 +167,20 @@ export const sessionRecordingsListPropertiesLogic = kea<sessionRecordingsListPro)} catch (e) {if (!extraSessionProperties.length) {- throw e+ // These are supplementary columns on the recordings list. A backend blip shouldn't+ // toast, it should just leave this batch's rows without properties.+ posthog.captureException(e)+ return values.recordingProperties+ }+ try {+ response = await api.queryHogQL(+ buildPropertiesQuery(sessionIds, oldestTimestamp, newestTimestamp, []),+ QUERY_TAGS+ )+ } catch (fallbackError) {+ posthog.captureException(fallbackError)+ return values.recordingProperties}- response = await api.queryHogQL(- buildPropertiesQuery(sessionIds, oldestTimestamp, newestTimestamp, []),- QUERY_TAGS- )// only a 400 (a pin missing from this project's session table) blacklists the pin set — transient errors retry next batchif (e instanceof ApiError && e.status === 400) {actions.markExtraPropertiesUnqueryable(extraSessionProperties)diff --git a/posthog/session_recordings/session_recording_api.py b/posthog/session_recordings/session_recording_api.pyindex ea9b406dc61d..653b94f1f52e 100644--- a/posthog/session_recordings/session_recording_api.py+++ b/posthog/session_recordings/session_recording_api.py@@ -1042,7 +1042,13 @@ class SessionRecordingViewSet(def capture_diagnostics(self, request: request.Request, *args: Any, **kwargs: Any) -> Response:"""Latest event properties for the recording's session, for the capture diagnostics panel."""recording = self.get_object()- properties = get_latest_session_event_properties(str(recording.session_id), self.team)+ try:+ properties = get_latest_session_event_properties(str(recording.session_id), self.team)+ except Exception as e:+ # This panel is supplementary - a ClickHouse blip shouldn't 500 the whole endpoint,+ # it should just render empty like a session with no matching event would.+ capture_exception(e)+ properties = Nonereturn Response({"properties": properties})# Returns metadata about the recordingdiff --git a/posthog/session_recordings/test/test_session_recordings.py b/posthog/session_recordings/test/test_session_recordings.pyindex 302e51fed14d..2c2b3c264b4a 100644--- a/posthog/session_recordings/test/test_session_recordings.py+++ b/posthog/session_recordings/test/test_session_recordings.py@@ -977,6 +977,21 @@ class TestSessionRecordings(APIBaseTest, ClickhouseTestMixin, QueryMatchingTest)"other_viewers": 0,}+ def test_capture_diagnostics_degrades_gracefully_on_clickhouse_error(self):+ session_recording_id = "session_1"+ produce_replay_summary(session_id=session_recording_id, team_id=self.team.pk, distinct_id="d1")++ with patch(+ "posthog.session_recordings.session_recording_api.get_latest_session_event_properties",+ side_effect=Exception("Connection refused"),+ ):+ response = self.client.get(+ f"/api/projects/{self.team.id}/session_recordings/{session_recording_id}/capture_diagnostics"+ )++ assert response.status_code == 200+ assert response.json() == {"properties": None}+def test_get_single_session_recording_viewed_stats_can_404(self):response = self.client.get(f"/api/projects/{self.team.id}/session_recordings/12345/viewed")assert response.status_code == status.HTTP_200_OK