Skip to content

feat(replay): add time duration for each playback speed #94888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 8, 2025
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {Button} from 'sentry/components/core/button';
import {CompositeSelect} from 'sentry/components/core/compactSelect/composite';
import {useReplayContext} from 'sentry/components/replays/replayContext';
import {IconSettings} from 'sentry/icons';
import {t} from 'sentry/locale';
import formatDuration from 'sentry/utils/duration/formatDuration';
import {useReplayPrefs} from 'sentry/utils/replays/playback/providers/replayPreferencesContext';
import {toTitleCase} from 'sentry/utils/string/toTitleCase';

Expand All @@ -17,9 +19,19 @@ export default function ReplayPreferenceDropdown({
isLoading?: boolean;
}) {
const [prefs, setPrefs] = useReplayPrefs();
const {isFetching, replay} = useReplayContext();

const SKIP_OPTION_VALUE = 'skip';

// Calculate adjusted duration for each speed (rounded up)
const calculateAdjustedDuration = (originalDurationMs: number, speed: number) => {
return Math.ceil(originalDurationMs / speed);
};

// Check if we should show duration (data is loaded and duration is available)
const shouldShowDuration =
!isLoading && !isFetching && replay && replay.getDurationMs() > 0;

return (
<CompositeSelect
disabled={isLoading}
Expand All @@ -37,10 +49,30 @@ export default function ReplayPreferenceDropdown({
label={t('Playback Speed')}
value={prefs.playbackSpeed}
onChange={opt => setPrefs({playbackSpeed: opt.value})}
options={speedOptions.map(option => ({
label: `${option}x`,
value: option,
}))}
options={speedOptions.map(option => {
const baseLabel = `${option}x`;

if (shouldShowDuration) {
const adjustedDurationMs = calculateAdjustedDuration(
replay.getDurationMs(),
option
);
const durationDisplay = formatDuration({
duration: [adjustedDurationMs, 'ms'],
precision: 'sec',
style: 'h:mm:ss',
});
return {
label: `${baseLabel} (${durationDisplay})`,
value: option,
};
}

return {
label: baseLabel,
value: option,
};
})}
/>
<CompositeSelect.Region
label={t('Timestamps')}
Expand Down
Loading