Skip to content

Commit 352efb3

Browse files
committed
add a tag tracking the overall invocation account
1 parent 71309b3 commit 352efb3

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/DebuggerContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public String tag() {
3939
public String tag() {
4040
return "cause:debug session disabled";
4141
}
42+
},
43+
BUDGET {
44+
@Override
45+
public String tag() {
46+
return "cause:budget exceeded";
47+
}
4248
};
4349

4450
public abstract String tag();

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.datadog.debugger.probe;
22

33
import static com.datadog.debugger.probe.LogProbe.Capture.toLimits;
4+
import static java.lang.String.format;
45

56
import com.datadog.debugger.agent.DebuggerAgent;
67
import com.datadog.debugger.agent.Generated;
@@ -575,14 +576,17 @@ public void commit(
575576
CapturedContext exitContext,
576577
List<CapturedContext.CapturedThrowable> caughtExceptions) {
577578
Snapshot snapshot = createSnapshot();
578-
boolean shouldCommit =
579-
inBudget() && fillSnapshot(entryContext, exitContext, caughtExceptions, snapshot);
579+
boolean shouldCommit = fillSnapshot(entryContext, exitContext, caughtExceptions, snapshot);
580580
DebuggerSink sink = DebuggerAgent.getSink();
581581
if (shouldCommit) {
582-
commitSnapshot(snapshot, sink);
583582
incrementBudget();
584-
if (snapshotProcessor != null) {
585-
snapshotProcessor.accept(snapshot);
583+
if (inBudget()) {
584+
commitSnapshot(snapshot, sink);
585+
if (snapshotProcessor != null) {
586+
snapshotProcessor.accept(snapshot);
587+
}
588+
} else {
589+
sink.skipSnapshot(id, DebuggerContext.SkipCause.BUDGET);
586590
}
587591
} else {
588592
sink.skipSnapshot(id, DebuggerContext.SkipCause.CONDITION);
@@ -866,7 +870,7 @@ public String toString() {
866870

867871
private boolean inBudget() {
868872
AtomicInteger budgetLevel = getBudgetLevel();
869-
return budgetLevel == null || budgetLevel.get() < PROBE_BUDGET;
873+
return budgetLevel == null || budgetLevel.get() <= PROBE_BUDGET;
870874
}
871875

872876
private AtomicInteger getBudgetLevel() {
@@ -881,6 +885,11 @@ private void incrementBudget() {
881885
AtomicInteger budgetLevel = getBudgetLevel();
882886
if (budgetLevel != null) {
883887
budgetLevel.incrementAndGet();
888+
TracerAPI tracer = AgentTracer.get();
889+
AgentSpan span = tracer != null ? tracer.activeSpan() : null;
890+
if (span != null) {
891+
span.getLocalRootSpan().setTag(format("_dd.ld.probe_id.%s", id), budgetLevel.get());
892+
}
884893
}
885894
}
886895

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ private void runTrace(TracerAPI tracer) {
110110
logProbe.evaluate(entryContext, new LogStatus(logProbe), MethodLocation.ENTRY);
111111
logProbe.evaluate(exitContext, new LogStatus(logProbe), MethodLocation.EXIT);
112112

113-
for (int i = 0; i < 20; i++) {
113+
for (int i = 0; i < LogProbe.PROBE_BUDGET * 2; i++) {
114114
logProbe.commit(entryContext, exitContext, emptyList());
115115
}
116+
assertEquals(
117+
LogProbe.PROBE_BUDGET * 2,
118+
span.getLocalRootSpan().getTag(format("_dd.ld.probe_id.%s", logProbe.id)));
116119
}
117120
}
118121

0 commit comments

Comments
 (0)