From 9ebc003a1b1ff737636b49897e074f1e0c40778d Mon Sep 17 00:00:00 2001 From: jean-philippe bempel Date: Tue, 21 Jan 2025 11:53:07 +0100 Subject: [PATCH 1/3] 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. --- .../debugger/exception/DefaultExceptionDebugger.java | 5 ++++- .../debugger/exception/ExceptionProbeManager.java | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java index 3c3bb225ca2..2d4b2dd5fe5 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java @@ -158,10 +158,13 @@ private static void processSnapshotsAndSetTags( String tagName = String.format(SNAPSHOT_ID_TAG_FMT, frameIndex); span.setTag(tagName, snapshot.getId()); LOGGER.debug("add tag to span[{}]: {}: {}", span.getSpanId(), tagName, snapshot.getId()); - DebuggerAgent.getSink().addSnapshot(snapshot); + if (!state.isSnapshotSent()) { + DebuggerAgent.getSink().addSnapshot(snapshot); + } snapshotAssigned = true; } if (snapshotAssigned) { + state.markAsSnapshotSent(); span.setTag(DD_DEBUG_ERROR_EXCEPTION_ID, state.getExceptionId()); LOGGER.debug( "add tag to span[{}]: {}: {}", diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java index b37708a3252..7b68b69afce 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java @@ -183,6 +183,7 @@ boolean hasExceptionStateTracked() { public static class ThrowableState { private final String exceptionId; private List snapshots; + private boolean snapshotSent; private ThrowableState(String exceptionId) { this.exceptionId = exceptionId; @@ -206,5 +207,13 @@ public void addSnapshot(Snapshot snapshot) { } snapshots.add(snapshot); } + + public boolean isSnapshotSent() { + return snapshotSent; + } + + public void markAsSnapshotSent() { + snapshotSent = true; + } } } From 3b953a5e239b684d1451bbca81b3447043ab464c Mon Sep 17 00:00:00 2001 From: jean-philippe bempel Date: Thu, 23 Jan 2025 18:26:15 +0100 Subject: [PATCH 2/3] Update system-tests to 9039f27868f0f7d6db344ca2f0631071a1b9de6f --- .circleci/config.continue.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.continue.yml.j2 b/.circleci/config.continue.yml.j2 index 586de334a68..bb629ff2dc4 100644 --- a/.circleci/config.continue.yml.j2 +++ b/.circleci/config.continue.yml.j2 @@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation 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" profiling_modules: &profiling_modules "dd-java-agent/agent-profiling" -default_system_tests_commit: &default_system_tests_commit 8b05076e897fe62206d7704f2e8e650ed83ebd1f +default_system_tests_commit: &default_system_tests_commit 9039f27868f0f7d6db344ca2f0631071a1b9de6f parameters: nightly: From 835da7b99e074e938aeb05d4d7fbc45db078ea78 Mon Sep 17 00:00:00 2001 From: jean-philippe bempel Date: Fri, 24 Jan 2025 17:59:36 +0100 Subject: [PATCH 3/3] Update system-tests to c706e333ef06800b866ac300e4b6cdb7566cc5e5 --- .circleci/config.continue.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.continue.yml.j2 b/.circleci/config.continue.yml.j2 index bb629ff2dc4..fcb73477800 100644 --- a/.circleci/config.continue.yml.j2 +++ b/.circleci/config.continue.yml.j2 @@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation 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" profiling_modules: &profiling_modules "dd-java-agent/agent-profiling" -default_system_tests_commit: &default_system_tests_commit 9039f27868f0f7d6db344ca2f0631071a1b9de6f +default_system_tests_commit: &default_system_tests_commit c706e333ef06800b866ac300e4b6cdb7566cc5e5 parameters: nightly: