Skip to content

Commit 6a92882

Browse files
Merge branch 'master' into alexeyk/debug-dump-logic
2 parents e1ce1f1 + 6c26663 commit 6a92882

1,171 files changed

Lines changed: 6780 additions & 811 deletions

File tree

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,14 @@
7777
/dd-java-agent/agent-ci-visibility/ @DataDog/ci-app-libraries-java
7878
/dd-java-agent/instrumentation/cucumber/ @DataDog/ci-app-libraries-java
7979
/dd-java-agent/instrumentation/jacoco/ @DataDog/ci-app-libraries-java
80-
/dd-java-agent/instrumentation/junit-4.10/ @DataDog/ci-app-libraries-java
81-
/dd-java-agent/instrumentation/junit-5.3/ @DataDog/ci-app-libraries-java
80+
/dd-java-agent/instrumentation/junit @DataDog/ci-app-libraries-java
8281
/dd-java-agent/instrumentation/karate/ @DataDog/ci-app-libraries-java
8382
/dd-java-agent/instrumentation/scalatest/ @DataDog/ci-app-libraries-java
8483
/dd-java-agent/instrumentation/selenium/ @DataDog/ci-app-libraries-java
8584
/dd-java-agent/instrumentation/testng/ @DataDog/ci-app-libraries-java
86-
/dd-java-agent/instrumentation/gradle-3.0/ @DataDog/ci-app-libraries-java
87-
/dd-java-agent/instrumentation/gradle-8.3/ @DataDog/ci-app-libraries-java
85+
/dd-java-agent/instrumentation/gradle/ @DataDog/ci-app-libraries-java
8886
/dd-java-agent/instrumentation/gradle-testing/ @DataDog/ci-app-libraries-java
89-
/dd-java-agent/instrumentation/maven-3.2.1/ @DataDog/ci-app-libraries-java
87+
/dd-java-agent/instrumentation/maven @DataDog/ci-app-libraries-java
9088
/dd-java-agent/instrumentation/maven-surefire/ @DataDog/ci-app-libraries-java
9189
/dd-java-agent/instrumentation/weaver/ @DataDog/ci-app-libraries-java
9290
/dd-smoke-tests/gradle/ @DataDog/ci-app-libraries-java

BUILDING.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ Requirements to build the full project:
6363

6464
Download and install JDK versions 8, 11, 17, 21 and 25, and GraalVM 17 for your OS.
6565

66-
> [!NOTE]
67-
> While Temurin JDK 25 from [Eclipse Temurin releases](https://adoptium.net/temurin/releases/) has not been released, please download the OpenJDK EA version at [this link](https://jdk.java.net/25/). Add the required environment variable using an `export` command along the lines of `export JAVA_25_HOME=/Library/Java/JavaVirtualMachines/jdk-25.jdk/Contents/Home`. Then, confirm that this was set properly by executing `echo $JAVA_25_HOME`.
68-
6966
#### macOS
7067

7168
* Install the required JDKs using `brew`:

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ plugins {
1313
id("com.gradleup.shadow") version "8.3.6" apply false
1414
id("me.champeau.jmh") version "0.7.3" apply false
1515
id("org.gradle.playframework") version "0.13" apply false
16-
id("info.solidsoft.pitest") version "1.9.11" apply false
1716
}
1817

1918
description = "dd-trace-java"

buildSrc/src/main/groovy/InstrumentingPlugin.groovy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,19 @@ class InstrumentingPlugin {
4949
.withErrorHandlers(
5050
Plugin.Engine.ErrorHandler.Enforcing.ALL_TYPES_RESOLVED,
5151
Plugin.Engine.ErrorHandler.Enforcing.NO_LIVE_INITIALIZERS,
52-
Plugin.Engine.ErrorHandler.Failing.FAIL_LAST)
52+
new Plugin.Engine.ErrorHandler() {
53+
@Delegate
54+
Plugin.Engine.ErrorHandler delegate = Plugin.Engine.ErrorHandler.Failing.FAIL_LAST
55+
56+
void onError(Map<TypeDescription, List<Throwable>> throwables) {
57+
throw new IllegalStateException("Failed to transform at least one type: " + throwables).tap { ise ->
58+
throwables.values().flatten().each {
59+
ise.addSuppressed(it)
60+
}
61+
};
62+
}
63+
}
64+
)
5365
.with(Plugin.Engine.Dispatcher.ForSerialTransformation.Factory.INSTANCE)
5466
.apply(source, target, factories)
5567

components/environment/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ val excludedClassesCoverage by extra {
2323
"datadog.environment.JavaVirtualMachine", // depends on OS and JVM vendor
2424
"datadog.environment.JavaVirtualMachine.JvmOptionsHolder", // depends on OS and JVM vendor
2525
"datadog.environment.JvmOptions", // depends on OS and JVM vendor
26-
"datadog.environment.OperatingSystem", // depends on OS
26+
"datadog.environment.OperatingSystem**", // depends on OS
2727
)
2828
}
2929
val excludedClassesBranchCoverage by extra {

components/environment/src/main/java/datadog/environment/OperatingSystem.java

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package datadog.environment;
22

3+
import static datadog.environment.OperatingSystem.Type.LINUX;
4+
import static datadog.environment.OperatingSystem.Type.MACOS;
5+
import static datadog.environment.OperatingSystem.Type.WINDOWS;
36
import static java.util.Locale.ROOT;
47

58
import java.io.BufferedReader;
@@ -10,11 +13,15 @@
1013
import java.nio.file.Path;
1114
import java.nio.file.Paths;
1215
import java.util.Arrays;
16+
import java.util.HashSet;
17+
import java.util.Set;
1318

1419
/** Detects operating systems and libc library. */
1520
public final class OperatingSystem {
1621
private static final String OS_NAME_PROPERTY = "os.name";
1722
private static final String OS_ARCH_PROPERTY = "os.arch";
23+
private static final Type TYPE = Type.current();
24+
private static final Architecture ARCHITECTURE = Architecture.current();
1825

1926
private OperatingSystem() {}
2027

@@ -24,7 +31,7 @@ private OperatingSystem() {}
2431
* @return @{@code true} if operating system is Linux based, {@code false} otherwise.
2532
*/
2633
public static boolean isLinux() {
27-
return propertyContains(OS_NAME_PROPERTY, "linux");
34+
return TYPE == LINUX;
2835
}
2936

3037
/**
@@ -33,8 +40,7 @@ public static boolean isLinux() {
3340
* @return @{@code true} if operating system is Windows, {@code false} otherwise.
3441
*/
3542
public static boolean isWindows() {
36-
// https://mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
37-
return propertyContains(OS_NAME_PROPERTY, "win");
43+
return TYPE == WINDOWS;
3844
}
3945

4046
/**
@@ -43,20 +49,21 @@ public static boolean isWindows() {
4349
* @return @{@code true} if operating system is macOS, {@code false} otherwise.
4450
*/
4551
public static boolean isMacOs() {
46-
return propertyContains(OS_NAME_PROPERTY, "mac");
52+
return TYPE == MACOS;
4753
}
4854

4955
/**
50-
* Checks whether the architecture is AArch64.
56+
* Gets the operating system type.
5157
*
52-
* @return {@code true} if the architecture is AArch64, {@code false} otherwise.
58+
* @return The operating system type, {@link Type#UNKNOWN} if not properly detected or supported.
5359
*/
54-
public static boolean isAarch64() {
55-
return propertyContains(OS_ARCH_PROPERTY, "aarch64");
60+
public static Type type() {
61+
return TYPE;
5662
}
5763

58-
private static boolean propertyContains(String property, String content) {
59-
return SystemProperties.getOrDefault(property, "").toLowerCase(ROOT).contains(content);
64+
/** Gets the operating system architecture . */
65+
public static Architecture architecture() {
66+
return ARCHITECTURE;
6067
}
6168

6269
/**
@@ -146,4 +153,65 @@ private static boolean containsArray(byte[] container, int offset, byte[] contai
146153
}
147154
return true;
148155
}
156+
157+
public enum Type {
158+
WINDOWS("Windows"),
159+
MACOS("MacOS"),
160+
LINUX("Linux"),
161+
UNKNOWN("unknown");
162+
163+
private final String name;
164+
165+
Type(String name) {
166+
this.name = name;
167+
}
168+
169+
static Type current() {
170+
String property = SystemProperties.getOrDefault(OS_NAME_PROPERTY, "").toLowerCase(ROOT);
171+
// https://mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
172+
if (property.contains("linux")) {
173+
return LINUX;
174+
} else if (property.contains("win")) {
175+
return WINDOWS;
176+
} else if (property.contains("mac")) {
177+
return MACOS;
178+
} else {
179+
return UNKNOWN;
180+
}
181+
}
182+
183+
@Override
184+
public String toString() {
185+
return this.name;
186+
}
187+
}
188+
189+
/** Detects the operating system architecture. */
190+
public enum Architecture {
191+
X64("x86_64", "amd64", "k8"),
192+
X86("x86", "i386", "i486", "i586", "i686"),
193+
ARM("arm", "aarch32"),
194+
ARM64("arm64", "aarch64"),
195+
UNKNOWN();
196+
197+
private final Set<String> identifiers;
198+
199+
Architecture(String... identifiers) {
200+
this.identifiers = new HashSet<>(Arrays.asList(identifiers));
201+
}
202+
203+
static Architecture of(String identifier) {
204+
for (Architecture architecture : Architecture.values()) {
205+
if (architecture.identifiers.contains(identifier)) {
206+
return architecture;
207+
}
208+
}
209+
return UNKNOWN;
210+
}
211+
212+
static Architecture current() {
213+
String property = SystemProperties.getOrDefault(OS_ARCH_PROPERTY, "").toLowerCase(ROOT);
214+
return Architecture.of(property);
215+
}
216+
}
149217
}

components/environment/src/test/java/datadog/environment/OperatingSystemTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package datadog.environment;
22

3+
import static datadog.environment.OperatingSystem.Architecture.ARM;
4+
import static datadog.environment.OperatingSystem.Architecture.ARM64;
5+
import static datadog.environment.OperatingSystem.Architecture.X64;
6+
import static datadog.environment.OperatingSystem.Architecture.X86;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
38
import static org.junit.jupiter.api.Assertions.assertFalse;
49
import static org.junit.jupiter.api.Assertions.assertTrue;
510
import static org.junit.jupiter.api.condition.OS.LINUX;
611
import static org.junit.jupiter.api.condition.OS.MAC;
712
import static org.junit.jupiter.api.condition.OS.WINDOWS;
813

14+
import datadog.environment.OperatingSystem.Type;
915
import org.junit.jupiter.api.Test;
1016
import org.junit.jupiter.api.condition.EnabledOnOs;
1117

@@ -16,6 +22,7 @@ void onLinuxOnly() {
1622
assertTrue(OperatingSystem.isLinux());
1723
assertFalse(OperatingSystem.isMacOs());
1824
assertFalse(OperatingSystem.isWindows());
25+
assertEquals(Type.LINUX, OperatingSystem.type());
1926
}
2027

2128
@Test
@@ -24,6 +31,7 @@ void onMacOsOnly() {
2431
assertFalse(OperatingSystem.isLinux());
2532
assertTrue(OperatingSystem.isMacOs());
2633
assertFalse(OperatingSystem.isWindows());
34+
assertEquals(Type.MACOS, OperatingSystem.type());
2735
}
2836

2937
@Test
@@ -32,5 +40,30 @@ void onWindowsOnly() {
3240
assertFalse(OperatingSystem.isLinux());
3341
assertFalse(OperatingSystem.isMacOs());
3442
assertTrue(OperatingSystem.isWindows());
43+
assertEquals(Type.WINDOWS, OperatingSystem.type());
44+
}
45+
46+
@Test
47+
@EnabledOnOs(architectures = {"x86_64", "amd64", "k8"})
48+
void onX64() {
49+
assertEquals(X64, OperatingSystem.architecture());
50+
}
51+
52+
@Test
53+
@EnabledOnOs(architectures = {"x86", "i386", "i486", "i586", "i686"})
54+
void onX86() {
55+
assertEquals(X86, OperatingSystem.architecture());
56+
}
57+
58+
@Test
59+
@EnabledOnOs(architectures = {"arm", "aarch32"})
60+
void onArm() {
61+
assertEquals(ARM, OperatingSystem.architecture());
62+
}
63+
64+
@Test
65+
@EnabledOnOs(architectures = {"arm64", "aarch64"})
66+
void onArm64() {
67+
assertEquals(ARM64, OperatingSystem.architecture());
3568
}
3669
}

dd-java-agent/agent-bootstrap/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ dependencies {
4848
main_java11CompileOnly sourceSets.main.output
4949
}
5050

51-
jar {
51+
tasks.named("jar", Jar) {
5252
from sourceSets.main_java11.output
5353
}
5454

55-
forbiddenApisMain_java11 {
55+
tasks.named("forbiddenApisMain_java11") {
5656
failOnMissingClasses = false
5757
}
5858

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpClientDecorator.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import datadog.trace.api.DDTags;
1111
import datadog.trace.api.InstrumenterConfig;
1212
import datadog.trace.api.ProductActivation;
13+
import datadog.trace.api.appsec.HttpClientRequest;
1314
import datadog.trace.api.gateway.BlockResponseFunction;
1415
import datadog.trace.api.gateway.Flow;
1516
import datadog.trace.api.gateway.RequestContext;
@@ -99,7 +100,7 @@ public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
99100
HTTP_RESOURCE_DECORATOR.withClientPath(span, method, url.getPath());
100101
}
101102
// SSRF exploit prevention check
102-
onNetworkConnection(url.toString());
103+
onHttpClientRequest(span, url.toString());
103104
} else if (shouldSetResourceName()) {
104105
span.setResourceName(DEFAULT_RESOURCE_NAME);
105106
}
@@ -178,24 +179,19 @@ public long getResponseContentLength(final RESPONSE response) {
178179
return 0;
179180
}
180181

181-
private void onNetworkConnection(final String networkConnection) {
182+
protected void onHttpClientRequest(final AgentSpan span, final String url) {
182183
if (!APPSEC_RASP_ENABLED) {
183184
return;
184185
}
185-
if (networkConnection == null) {
186+
if (url == null) {
186187
return;
187188
}
188-
final BiFunction<RequestContext, String, Flow<Void>> networkConnectionCallback =
189+
final BiFunction<RequestContext, HttpClientRequest, Flow<Void>> requestCb =
189190
AgentTracer.get()
190191
.getCallbackProvider(RequestContextSlot.APPSEC)
191-
.getCallback(EVENTS.networkConnection());
192+
.getCallback(EVENTS.httpClientRequest());
192193

193-
if (networkConnectionCallback == null) {
194-
return;
195-
}
196-
197-
final AgentSpan span = AgentTracer.get().activeSpan();
198-
if (span == null) {
194+
if (requestCb == null) {
199195
return;
200196
}
201197

@@ -204,7 +200,8 @@ private void onNetworkConnection(final String networkConnection) {
204200
return;
205201
}
206202

207-
Flow<Void> flow = networkConnectionCallback.apply(ctx, networkConnection);
203+
final long requestId = span.getSpanId();
204+
Flow<Void> flow = requestCb.apply(ctx, new HttpClientRequest(requestId, url));
208205
Flow.Action action = flow.getAction();
209206
if (action instanceof Flow.Action.RequestBlockingAction) {
210207
BlockResponseFunction brf = ctx.getBlockResponseFunction();

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/HttpClientDecoratorTest.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.bootstrap.instrumentation.decorator
22

33
import datadog.trace.api.DDTags
4+
import datadog.trace.api.appsec.HttpClientRequest
45
import datadog.trace.api.config.AppSecConfig
56
import datadog.trace.api.gateway.CallbackProvider
67
import static datadog.trace.api.gateway.Events.EVENTS
@@ -249,8 +250,8 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
249250
decorator.onRequest(span2, req)
250251

251252
then:
252-
1 * callbackProvider.getCallback(EVENTS.networkConnection()) >> listener
253-
1 * listener.apply(reqCtx, _ as String)
253+
1 * callbackProvider.getCallback(EVENTS.httpClientRequest()) >> listener
254+
1 * listener.apply(reqCtx, _ as HttpClientRequest)
254255
}
255256

256257
@Override

0 commit comments

Comments
 (0)