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.

fix(replay): explain a missing recording without blaming project settings (#103203)

Paul D'Ambra69836ca42f45
diff --git a/frontend/src/scenes/session-recordings/player/RecordingNotFound.tsx b/frontend/src/scenes/session-recordings/player/RecordingNotFound.tsx
index 21dec7e58cad..877b3abae099 100644
--- a/frontend/src/scenes/session-recordings/player/RecordingNotFound.tsx
+++ b/frontend/src/scenes/session-recordings/player/RecordingNotFound.tsx
@@ -1,16 +1,9 @@
-import { useValues } from 'kea'
-
import { NotFound } from 'lib/components/NotFound'
-import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
-import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { Link } from 'lib/lemon-ui/Link'
import { ReplayCaptureDiagnosticsPanel } from 'scenes/session-recordings/components/ReplayCaptureDiagnosticsPanel'
-import { teamLogic } from 'scenes/teamLogic'
-import { urls } from 'scenes/urls'
+import { ReplayStatusBanner } from 'scenes/session-recordings/player/ReplayStatusBanner'
export function RecordingNotFound({ sessionRecordingId }: { sessionRecordingId?: string }): JSX.Element {
- const { currentTeam } = useValues(teamLogic)
-
return (
<div className="flex flex-col items-center w-full overflow-y-auto">
<NotFound
@@ -25,35 +18,7 @@ export function RecordingNotFound({ sessionRecordingId }: { sessionRecordingId?:
troubleshooting guide
</Link>
.
- {currentTeam?.session_recording_opt_in ? (
- <LemonBanner type="success" className="mt-4 max-w-xl mx-auto">
- <div className="flex justify-between items-center">
- <div>Session replay is enabled for this project</div>
- <LemonButton
- data-attr="recording-404-edit-settings"
- type="secondary"
- size="small"
- to={urls.settings('project-replay')}
- >
- Edit settings
- </LemonButton>
- </div>
- </LemonBanner>
- ) : (
- <LemonBanner type="warning" className="mt-4 max-w-xl mx-auto">
- <div className="flex justify-between items-center">
- <div>Session replay is disabled for this project</div>
- <LemonButton
- data-attr="recording-404-edit-settings"
- type="secondary"
- size="small"
- to={urls.settings('project-replay')}
- >
- Edit settings
- </LemonButton>
- </div>
- </LemonBanner>
- )}
+ <ReplayStatusBanner />
</>
}
/>
diff --git a/frontend/src/scenes/session-recordings/player/ReplayStatusBanner.test.tsx b/frontend/src/scenes/session-recordings/player/ReplayStatusBanner.test.tsx
new file mode 100644
index 000000000000..9bd4de3823fb
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/ReplayStatusBanner.test.tsx
@@ -0,0 +1,36 @@
+import { TeamPublicType, TeamType } from '~/types'
+
+import { replayOptInStatus } from './ReplayStatusBanner'
+
+const teamWithOptIn = (session_recording_opt_in: boolean): TeamType =>
+ ({ id: 1, session_recording_opt_in }) as unknown as TeamType
+
+// The public payload for shared pages carries no replay fields at all.
+const publicTeam: TeamPublicType = { id: 1, uuid: 'uuid', name: 'Public', timezone: 'UTC' }
+
+describe('replayOptInStatus', () => {
+ it('reports the opt-in once the team is known', () => {
+ expect(replayOptInStatus(teamWithOptIn(true), false)).toBe('enabled')
+ expect(replayOptInStatus(teamWithOptIn(false), false)).toBe('disabled')
+ })
+
+ it('waits while the first team load is in flight', () => {
+ expect(replayOptInStatus(null, true)).toBe('loading')
+ })
+
+ // teamLogic swallows a failed `api/environments/@current` and resolves with the existing value,
+ // so a page that never got a team settles on null with loading false. That must not sit on the
+ // skeleton forever, and must not claim replay is off either.
+ it('gives up rather than waiting forever when the team never arrives', () => {
+ expect(replayOptInStatus(null, false)).toBe('unknown')
+ })
+
+ it('stays silent when the team carries no replay fields', () => {
+ expect(replayOptInStatus(publicTeam, false)).toBe('unknown')
+ })
+
+ it('keeps a settled opt-in while a background refresh runs', () => {
+ expect(replayOptInStatus(teamWithOptIn(true), true)).toBe('enabled')
+ expect(replayOptInStatus(teamWithOptIn(false), true)).toBe('disabled')
+ })
+})
diff --git a/frontend/src/scenes/session-recordings/player/ReplayStatusBanner.tsx b/frontend/src/scenes/session-recordings/player/ReplayStatusBanner.tsx
new file mode 100644
index 000000000000..d3f9304e03ab
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/ReplayStatusBanner.tsx
@@ -0,0 +1,62 @@
+import { useValues } from 'kea'
+
+import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
+import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
+
+import { TeamPublicType, TeamType } from '~/types'
+
+export type ReplayOptInStatus = 'loading' | 'unknown' | 'enabled' | 'disabled'
+
+/**
+ * `session_recording_opt_in` is absent while the team loads, and the public team payload used by
+ * shared pages never carries it at all. Neither means replay is off, so both resolve to `unknown`
+ * and the banner says nothing rather than telling someone with replay running that it is off.
+ *
+ * A known opt-in wins over an in-flight load, so a background team refresh does not drop a settled
+ * banner back to a skeleton.
+ */
+export function replayOptInStatus(
+ currentTeam: TeamType | TeamPublicType | null,
+ currentTeamLoading: boolean
+): ReplayOptInStatus {
+ const optIn = currentTeam?.session_recording_opt_in
+ if (optIn !== undefined) {
+ return optIn ? 'enabled' : 'disabled'
+ }
+ return currentTeamLoading ? 'loading' : 'unknown'
+}
+
+export function ReplayStatusBanner(): JSX.Element | null {
+ const { currentTeam, currentTeamLoading } = useValues(teamLogic)
+ const status = replayOptInStatus(currentTeam, currentTeamLoading)
+
+ if (status === 'loading') {
+ return <LemonSkeleton className="mt-4 h-12 max-w-xl mx-auto" />
+ }
+
+ if (status === 'unknown') {
+ return null
+ }
+
+ const enabled = status === 'enabled'
+
+ return (
+ <LemonBanner type={enabled ? 'success' : 'warning'} className="mt-4 max-w-xl mx-auto">
+ <div className="flex justify-between items-center">
+ {/* One text node, so an in-page translation extension cannot detach a changing sibling. */}
+ <div>{`Session replay is ${enabled ? 'enabled' : 'disabled'} for this project`}</div>
+ <LemonButton
+ data-attr="recording-404-edit-settings"
+ type="secondary"
+ size="small"
+ to={urls.settings('project-replay')}
+ >
+ Edit settings
+ </LemonButton>
+ </div>
+ </LemonBanner>
+ )
+}
diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.test.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.test.tsx
new file mode 100644
index 000000000000..67fc8bd955f6
--- /dev/null
+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.test.tsx
@@ -0,0 +1,106 @@
+import { render } from '@testing-library/react'
+import { BindLogic, Provider } from 'kea'
+
+import { errorPropertiesLogic } from 'lib/components/Errors/errorPropertiesLogic'
+import { ErrorEventProperties } from 'lib/components/Errors/types'
+
+import { initKeaTests } from '~/test/init'
+
+import { SessionRecordingContent } from './SessionRecordingTab'
+
+const SESSION_ID = '0199aaaa-bbbb-cccc-dddd-eeeeffff0000'
+
+// What the existence lookup has answered for this session, read fresh on every render.
+const mockRecordingExists: { value: boolean | undefined } = { value: undefined }
+
+jest.mock('scenes/session-recordings/player/SessionRecordingPlayer', () => ({
+ SessionRecordingPlayer: () => <div data-attr="session-recording-player" />,
+}))
+
+jest.mock('lib/components/ViewRecordingButton/sessionRecordingInfoLogic', () => {
+ const kea = jest.requireActual('kea')
+ return {
+ sessionRecordingInfoLogic: kea.kea([
+ kea.path(['test', 'sessionRecordingInfoLogicStub']),
+ kea.actions({ checkRecordingInfo: (sessionId: string) => ({ sessionId }) }),
+ kea.selectors({ getRecordingExists: [() => [], () => () => mockRecordingExists.value] }),
+ ]),
+ }
+})
+
+// The real logic connects to the recording data coordinator, which mounts the whole playback
+// pipeline. The tab only reads four settled values from it, so a static stand-in is enough.
+jest.mock('./sessionTabLogic', () => {
+ const kea = jest.requireActual('kea')
+ // `jest.mock` factories are hoisted above module scope, so the id is inlined here.
+ const sessionId = '0199aaaa-bbbb-cccc-dddd-eeeeffff0000'
+ return {
+ sessionTabLogic: kea.kea([
+ kea.path(['test', 'sessionTabLogicStub']),
+ kea.reducers({
+ recordingProps: [{ playerKey: 'session-tab', sessionRecordingId: sessionId }, {}],
+ recordingTimestamp: [null, {}],
+ isTimestampOutsideRecording: [false, {}],
+ sessionId: [sessionId, {}],
+ }),
+ ]),
+ }
+})
+
+function renderTab(recordingStatus?: string): HTMLElement {
+ const properties = {
+ $session_id: SESSION_ID,
+ $recording_status: recordingStatus,
+ } as unknown as ErrorEventProperties
+
+ const { container } = render(
+ <Provider>
+ <BindLogic logic={errorPropertiesLogic} props={{ id: 'exception-uuid', properties }}>
+ <SessionRecordingContent />
+ </BindLogic>
+ </Provider>
+ )
+ return container
+}
+
+const playerIn = (container: HTMLElement): Element | null =>
+ container.querySelector('[data-attr="session-recording-player"]')
+
+describe('SessionRecordingContent', () => {
+ beforeEach(() => {
+ initKeaTests()
+ mockRecordingExists.value = undefined
+ })
+
+ it('explains the miss on the event instead of mounting a player that can only 404', () => {
+ mockRecordingExists.value = false
+ const container = renderTab('disabled')
+
+ expect(container.textContent).toContain('Replay was not active when capturing this event')
+ expect(playerIn(container)).toBeNull()
+ })
+
+ it('falls back to the plain miss when the recorder reported no status', () => {
+ mockRecordingExists.value = false
+ const container = renderTab(undefined)
+
+ expect(container.textContent).toContain('No recording for this event')
+ expect(playerIn(container)).toBeNull()
+ })
+
+ // Loading, empty and error are three different screens — an unanswered lookup is not "empty",
+ // and an inactive recorder status alone must not retire the player.
+ it('keeps the player while the existence lookup has not answered', () => {
+ mockRecordingExists.value = undefined
+ const container = renderTab('disabled')
+
+ expect(playerIn(container)).not.toBeNull()
+ })
+
+ it('keeps the player when a recording is known to exist', () => {
+ mockRecordingExists.value = true
+ const container = renderTab('disabled')
+
+ expect(playerIn(container)).not.toBeNull()
+ })
+})
diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx
index e0f2c93aaedb..db7d8f3e8e2f 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx
+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx
@@ -1,8 +1,12 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
+import { useEffect } from 'react'
import { IconExternal } from '@posthog/icons'
import { LemonBanner } from '@posthog/lemon-ui'
+import { errorPropertiesLogic } from 'lib/components/Errors/errorPropertiesLogic'
+import { sessionRecordingInfoLogic } from 'lib/components/ViewRecordingButton/sessionRecordingInfoLogic'
+import { recordingDisabledReason } from 'lib/components/ViewRecordingButton/ViewRecordingButton'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { Button, TabsContent } from 'lib/ui/quill'
import { SessionRecordingPlayer } from 'scenes/session-recordings/player/SessionRecordingPlayer'
@@ -21,7 +25,29 @@ export function SessionRecordingTab(): JSX.Element {
}
export function SessionRecordingContent(): JSX.Element {
+ const { recordingStatus } = useValues(errorPropertiesLogic)
const { recordingProps, recordingTimestamp, isTimestampOutsideRecording, sessionId } = useValues(sessionTabLogic)
+ const { getRecordingExists } = useValues(sessionRecordingInfoLogic)
+ const { checkRecordingInfo } = useActions(sessionRecordingInfoLogic)
+
+ useEffect(() => {
+ checkRecordingInfo(sessionId)
+ }, [sessionId, checkRecordingInfo])
+
+ // The event's own `$has_recording` is not authoritative: it can be missing, or snapshot false
+ // before the replay rows land. So the existence lookup decides whether there is anything to
+ // play, and until it answers the player stays and shows its own loading state. Only a confirmed
+ // miss gets the explanation, with `$recording_status` choosing the wording.
+ const noRecordingReason =
+ getRecordingExists(sessionId) === false ? recordingDisabledReason(sessionId, recordingStatus, false) : null
+
+ if (noRecordingReason) {
+ return (
+ <div className="flex h-full w-full items-center justify-center p-4">
+ <p className="max-w-md text-center text-secondary">{noRecordingReason}</p>
+ </div>
+ )
+ }
const replayUrl = urls.replaySingle(
sessionId,