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..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 @@ -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( @@ -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 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(