Skip to content

fix(replays): Keep replay recordings in /data/replays and prune them - #4607

Open
sentry-junior[bot] wants to merge 4 commits into
masterfrom
dominikbuszowiecki/replay-969-replay-recording-retention
Open

sentry-junior[bot] wants to merge 4 commits into
masterfrom
dominikbuszowiecki/replay-969-replay-recording-retention

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes an issue where replay were not getting cleaned up after retention period. This is because the nightly sentry cleanup job only deletes files it has database records for, replay recordings do not have a record. We do this by changing the default filestore location and using a nightly cron job to cleanup up data in that location when the data on the file is past the SENTRY_EVENT_RETENTION_DAYS

Generated description

Replay recording segments are written to the default filestore (/data/files on sentry-data) because replay.storage.backend is not set. Sentry writes these blobs straight to storage, with no File rows, so sentry cleanup never deletes them and they pile up forever on both fresh installs and upgrades. See getsentry/sentry#121278.

This keeps the filesystem backend but points replay.storage.* at a dedicated /data/replays directory. A second daily cron entry in sentry-cleanup deletes anything there older than SENTRY_EVENT_RETENTION_DAYS. The new install/migrate-replay-storage.sh creates the directory. On upgrades, if APPLY_AUTOMATIC_CONFIG_UPDATES allows it, it appends the config and moves existing recordings out of /data/files. It only moves <retention>/<project_id>/<32-hex replay_id> directories, so regular file blobs (<2hex>/<4hex>/<26hex> files) are never touched. Moved recordings keep their mtimes, so ones already past retention are removed on the next cleanup run.

Open question:

  • Non-interactive upgrades with APPLY_AUTOMATIC_CONFIG_UPDATES=1 switch the path and move recordings without a prompt.

…olicy

Replay recording segments were written to the default filestore on the
sentry-data volume. Sentry writes them without File rows and relies on a
bucket lifecycle policy to expire them, so nothing ever deleted them.

Store them in a 'replays' SeaweedFS bucket that expires objects after
SENTRY_EVENT_RETENTION_DAYS, mirroring the profiles bucket setup.

Refs getsentry/sentry#121278

Co-Authored-By: Dominik Buszowiecki <44422760+DominikB2014@users.noreply.github.com>
@linear-code

linear-code Bot commented Nov 2, 2026

Copy link
Copy Markdown

REPLAY-969

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Coverage Results 📊

✅ 22 passed | Total: 22 | Pass Rate: 100% | Execution Time: 9m 40s

📊 Comparison with Base Branch

Metric Change
Total Tests —
Passed Tests —
Failed Tests —
Skipped Tests —

✨ Test counts unchanged from base.

All tests are passing successfully.

✅ Patch coverage is 100.00% (no changed executable lines found; target 50%).
Project statement coverage is 95.58% (unchanged from base (0ba08be) to head (5d7bfa1)).

Coverage diff
@@            Coverage Diff             @@
##        master     #4607       +/-##
==========================================
  Coverage    95.58%    95.58%        —%
==========================================
  Files            5         5         —
  Tracked lines       339       339         —
  Branches         0         0         —
==========================================
  Hits           324       324         —
  Misses          15        15         —
  Partials         0         0         —

Generated by Coverage Action

@aldy505

aldy505 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@DominikB2014 I would avoid using SeaweedFS here. Can we just use filesystem with a separate path? Or is there any plan of moving replay recordings to objectstore?

Drop the SeaweedFS bucket in favor of the filesystem backend with a
dedicated /data/replays directory. A daily sentry-cleanup cron job
deletes recordings older than SENTRY_EVENT_RETENTION_DAYS.

On upgrade, install points replay.storage.* at /data/replays and moves
existing recordings out of /data/files so they keep playing back and
expire like new ones.

Co-Authored-By: Dominik Buszowiecki <44422760+DominikB2014@users.noreply.github.com>
@sentry-junior sentry-junior Bot changed the title fix(replays): Store replay recordings in SeaweedFS with a lifecycle policy fix(replays): Keep replay recordings in /data/replays and prune them Nov 3, 2026
Installs that keep the default filestore in S3 or GCS already store
replay recordings in that bucket. Pointing replay.storage at
/data/replays would break playback of existing recordings and start
filling local disk, so leave those installs alone.

Co-Authored-By: Dominik Buszowiecki <44422760+DominikB2014@users.noreply.github.com>
@DominikB2014
DominikB2014 marked this pull request as ready for review November 23, 2026 17:38
@sentry-junior
sentry-junior Bot requested a review from DominikB2014 November 23, 2026 17:38
The move only ran on the install that appended the replay.storage
config. If it failed partway, later runs saw the config and skipped
the move, leaving recordings in /data/files where they could not be
played back or pruned. Run the move whenever replays are configured
to live in /data/replays; it skips anything already moved.

Co-Authored-By: Dominik Buszowiecki <44422760+DominikB2014@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5d7bfa1. Configure here.

Comment thread docker-compose.yml Resolved
@DominikB2014
DominikB2014 requested review from a team and removed request for DominikB2014 November 30, 2026 20:19

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense overall, just raised a few questions that I'm not sure about

Comment thread docker-compose.yml
BASE_IMAGE: sentry-self-hosted-local
entrypoint: "/entrypoint.sh"
command: '"0 0 * * * gosu sentry sentry cleanup --days $SENTRY_EVENT_RETENTION_DAYS"'
command: '"0 0 * * * gosu sentry sentry cleanup --days $SENTRY_EVENT_RETENTION_DAYS" "0 0 * * * gosu sentry find /data/replays -mindepth 1 -mtime +$SENTRY_EVENT_RETENTION_DAYS -delete"'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I wonder if it would make sense to integrate this deletion code into sentry cleanup? I'm not sure if that would be easy or make sense here, though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, makes sense to me. Wondering if this needs a test? Maybe moving the Python code into its own file would help

@aldy505

aldy505 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

@gggritso hey, honestly I'm not that confident about this change. the path I want to see is to move filestore into objectstore soon.

@gggritso

gggritso commented Dec 1, 2026

Copy link
Copy Markdown
Member

@aldy505 that's fair, but even though there's a plan to move Replays to ObjectStore it's not currently scheduled, and we don't know when people will get to it (we can ask!). Is is still worth it to merge a small short-term fix? IMO yes, even if it's relying on SeaweedFS and its known problems. What's your take on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants