Skip to content

Commit 2c7da55

Browse files
authored
Fix Exception Probes to not emit any probe status (#9669)
Fix Exception Probes to not emit any probe status filter on probe definition type
1 parent ea77c10 commit 2c7da55

File tree

9 files changed

+41
-25
lines changed

9 files changed

+41
-25
lines changed

dd-java-agent/agent-ci-visibility/civisibility-test-fixtures/src/main/groovy/datadog/trace/civisibility/CiVisibilitySmokeTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ abstract class CiVisibilitySmokeTest extends Specification {
149149
assert logs.findAll { log -> ((String) log.message).endsWith("is emitting.") }.size() == expectedCount
150150
}
151151

152-
private static verifySnapshots(List<Map<String, Object>> logs, expectedCount) {
152+
protected static verifySnapshots(List<Map<String, Object>> logs, expectedCount) {
153153
assert logs.size() == expectedCount
154154

155155
def requiredLogFields = ["logger.name", "logger.method", "dd.spanid", "dd.traceid"]

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/ConfigurationUpdater.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
88

99
import com.datadog.debugger.instrumentation.InstrumentationResult;
10+
import com.datadog.debugger.probe.ExceptionProbe;
1011
import com.datadog.debugger.probe.LogProbe;
1112
import com.datadog.debugger.probe.ProbeDefinition;
1213
import com.datadog.debugger.probe.Sampled;
@@ -176,6 +177,10 @@ private void handleProbesChanges(ConfigurationComparer changes, Configuration ne
176177

177178
private void reportReceived(ConfigurationComparer changes) {
178179
for (ProbeDefinition def : changes.getAddedDefinitions()) {
180+
if (def instanceof ExceptionProbe) {
181+
// do not report received for exception probes
182+
continue;
183+
}
179184
sink.addReceived(def.getProbeId());
180185
}
181186
for (ProbeDefinition def : changes.getRemovedDefinitions()) {

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ private void handleInstrumentationResult(
590590
if (listener != null) {
591591
listener.instrumentationResult(definition, result);
592592
}
593+
if (definition instanceof ExceptionProbe) {
594+
// do not report diagnostics for exception probes
595+
continue;
596+
}
593597
List<DiagnosticMessage> diagnosticMessages =
594598
result.getDiagnostics().get(definition.getProbeId());
595599
if (!result.getDiagnostics().isEmpty()) {

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/DebuggerSink.java

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

33
import com.datadog.debugger.instrumentation.DiagnosticMessage;
4+
import com.datadog.debugger.probe.ExceptionProbe;
45
import com.datadog.debugger.uploader.BatchUploader;
56
import com.datadog.debugger.util.DebuggerMetrics;
67
import datadog.trace.api.Config;
@@ -123,7 +124,10 @@ public void addSnapshot(Snapshot snapshot) {
123124
if (!added) {
124125
debuggerMetrics.count(DROPPED_REQ_METRIC, 1);
125126
} else {
126-
probeStatusSink.addEmitting(snapshot.getProbe().getProbeId());
127+
if (!(snapshot.getProbe() instanceof ExceptionProbe)) {
128+
// do not report emitting for exception probes
129+
probeStatusSink.addEmitting(snapshot.getProbe().getProbeId());
130+
}
127131
}
128132
}
129133

dd-smoke-tests/debugger-integration-tests/src/test/java/datadog/smoketest/ExceptionDebuggerIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected ProcessBuilder createProcessBuilder(Path logFilePath, String... params
4949
void testSimpleSingleFrameException() throws Exception {
5050
appUrl = startAppAndAndGetUrl();
5151
execute(appUrl, TRACED_METHOD_NAME, "oops"); // instrumenting first exception
52-
waitForInstrumentation(appUrl);
52+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
5353
execute(appUrl, TRACED_METHOD_NAME, "oops"); // collecting snapshots and sending them
5454
registerTraceListener(this::receiveExceptionReplayTrace);
5555
registerSnapshotListener(this::receiveSnapshot);
@@ -116,7 +116,7 @@ void testNoSubsequentCaptureAfterFirst() throws Exception {
116116
void test3CapturedFrames() throws Exception {
117117
appUrl = startAppAndAndGetUrl();
118118
execute(appUrl, TRACED_METHOD_NAME, "deepOops"); // instrumenting first exception
119-
waitForInstrumentation(appUrl);
119+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
120120
execute(appUrl, TRACED_METHOD_NAME, "deepOops"); // collecting snapshots and sending them
121121
registerTraceListener(this::receiveExceptionReplayTrace);
122122
registerSnapshotListener(this::receiveSnapshot);
@@ -173,7 +173,7 @@ void test5CapturedFrames() throws Exception {
173173
additionalJvmArgs.add("-Ddd.exception.replay.capture.max.frames=5");
174174
appUrl = startAppAndAndGetUrl();
175175
execute(appUrl, TRACED_METHOD_NAME, "deepOops"); // instrumenting first exception
176-
waitForInstrumentation(appUrl);
176+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
177177
execute(appUrl, TRACED_METHOD_NAME, "deepOops"); // collecting snapshots and sending them
178178
registerTraceListener(this::receiveExceptionReplayTrace);
179179
registerSnapshotListener(this::receiveSnapshot);
@@ -249,7 +249,7 @@ void test5CapturedFrames() throws Exception {
249249
void test3CapturedRecursiveFrames() throws Exception {
250250
appUrl = startAppAndAndGetUrl();
251251
execute(appUrl, TRACED_METHOD_NAME, "recursiveOops"); // instrumenting first exception
252-
waitForInstrumentation(appUrl);
252+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
253253
execute(appUrl, TRACED_METHOD_NAME, "recursiveOops"); // collecting snapshots and sending them
254254
registerTraceListener(this::receiveExceptionReplayTrace);
255255
registerSnapshotListener(this::receiveSnapshot);
@@ -296,7 +296,7 @@ void testLambdaHiddenFrames() throws Exception {
296296
additionalJvmArgs.add("-XX:+ShowHiddenFrames");
297297
appUrl = startAppAndAndGetUrl();
298298
execute(appUrl, TRACED_METHOD_NAME, "lambdaOops"); // instrumenting first exception
299-
waitForInstrumentation(appUrl);
299+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
300300
execute(appUrl, TRACED_METHOD_NAME, "lambdaOops"); // collecting snapshots and sending them
301301
registerTraceListener(this::receiveExceptionReplayTrace);
302302
registerSnapshotListener(this::receiveSnapshot);

dd-smoke-tests/debugger-integration-tests/src/test/java/datadog/smoketest/InProductEnablementIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void testDynamicInstrumentationEnablementWithLineProbe() throws Exception {
5151
setCurrentConfiguration(createConfig(probe));
5252
waitForFeatureStarted(appUrl, "Dynamic Instrumentation");
5353
execute(appUrl, "topLevelMethod", "");
54-
waitForInstrumentation(appUrl, "datadog.smoketest.debugger.TopLevel");
54+
waitForInstrumentation(appUrl, "datadog.smoketest.debugger.TopLevel", true);
5555
// disable DI
5656
setConfigOverrides(createConfigOverrides(false, false));
5757
waitForFeatureStopped(appUrl, "Dynamic Instrumentation");
@@ -81,7 +81,7 @@ void testExceptionReplayEnablement() throws Exception {
8181
setConfigOverrides(createConfigOverrides(false, true));
8282
waitForFeatureStarted(appUrl, "Exception Replay");
8383
execute(appUrl, TRACED_METHOD_NAME, "oops"); // instrumenting first exception
84-
waitForInstrumentation(appUrl);
84+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
8585
// disable ER
8686
setConfigOverrides(createConfigOverrides(false, false));
8787
waitForFeatureStopped(appUrl, "Exception Replay");

dd-smoke-tests/debugger-integration-tests/src/test/java/datadog/smoketest/ServerAppDebuggerIntegrationTest.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,28 @@ protected void execute(String appUrl, String methodName, String arg) throws IOEx
9999
}
100100

101101
protected void waitForInstrumentation(String appUrl) throws Exception {
102-
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS);
102+
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, true);
103103
}
104104

105-
protected void waitForInstrumentation(String appUrl, String className) throws Exception {
105+
protected void waitForInstrumentation(
106+
String appUrl, String className, boolean waitOnProbeStatuses) throws Exception {
106107
String url = String.format(appUrl + "/waitForInstrumentation?classname=%s", className);
107108
LOG.info("waitForInstrumentation with url={}", url);
108109
sendRequest(url);
109-
AtomicBoolean received = new AtomicBoolean();
110-
AtomicBoolean installed = new AtomicBoolean();
111-
registerProbeStatusListener(
112-
probeStatus -> {
113-
if (probeStatus.getDiagnostics().getStatus() == ProbeStatus.Status.RECEIVED) {
114-
received.set(true);
115-
}
116-
if (probeStatus.getDiagnostics().getStatus() == ProbeStatus.Status.INSTALLED) {
117-
installed.set(true);
118-
}
119-
});
120-
processRequests(() -> received.get() && installed.get());
110+
if (waitOnProbeStatuses) {
111+
AtomicBoolean received = new AtomicBoolean();
112+
AtomicBoolean installed = new AtomicBoolean();
113+
registerProbeStatusListener(
114+
probeStatus -> {
115+
if (probeStatus.getDiagnostics().getStatus() == ProbeStatus.Status.RECEIVED) {
116+
received.set(true);
117+
}
118+
if (probeStatus.getDiagnostics().getStatus() == ProbeStatus.Status.INSTALLED) {
119+
installed.set(true);
120+
}
121+
});
122+
processRequests(() -> received.get() && installed.get());
123+
}
121124
LOG.info("instrumentation done");
122125
}
123126

dd-smoke-tests/junit-console/src/test/groovy/datadog/smoketest/JUnitConsoleSmokeTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class JUnitConsoleSmokeTest extends CiVisibilitySmokeTest {
5959

6060
def additionalDynamicTags = ["content.meta.['_dd.debug.error.6.snapshot_id']", "content.meta.['_dd.debug.error.exception_id']"]
6161
verifyEventsAndCoverages(projectName, "junit-console", "headless", mockBackend.waitForEvents(7), mockBackend.waitForCoverages(0), additionalDynamicTags)
62-
verifySnapshotLogs(mockBackend.waitForLogs(5), 1, 2)
62+
verifySnapshots(mockBackend.waitForLogs(2), 2)
6363

6464
where:
6565
projectName = "test_junit_console_failed_test_replay"

dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
247247

248248
def additionalDynamicTags = ["content.meta.['_dd.debug.error.3.snapshot_id']", "content.meta.['_dd.debug.error.exception_id']"]
249249
verifyEventsAndCoverages(projectName, "maven", mavenVersion, mockBackend.waitForEvents(7), mockBackend.waitForCoverages(0), additionalDynamicTags)
250-
verifySnapshotLogs(mockBackend.waitForLogs(5), 1, 2)
250+
verifySnapshots(mockBackend.waitForLogs(2), 2)
251251

252252
where:
253253
projectName | mavenVersion

0 commit comments

Comments
 (0)