Skip to content

Commit 77d92e4

Browse files
jpbempeldevflow.devflow-routing-intake
andauthored
No captures in eval errors snapshots (#11973)
No captures in eval errors snapshots for Log line probe captures was included even though there is an evaluation error while for method probe it was not included make sure we are only including captures if no eval errors Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 3b6d2ee commit 77d92e4

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,13 @@ public void commit(CapturedContext lineContext, int line) {
834834
Snapshot snapshot = createSnapshot();
835835
boolean shouldCommit = false;
836836
if (status.shouldSend()) {
837+
if (isFullSnapshot()) {
838+
// freeze context just before commit because line probes have only one context
839+
Duration timeout =
840+
Duration.ofMillis(Config.get().getDynamicInstrumentationCaptureTimeout());
841+
lineContext.freeze(TimeoutChecker.create(Config.get(), timeout));
842+
snapshot.addLine(lineContext, line);
843+
}
837844
snapshot.setTraceId(CorrelationIdentifier.getTraceId());
838845
snapshot.setSpanId(CorrelationIdentifier.getSpanId());
839846
snapshot.setMessage(status.getMessage());
@@ -846,13 +853,6 @@ public void commit(CapturedContext lineContext, int line) {
846853
if (shouldCommit) {
847854
incrementBudget();
848855
if (inBudget()) {
849-
if (isFullSnapshot()) {
850-
// freeze context just before commit because line probes have only one context
851-
Duration timeout =
852-
Duration.ofMillis(Config.get().getDynamicInstrumentationCaptureTimeout());
853-
lineContext.freeze(TimeoutChecker.create(Config.get(), timeout));
854-
snapshot.addLine(lineContext, line);
855-
}
856856
commitSnapshot(snapshot, sink);
857857
return;
858858
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,26 @@ public void lineProbeCondition() throws IOException, URISyntaxException {
12491249
"5");
12501250
}
12511251

1252+
@Test
1253+
public void lineProbeConditionFailed() throws IOException, URISyntaxException {
1254+
final String CLASS_NAME = "CapturedSnapshot08";
1255+
int line = getLineForLineProbe(CLASS_NAME, LINE_PROBE_ID1);
1256+
LogProbe logProbe =
1257+
createProbeBuilder(LINE_PROBE_ID1, CLASS_NAME, line)
1258+
.when(
1259+
new ProbeCondition(DSL.when(DSL.eq(ref("foobar"), nullValue())), "foobar == null"))
1260+
.build();
1261+
TestSnapshotListener listener = installProbes(logProbe);
1262+
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
1263+
int result = Reflect.onClass(testClass).call("main", "0").get();
1264+
assertEquals(3, result);
1265+
Snapshot snapshot = assertOneSnapshot(LINE_PROBE_ID1, listener);
1266+
assertNull(snapshot.getCaptures().getLines());
1267+
assertEquals(1, snapshot.getEvaluationErrors().size());
1268+
assertEquals(
1269+
"Cannot dereference field: foobar", snapshot.getEvaluationErrors().get(0).getMessage());
1270+
}
1271+
12521272
@Test
12531273
public void staticFieldCondition() throws IOException, URISyntaxException {
12541274
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot19";

0 commit comments

Comments
 (0)