Skip to content

Commit aab9e17

Browse files
romtsnclaude
andcommitted
fix(core): Read replayId from controller instead of scope
The scope passed to captureEvent can be a clone (when using ScopeCallback), which misses the replayId set by captureReplay() on the live scope. Read from ReplayController.getReplayId() instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c25645d commit aab9e17

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,13 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
250250
}
251251
if (shouldCaptureReplay) {
252252
options.getReplayController().captureReplay(event.isCrashed());
253-
if (scope != null) {
254-
final @Nullable SentryId replayId = scope.getReplayId();
255-
if (replayId != null && !replayId.equals(SentryId.EMPTY_ID)) {
256-
final @Nullable ITransaction transaction = scope.getTransaction();
257-
if (transaction != null) {
258-
final @Nullable Baggage baggage = transaction.getSpanContext().getBaggage();
259-
if (baggage != null) {
260-
baggage.forceSetReplayId(replayId);
261-
}
253+
final @NotNull SentryId replayId = options.getReplayController().getReplayId();
254+
if (!replayId.equals(SentryId.EMPTY_ID) && scope != null) {
255+
final @Nullable ITransaction transaction = scope.getTransaction();
256+
if (transaction != null) {
257+
final @Nullable Baggage baggage = transaction.getSpanContext().getBaggage();
258+
if (baggage != null) {
259+
baggage.forceSetReplayId(replayId);
262260
}
263261
}
264262
}

sentry/src/test/java/io/sentry/SentryClientTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,6 +3291,8 @@ class SentryClientTest {
32913291
fixture.sentryOptions.setReplayController(
32923292
object : ReplayController by NoOpReplayController.getInstance() {
32933293
override fun captureReplay(isTerminating: Boolean?) {}
3294+
3295+
override fun getReplayId(): SentryId = replayId
32943296
}
32953297
)
32963298
val sut = fixture.getSut()

0 commit comments

Comments
 (0)