: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
feat(replay): explain unplayable recordings missing their full snapshot (#63297)
Arno Hillen1b02a4a45f67
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsxindex 52cf54a042c4..63159b886a89 100644--- a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx+++ b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx@@ -69,7 +69,7 @@ const PlayerFrameOverlayActions = (): JSX.Element | null => {}const PlayerFrameOverlayContent = (): JSX.Element | null => {- const { currentPlayerState, endReached, logicProps } = useValues(sessionRecordingPlayerLogic)+ const { currentPlayerState, endReached, logicProps, playerError } = useValues(sessionRecordingPlayerLogic)const { setPlay } = useActions(sessionRecordingPlayerLogic)const handlePlay = (e: MouseEvent): void => {@@ -85,24 +85,28 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {const showActionsOnOverlay = playerMode === SessionRecordingPlayerMode.Standard && pausedStateif (currentPlayerState === SessionPlayerState.ERROR) {+ const isMissingFullSnapshot = playerError === 'noPlayableFullSnapshot'content = (<div className="flex flex-col justify-center items-center p-6 bg-surface-primary rounded m-6 gap-2 max-w-120 shadow-sm"><IconWarning className="text-danger text-5xl" /><div className="font-bold text-text-3000 text-lg">We're unable to play this recording</div><div className="text-secondary text-sm text-center">- An error occurred that is preventing this recording from being played. You can refresh the page to- reload the recording.+ {isMissingFullSnapshot+ ? 'This part of the recording is missing the snapshot data needed to render it. The data never reached PostHog, usually because the browser was closed or went offline before the recording finished uploading.'+ : 'An error occurred that is preventing this recording from being played. You can refresh the page to reload the recording.'}</div>- <LemonButton- onClick={() => {- window.location.reload()- }}- type="primary"- fullWidth- center- >- Reload- </LemonButton>+ {!isMissingFullSnapshot && (+ <LemonButton+ onClick={() => {+ window.location.reload()+ }}+ type="primary"+ fullWidth+ center+ >+ Reload+ </LemonButton>+ )}<LemonButtontargetBlankto="https://posthog.com/support?utm_medium=in-product&utm_campaign=recording-not-found"diff --git a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx b/frontend/src/scenes/session-recordings/player/PurePlayer.tsxindex 031af2f9c1ae..605a5becaf60 100644--- a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx+++ b/frontend/src/scenes/session-recordings/player/PurePlayer.tsx@@ -7,12 +7,13 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { LemonBanner, LemonButton } from '@posthog/lemon-ui'-import { BuilderHog2 } from 'lib/components/hedgehogs'+import { BuilderHog2, WarningHog } from 'lib/components/hedgehogs'import { FloatingContainerContext } from 'lib/hooks/useFloatingContainerContext'import useIsHovering from 'lib/hooks/useIsHovering'import { HotkeysInterface, useKeyboardHotkeys } from 'lib/hooks/useKeyboardHotkeys'import { usePageVisibilityCb } from 'lib/hooks/usePageVisibility'import { useResizeBreakpoints } from 'lib/hooks/useResizeObserver'+import { Link } from 'lib/lemon-ui/Link'import { useNotebookDrag } from 'scenes/notebooks/AddToNotebook/DraggableToNotebook'import { PlayerFrameCommentOverlay } from 'scenes/session-recordings/player/commenting/PlayerFrameCommentOverlay'import { RecordingDeleted } from 'scenes/session-recordings/player/RecordingDeleted'@@ -93,6 +94,7 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsisNotFound,loadMetaError,isRecentAndInvalid,+ isOldAndInvalid,isRecordingDeleted,recordingDeletedAt,recordingDeletedBy,@@ -133,6 +135,19 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerProps[isRecentAndInvalid])+ useEffect(+ () => {+ if (isOldAndInvalid) {+ posthog.capture('session loaded old and invalid', {+ viewedSessionRecording: sessionRecordingId,+ recordingStartTime: sessionPlayerData?.start,+ })+ }+ },+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [isOldAndInvalid]+ )+// Track if the recording has ended to be able to reliably get it from the BE and stop the recordinguseEffect(() => {if (typeof window !== 'undefined') {@@ -290,6 +305,20 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsReload</LemonButton></div>+ ) : isOldAndInvalid ? (+ <div className="flex flex-1 flex-col items-center justify-center p-4 text-center">+ <WarningHog height={200} width={200} />+ <h1>This recording can't be played</h1>+ <p className="max-w-120">+ The snapshot of the screen taken when this recording started never reached PostHog,+ so there is nothing to play back. This usually happens when the browser is closed or+ goes offline before the recording finishes uploading.{' '}+ <Link to="https://posthog.com/docs/session-replay/troubleshooting">Learn more</Link>+ </p>+ <LemonButton type="secondary" onClick={loadSnapshots}>+ Reload+ </LemonButton>+ </div>) : (<div className="flex w-full h-full"><div className="flex flex-col flex-1 w-full relative">diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.tsindex d89ff38719b7..08d23b4ee471 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts@@ -4,6 +4,7 @@ import { expectLogic } from 'kea-test-utils'import { processAllSnapshots, SourceKey, ViewportResolution } from '@posthog/replay-shared'+import { dayjs } from 'lib/dayjs'import { convertSnapshotsByWindowId } from 'scenes/session-recordings/__mocks__/recording_snapshots'import { sessionRecordingDataCoordinatorLogic } from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'import { sessionRecordingMetaLogic } from 'scenes/session-recordings/player/sessionRecordingMetaLogic'@@ -22,11 +23,13 @@ import {import { sortedRecordingSnapshots } from '../__mocks__/recording_snapshots'import { sessionRecordingEventUsageLogic } from '../sessionRecordingEventUsageLogic'import {+ BLOB_SOURCE_V2,createDifferentiatedQueryHandler,overrideSessionRecordingMocks,recordingEventsJson,recordingMetaJson,setupSessionRecordingTest,+ snapshotsAsJSONLines,} from './__mocks__/test-setup'import { snapshotDataLogic } from './snapshotDataLogic'@@ -267,6 +270,110 @@ describe('sessionRecordingDataCoordinatorLogic', () => {})})+ describe('missing full snapshot detection', () => {+ // start is the earlier of meta start_time and the first snapshot timestamp,+ // so the recent case needs recent snapshot timestamps too+ const incrementalOnlySnapshotsAsJSONLines = (baseTimestamp: number): string =>+ `${JSON.stringify({+ window_id: '187d7c761a0525d-05f175487d4b65-1d525634-384000-187d7c761a149d0',+ data: [+ {+ type: 4,+ data: { href: 'http://localhost:3000/', width: 2560, height: 1304 },+ timestamp: baseTimestamp,+ },+ {+ type: 3,+ data: { source: 1, positions: [{ x: 2027, y: 120, id: 22, timeOffset: 0 }] },+ timestamp: baseTimestamp + 2000,+ },+ {+ type: 3,+ data: { source: 2, type: 2, id: 33, x: 852, y: 133, pointerType: 0 },+ timestamp: baseTimestamp + 9000,+ },+ ],+ })}\n`++ const mountWithSnapshots = (jsonLines: string, metaOverride?: Record<string, unknown>): void => {+ logic?.unmount()+ snapshotLogic?.unmount()+ setupSessionRecordingTest({+ getMocks: {+ '/api/environments/:team_id/session_recordings/:id/snapshots': async (req, res, ctx) => {+ const sourceParam = req.url.searchParams.get('source')+ if (sourceParam === 'blob_v2' || sourceParam === 'blob') {+ return res(ctx.text(jsonLines))+ }+ return [200, { sources: [BLOB_SOURCE_V2] }]+ },+ ...(metaOverride+ ? { '/api/environments/:team_id/session_recordings/:id': () => [200, metaOverride] }+ : {}),+ },+ })+ const props = {+ sessionRecordingId: '2',+ blobV2PollingDisabled: true,+ }+ logic = sessionRecordingDataCoordinatorLogic(props)+ snapshotLogic = snapshotDataLogic(props)+ logic.mount()+ }++ const loadFully = async (): Promise<void> => {+ await expectLogic(logic, () => {+ logic.actions.loadRecordingMeta()+ logic.actions.loadSnapshots()+ })+ .toDispatchActions(['loadRecordingMetaSuccess', 'reportUsageIfFullyLoaded'])+ .toFinishAllListeners()+ expect(logic.values.fullyLoaded).toBe(true)+ }++ it.each<{+ case: string+ mocks: () => { jsonLines: string; metaOverride?: Record<string, unknown> }+ expected: { snapshotsInvalid: boolean; isRecentAndInvalid: boolean; isOldAndInvalid: boolean }+ }>([+ {+ case: 'an old recording with no full snapshot is old and invalid',+ mocks: () => ({ jsonLines: incrementalOnlySnapshotsAsJSONLines(1682952380877) }),+ expected: { snapshotsInvalid: true, isRecentAndInvalid: false, isOldAndInvalid: true },+ },+ {+ case: 'a recent recording with no full snapshot is recent and invalid',+ mocks: () => {+ const recentStart = dayjs().subtract(1, 'minute')+ return {+ jsonLines: incrementalOnlySnapshotsAsJSONLines(recentStart.valueOf()),+ metaOverride: {+ ...recordingMetaJson,+ start_time: recentStart.toISOString(),+ end_time: dayjs().toISOString(),+ },+ }+ },+ expected: { snapshotsInvalid: true, isRecentAndInvalid: true, isOldAndInvalid: false },+ },+ {+ case: 'a recording with a full snapshot is valid',+ mocks: () => ({ jsonLines: snapshotsAsJSONLines() }),+ expected: { snapshotsInvalid: false, isRecentAndInvalid: false, isOldAndInvalid: false },+ },+ ])('$case', async ({ mocks, expected }) => {+ const { jsonLines, metaOverride } = mocks()+ mountWithSnapshots(jsonLines, metaOverride)+ await loadFully()++ expect({+ snapshotsInvalid: logic.values.snapshotsInvalid,+ isRecentAndInvalid: logic.values.isRecentAndInvalid,+ isOldAndInvalid: logic.values.isOldAndInvalid,+ }).toEqual(expected)+ })+ })+// TODO need deduplication tests for blob_v2 sources before we deprecate blob_v1describe('deduplicateSnapshots', () => {const sources: SessionRecordingSnapshotSource[] = [diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.tsindex 99bffeb4823d..0c8c7025047b 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts@@ -447,6 +447,13 @@ export const sessionRecordingDataCoordinatorLogic = kea<sessionRecordingDataCoor},],+ // past the ingestion grace period, a missing full snapshot means the data never arrived,+ // e.g. the browser closed or went offline before the recording finished uploading+ isOldAndInvalid: [+ (s) => [s.snapshotsInvalid, s.isRecentAndInvalid],+ (snapshotsInvalid, isRecentAndInvalid) => snapshotsInvalid && !isRecentAndInvalid,+ ],+windowIds: [(s) => [s.snapshotsByWindowId],(snapshotsByWindowId: Record<number, eventWithTime[]>): number[] => {