Skip to content

Commit 93b44ea

Browse files
authored
Avoid double snapshots for Exception Replay (#8273)
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 088b7bf commit 93b44ea

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.circleci/config.continue.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation
3636
debugger_modules: &debugger_modules "dd-java-agent/agent-debugger|dd-java-agent/agent-bootstrap|dd-java-agent/agent-builder|internal-api|communication|dd-trace-core"
3737
profiling_modules: &profiling_modules "dd-java-agent/agent-profiling"
3838

39-
default_system_tests_commit: &default_system_tests_commit 8b05076e897fe62206d7704f2e8e650ed83ebd1f
39+
default_system_tests_commit: &default_system_tests_commit c706e333ef06800b866ac300e4b6cdb7566cc5e5
4040

4141
parameters:
4242
nightly:

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)