Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { IssueStatusButton } from '../../components/IssueStatusButton'
import { ErrorTrackingSetupPrompt } from '../../components/SetupPrompt/SetupPrompt'
import { StyleVariables } from '../../components/StyleVariables'
import { useErrorTagRenderer } from '../../hooks/use-error-tag-renderer'
import { getIssueReplayDateRange } from '../../utils'
import {
ErrorTrackingIssueSceneCategory,
errorTrackingIssueSceneConfigurationLogic,
Expand Down Expand Up @@ -124,8 +125,7 @@ export function ErrorTrackingIssueScene(): JSX.Element {
<SceneMenuBarItem
onClick={() => {
const url = urls.replay(ReplayTabs.Home, {
date_from: issue.first_seen ?? '-30d',
date_to: lastSeen ? lastSeen.toISOString() : null,
...getIssueReplayDateRange(issue.first_seen, lastSeen),
filter_group: {
type: FilterLogicalOperator.And,
values: [
Expand Down Expand Up @@ -176,8 +176,7 @@ export function ErrorTrackingIssueScene(): JSX.Element {
/>
<ViewRecordingsPlaylistButton
filters={{
date_from: issue.first_seen ?? '-30d',
date_to: lastSeen ? lastSeen.toISOString() : null,
...getIssueReplayDateRange(issue.first_seen, lastSeen),
filter_group: {
type: FilterLogicalOperator.And,
values: [
Expand Down
27 changes: 26 additions & 1 deletion products/error_tracking/frontend/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Dayjs, dayjs } from 'lib/dayjs'

import { ErrorTrackingIssue, ErrorTrackingIssueAggregations } from '~/queries/schema/schema-general'

import { generateDateRangeLabel, mergeIssues, sourceDisplay } from './utils'
import { generateDateRangeLabel, getIssueReplayDateRange, mergeIssues, sourceDisplay } from './utils'

function wrapVolumeBuckets(
initialDate: Dayjs,
Expand Down Expand Up @@ -176,6 +176,31 @@ describe('date range label generation', () => {
})
})

describe('getIssueReplayDateRange', () => {
it('pads a single-occurrence issue so the window is not zero width', () => {
const seenAt = '2024-01-01T12:00:00.000Z'
const range = getIssueReplayDateRange(seenAt, dayjs(seenAt))
expect(range.date_from).toEqual('2024-01-01T11:00:00.000Z')
expect(range.date_to).toEqual('2024-01-01T13:00:00.000Z')
})

it('extends date_from before first_seen to catch sessions that started earlier', () => {
const firstSeen = '2024-01-01T12:00:00.000Z'
const lastSeen = dayjs('2024-01-02T12:00:00.000Z')
const range = getIssueReplayDateRange(firstSeen, lastSeen)
expect(range.date_from).toEqual('2024-01-01T11:00:00.000Z')
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', () => {
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(
'2024-01-01T13:00:00.000Z'
)
})
})

describe('sourceDisplay', () => {
it('nicely formats paths', async () => {
expect(sourceDisplay('')).toEqual('')
Expand Down
11 changes: 11 additions & 0 deletions products/error_tracking/frontend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ export function isThirdPartyScriptError(value: ErrorTrackingException['value']):
return value === THIRD_PARTY_SCRIPT_ERROR
}

// 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 {
const from = dayjs(firstSeen)
const to = lastSeen && lastSeen.isAfter(from) ? lastSeen : from
return {
date_from: from.subtract(1, 'hour').toISOString(),
date_to: to.add(1, 'hour').toISOString(),
}
}

const customOptions: Record<string, string> = {
dStart: 'Today', // today
mStart: 'Month',
Expand Down
Loading