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): fix and contain inspector crashes, label recorded-page errors (#80165)

posthog[bot]77f7c0e5c71e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index fdbc225e5820..8099bc42834c 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1664,6 +1664,10 @@ snapshots:
hash: v1.k794b7964.c7010a17087a5d938010755a647e04d0950b272490f72652e39952e9f43c8ee7.V8sVtA7GO9RV46TXBX4MJPAjicCqlNF-vrsNyGXHeV8
components-playerinspector-itemevent--web-vitals-event--light:
hash: v1.k794b7964.f6eecbe85fedd1c71f63c301b70f28e9a2d2291e70bc7587bb2e3cb4de64db4c.s1Qr84WeSsLBSWJ5OQl15QkQ9qIMCjr1L70pxgqHzzI
+ components-playerinspector-itemevent--web-vitals-event-with-unusable-values--dark:
+ hash: v1.k794b7964.a0a2c7917255169a045b428aedfabaaf585549938336fa3ef6b3ea43ba75f890.jEMfcnfMMDUB1vNcE2GLiXrIBVnUjT81wg24-XNLJkM
+ components-playerinspector-itemevent--web-vitals-event-with-unusable-values--light:
+ hash: v1.k794b7964.977488d5c87c3666827d8e7247a7ad4ef0db4d9c18537a5b1fccf46827ff9012.pxOweNjiGiwl8ADJsqty3CIvXkMKose2gO3FiRpaz7A
components-playerinspector-itemexperimentvariant--default--dark:
hash: v1.k794b7964.16972cbc7f6e7bf8b96068c9870985988263ded5d21d1417f67313d47cd46534.fRpxzpthpTvisi_q793m1PcRBjqfU_QQ8E_rFmg8djs
components-playerinspector-itemexperimentvariant--default--light:
diff --git a/frontend/src/scenes/session-recordings/player/inspector/PlayerInspector.tsx b/frontend/src/scenes/session-recordings/player/inspector/PlayerInspector.tsx
index ec00c7285f6b..90094a988d4c 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/PlayerInspector.tsx
+++ b/frontend/src/scenes/session-recordings/player/inspector/PlayerInspector.tsx
@@ -1,12 +1,24 @@
+import { useValues } from 'kea'
+
import { PlayerInspectorBottomSettings } from 'scenes/session-recordings/player/inspector/PlayerInspectorBottomSettings'
import { PlayerInspectorControls } from 'scenes/session-recordings/player/inspector/PlayerInspectorControls'
import { PlayerInspectorList } from 'scenes/session-recordings/player/inspector/PlayerInspectorList'
+import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
+
+import { ErrorBoundary } from '~/layout/ErrorBoundary'
export function PlayerInspector(): JSX.Element {
+ // The player can swap recordings without remounting this component, and a React error boundary
+ // holds its failed state until it unmounts. Key the boundary on the recording so a new recording
+ // remounts it and clears a stale fallback from an earlier crash.
+ const { sessionRecordingId } = useValues(sessionRecordingPlayerLogic)
return (
<>
<PlayerInspectorControls />
- <PlayerInspectorList />
+ {/* Only the list is wrapped, so a crashing row leaves the filters that navigate around it usable. */}
+ <ErrorBoundary key={sessionRecordingId} exceptionProps={{ feature: 'replay-inspector' }}>
+ <PlayerInspectorList />
+ </ErrorBoundary>
<PlayerInspectorBottomSettings />
</>
)
diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.stories.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.stories.tsx
index 3eb25f17b2d3..3f924d579a6b 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.stories.tsx
+++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.stories.tsx
@@ -226,6 +226,35 @@ export const WebVitalsEvent: Story = {
},
}
+// captured web vitals properties reach us with a missing or non-numeric `value`, so the
+// metric name and rating have to render on their own
+export const WebVitalsEventWithUnusableValues: Story = {
+ render: renderBasic as any,
+ args: {
+ item: makeItem(
+ {},
+ { event: '$web_vitals' },
+ {
+ $lib: 'web',
+ $current_url: 'http://localhost:8000/project/1/activity/explore',
+ $web_vitals_INP_event: {
+ name: 'INP',
+ rating: 'good',
+ id: 'v4-1719484470693-6845621238957',
+ timestamp: 1719484490693,
+ },
+ $web_vitals_CLS_event: {
+ name: 'CLS',
+ value: '0.106',
+ rating: 'needs-improvement',
+ id: 'v4-1719484470710-6118725051157',
+ timestamp: 1719484490693,
+ },
+ }
+ ),
+ },
+}
+
export const GroupIdentifyEvent: Story = {
render: renderBasic as any,
args: {
diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.tsx
index d972570add32..84b8c3a23502 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.tsx
+++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemEvent.tsx
@@ -17,11 +17,12 @@ import { TitledSnack } from 'lib/components/TitledSnack'
import { FEATURE_FLAGS } from 'lib/constants'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { Spinner } from 'lib/lemon-ui/Spinner'
+import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { ceilMsToClosestSecond } from 'lib/utils/durations'
import { autoCaptureEventToDescription } from 'lib/utils/events'
import { getPrimaryPropertyForEvent } from 'lib/utils/events'
-import { isString } from 'lib/utils/guards'
+import { isNumber, isString } from 'lib/utils/guards'
import { capitalizeFirstLetter } from 'lib/utils/strings'
import { insightUrlForEvent } from 'scenes/insights/utils'
import { urls } from 'scenes/urls'
@@ -41,6 +42,13 @@ export interface ItemEventProps {
groupedItems?: InspectorListItemEvent[]
}
+// Captured web vitals reach us with the value missing, or as a numeric string, or as something
+// unusable, so only render it when it converts to a finite number.
+function webVitalValue(value: unknown): string {
+ const asNumber = isString(value) && value.trim() !== '' ? Number(value) : value
+ return isNumber(asNumber) && Number.isFinite(asNumber) ? `: ${asNumber.toFixed(2)}` : ''
+}
+
function WebVitalEventSummary({ event }: { event: Record<string, any> }): JSX.Element {
return (
<>
@@ -51,7 +59,8 @@ function WebVitalEventSummary({ event }: { event: Record<string, any> }): JSX.El
titleSuffix=""
value={
<>
- {event.rating}: {event.value.toFixed(2)}
+ {event.rating}
+ {webVitalValue(event.value)}
</>
}
/>
@@ -80,11 +89,13 @@ function ExceptionTitlePill({ event }: { event: Record<string, any> }): JSX.Elem
connector = ':'
}
return (
- <div className="flex flex-row items-center gap-1 justify-between border px-1 truncate ellipsis border-x-danger-dark bg-danger-highlight">
- <span>{errorProps.type}</span>
- <span>{connector}</span>
- <span>{errorProps.value}</span>
- </div>
+ <Tooltip title="This error was captured on the recorded page.">
+ <div className="flex flex-row items-center gap-1 justify-between border px-1 truncate ellipsis border-x-danger-dark bg-danger-highlight">
+ <span>{errorProps.type}</span>
+ <span>{connector}</span>
+ <span>{errorProps.value}</span>
+ </div>
+ </Tooltip>
)
}
diff --git a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts
index 1765257d04e1..e5084d5e8a08 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts
@@ -1,5 +1,7 @@
import { expectLogic } from 'kea-test-utils'
+import { RecordingSnapshot } from '@posthog/replay-shared'
+
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import {
@@ -223,6 +225,23 @@ describe('playerInspectorLogic', () => {
})
})
+ describe('custom snapshots', () => {
+ const customSnapshot = (timestamp: number, data: Record<string, any>): RecordingSnapshot =>
+ ({ type: 5, timestamp, windowId: 1, data }) as unknown as RecordingSnapshot
+
+ it('derives doctor items from tagged custom snapshots and skips untagged ones', () => {
+ dataLogic.actions.setProcessedSnapshots([
+ customSnapshot(1691755416097, { tag: '$session_options', payload: {} }),
+ customSnapshot(1691755417097, { payload: { without: 'a tag' } }),
+ ])
+
+ expect(logic.values.processedSnapshotData.doctorEvents.map((item) => item.tag)).toEqual([
+ 'session options',
+ 'count of snapshot types by window',
+ ])
+ })
+ })
+
describe('setTrackedWindow', () => {
it('starts with no tracked window', async () => {
await expectLogic(logic, () => {
diff --git a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts
index e093fd78bc78..d7b975332d8a 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts
@@ -31,6 +31,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { ceilMsToClosestSecond } from 'lib/utils/durations'
import { eventToDescription } from 'lib/utils/events'
import { createFuse } from 'lib/utils/fuseSearch'
+import { isString } from 'lib/utils/guards'
import { humanizeBytes } from 'lib/utils/numbers'
import { toParams } from 'lib/utils/url'
import { getText } from 'scenes/comments/Comment'
@@ -306,7 +307,9 @@ export function computeDisplayGroups(items: InspectorListItem[], groupSimilar: b
}
function _isCustomSnapshot(x: unknown): x is customEvent {
- return (x as customEvent).type === 5
+ // rrweb types `data.tag` as a required string, but captured snapshots reach us without it,
+ // and every consumer below reads the tag as one
+ return (x as customEvent).type === 5 && isString((x as customEvent).data?.tag)
}
function _isPluginSnapshot(x: unknown): x is pluginEvent {
@@ -1689,6 +1692,11 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([
let errorCount = 0
for (const event of eventsData || []) {
+ // A malformed or missing event row must not crash the whole inspector list.
+ if (!event) {
+ continue
+ }
+
let isMatchingEvent = false
if (event.event === '$exception') {