From d54dd6b253185f804498e766b45b32fae4e8b0de Mon Sep 17 00:00:00 2001 From: jean-philippe bempel Date: Wed, 7 Jan 2026 12:24:43 +0100 Subject: [PATCH 1/2] fix Capture Expressions for line probes Captures were not added if captureSnapshot=false. using isFullSnapshot method to determine if we adding them or not --- .../com/datadog/debugger/probe/LogProbe.java | 2 +- .../debugger/agent/CapturedSnapshotTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java index e79ef419c39..b56ecb42438 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java @@ -756,7 +756,7 @@ public void commit(CapturedContext lineContext, int line) { if (shouldCommit) { incrementBudget(); if (inBudget()) { - if (isCaptureSnapshot()) { + if (isFullSnapshot()) { // freeze context just before commit because line probes have only one context Duration timeout = Duration.of( diff --git a/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java b/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java index 891f497d449..e291ba8d8aa 100644 --- a/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java +++ b/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java @@ -2713,6 +2713,7 @@ public void captureExpressions() throws IOException, URISyntaxException { LogProbe probe = createProbeBuilder(PROBE_ID, CLASS_NAME, "doit", null) .evaluateAt(MethodLocation.EXIT) + .captureSnapshot(false) .captureExpressions( Arrays.asList( new LogProbe.CaptureExpression( @@ -2744,12 +2745,48 @@ public void captureExpressions() throws IOException, URISyntaxException { snapshot.getCaptures().getReturn(), "nullTyped_fld", Object.class.getTypeName(), null); } + @Test + public void captureExpressionsLineProbe() throws IOException, URISyntaxException { + final String CLASS_NAME = "CapturedSnapshot08"; + int line = getLineForLineProbe(CLASS_NAME, LINE_PROBE_ID3); + LogProbe probe = + createProbeBuilder(PROBE_ID, CLASS_NAME, line) + .captureSnapshot(false) + .captureExpressions( + Arrays.asList( + new LogProbe.CaptureExpression( + "typed_fld_fld_msg", + new ValueScript( + DSL.getMember( + DSL.getMember(DSL.getMember(DSL.ref("typed"), "fld"), "fld"), + "msg"), + "typed.fld.fld.msg"), + null), + new LogProbe.CaptureExpression( + "nullTyped_fld", + new ValueScript( + DSL.getMember(DSL.ref("nullTyped"), "fld"), "nullTyped.fld"), + null))) + .build(); + TestSnapshotListener listener = installProbes(probe); + Class testClass = compileAndLoadClass(CLASS_NAME); + int result = Reflect.onClass(testClass).call("main", "1").get(); + assertEquals(3, result); + Snapshot snapshot = assertOneSnapshot(listener); + CapturedContext capturedContext = snapshot.getCaptures().getLines().get(line); + assertEquals(2, capturedContext.getCaptureExpressions().size()); + assertCaptureExpressions( + capturedContext, "typed_fld_fld_msg", String.class.getTypeName(), "hello"); + assertCaptureExpressions(capturedContext, "nullTyped_fld", Object.class.getTypeName(), null); + } + @Test public void captureExpressionsWithCaptureLimits() throws IOException, URISyntaxException { final String CLASS_NAME = "CapturedSnapshot08"; LogProbe probe = createProbeBuilder(PROBE_ID, CLASS_NAME, "doit", null) .evaluateAt(MethodLocation.EXIT) + .captureSnapshot(false) .captureExpressions( Arrays.asList( new LogProbe.CaptureExpression( From 84ec8a69ddb36147d019cc526c53ff43ce806023 Mon Sep 17 00:00:00 2001 From: jean-philippe bempel Date: Wed, 7 Jan 2026 17:32:50 +0100 Subject: [PATCH 2/2] fix unit tests --- .../src/main/java/com/datadog/debugger/probe/LogProbe.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java index b56ecb42438..e5ea2051ff7 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java @@ -811,9 +811,7 @@ private LogStatus(ProbeImplementation probeImplementation, boolean condition) { @Override public boolean shouldFreezeContext() { - return sampled - && ((CapturedContextProbe) probeImplementation).isCaptureSnapshot() - && shouldSend(); + return sampled && (((LogProbe) probeImplementation).isFullSnapshot()) && shouldSend(); } @Override