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(error-tracking): keep replay range valid while issue loads (#82485)

Hugues Pouillot968b809bdf2d
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ErrorTrackingIssueScene.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ErrorTrackingIssueScene.tsx
index d51ff7aca90f..9a9dc29571fe 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ErrorTrackingIssueScene.tsx
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ErrorTrackingIssueScene.tsx
@@ -68,7 +68,8 @@ export const scene: SceneExport<ErrorTrackingIssueSceneLogicProps> = {
}
export function ErrorTrackingIssueScene(): JSX.Element {
- const { issue, issueId, lastSeen, mobileDetailOpen } = useValues(errorTrackingIssueSceneLogic)
+ const { issue, issueId, lastSeen, initialEventTimestamp, selectedEvent, mobileDetailOpen } =
+ useValues(errorTrackingIssueSceneLogic)
const { updateAssignee, updateStatus, updateName, setMobileDetailOpen } = useActions(errorTrackingIssueSceneLogic)
const { isWindowLessThan } = useWindowSize()
const isMobile = isWindowLessThan('md')
@@ -122,7 +123,11 @@ export function ErrorTrackingIssueScene(): JSX.Element {
<SceneMenuBarItem
onClick={() => {
const url = urls.replay(ReplayTabs.Home, {
- ...getIssueReplayDateRange(issue.first_seen, lastSeen),
+ ...getIssueReplayDateRange(
+ issue.first_seen,
+ lastSeen,
+ selectedEvent?.timestamp ?? initialEventTimestamp
+ ),
filter_group: getIssueReplayFilterGroup(issue.id),
})
newInternalTab(url)
@@ -158,7 +163,11 @@ export function ErrorTrackingIssueScene(): JSX.Element {
/>
<ViewRecordingsPlaylistButton
filters={{
- ...getIssueReplayDateRange(issue.first_seen, lastSeen),
+ ...getIssueReplayDateRange(
+ issue.first_seen,
+ lastSeen,
+ selectedEvent?.timestamp ?? initialEventTimestamp
+ ),
filter_group: getIssueReplayFilterGroup(issue.id),
}}
size="small"
diff --git a/products/error_tracking/frontend/utils.test.ts b/products/error_tracking/frontend/utils.test.ts
index b02c0d21f1dc..6b491795e42e 100644
--- a/products/error_tracking/frontend/utils.test.ts
+++ b/products/error_tracking/frontend/utils.test.ts
@@ -199,7 +199,21 @@ describe('getIssueReplayDateRange', () => {
expect(range.date_to).toEqual('2024-01-02T13:00:00.000Z')
})
- it('falls back to first_seen when last_seen is missing or predates it', () => {
+ it('uses the selected event while last_seen is still loading', () => {
+ const range = getIssueReplayDateRange('2024-01-01T12:00:00.000Z', null, '2024-04-01T12:00:00.000Z')
+ expect(range.date_to).toEqual('2024-04-01T13:00:00.000Z')
+ })
+
+ it('uses a selected event that is newer than a stale last_seen', () => {
+ const range = getIssueReplayDateRange(
+ '2024-01-01T12:00:00.000Z',
+ dayjs('2024-02-01T12:00:00.000Z'),
+ '2024-04-01T12:00:00.000Z'
+ )
+ expect(range.date_to).toEqual('2024-04-01T13:00:00.000Z')
+ })
+
+ it('falls back to first_seen when no later timestamp is known', () => {
const firstSeen = '2024-01-01T12:00:00.000Z'
expect(getIssueReplayDateRange(firstSeen, null).date_to).toEqual('2024-01-01T13:00:00.000Z')
expect(getIssueReplayDateRange(firstSeen, dayjs('2023-12-31T00:00:00.000Z')).date_to).toEqual(
diff --git a/products/error_tracking/frontend/utils.ts b/products/error_tracking/frontend/utils.ts
index 5028b64c1187..ece17638fc34 100644
--- a/products/error_tracking/frontend/utils.ts
+++ b/products/error_tracking/frontend/utils.ts
@@ -113,9 +113,20 @@ export function isThirdPartyScriptError(value: ErrorTrackingException['value']):
// Recordings match on session start time, so pad past first_seen to catch a session that began
// before the exception fired, and past last_seen so a single-occurrence issue isn't a zero-width window.
-export function getIssueReplayDateRange(firstSeen: string, lastSeen: Dayjs | null): DateRange {
+// The selected event keeps the range valid when the user clicks before the last_seen query finishes.
+export function getIssueReplayDateRange(
+ firstSeen: string,
+ lastSeen: Dayjs | null,
+ selectedEventTimestamp?: string | null
+): DateRange {
const from = dayjs(firstSeen)
- const to = lastSeen && lastSeen.isAfter(from) ? lastSeen : from
+ const selectedEventSeenAt = selectedEventTimestamp ? dayjs(selectedEventTimestamp) : null
+ const latestKnownSeenAt =
+ selectedEventSeenAt?.isValid() && (!lastSeen || selectedEventSeenAt.isAfter(lastSeen))
+ ? selectedEventSeenAt
+ : lastSeen
+ const to = latestKnownSeenAt?.isAfter(from) ? latestKnownSeenAt : from
+
return {
date_from: from.subtract(1, 'hour').toISOString(),
date_to: to.add(1, 'hour').toISOString(),