Skip to content

Commit 83a9432

Browse files
committed
Disable process advice until after agent tracer is registered
This avoids a potential loop back when tracer debug is enabled: 1. The full `Config` is logged during startup in its constructor 2. This includes any lazy config fields, such as the `hostname` 3. If the host is not available in the environment/host-files then `Config` calls the `hostname` command using `Runtime.exec(...)` 4. The `Runtime.exec(...)` call is intercepted by the process advice 5. The process advice calls `Config.get()` to see if RASP is enabled 6. `Config.get()` returns `null` as the config is still being built The resulting NPE is caught before it escapes to the application, but it still results in log-spam that could confuse investigations.
1 parent 4e48384 commit 83a9432

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

dd-java-agent/instrumentation/java/java-lang/java-lang-1.8/src/main/java/datadog/trace/instrumentation/java/lang/ProcessImplStartAdvice.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
44
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
55
import datadog.trace.bootstrap.instrumentation.api.java.lang.ProcessImplInstrumentationHelpers;
6-
import java.io.IOException;
76
import net.bytebuddy.asm.Advice;
87

98
class ProcessImplStartAdvice {
109
@Advice.OnMethodEnter(suppress = Throwable.class)
11-
public static AgentSpan startSpan(@Advice.Argument(0) final String[] command) throws IOException {
10+
public static AgentSpan beforeStart(@Advice.Argument(0) final String[] command) {
1211
if (!ProcessImplInstrumentationHelpers.ONLINE) {
1312
return null;
1413
}
1514

16-
if (command.length == 0) {
15+
if (command.length == 0 || !AgentTracer.isRegistered()) {
1716
return null;
1817
}
1918

20-
final AgentTracer.TracerAPI tracer = AgentTracer.get();
21-
final AgentSpan span = tracer.startSpan("appsec", "command_execution");
19+
final AgentSpan span = AgentTracer.startSpan("appsec", "command_execution");
2220
span.setSpanType("system");
2321
span.setResourceName(ProcessImplInstrumentationHelpers.determineResource(command));
2422
span.setTag("component", "subprocess");
@@ -29,7 +27,7 @@ public static AgentSpan startSpan(@Advice.Argument(0) final String[] command) th
2927
}
3028

3129
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
32-
public static void endSpan(
30+
public static void afterStart(
3331
@Advice.Return Process p, @Advice.Enter AgentSpan span, @Advice.Thrown Throwable t) {
3432
if (span == null) {
3533
return;
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package datadog.trace.instrumentation.java.lang;
22

3+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
34
import datadog.trace.bootstrap.instrumentation.api.java.lang.ProcessImplInstrumentationHelpers;
4-
import java.io.IOException;
55
import net.bytebuddy.asm.Advice;
66

77
class RuntimeExecStringAdvice {
88
@Advice.OnMethodEnter(suppress = Throwable.class)
9-
public static void beforeExec(@Advice.Argument(0) final String command) throws IOException {
10-
if (command == null) {
11-
return;
9+
public static boolean beforeExec(@Advice.Argument(0) final String command) {
10+
if (command == null || !AgentTracer.isRegistered()) {
11+
return false;
1212
}
1313
ProcessImplInstrumentationHelpers.shiRaspCheck(command);
14+
return true;
1415
}
1516

1617
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
17-
public static void afterExec() {
18-
ProcessImplInstrumentationHelpers.resetCheckShi();
18+
public static void afterExec(@Advice.Enter boolean checking) {
19+
if (checking) {
20+
ProcessImplInstrumentationHelpers.resetCheckShi();
21+
}
1922
}
2023
}

0 commit comments

Comments
 (0)