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(replay): add per-person sessions tab to the player sidebar (#74421)

Kim Svatos Dugan0b8aee084aaf
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 0f5d96d0b434..5235cbf12076 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6235,7 +6235,7 @@ snapshots:
scenes-app-inbox-scene--self-driving-onboarding--light:
hash: v1.k794b7964.35ccf8547b124cd9adeaae5edaf9943755f7788cfd4296e2f6c254490c5e6c17.pvQ5JFSpCQy5ZVl3jGG9wuCyEMqfmS1PIXl49SD8Yzg
scenes-app-inbox-scene--self-driving-paused--dark:
- hash: v1.k794b7964.eae93d2c506e66eb23f36e19f05bf6f07286d9a895dbad8f970c009fd98f1d53.7hksyy3ldoFdJY9rpLYMe7FNYuMAi-U1Vlh3OGhv3wY
+ hash: v1.k794b7964.0510b996167600e7acbceee1be6c6afc0bffd1e8fee0f553654234b85b3d72de.LmiU3KuU9y44MAKZ8DzizEXjHBTsDsZpvH_zysTInAU
scenes-app-inbox-scene--self-driving-paused--light:
hash: v1.k794b7964.f9b5a6f1ecd482963d9850ced2d07c1ea729d2d63be8679db907709e5a6fde89.upcV4EokxFjnADvyUmiBiIp7UTjShqKZHDv2EKVV6HM
scenes-app-inbox-tabs--pull-requests--dark:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 7263b47f70ff..e009c401f0ee 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -217,6 +217,7 @@ export const FEATURE_FLAGS = {
PERSONLESS_EVENTS_NOT_SUPPORTED: 'personless-events-not-supported', // owner: #team-analytics-platform
QUERY_RUNNING_TIME: 'query_running_time', // owner: #team-analytics-platform
REPLAY_HOGQL_FILTERS: 'replay-hogql-filters', // owner: @pauldambra #team-replay
+ REPLAY_PLAYER_PERSON_SESSIONS_TAB: 'replay-player-person-sessions-tab', // owner: @ksvat #team-replay
REPLAY_SETTINGS_HELP: 'replay-settings-help', // owner: @veryayskiy #team-replay
REPLAY_TRIGGER_TYPE_CHOICE: 'replay-trigger-type-choice', // owner: @pauldambra #team-replay
SESSION_REPLAY_BACKEND_LOGS: 'session-replay-backend-logs', // owner: #team-replay
diff --git a/frontend/src/scenes/session-recordings/player/PlayerSidebar.tsx b/frontend/src/scenes/session-recordings/player/PlayerSidebar.tsx
index 179523fa8e75..343c27cf0623 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerSidebar.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerSidebar.tsx
@@ -7,7 +7,9 @@ import { LemonButton, LemonTabs } from '@posthog/lemon-ui'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'
+import { FEATURE_FLAGS } from 'lib/constants'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { capitalizeFirstLetter, splitKebabCase } from 'lib/utils/strings'
import { SessionRecordingSidebarStacking, SessionRecordingSidebarTab } from '~/types'
@@ -26,6 +28,7 @@ export function PlayerSidebar(): JSX.Element {
const { setSidebarOpen, setPreferredSidebarStacking } = useActions(playerSettingsLogic)
const { getIntegrationsByKind } = useValues(integrationsLogic)
const { sessionPlayerMetaData } = useValues(sessionRecordingPlayerLogic)
+ const { featureFlags } = useValues(featureFlagLogic)
const logicKey = `player-sidebar-${isVerticallyStacked ? 'vertical' : 'horizontal'}`
@@ -47,6 +50,11 @@ export function PlayerSidebar(): JSX.Element {
SessionRecordingSidebarTab.NETWORK_WATERFALL,
]
+ // Show the person's other recordings once we know who they are
+ if (featureFlags[FEATURE_FLAGS.REPLAY_PLAYER_PERSON_SESSIONS_TAB] && sessionPlayerMetaData?.person) {
+ sidebarTabs.push(SessionRecordingSidebarTab.SESSIONS)
+ }
+
// Show linked issues tab if there are integrations or existing references
const sessionReplayIntegrations = getIntegrationsByKind(['linear', 'github', 'gitlab', 'jira'])
const externalReferences = sessionPlayerMetaData?.external_references ?? []
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarPersonRecordingsTab.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarPersonRecordingsTab.tsx
new file mode 100644
index 000000000000..690b46d8f8eb
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarPersonRecordingsTab.tsx
@@ -0,0 +1,106 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton, LemonTag, Link } from '@posthog/lemon-ui'
+
+import { TZLabel } from 'lib/components/TZLabel'
+import { WrappingLoadingSkeleton } from 'lib/ui/WrappingLoadingSkeleton/WrappingLoadingSkeleton'
+import { humanFriendlyDuration } from 'lib/utils/durations'
+import { urls } from 'scenes/urls'
+
+import { SessionRecordingType } from '~/types'
+
+import { sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'
+import { playerPersonRecordingsLogic } from './playerPersonRecordingsLogic'
+
+export function PlayerSidebarPersonRecordingsTab(): JSX.Element {
+ const { logicProps, sessionRecordingId } = useValues(sessionRecordingPlayerLogic)
+ const { recordings, recordingsResponseLoading, hasMore, hasLoaded, loadError, loadMoreError } = useValues(
+ playerPersonRecordingsLogic(logicProps)
+ )
+ const { loadRecordings, loadMoreRecordings } = useActions(playerPersonRecordingsLogic(logicProps))
+
+ if (recordingsResponseLoading && recordings.length === 0) {
+ return (
+ <div className="p-4">
+ <WrappingLoadingSkeleton fullWidth>
+ <div aria-hidden>Loading</div>
+ </WrappingLoadingSkeleton>
+ </div>
+ )
+ }
+
+ if (loadError) {
+ return (
+ <div className="p-4 deprecated-space-y-2">
+ <p className="text-muted text-sm">Could not load this person's recordings.</p>
+ <LemonButton size="small" type="secondary" onClick={() => loadRecordings({})}>
+ Try again
+ </LemonButton>
+ </div>
+ )
+ }
+
+ if (hasLoaded && recordings.length <= 1) {
+ return <p className="p-4 text-muted text-sm">This is the only recording for this person.</p>
+ }
+
+ return (
+ <div className="p-2 deprecated-space-y-1">
+ {recordings.map((recording) => (
+ <RecordingRow
+ key={recording.id}
+ recording={recording}
+ isCurrent={recording.id === sessionRecordingId}
+ />
+ ))}
+ {hasMore && (
+ <>
+ {loadMoreError && (
+ <p className="text-danger text-xs text-center">Could not load older recordings.</p>
+ )}
+ <LemonButton
+ fullWidth
+ center
+ size="small"
+ type="secondary"
+ loading={recordingsResponseLoading}
+ onClick={() => loadMoreRecordings({})}
+ >
+ {loadMoreError ? 'Try again' : 'Load older recordings'}
+ </LemonButton>
+ </>
+ )}
+ </div>
+ )
+}
+
+function RecordingRow({ recording, isCurrent }: { recording: SessionRecordingType; isCurrent: boolean }): JSX.Element {
+ const content = (
+ <div className="flex items-center justify-between gap-2 w-full min-w-0">
+ <div className="flex items-center gap-2 min-w-0">
+ <TZLabel time={recording.start_time} className="text-sm" />
+ {isCurrent && (
+ <LemonTag type="highlight" size="small">
+ Playing now
+ </LemonTag>
+ )}
+ </div>
+ <span className="text-xs text-muted flex-shrink-0">
+ {humanFriendlyDuration(recording.recording_duration)}
+ </span>
+ </div>
+ )
+
+ if (isCurrent) {
+ return <div className="flex items-center rounded px-2 py-1 bg-accent-highlight-secondary">{content}</div>
+ }
+
+ return (
+ <Link
+ to={urls.replaySingle(recording.id)}
+ className="flex items-center rounded px-2 py-1 hover:bg-fill-highlight-50"
+ >
+ {content}
+ </Link>
+ )
+}
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarTab.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarTab.tsx
index afae01efbba7..7e4e11cee711 100644
--- a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarTab.tsx
+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarTab.tsx
@@ -8,6 +8,7 @@ import { SessionRecordingSidebarTab } from '~/types'
import { PlayerSidebarLinkedIssuesTab } from './PlayerSidebarLinkedIssuesTab'
import { playerSidebarLogic } from './playerSidebarLogic'
import { PlayerSidebarOverviewTab } from './PlayerSidebarOverviewTab'
+import { PlayerSidebarPersonRecordingsTab } from './PlayerSidebarPersonRecordingsTab'
export function PlayerSidebarTab(): JSX.Element | null {
const { activeTab } = useValues(playerSidebarLogic)
@@ -21,6 +22,8 @@ export function PlayerSidebarTab(): JSX.Element | null {
return <NetworkView />
case SessionRecordingSidebarTab.LINKED_ISSUES:
return <PlayerSidebarLinkedIssuesTab />
+ case SessionRecordingSidebarTab.SESSIONS:
+ return <PlayerSidebarPersonRecordingsTab />
default:
return null
}
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/playerPersonRecordingsLogic.test.ts b/frontend/src/scenes/session-recordings/player/sidebar/playerPersonRecordingsLogic.test.ts
new file mode 100644
index 000000000000..0957cd84292a
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/sidebar/playerPersonRecordingsLogic.test.ts
@@ -0,0 +1,43 @@
+import { RecordingsQueryResponse } from '~/queries/schema/schema-general'
+import { SessionRecordingType } from '~/types'
+
+import { mergeRecordingPage, retentionDateFrom } from './playerPersonRecordingsLogic'
+
+describe('playerPersonRecordingsLogic', () => {
+ const rec = (id: string): SessionRecordingType => ({ id }) as SessionRecordingType
+ const page = (ids: string[], overrides: Partial<RecordingsQueryResponse> = {}): RecordingsQueryResponse => ({
+ results: ids.map(rec),
+ has_next: false,
+ ...overrides,
+ })
+
+ it('appends the next page onto the accumulated results and keeps the new page cursor', () => {
+ const previous = page(['a', 'b'], { has_next: true, next_cursor: 'cursor-1' })
+ const next = page(['c', 'd'], { has_next: false, next_cursor: undefined })
+
+ const merged = mergeRecordingPage(previous, next)
+
+ // guards against "Load older" replacing instead of appending, which silently drops earlier recordings
+ expect(merged.results.map((r) => r.id)).toEqual(['a', 'b', 'c', 'd'])
+ expect(merged.has_next).toBe(false)
+ expect(merged.next_cursor).toBeUndefined()
+ })
+
+ it('treats a null previous page as an empty accumulator', () => {
+ const merged = mergeRecordingPage(null, page(['a', 'b'], { has_next: true, next_cursor: 'cursor-1' }))
+
+ expect(merged.results.map((r) => r.id)).toEqual(['a', 'b'])
+ expect(merged.has_next).toBe(true)
+ })
+
+ // A window shorter than the retention period would drop the current recording (which sits at
+ // the retention edge) from its own list; the +1 buffer and the fallback both guard against that.
+ it.each([
+ [90, '-91d'],
+ [30, '-31d'],
+ [null, '-31d'],
+ [undefined, '-31d'],
+ ])('retentionDateFrom(%s) is %s', (retention, expected) => {
+ expect(retentionDateFrom(retention as number | null | undefined)).toBe(expected)
+ })
+})
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/playerPersonRecordingsLogic.ts b/frontend/src/scenes/session-recordings/player/sidebar/playerPersonRecordingsLogic.ts
new file mode 100644
index 000000000000..4904aead327b
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/sidebar/playerPersonRecordingsLogic.ts
@@ -0,0 +1,236 @@
+import { MakeLogicType, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import { loaders } from 'kea-loaders'
+
+import api from 'lib/api'
+
+import { NodeKind, RecordingsQuery, RecordingsQueryResponse } from '~/queries/schema/schema-general'
+import { PersonType, SessionRecordingType } from '~/types'
+
+import { playerMetaLogic } from '../player-meta/playerMetaLogic'
+import { SessionRecordingPlayerLogicProps, sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'
+
+// One page is plenty for the common "which other session was this" case; a
+// "Load older" control walks the cursor for people with long histories.
+const PAGE_SIZE = 50
+
+// Fallback window when the recording's retention period is unknown.
+const DEFAULT_RETENTION_DAYS = 30
+
+// The recordings query defaults to the last 3 days server-side, which would hide older
+// sessions and even the current recording if it's older than that. Scope the window to the
+// team's recording retention period instead: nothing older can still exist, and the current
+// recording is by definition within it. A one-day buffer avoids edge-of-window rounding.
+export function retentionDateFrom(retentionPeriodDays: number | null | undefined): string {
+ return `-${(retentionPeriodDays ?? DEFAULT_RETENTION_DAYS) + 1}d`
+}
+
+function personRecordingsQuery(
+ personUuid: string,
+ distinctIds: string[] | undefined,
+ dateFrom: string,
+ after?: string
+): RecordingsQuery {
+ return {
+ kind: NodeKind.RecordingsQuery,
+ person_uuid: personUuid,
+ // person_uuid resolves the person server-side; skip distinct_ids for heavily merged
+ // persons to avoid an unwieldy query string. Matches sessionRecordingsPlaylistLogic.
+ distinct_ids: (distinctIds?.length ?? 0) < 100 ? distinctIds : undefined,
+ date_from: dateFrom,
+ order: 'start_time',
+ order_direction: 'DESC',
+ limit: PAGE_SIZE,
+ after,
+ }
+}
+
+// Append the next page onto the accumulated results so "Load older" grows the list
+// rather than replacing it. Keeps the newer response's has_next / next_cursor.
+export function mergeRecordingPage(
+ previous: RecordingsQueryResponse | null,
+ next: RecordingsQueryResponse
+): RecordingsQueryResponse {
+ return { ...next, results: [...(previous?.results ?? []), ...next.results] }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface playerPersonRecordingsLogicValues {
+ sessionPerson: PersonType | null // playerMetaLogic
+ sessionPlayerMetaData: SessionRecordingType | null // playerMetaLogic
+ sessionRecordingId: string // sessionRecordingPlayerLogic
+ hasLoaded: boolean
+ hasMore: boolean
+ loadError: boolean
+ loadMoreError: boolean
+ recordings: SessionRecordingType[]
+ recordingsResponse: RecordingsQueryResponse | null
+ recordingsResponseLoading: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface playerPersonRecordingsLogicActions {
+ loadRecordingMetaSuccess: (
+ sessionPlayerMetaData: SessionRecordingType | null,
+ payload?:
+ | {
+ value: true
+ }
+ | undefined
+ ) => {
+ payload?: {
+ value: true
+ }
+ sessionPlayerMetaData: SessionRecordingType | null
+ } // playerMetaLogic
+ loadMoreRecordings: (_: any) => any
+ loadMoreRecordingsFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadMoreRecordingsSuccess: (
+ recordingsResponse: RecordingsQueryResponse | null,
+ payload?: any
+ ) => {
+ recordingsResponse: RecordingsQueryResponse | null
+ payload?: any
+ }
+ loadRecordings: (_: any) => any
+ loadRecordingsFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadRecordingsSuccess: (
+ recordingsResponse: RecordingsQueryResponse | null,
+ payload?: any
+ ) => {
+ recordingsResponse: RecordingsQueryResponse | null
+ payload?: any
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface playerPersonRecordingsLogicMeta {
+ key: string
+ __keaTypeGenInternalSelectorTypes: {
+ recordings: (recordingsResponse: RecordingsQueryResponse | null) => SessionRecordingType[]
+ hasMore: (recordingsResponse: RecordingsQueryResponse | null) => boolean
+ }
+}
+
+export type playerPersonRecordingsLogicType = MakeLogicType<
+ playerPersonRecordingsLogicValues,
+ playerPersonRecordingsLogicActions,
+ SessionRecordingPlayerLogicProps,
+ playerPersonRecordingsLogicMeta
+>
+
+export const playerPersonRecordingsLogic = kea<playerPersonRecordingsLogicType>([
+ path((key) => ['scenes', 'session-recordings', 'player', 'sidebar', 'playerPersonRecordingsLogic', key]),
+ props({} as SessionRecordingPlayerLogicProps),
+ // Keyed per recording: sessionPerson isn't available synchronously when the key is
+ // computed, so we can't key on the person. Each jump remounts and refetches one page.
+ key((props: SessionRecordingPlayerLogicProps) => `${props.playerKey}-${props.sessionRecordingId}`),
+ connect((props: SessionRecordingPlayerLogicProps) => ({
+ values: [
+ playerMetaLogic(props),
+ ['sessionPerson', 'sessionPlayerMetaData'],
+ sessionRecordingPlayerLogic(props),
+ ['sessionRecordingId'],
+ ],
+ actions: [playerMetaLogic(props), ['loadRecordingMetaSuccess']],
+ })),
+ loaders(({ values }) => ({
+ recordingsResponse: [
+ null as RecordingsQueryResponse | null,
+ {
+ loadRecordings: async (_, breakpoint) => {
+ const person = values.sessionPerson
+ if (!person?.uuid) {
+ return null
+ }
+ const dateFrom = retentionDateFrom(values.sessionPlayerMetaData?.retention_period_days)
+ const response = await api.recordings.list(
+ personRecordingsQuery(person.uuid, person.distinct_ids, dateFrom)
+ )
+ breakpoint()
+ return response
+ },
+ loadMoreRecordings: async (_, breakpoint) => {
+ const person = values.sessionPerson
+ const cursor = values.recordingsResponse?.next_cursor
+ if (!person?.uuid || !cursor) {
+ return values.recordingsResponse
+ }
+ const dateFrom = retentionDateFrom(values.sessionPlayerMetaData?.retention_period_days)
+ const response = await api.recordings.list(
+ personRecordingsQuery(person.uuid, person.distinct_ids, dateFrom, cursor)
+ )
+ breakpoint()
+ return mergeRecordingPage(values.recordingsResponse, response)
+ },
+ },
+ ],
+ })),
+ reducers(() => ({
+ // Distinguishes "loaded, genuinely few recordings" from "still loading or errored",
+ // so the empty state only renders once a successful response has come back.
+ hasLoaded: [
+ false,
+ {
+ loadRecordingsSuccess: () => true,
+ },
+ ],
+ // Initial-load failure: replaces the whole tab with a retry.
+ loadError: [
+ false,
+ {
+ loadRecordings: () => false,
+ loadRecordingsSuccess: () => false,
+ loadRecordingsFailure: () => true,
+ },
+ ],
+ // "Load older" failure: surfaced next to the button so the already-loaded list stays put.
+ loadMoreError: [
+ false,
+ {
+ loadMoreRecordings: () => false,
+ loadMoreRecordingsSuccess: () => false,
+ loadMoreRecordingsFailure: () => true,
+ },
+ ],
+ })),
+ selectors(() => ({
+ recordings: [
+ (s) => [s.recordingsResponse],
+ (recordingsResponse: RecordingsQueryResponse | null): SessionRecordingType[] =>
+ recordingsResponse?.results ?? [],
+ ],
+ hasMore: [
+ (s) => [s.recordingsResponse],
+ (recordingsResponse: RecordingsQueryResponse | null): boolean => !!recordingsResponse?.has_next,
+ ],
+ })),
+ listeners(({ actions, values }) => {
+ const maybeLoad = (): void => {
+ if (values.sessionPerson?.uuid && !values.recordingsResponse && !values.recordingsResponseLoading) {
+ actions.loadRecordings({})
+ }
+ }
+ return {
+ // The person only exists after metadata loads. Metadata may resolve before or after
+ // this tab is opened, so cover both: fetch on meta success and on mount.
+ loadRecordingMetaSuccess: maybeLoad,
+ }
+ }),
+ afterMount(({ actions, values }) => {
+ if (values.sessionPerson?.uuid && !values.recordingsResponse && !values.recordingsResponseLoading) {
+ actions.loadRecordings({})
+ }
+ }),
+])
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 09b098618117..499f7865192c 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -1444,6 +1444,7 @@ export enum SessionRecordingSidebarTab {
INSPECTOR = 'inspector',
NETWORK_WATERFALL = 'network-waterfall',
LINKED_ISSUES = 'linked-issues',
+ SESSIONS = 'sessions',
}
export enum SessionRecordingSidebarStacking {