Skip to content

Commit 43dceab

Browse files
romtsnclaude
andcommitted
fix(core): Force-set replayId on frozen baggage for buffer mode errors
Replace the TraceContext.withReplayId approach with Baggage.forceSetReplayId — the DSC that relay reads comes from the transaction's baggage, not the envelope header trace context. After captureReplay() sets the replayId on scope, force-set it on the transaction's frozen baggage so the envelope header carries the correct replay_id in the DSC. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b7b6adf commit 43dceab

4 files changed

Lines changed: 20 additions & 34 deletions

File tree

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public final class io/sentry/Baggage {
3737
public fun <init> (Lio/sentry/Baggage;)V
3838
public fun <init> (Lio/sentry/ILogger;)V
3939
public fun <init> (Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/Double;Ljava/lang/Double;Ljava/lang/String;ZZLio/sentry/ILogger;)V
40+
public fun forceSetReplayId (Lio/sentry/protocol/SentryId;)V
4041
public fun forceSetSampleRate (Ljava/lang/Double;)V
4142
public fun freeze ()V
4243
public static fun fromEvent (Lio/sentry/SentryBaseEvent;Ljava/lang/String;Lio/sentry/SentryOptions;)Lio/sentry/Baggage;
@@ -4567,7 +4568,6 @@ public final class io/sentry/TraceContext : io/sentry/JsonSerializable, io/sentr
45674568
public fun getUserId ()Ljava/lang/String;
45684569
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
45694570
public fun setUnknown (Ljava/util/Map;)V
4570-
public fun withReplayId (Lio/sentry/protocol/SentryId;)Lio/sentry/TraceContext;
45714571
}
45724572

45734573
public final class io/sentry/TraceContext$Deserializer : io/sentry/JsonDeserializer {

sentry/src/main/java/io/sentry/Baggage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ public void setReplayId(final @Nullable String replayId) {
451451
set(DSCKeys.REPLAY_ID, replayId);
452452
}
453453

454+
@ApiStatus.Internal
455+
public void forceSetReplayId(final @NotNull SentryId replayId) {
456+
if (!SentryId.EMPTY_ID.equals(replayId)) {
457+
keyValues.put(DSCKeys.REPLAY_ID, replayId.toString());
458+
}
459+
}
460+
454461
@ApiStatus.Internal
455462
public @Nullable String getOrgId() {
456463
return get(DSCKeys.ORG_ID);

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,23 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
250250
}
251251
if (shouldCaptureReplay) {
252252
options.getReplayController().captureReplay(event.isCrashed());
253-
}
254-
if (scope != null && event != null) {
255-
final @Nullable SentryId replayId = scope.getReplayId();
256-
if (replayId != null && !replayId.equals(SentryId.EMPTY_ID)) {
257-
event.getContexts().put(Contexts.REPLAY_ID, replayId.toString());
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+
}
262+
}
263+
}
258264
}
259265
}
260266
}
261267

262268
try {
263-
@Nullable TraceContext traceContext = getTraceContext(scope, hint, event);
264-
if (traceContext != null && scope != null) {
265-
final @Nullable SentryId replayId = scope.getReplayId();
266-
if (replayId != null
267-
&& !replayId.equals(SentryId.EMPTY_ID)
268-
&& (traceContext.getReplayId() == null
269-
|| SentryId.EMPTY_ID.equals(traceContext.getReplayId()))) {
270-
traceContext = traceContext.withReplayId(replayId);
271-
}
272-
}
269+
final @Nullable TraceContext traceContext = getTraceContext(scope, hint, event);
273270
final boolean shouldSendAttachments = event != null;
274271
List<Attachment> attachments = shouldSendAttachments ? getAttachments(hint) : null;
275272
final @Nullable SentryEnvelope envelope =

sentry/src/main/java/io/sentry/TraceContext.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,6 @@ public final class TraceContext implements JsonUnknown, JsonSerializable {
131131
return replayId;
132132
}
133133

134-
@ApiStatus.Internal
135-
public @NotNull TraceContext withReplayId(final @NotNull SentryId replayId) {
136-
final TraceContext copy =
137-
new TraceContext(
138-
traceId,
139-
publicKey,
140-
release,
141-
environment,
142-
userId,
143-
transaction,
144-
sampleRate,
145-
sampled,
146-
replayId,
147-
sampleRand);
148-
copy.unknown = unknown;
149-
return copy;
150-
}
151-
152134
// region json
153135

154136
@Nullable

0 commit comments

Comments
 (0)