Skip to content

Commit 1eee393

Browse files
committed
Avoid double snapshots for Exception Replay
As Exception replay is supported by default for intermediate spans we can end up in a situation where 2 spans are attaching the same exception with the snapshots. in that case DebuggerContext::handleException is called twice, once for each span and we are also sending the same snapshots to the backend while only one version is necessary and we tag it to the according spans. We can just make sure we are sending the snapshots only once.
1 parent ae1aa30 commit 1eee393

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ private static void processSnapshotsAndSetTags(
158158
String tagName = String.format(SNAPSHOT_ID_TAG_FMT, frameIndex);
159159
span.setTag(tagName, snapshot.getId());
160160
LOGGER.debug("add tag to span[{}]: {}: {}", span.getSpanId(), tagName, snapshot.getId());
161-
DebuggerAgent.getSink().addSnapshot(snapshot);
161+
if (!state.isSnapshotSent()) {
162+
DebuggerAgent.getSink().addSnapshot(snapshot);
163+
}
162164
snapshotAssigned = true;
163165
}
164166
if (snapshotAssigned) {
167+
state.markAsSnapshotSent();
165168
span.setTag(DD_DEBUG_ERROR_EXCEPTION_ID, state.getExceptionId());
166169
LOGGER.debug(
167170
"add tag to span[{}]: {}: {}",

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ boolean hasExceptionStateTracked() {
183183
public static class ThrowableState {
184184
private final String exceptionId;
185185
private List<Snapshot> snapshots;
186+
private boolean snapshotSent;
186187

187188
private ThrowableState(String exceptionId) {
188189
this.exceptionId = exceptionId;
@@ -206,5 +207,13 @@ public void addSnapshot(Snapshot snapshot) {
206207
}
207208
snapshots.add(snapshot);
208209
}
210+
211+
public boolean isSnapshotSent() {
212+
return snapshotSent;
213+
}
214+
215+
public void markAsSnapshotSent() {
216+
snapshotSent = true;
217+
}
209218
}
210219
}

0 commit comments

Comments
 (0)