Skip to content

fix(replay): Set replay_id on DSC after buffer-to-session conversion - #20686

Merged
billyvg merged 4 commits into
developfrom
billy/fix-dsc-after-buffer-to-session
May 13, 2026
Merged

fix(replay): Set replay_id on DSC after buffer-to-session conversion#20686
billyvg merged 4 commits into
developfrom
billy/fix-dsc-after-buffer-to-session

Conversation

@billyvg

@billyvgbillyvg commented May 5, 2026

Copy link
Copy Markdown
Member

Follow-up to a code review comment on #20129 -- this sets a replayId on the DSC when a buffer mode replay is saved and converted to a session-based replay.

Normally, we attach the replay_id to a DSC using the createDsc hook, but only when replay is enabled and recordingMode is session (and not for buffer). https://github.com/getsentry/sentry-javascript/blob/billy/fix-dsc-after-buffer-to-session/packages/replay-internal/src/util/addGlobalListeners.ts#L40-L46

What I'm unsure of is if this does anything since we're mutating the DSC after an unknown period of time (e.g. we're in buffer mode, and an error happens after 30 minutes).

Slop

  • When sendBufferedReplayOrFlush converts from buffer to session mode, it calls startRecording() directly but never updates the cached DSC with replay_id
  • The createDsc hook only fires for new spans, not for an already-cached DSC on the scope (set by browserTracingIntegration), so replay_id was missing from outgoing requests until a new span happened to be created
  • Adds setReplayIdOnDynamicSamplingContext() (symmetric to the existing resetReplayIdOnDynamicSamplingContext()) and calls it after the buffer-to-session conversion completes

🤖 Generated with Claude Code

@billyvg
billyvgforce-pushed the billy/fix-dsc-after-buffer-to-session branch from 0dcea38 to 2e84c24CompareMay 5, 2026 18:56
@billyvg
billyvg marked this pull request as ready for review May 5, 2026 19:07
@billyvg
billyvg requested a review from a team as a code ownerMay 5, 2026 19:07

@cursorcursorBot 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 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 8f8732f. Configure here.

Comment threadpackages/replay-internal/src/replay.ts
@github-actions

github-actionsBot commented May 5, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser26.89 kB--
@sentry/browser - with treeshaking flags25.33 kB--
@sentry/browser (incl. Tracing)44.79 kB--
@sentry/browser (incl. Tracing + Span Streaming)46.8 kB--
@sentry/browser (incl. Tracing, Profiling)49.78 kB--
@sentry/browser (incl. Tracing, Replay)84.42 kB-0.01%-3 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags73.87 kB+0.03%+17 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas)89.12 kB-0.01%-8 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback)101.77 kB--
@sentry/browser (incl. Feedback)44.08 kB--
@sentry/browser (incl. sendFeedback)31.7 kB--
@sentry/browser (incl. FeedbackAsync)36.81 kB--
@sentry/browser (incl. Metrics)27.98 kB--
@sentry/browser (incl. Logs)28.13 kB--
@sentry/browser (incl. Metrics & Logs)28.8 kB--
@sentry/react28.64 kB--
@sentry/react (incl. Tracing)47.06 kB--
@sentry/vue31.82 kB--
@sentry/vue (incl. Tracing)46.67 kB--
@sentry/svelte26.91 kB--
CDN Bundle29.28 kB--
CDN Bundle (incl. Tracing)47.2 kB--
CDN Bundle (incl. Logs, Metrics)30.65 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)48.34 kB--
CDN Bundle (incl. Replay, Logs, Metrics)70 kB+0.04%+21 B 🔺
CDN Bundle (incl. Tracing, Replay)84.62 kB+0.03%+18 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)85.68 kB+0.03%+19 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback)90.43 kB+0.03%+20 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)91.52 kB+0.02%+16 B 🔺
CDN Bundle - uncompressed86.14 kB--
CDN Bundle (incl. Tracing) - uncompressed141.7 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed90.33 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed145.16 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed215.18 kB+0.02%+25 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed260.43 kB+0.01%+25 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed263.88 kB+0.01%+25 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed274.13 kB+0.01%+25 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed277.57 kB+0.01%+25 B 🔺
@sentry/nextjs (client)49.57 kB--
@sentry/sveltekit (client)45.28 kB--
@sentry/node-core61.97 kB+0.02%+11 B 🔺
@sentry/node166.93 kB+0.01%+6 B 🔺
@sentry/node - without tracing74.38 kB+0.01%+7 B 🔺
@sentry/aws-serverless109.18 kB+0.01%+6 B 🔺
@sentry/cloudflare (withSentry) - minified170.88 kB--
@sentry/cloudflare (withSentry)431.1 kB--

View base workflow run

billyvgand others added 3 commits May 13, 2026 14:30
When `sendBufferedReplayOrFlush` converts from buffer to session mode,
it calls `startRecording()` directly but never updates the cached DSC
with the new replay_id. The `createDsc` hook only fires for new spans,
not for an already-cached DSC on the scope, so the replay_id was missing
from all outgoing requests until a new span was created.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…onversion
Verifies that a cached DSC on the scope gets replay_id set after
sendBufferedReplayOrFlush converts from buffer to session mode.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@billyvg
billyvgforce-pushed the billy/fix-dsc-after-buffer-to-session branch from 4c60a87 to 59a516bCompareMay 13, 2026 18:30
@billyvg
billyvg enabled auto-merge (squash) May 13, 2026 18:30
@billyvg
billyvg merged commit cc3ecb2 into developMay 13, 2026
193 of 194 checks passed
@billyvg
billyvg deleted the billy/fix-dsc-after-buffer-to-session branch May 13, 2026 21:28
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@billyvg@mydea@logaretm