Skip to content

fix(core): Inject replayId into trace context for buffer mode errors#5754

Merged
romtsn merged 5 commits into
mainfrom
rz/fix/replay-error-linkage
Jul 13, 2026
Merged

fix(core): Inject replayId into trace context for buffer mode errors#5754
romtsn merged 5 commits into
mainfrom
rz/fix/replay-error-linkage

Conversation

@romtsn

@romtsn romtsn commented Jul 10, 2026

Copy link
Copy Markdown
Member

📜 Description

In buffer mode, the scope's replayId is intentionally empty until captureReplay() is called (to avoid tagging events with a replay that may never be sent). However, the event's DSC is built from the active transaction's frozen baggage, which was frozen before captureReplay() set the replayId. This means error events that trigger a buffer replay flush have no replay_id in their DSC, breaking error-to-replay linkage.

After captureReplay() runs, we now force-set the replayId on the transaction's frozen baggage via Baggage.forceSetReplayId(), so the envelope header carries the correct replay_id in the DSC. This mirrors the JS SDK's setReplayIdOnDynamicSamplingContext.

💡 Motivation and Context

Error events that trigger buffer-mode replay capture were not linked to the resulting replay, making it impossible to navigate from the error to its replay in the Sentry UI.

Example replay with a linked error event: https://sentry-sdks.sentry.io/explore/replays/49e737e2f6dc48f1a9c14692bd898bb7/?playlistEnd=2026-07-13T07:15:41&playlistStart=2026-07-06T07:15:41&project=5428559&query=&referrer=replayList&t_main=errors

💚 How did you test it?

  • Existing SentryClientTest suite passes
  • Manual verification with sample app in buffer mode: captured exception's DSC now contains the replay_id, and the error appears linked to the replay in Sentry

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@sentry

sentry Bot commented Jul 10, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.48.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 327.25 ms 381.92 ms 54.67 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6b019b7 319.84 ms 333.15 ms 13.31 ms
eb95ded 317.51 ms 369.08 ms 51.57 ms
319f256 317.53 ms 370.83 ms 53.29 ms
b3d8889 420.46 ms 453.71 ms 33.26 ms
6b019b7 403.90 ms 546.09 ms 142.19 ms
889ecea 367.58 ms 437.52 ms 69.94 ms
d15471f 303.49 ms 439.08 ms 135.59 ms
d364ace 384.53 ms 453.51 ms 68.98 ms
6ea4329 309.06 ms 353.48 ms 44.42 ms
c8125f3 383.82 ms 441.66 ms 57.84 ms

App size

Revision Plain With Sentry Diff
6b019b7 0 B 0 B 0 B
eb95ded 0 B 0 B 0 B
319f256 1.58 MiB 2.19 MiB 619.79 KiB
b3d8889 1.58 MiB 2.10 MiB 535.07 KiB
6b019b7 0 B 0 B 0 B
889ecea 1.58 MiB 2.11 MiB 539.75 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d364ace 1.58 MiB 2.11 MiB 539.75 KiB
6ea4329 1.58 MiB 2.29 MiB 719.82 KiB
c8125f3 1.58 MiB 2.10 MiB 532.32 KiB

Previous results on branch: rz/fix/replay-error-linkage

Startup times

Revision Plain With Sentry Diff
4f9605b 382.72 ms 476.24 ms 93.52 ms
9fbe087 391.26 ms 480.70 ms 89.44 ms
e6285ac 315.38 ms 353.88 ms 38.50 ms
cf20b6f 319.82 ms 356.96 ms 37.14 ms
01678a6 315.83 ms 347.92 ms 32.09 ms
7dd24bc 315.35 ms 363.57 ms 48.22 ms
48dcd0f 322.68 ms 374.14 ms 51.46 ms

App size

Revision Plain With Sentry Diff
4f9605b 0 B 0 B 0 B
9fbe087 0 B 0 B 0 B
e6285ac 0 B 0 B 0 B
cf20b6f 0 B 0 B 0 B
01678a6 0 B 0 B 0 B
7dd24bc 0 B 0 B 0 B
48dcd0f 0 B 0 B 0 B

@romtsn romtsn changed the base branch from main to rz/fix/replay-segment-id-normalization July 10, 2026 13:02
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch 2 times, most recently from e63a32e to 6f89328 Compare July 10, 2026 13:35
Comment thread CHANGELOG.md Outdated
@romtsn romtsn marked this pull request as ready for review July 13, 2026 09:28
Comment thread sentry/src/main/java/io/sentry/SentryClient.java

@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 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 aab9e17. Configure here.

Comment thread sentry/src/main/java/io/sentry/SentryClient.java Outdated
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch 2 times, most recently from 64766b2 to fa65f2e Compare July 13, 2026 09:48
Base automatically changed from rz/fix/replay-segment-id-normalization to main July 13, 2026 19:53
romtsn and others added 5 commits July 13, 2026 22:40
In buffer mode, the scope's replayId is empty until captureReplay()
is called. The transaction's baggage is frozen before that, so the
DSC in the envelope header has no replay_id — breaking error-to-replay
linkage.

After captureReplay() sets the replayId on scope, force-set it on
the transaction's frozen baggage via Baggage.forceSetReplayId() so
the envelope header carries the correct replay_id in the DSC. This
matches the JS SDK's approach of updating the DSC after buffer-to-
session conversion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Read scope.getReplayId() which is only set when on-error sampling
succeeds. Using ReplayController.getReplayId() would return the
buffer's internal ID even when sampling rejected the replay.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch from fa65f2e to 864b2de Compare July 13, 2026 20:40
@romtsn romtsn enabled auto-merge (squash) July 13, 2026 20:43
@romtsn romtsn merged commit c94d7ba into main Jul 13, 2026
71 checks passed
@romtsn romtsn deleted the rz/fix/replay-error-linkage branch July 13, 2026 20:59
Sign up for free to 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.

2 participants