Skip to content

Commit db4aefa

Browse files
committed
fix the session id tag
PR clean up
1 parent 30b62bc commit db4aefa

3 files changed

Lines changed: 40 additions & 9 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ public void evaluate(
465465
// sample when no condition associated
466466
sample(logStatus, methodLocation);
467467
}
468-
logStatus.setCondition(
469-
!logStatus.getDebugSessionStatus().isDisabled() && evaluateCondition(context, logStatus));
468+
logStatus.setCondition(evaluateCondition(context, logStatus));
470469
CapturedContext.CapturedThrowable throwable = context.getCapturedThrowable();
471470
if (logStatus.hasConditionErrors() && throwable != null) {
472471
logStatus.addError(
@@ -755,7 +754,11 @@ public boolean isCapturing() {
755754
}
756755

757756
public boolean shouldSend() {
758-
return sampled && condition && !hasConditionErrors;
757+
DebugSessionStatus status = getDebugSessionStatus();
758+
// an ACTIVE status overrides the sampling as the sampling decision was made by the trigger
759+
// probe
760+
return status == DebugSessionStatus.ACTIVE
761+
|| !status.isDisabled() && sampled && condition && !hasConditionErrors;
759762
}
760763

761764
public boolean shouldReportError() {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ public InstrumentationResult.Status instrument(
5959
.instrument();
6060
}
6161

62+
public String getSessionId() {
63+
return sessionId;
64+
}
65+
66+
public TriggerProbe setSessionId(String sessionId) {
67+
this.sessionId = sessionId;
68+
return this;
69+
}
70+
6271
public Sampling getSampling() {
6372
return sampling;
6473
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/trigger/TriggerProbeTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
public class TriggerProbeTest extends CapturingTestBase {
3737
private static final ProbeId TRIGGER_PROBE_ID1 = new ProbeId("trigger probe 1", 0);
38+
private static final String TRIGGER_PROBE_SESSION_ID = "trigger probe sessionID";
3839

3940
private TestTraceInterceptor traceInterceptor;
4041

@@ -61,7 +62,13 @@ public void cooldown() throws IOException, URISyntaxException {
6162
final String className = "com.datadog.debugger.TriggerProbe01";
6263
TriggerProbe probe1 =
6364
createTriggerProbe(
64-
TRIGGER_PROBE_ID1, className, "entry", "()", null, new Sampling(10, 10.0));
65+
TRIGGER_PROBE_ID1,
66+
TRIGGER_PROBE_SESSION_ID,
67+
className,
68+
"entry",
69+
"()",
70+
null,
71+
new Sampling(10, 10.0));
6572
installProbes(
6673
Configuration.builder()
6774
.setService(SERVICE_NAME)
@@ -75,25 +82,27 @@ public void cooldown() throws IOException, URISyntaxException {
7582

7683
assertEquals(1, sampler.getCallCount());
7784
List<List<? extends MutableSpan>> allTraces = traceInterceptor.getAllTraces();
85+
assertEquals(runs, allTraces.size(), "actual traces: " + allTraces.size());
86+
7887
long debugSessions =
7988
allTraces.stream()
8089
.map(span -> span.get(0))
8190
.filter(
8291
span -> {
8392
DDSpan ddSpan = (DDSpan) span;
8493
PropagationTags tags = ddSpan.context().getPropagationTags();
85-
return "1".equals(tags.getDebugPropagation());
94+
return (TRIGGER_PROBE_SESSION_ID + ":1").equals(tags.getDebugPropagation());
8695
})
8796
.count();
97+
assertEquals(1, debugSessions, "Should only have 1 debug session. found: " + debugSessions);
98+
8899
long tagged =
89100
allTraces.stream()
90101
.flatMap(Collection::stream)
91102
.filter(
92103
span ->
93104
span.getTag(format("_dd.ld.probe_id.%s", TRIGGER_PROBE_ID1.getId())) != null)
94105
.count();
95-
assertEquals(runs, allTraces.size(), "actual traces: " + allTraces.size());
96-
assertEquals(1, debugSessions, "Should only have 1 debug session. found: " + debugSessions);
97106
assertEquals(1, tagged, "Should only have 1 tagged span. found: " + tagged);
98107
} finally {
99108
ProbeRateLimiter.setSamplerSupplier(null);
@@ -108,7 +117,14 @@ public void sampling() throws IOException, URISyntaxException {
108117

109118
final String className = "com.datadog.debugger.TriggerProbe01";
110119
TriggerProbe probe1 =
111-
createTriggerProbe(TRIGGER_PROBE_ID1, className, "entry", "()", null, new Sampling(10.0));
120+
createTriggerProbe(
121+
TRIGGER_PROBE_ID1,
122+
TRIGGER_PROBE_SESSION_ID,
123+
className,
124+
"entry",
125+
"()",
126+
null,
127+
new Sampling(10.0));
112128
Configuration config =
113129
Configuration.builder()
114130
.setService(SERVICE_NAME)
@@ -133,6 +149,7 @@ public void conditions() throws IOException, URISyntaxException {
133149
TriggerProbe probe1 =
134150
createTriggerProbe(
135151
TRIGGER_PROBE_ID1,
152+
TRIGGER_PROBE_SESSION_ID,
136153
className,
137154
"entry",
138155
"(int)",
@@ -155,7 +172,7 @@ public void conditions() throws IOException, URISyntaxException {
155172
span -> {
156173
DDSpan ddSpan = (DDSpan) span;
157174
PropagationTags tags = ddSpan.context().getPropagationTags();
158-
return "1".equals(tags.getDebugPropagation());
175+
return (TRIGGER_PROBE_SESSION_ID + ":1").equals(tags.getDebugPropagation());
159176
})
160177
.count();
161178
assertEquals(100, allTraces.size(), "actual traces: " + allTraces.size());
@@ -164,13 +181,15 @@ public void conditions() throws IOException, URISyntaxException {
164181

165182
public static TriggerProbe createTriggerProbe(
166183
ProbeId id,
184+
String sessionId,
167185
String typeName,
168186
String methodName,
169187
String signature,
170188
ProbeCondition probeCondition,
171189
Sampling sampling,
172190
String... lines) {
173191
return new TriggerProbe(id, Where.of(typeName, methodName, signature, lines))
192+
.setSessionId(sessionId)
174193
.setProbeCondition(probeCondition)
175194
.setSampling(sampling);
176195
}

0 commit comments

Comments
 (0)