Skip to content

Commit 0f304c7

Browse files
authored
Merge branch 'master' into dylan/sfn-trace-ctx
2 parents 1197c1d + 0ba7b76 commit 0f304c7

File tree

456 files changed

+27641
-3485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

456 files changed

+27641
-3485
lines changed

.circleci/config.continue.yml.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation
3636
debugger_modules: &debugger_modules "dd-java-agent/agent-debugger|dd-java-agent/agent-bootstrap|dd-java-agent/agent-builder|internal-api|communication|dd-trace-core"
3737
profiling_modules: &profiling_modules "dd-java-agent/agent-profiling"
3838

39-
default_system_tests_commit: &default_system_tests_commit 35bb7f9753dc82b7c8e4a8276bf6f0ccad0e5dc3
39+
default_system_tests_commit: &default_system_tests_commit 315bc8a32cc888834726397f088336ba8038277f
4040

4141
parameters:
4242
nightly:

.github/CODEOWNERS

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ dd-java-agent/instrumentation/spring-security-5/ @DataDog/asm-java
5757
**/Iast*.java @DataDog/asm-java
5858
**/Iast*.groovy @DataDog/asm-java
5959
**/rasp/ @Datadog/asm-java
60-
**/*Rasp*.java @DataDog/asm-java
61-
**/*Rasp*.groovy @DataDog/asm-java
60+
**/*Rasp*.java @DataDog/asm-java
61+
**/*Rasp*.groovy @DataDog/asm-java
62+
**/*Waf*.java @DataDog/asm-java
63+
**/*Waf*.groovy @DataDog/asm-java
6264

6365
# @DataDog/data-jobs-monitoring
6466
dd-java-agent/instrumentation/spark/ @DataDog/data-jobs-monitoring

communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package datadog.communication.ddagent;
22

3+
import static datadog.communication.serialization.msgpack.MsgPackWriter.FIXARRAY;
4+
import static java.util.Collections.singletonList;
5+
36
import com.squareup.moshi.JsonAdapter;
47
import com.squareup.moshi.Moshi;
58
import com.squareup.moshi.Types;
@@ -11,7 +14,6 @@
1114
import datadog.trace.util.Strings;
1215
import java.nio.ByteBuffer;
1316
import java.security.NoSuchAlgorithmException;
14-
import java.util.Collections;
1517
import java.util.HashSet;
1618
import java.util.List;
1719
import java.util.Map;
@@ -32,6 +34,12 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
3234
.build()
3335
.adapter(Types.newParameterizedType(Map.class, String.class, Object.class));
3436

37+
// Currently all the endpoints that we probe expect a msgpack body of an array of arrays, v3/v4
38+
// arbitrary size and v5 two elements, so let's give them a two element array of empty arrays
39+
private static final byte[] PROBE_MESSAGE = {
40+
(byte) FIXARRAY | 2, (byte) FIXARRAY, (byte) FIXARRAY
41+
};
42+
3543
public static final String V3_ENDPOINT = "v0.3/traces";
3644
public static final String V4_ENDPOINT = "v0.4/traces";
3745
public static final String V5_ENDPOINT = "v0.5/traces";
@@ -191,7 +199,9 @@ private String probeTracesEndpoint(String[] endpoints) {
191199
client
192200
.newCall(
193201
new Request.Builder()
194-
.put(OkHttpUtils.msgpackRequestBodyOf(Collections.<ByteBuffer>emptyList()))
202+
.put(
203+
OkHttpUtils.msgpackRequestBodyOf(
204+
singletonList(ByteBuffer.wrap(PROBE_MESSAGE))))
195205
.url(agentBaseUrl.resolve(candidate))
196206
.build())
197207
.execute()) {

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@ public void run() {
329329
if (appUsingCustomJMXBuilder) {
330330
log.debug("Custom JMX builder detected. Delaying JMXFetch initialization.");
331331
registerMBeanServerBuilderCallback(new StartJmxCallback(jmxStartDelay));
332-
// one minute fail-safe in case nothing touches JMX and callback isn't triggered
333-
scheduleJmxStart(60 + jmxStartDelay);
334332
} else if (appUsingCustomLogManager) {
335333
log.debug("Custom logger detected. Delaying JMXFetch initialization.");
336334
registerLogManagerCallback(new StartJmxCallback(jmxStartDelay));
@@ -437,6 +435,8 @@ public static void startDatadogTracer(InitializationTelemetry initTelemetry) thr
437435
}
438436

439437
private static void registerLogManagerCallback(final ClassLoadCallBack callback) {
438+
// one minute fail-safe in case the class was unintentionally loaded during premain
439+
AgentTaskScheduler.INSTANCE.schedule(callback, 1, TimeUnit.MINUTES);
440440
try {
441441
final Class<?> agentInstallerClass = AGENT_CLASSLOADER.loadClass(AGENT_INSTALLER_CLASS_NAME);
442442
final Method registerCallbackMethod =
@@ -448,6 +448,8 @@ private static void registerLogManagerCallback(final ClassLoadCallBack callback)
448448
}
449449

450450
private static void registerMBeanServerBuilderCallback(final ClassLoadCallBack callback) {
451+
// one minute fail-safe in case the class was unintentionally loaded during premain
452+
AgentTaskScheduler.INSTANCE.schedule(callback, 1, TimeUnit.MINUTES);
451453
try {
452454
final Class<?> agentInstallerClass = AGENT_CLASSLOADER.loadClass(AGENT_INSTALLER_CLASS_NAME);
453455
final Method registerCallbackMethod =
@@ -459,8 +461,14 @@ private static void registerMBeanServerBuilderCallback(final ClassLoadCallBack c
459461
}
460462

461463
protected abstract static class ClassLoadCallBack implements Runnable {
464+
private final AtomicBoolean starting = new AtomicBoolean();
465+
462466
@Override
463467
public void run() {
468+
if (starting.getAndSet(true)) {
469+
return; // someone has already called us
470+
}
471+
464472
/*
465473
* This callback is called from within bytecode transformer. This can be a problem if callback tries
466474
* to load classes being transformed. To avoid this we start a thread here that calls the callback.
@@ -558,6 +566,7 @@ public void execute() {
558566
}
559567

560568
private void resumeRemoteComponents() {
569+
log.debug("Resuming remote components.");
561570
try {
562571
// remote components were paused for custom log-manager/jmx-builder
563572
// add small delay before resuming remote I/O to help stabilization

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/AdviceUtils.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package datadog.trace.bootstrap.instrumentation.java.concurrent;
22

3-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
3+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.isAsyncPropagationEnabled;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.setAsyncPropagationEnabled;
56

67
import datadog.trace.bootstrap.ContextStore;
78
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
9+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
810

911
/** Helper utils for Runnable/Callable instrumentation */
1012
public class AdviceUtils {
@@ -51,14 +53,14 @@ public static <T> void cancelTask(ContextStore<T, State> contextStore, final T t
5153
}
5254

5355
public static <T> void capture(ContextStore<T, State> contextStore, T task) {
54-
AgentScope activeScope = activeScope();
55-
if (null != activeScope && activeScope.isAsyncPropagating()) {
56+
AgentSpan span = activeSpan();
57+
if (span != null && isAsyncPropagationEnabled()) {
5658
State state = contextStore.get(task);
5759
if (null == state) {
5860
state = State.FACTORY.create();
5961
contextStore.put(task, state);
6062
}
61-
state.captureAndSetContinuation(activeScope);
63+
state.captureAndSetContinuation(span);
6264
}
6365
}
6466
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/ConcurrentState.java

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package datadog.trace.bootstrap.instrumentation.java.concurrent;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.isAsyncPropagationEnabled;
35
import static datadog.trace.bootstrap.instrumentation.java.concurrent.ContinuationClaim.CLAIMED;
46

57
import datadog.trace.bootstrap.ContextStore;
68
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
9+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
710
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
811
import org.slf4j.Logger;
912
import org.slf4j.LoggerFactory;
@@ -28,22 +31,17 @@ public final class ConcurrentState {
2831

2932
private ConcurrentState() {}
3033

31-
public static <K> ConcurrentState captureScope(
32-
ContextStore<K, ConcurrentState> contextStore, K key, AgentScope scope) {
33-
if (scope != null && scope.isAsyncPropagating()) {
34-
if (!scope.span().isValid()) {
35-
return null;
36-
}
37-
final ConcurrentState state = contextStore.putIfAbsent(key, FACTORY);
38-
if (!state.captureAndSetContinuation(scope) && log.isDebugEnabled()) {
39-
log.debug(
40-
"continuation was already set for {} in scope {}, no continuation captured.",
41-
key,
42-
scope);
43-
}
44-
return state;
34+
public static <K> ConcurrentState captureContinuation(
35+
ContextStore<K, ConcurrentState> contextStore, K key, AgentSpan span) {
36+
if (span == null || !span.isValid() || !isAsyncPropagationEnabled()) {
37+
return null;
4538
}
46-
return null;
39+
final ConcurrentState state = contextStore.putIfAbsent(key, FACTORY);
40+
if (!state.captureAndSetContinuation(span) && log.isDebugEnabled()) {
41+
log.debug(
42+
"continuation was already set for {} in span {}, no continuation captured.", key, span);
43+
}
44+
return state;
4745
}
4846

4947
public static <K> AgentScope activateAndContinueContinuation(
@@ -81,10 +79,10 @@ public static <K> void cancelAndClearContinuation(
8179
state.cancelAndClearContinuation();
8280
}
8381

84-
private boolean captureAndSetContinuation(final AgentScope scope) {
82+
private boolean captureAndSetContinuation(final AgentSpan span) {
8583
if (CONTINUATION.compareAndSet(this, null, CLAIMED)) {
8684
// lazy write is guaranteed to be seen by getAndSet
87-
CONTINUATION.lazySet(this, scope.capture().hold());
85+
CONTINUATION.lazySet(this, captureSpan(span).hold());
8886
return true;
8987
}
9088
return false;

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/ContinuationClaim.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public AgentScope activate() {
1818
}
1919

2020
@Override
21-
public AgentSpan getSpan() {
21+
public AgentSpan span() {
2222
throw new IllegalStateException();
2323
}
2424

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/ExecutorInstrumentationUtils.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import datadog.trace.bootstrap.ContextStore;
77
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
8+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
89
import java.util.concurrent.Executor;
910
import org.slf4j.Logger;
1011
import org.slf4j.LoggerFactory;
@@ -36,24 +37,22 @@ public static boolean shouldAttachStateToTask(final Object task, final Executor
3637
}
3738

3839
/**
39-
* Create task state given current scope.
40+
* Create task state given current span.
4041
*
4142
* @param contextStore context storage
4243
* @param task task instance
43-
* @param scope current scope
44+
* @param span current span
4445
* @param <T> task class type
4546
* @return new state
4647
*/
4748
public static <T> State setupState(
48-
final ContextStore<T, State> contextStore, final T task, final AgentScope scope) {
49+
final ContextStore<T, State> contextStore, final T task, final AgentSpan span) {
4950

5051
final State state = contextStore.putIfAbsent(task, State.FACTORY);
5152

52-
if (!state.captureAndSetContinuation(scope)) {
53+
if (!state.captureAndSetContinuation(span)) {
5354
log.debug(
54-
"continuation was already set for {} in scope {}, no continuation captured.",
55-
task,
56-
scope);
55+
"continuation was already set for {} in span {}, no continuation captured.", task, span);
5756
}
5857

5958
return state;

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/State.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.bootstrap.instrumentation.java.concurrent;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureSpan;
34
import static datadog.trace.bootstrap.instrumentation.java.concurrent.ContinuationClaim.CLAIMED;
45

56
import datadog.trace.api.profiling.Timing;
@@ -25,15 +26,15 @@ public final class State {
2526

2627
private State() {}
2728

28-
public boolean captureAndSetContinuation(final AgentScope scope) {
29+
public boolean captureAndSetContinuation(final AgentSpan span) {
2930
if (CONTINUATION.compareAndSet(this, null, CLAIMED)) {
3031
// it's a real pain to do this twice, and this can actually
3132
// happen systematically - WITHOUT RACES - because of broken
3233
// instrumentation, e.g. SetExecuteRunnableStateAdvice
3334
// "double instruments" calls to ScheduledExecutorService.submit/schedule
3435
//
3536
// lazy write is guaranteed to be seen by getAndSet
36-
CONTINUATION.lazySet(this, scope.capture());
37+
CONTINUATION.lazySet(this, captureSpan(span));
3738
return true;
3839
}
3940
return false;
@@ -60,7 +61,7 @@ public void closeContinuation() {
6061
public AgentSpan getSpan() {
6162
AgentScope.Continuation continuation = CONTINUATION.get(this);
6263
if (null != continuation) {
63-
return continuation.getSpan();
64+
return continuation.span();
6465
}
6566
return null;
6667
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/Wrapper.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.bootstrap.instrumentation.java.concurrent;
22

3-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
3+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.captureActiveSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopContinuation;
45
import static datadog.trace.bootstrap.instrumentation.java.concurrent.ExcludeFilter.ExcludeType.RUNNABLE;
56
import static datadog.trace.bootstrap.instrumentation.java.concurrent.ExcludeFilter.exclude;
67

@@ -17,12 +18,12 @@ public static <T extends Runnable> Runnable wrap(T task) {
1718
|| exclude(RUNNABLE, task)) {
1819
return task;
1920
}
20-
AgentScope scope = activeScope();
21-
if (null != scope) {
21+
AgentScope.Continuation continuation = captureActiveSpan();
22+
if (continuation != noopContinuation()) {
2223
if (task instanceof Comparable) {
23-
return new ComparableRunnable(task, scope.capture());
24+
return new ComparableRunnable(task, continuation);
2425
}
25-
return new Wrapper<>(task, scope.capture());
26+
return new Wrapper<>(task, continuation);
2627
}
2728
// don't wrap unless there is scope to propagate
2829
return task;

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/CiVisibilitySettings.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ public CiVisibilitySettings fromJson(Map<String, Object> json) {
142142
getBoolean(json, "flaky_test_retries_enabled", false),
143143
getBoolean(json, "impacted_tests_enabled", false),
144144
getBoolean(json, "known_tests_enabled", false),
145-
EarlyFlakeDetectionSettingsJsonAdapter.INSTANCE.fromJson(
145+
EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE.fromJson(
146146
(Map<String, Object>) json.get("early_flake_detection")),
147-
TestManagementSettingsJsonAdapter.INSTANCE.fromJson(
147+
TestManagementSettings.JsonAdapter.INSTANCE.fromJson(
148148
(Map<String, Object>) json.get("test_management")));
149149
}
150150

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector m
8484
new Moshi.Builder()
8585
.add(ConfigurationsJsonAdapter.INSTANCE)
8686
.add(CiVisibilitySettings.JsonAdapter.INSTANCE)
87-
.add(EarlyFlakeDetectionSettingsJsonAdapter.INSTANCE)
87+
.add(EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE)
8888
.add(MetaDtoJsonAdapter.INSTANCE)
8989
.build();
9090

0 commit comments

Comments
 (0)