Skip to content

Commit

Permalink
feat: track unplayable replay (#18544)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Nov 10, 2023
1 parent 8a6444b commit 4f270e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
SessionRecordingUsageType,
} from '~/types'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { eventWithTime } from '@rrweb/types'
import { EventType, eventWithTime } from '@rrweb/types'
import { Dayjs, dayjs } from 'lib/dayjs'
import type { sessionRecordingDataLogicType } from './sessionRecordingDataLogicType'
import { chainToElements } from 'lib/utils/elements-chain'
Expand Down Expand Up @@ -600,6 +600,42 @@ export const sessionRecordingDataLogic = kea<sessionRecordingDataLogicType>([
},
],

snapshotsInvalid: [
(s, p) => [s.snapshotsByWindowId, s.fullyLoaded, p.sessionRecordingId],
(snapshotsByWindowId, fullyLoaded, sessionRecordingId): boolean => {
if (!fullyLoaded) {
return false
}

const windowsHaveFullSnapshot = Object.entries(snapshotsByWindowId).reduce(
(acc, [windowId, events]) => {
acc[`window-id-${windowId}-has-full-snapshot`] = events.some(
(event) => event.type === EventType.FullSnapshot
)
return acc
},
{}
)
const anyWindowMissingFullSnapshot = !Object.values(windowsHaveFullSnapshot).some((x) => x)
const everyWindowMissingFullSnapshot = !Object.values(windowsHaveFullSnapshot).every((x) => x)

if (everyWindowMissingFullSnapshot) {
// video is definitely unplayable
posthog.capture('recording_has_no_full_snapshot', {
...windowsHaveFullSnapshot,
sessionId: sessionRecordingId,
})
} else if (anyWindowMissingFullSnapshot) {
posthog.capture('recording_window_missing_full_snapshot', {
...windowsHaveFullSnapshot,
sessionId: sessionRecordingId,
})
}

return everyWindowMissingFullSnapshot || anyWindowMissingFullSnapshot
},
],

bufferedToTime: [
(s) => [s.segments],
(segments): number | null => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
'sessionPlayerData',
'sessionPlayerSnapshotDataLoading',
'sessionPlayerMetaDataLoading',
'snapshotsInvalid',
],
playerSettingsLogic,
['speed', 'skipInactivitySetting'],
Expand Down Expand Up @@ -345,6 +346,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
s.isSkippingInactivity,
s.snapshotsLoaded,
s.sessionPlayerSnapshotDataLoading,
s.snapshotsInvalid,
],
(
playingState,
Expand All @@ -353,8 +355,13 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
isScrubbing,
isSkippingInactivity,
snapshotsLoaded,
snapshotsLoading
snapshotsLoading,
snapshotsInvalid
) => {
if (snapshotsInvalid) {
return SessionPlayerState.ERROR
}

if (isScrubbing) {
// If scrubbing, playingState takes precedence
return playingState
Expand Down

0 comments on commit 4f270e0

Please sign in to comment.