Skip to content

Commit 06de71b

Browse files
committed
fix unit tests
We are delegating the decision to capture through a new field in CapturedContextInstrumentor
1 parent 9d160dc commit 06de71b

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,7 @@ private static ExceptionProbe createMethodProbe(
118118
ExceptionProbeManager exceptionProbeManager, Where where, int chainedExceptionIdx) {
119119
String probeId = UUID.randomUUID().toString();
120120
return new ExceptionProbe(
121-
new ProbeId(probeId, 0),
122-
where,
123-
null,
124-
null,
125-
null,
126-
exceptionProbeManager,
127-
chainedExceptionIdx);
121+
new ProbeId(probeId, 0), where, null, null, exceptionProbeManager, chainedExceptionIdx);
128122
}
129123

130124
public boolean isAlreadyInstrumented(String fingerprint) {

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/instrumentation/CapturedContextInstrumentor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import static org.objectweb.asm.Type.VOID_TYPE;
2828
import static org.objectweb.asm.Type.getType;
2929

30-
import com.datadog.debugger.probe.ExceptionProbe;
3130
import com.datadog.debugger.probe.ProbeDefinition;
3231
import com.datadog.debugger.probe.SpanDecorationProbe;
3332
import com.datadog.debugger.probe.Where;
@@ -70,6 +69,7 @@
7069
public class CapturedContextInstrumentor extends Instrumentor {
7170
private static final Logger LOGGER = LoggerFactory.getLogger(CapturedContextInstrumentor.class);
7271
private final boolean captureSnapshot;
72+
private final boolean captureEntry;
7373
private final Limits limits;
7474
private final LabelNode contextInitLabel = new LabelNode();
7575
private int entryContextVar = -1;
@@ -84,9 +84,11 @@ public CapturedContextInstrumentor(
8484
List<DiagnosticMessage> diagnostics,
8585
List<ProbeId> probeIds,
8686
boolean captureSnapshot,
87+
boolean captureEntry,
8788
Limits limits) {
8889
super(definition, methodInfo, diagnostics, probeIds);
8990
this.captureSnapshot = captureSnapshot;
91+
this.captureEntry = captureEntry;
9092
this.limits = limits;
9193
}
9294

@@ -423,11 +425,7 @@ private void instrumentMethodEnter() {
423425
LabelNode targetNode = new LabelNode();
424426
LabelNode gotoNode = new LabelNode();
425427
insnList.add(new JumpInsnNode(Opcodes.IFEQ, targetNode));
426-
// if evaluation is at exit and with condition and not exception probe, skip collecting data at
427-
// enter
428-
if ((definition.getEvaluateAt() != MethodLocation.EXIT
429-
|| !definition.hasCondition())
430-
&& !(definition instanceof ExceptionProbe)) {
428+
if (captureEntry) {
431429
LabelNode inProbeStartLabel = new LabelNode();
432430
insnList.add(inProbeStartLabel);
433431
// stack []

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.datadog.debugger.util.ExceptionHelper.getInnerMostThrowable;
44
import static java.util.Collections.emptyList;
55

6+
import com.datadog.debugger.el.DSL;
67
import com.datadog.debugger.el.ProbeCondition;
78
import com.datadog.debugger.exception.ExceptionProbeManager;
89
import com.datadog.debugger.exception.Fingerprinter;
@@ -26,7 +27,6 @@ public class ExceptionProbe extends LogProbe implements ForceMethodInstrumentati
2627
public ExceptionProbe(
2728
ProbeId probeId,
2829
Where where,
29-
ProbeCondition probeCondition,
3030
Capture capture,
3131
Sampling sampling,
3232
ExceptionProbeManager exceptionProbeManager,
@@ -40,7 +40,8 @@ public ExceptionProbe(
4040
null,
4141
null,
4242
true,
43-
probeCondition,
43+
// forcing a useless condition to be instrumented with captureEntry=false
44+
new ProbeCondition(DSL.when(DSL.TRUE), "true"),
4445
capture,
4546
sampling);
4647
this.exceptionProbeManager = exceptionProbeManager;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,16 @@ public Sampling getSampling() {
409409
@Override
410410
public InstrumentationResult.Status instrument(
411411
MethodInfo methodInfo, List<DiagnosticMessage> diagnostics, List<ProbeId> probeIds) {
412+
// if evaluation is at exit and with condition, skip collecting data at entry
413+
boolean captureEntry = !(getEvaluateAt() == MethodLocation.EXIT && hasCondition());
412414
return new CapturedContextInstrumentor(
413-
this, methodInfo, diagnostics, probeIds, isCaptureSnapshot(), toLimits(getCapture()))
415+
this,
416+
methodInfo,
417+
diagnostics,
418+
probeIds,
419+
isCaptureSnapshot(),
420+
captureEntry,
421+
toLimits(getCapture()))
414422
.instrument();
415423
}
416424

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ public SpanDecorationProbe(
135135
@Override
136136
public InstrumentationResult.Status instrument(
137137
MethodInfo methodInfo, List<DiagnosticMessage> diagnostics, List<ProbeId> probeIds) {
138+
boolean captureEntry = evaluateAt != MethodLocation.EXIT;
138139
return new CapturedContextInstrumentor(
139-
this, methodInfo, diagnostics, probeIds, false, Limits.DEFAULT)
140+
this, methodInfo, diagnostics, probeIds, false, captureEntry, Limits.DEFAULT)
140141
.instrument();
141142
}
142143

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public TriggerProbe(ProbeId probeId, Where where) {
5454
@Override
5555
public InstrumentationResult.Status instrument(
5656
MethodInfo methodInfo, List<DiagnosticMessage> diagnostics, List<ProbeId> probeIds) {
57-
return new CapturedContextInstrumentor(this, methodInfo, diagnostics, probeIds, false, null)
57+
return new CapturedContextInstrumentor(
58+
this, methodInfo, diagnostics, probeIds, false, false, null)
5859
.instrument();
5960
}
6061

0 commit comments

Comments
 (0)