Skip to content

Commit 38417f3

Browse files
Merge branch 'master' into alexeyk/refactor-buildSrc-from-groovy-to-kotlin
2 parents 68084c3 + 89639f7 commit 38417f3

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
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
}

dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class FieldInjectionSmokeTest extends Specification {
6161
command.add("-XX:ErrorFile=/tmp/hs_err_pid%p.log")
6262
// turn off these features as their debug output can break up our expected logging lines on IBM JVMs
6363
// causing random test failures (we are not testing these features here so they don't need to be on)
64-
command.add("-Ddd.crashtracking.enabled=false")
6564
command.add("-Ddd.instrumentation.telemetry.enabled=false")
6665
command.add("-Ddd.remote_config.enabled=false")
6766
command.add("-Ddd.writer.type=TraceStructureWriter")

internal-api/src/main/java/datadog/trace/util/AgentTaskScheduler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.util.AgentThreadFactory.AgentThread.TASK_SCHEDULER;
55
import static datadog.trace.util.AgentThreadFactory.newAgentThread;
66
import static java.util.concurrent.TimeUnit.MILLISECONDS;
7+
import static java.util.concurrent.TimeUnit.MINUTES;
78
import static java.util.concurrent.TimeUnit.NANOSECONDS;
89
import static java.util.concurrent.TimeUnit.SECONDS;
910

@@ -225,6 +226,12 @@ private void prepareWorkQueue() {
225226
} catch (final InterruptedException e) {
226227
// ignore, we only want to preload queue internals
227228
}
229+
if (this == INSTANCE) {
230+
// preload a future no-op task to ensure workQueue.take() will use await with timeout during
231+
// premain - otherwise on Java 25 it will load ForkJoinPool which in turn loads ForkJoinTask,
232+
// which then means we lose the chance to field-inject context into ForkJoinTask instances
233+
workQueue.offer(FUTURE_NOOP_PLACEHOLDER);
234+
}
228235
}
229236

230237
// for testing
@@ -302,6 +309,9 @@ public void run() {
302309

303310
private static final AtomicInteger TASK_SEQUENCE_GENERATOR = new AtomicInteger();
304311

312+
private static final PeriodicTask<Object> FUTURE_NOOP_PLACEHOLDER =
313+
new PeriodicTask<>(null, new Scheduled<>(null), 10, 0, MINUTES);
314+
305315
private static final class PeriodicTask<T> implements Delayed {
306316

307317
private final Task<T> task;

0 commit comments

Comments
 (0)