Skip to content

Commit 5d03203

Browse files
authored
optimize line probe without condition (#9787)
In case of a line probe without condition we can move the sampling is currently done in LogProbe::evaluate to LogProbe::isReadToCapture. This way if the sample fails we return false on isReadyTocapture and no CapturedContext is created and nothing captured. If we sample the execution the CapturedContext will be created, we capture the context and serialize the result, but we are sure that we are not doing for nothing.
1 parent c60b3c3 commit 5d03203

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ public InstrumentationResult.Status instrument(
485485

486486
@Override
487487
public boolean isReadyToCapture() {
488+
if (isLineProbe() && !hasCondition()) {
489+
// we are sampling here to avoid creating CapturedContext when the sampling result is negative
490+
return ProbeRateLimiter.tryProbe(id);
491+
}
488492
return true;
489493
}
490494

@@ -494,9 +498,14 @@ public void evaluate(
494498
if (!(status instanceof LogStatus)) {
495499
throw new IllegalStateException("Invalid status: " + status.getClass());
496500
}
497-
498501
LogStatus logStatus = (LogStatus) status;
499-
if (!hasCondition()) {
502+
if (isLineProbe() && !hasCondition()) {
503+
// sampling was already done in isReadToCapture so we assume that if we are executing the
504+
// current method it means the status should be sampled
505+
if (!logStatus.getDebugSessionStatus().isDisabled()) {
506+
logStatus.setSampled(true);
507+
}
508+
} else if (!hasCondition()) {
500509
// sample when no condition associated
501510
sample(logStatus, methodLocation);
502511
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/probe/LogProbeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ private Builder createLog(String template) {
342342
return LogProbe.builder()
343343
.language(LANGUAGE)
344344
.probeId(PROBE_ID)
345+
.where("String.java", 42)
345346
.template(template, parseTemplate(template));
346347
}
347348

0 commit comments

Comments
 (0)