Skip to content

Commit deb8831

Browse files
committed
Merge branch 'dougqh/guardrails-telemetry' of https://github.com/DataDog/dd-trace-java into dougqh/guardrails-telemetry
2 parents 79197c1 + d729531 commit deb8831

File tree

439 files changed

+1717
-1155
lines changed

Some content is hidden

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

439 files changed

+1717
-1155
lines changed

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
implementation(gradleApi())
3333
implementation(localGroovy())
3434

35-
implementation("net.bytebuddy", "byte-buddy-gradle-plugin", "1.14.16")
35+
implementation("net.bytebuddy", "byte-buddy-gradle-plugin", "1.14.18")
3636

3737
implementation("org.eclipse.aether", "aether-connector-basic", "1.1.0")
3838
implementation("org.eclipse.aether", "aether-transport-http", "1.1.0")

buildSrc/call-site-instrumentation-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
implementation("org.ow2.asm", "asm-tree", "9.0")
3939
implementation("com.github.javaparser", "javaparser-symbol-solver-core", "3.24.4")
4040

41-
testImplementation("net.bytebuddy", "byte-buddy", "1.14.16")
41+
testImplementation("net.bytebuddy", "byte-buddy", "1.14.18")
4242
testImplementation("org.spockframework", "spock-core", "2.0-groovy-3.0")
4343
testImplementation("org.objenesis", "objenesis", "3.0.1")
4444
testImplementation("org.codehaus.groovy", "groovy-all", "3.0.17")

buildSrc/src/test/groovy/CallSiteInstrumentationPluginTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CallSiteInstrumentationPluginTest extends Specification {
2727
}
2828
2929
dependencies {
30-
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.16'
30+
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.18'
3131
implementation group: 'com.google.auto.service', name: 'auto-service-annotations', version: '1.0-rc7'
3232
}
3333
'''

buildSrc/src/test/groovy/InstrumentPluginTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class InstrumentPluginTest extends Specification {
2323
}
2424
2525
dependencies {
26-
compileOnly group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.16' // just to build TestPlugin
26+
compileOnly group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.18' // just to build TestPlugin
2727
}
2828
2929
apply plugin: 'instrument'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ commons-fileupload:commons-fileupload:1.5=jmhRuntimeClasspath,testCompileClasspa
3939
commons-io:commons-io:2.11.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4040
de.thetaphi:forbiddenapis:3.1=compileClasspath,jmhCompileClasspath
4141
info.picocli:picocli:4.6.3=jmhRuntimeClasspath,testRuntimeClasspath
42-
io.sqreen:libsqreen:10.0.0=jmhRuntimeClasspath,testRuntimeClasspath
42+
io.sqreen:libsqreen:10.1.0=jmhRuntimeClasspath,testRuntimeClasspath
4343
javax.servlet:javax.servlet-api:3.1.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4444
jaxen:jaxen:1.2.0=spotbugs
4545
jline:jline:2.14.6=jmhRuntimeClasspath,testRuntimeClasspath

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import datadog.trace.bootstrap.ContextStore;
66
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
7-
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
87

98
/** Helper utils for Runnable/Callable instrumentation */
109
public class AdviceUtils {
@@ -19,10 +18,10 @@ public class AdviceUtils {
1918
*/
2019
public static <T> AgentScope startTaskScope(
2120
final ContextStore<T, State> contextStore, final T task) {
22-
return startTaskScope(contextStore.get(task), false);
21+
return startTaskScope(contextStore.get(task));
2322
}
2423

25-
public static AgentScope startTaskScope(State state, boolean migrated) {
24+
public static AgentScope startTaskScope(State state) {
2625
if (state != null) {
2726
final AgentScope.Continuation continuation = state.getAndResetContinuation();
2827
if (continuation != null) {
@@ -50,16 +49,7 @@ public static <T> void cancelTask(ContextStore<T, State> contextStore, final T t
5049
}
5150
}
5251

53-
public static <T> AgentSpan getCapturedSpan(ContextStore<T, State> contextStore, final T task) {
54-
State state = contextStore.get(task);
55-
if (null != state) {
56-
return state.getSpan();
57-
}
58-
return null;
59-
}
60-
61-
public static <T> void capture(
62-
ContextStore<T, State> contextStore, T task, boolean startThreadMigration) {
52+
public static <T> void capture(ContextStore<T, State> contextStore, T task) {
6353
AgentScope activeScope = activeScope();
6454
if (null != activeScope && activeScope.isAsyncPropagating()) {
6555
State state = contextStore.get(task);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static boolean shouldPropagate(
7474

7575
public static void capture(ContextStore<Runnable, State> contextStore, Runnable task) {
7676
if (task != null && !exclude(RUNNABLE, task)) {
77-
AdviceUtils.capture(contextStore, task, true);
77+
AdviceUtils.capture(contextStore, task);
7878
}
7979
}
8080

dd-java-agent/agent-builder/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ commons-fileupload:commons-fileupload:1.5=testCompileClasspath,testRuntimeClassp
3939
commons-io:commons-io:2.11.0=testCompileClasspath,testRuntimeClasspath
4040
de.thetaphi:forbiddenapis:3.1=compileClasspath
4141
info.picocli:picocli:4.6.3=testRuntimeClasspath
42-
io.sqreen:libsqreen:10.0.0=testRuntimeClasspath
42+
io.sqreen:libsqreen:10.1.0=testRuntimeClasspath
4343
javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath
4444
jaxen:jaxen:1.2.0=spotbugs
4545
jline:jline:2.14.6=testRuntimeClasspath

dd-java-agent/agent-ci-visibility/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ commons-io:commons-io:2.11.0=testCompileClasspath,testFixturesApiDependenciesMet
5454
de.thetaphi:forbiddenapis:3.1=compileClasspath,compileOnlyDependenciesMetadata
5555
info.picocli:picocli:4.6.3=testFixturesRuntimeClasspath,testRuntimeClasspath
5656
io.github.java-diff-utils:java-diff-utils:4.12=zinc
57-
io.sqreen:libsqreen:10.0.0=testFixturesRuntimeClasspath,testRuntimeClasspath
57+
io.sqreen:libsqreen:10.1.0=testFixturesRuntimeClasspath,testRuntimeClasspath
5858
javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testFixturesApiDependenciesMetadata,testFixturesCompileClasspath,testFixturesImplementationDependenciesMetadata,testFixturesRuntimeClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
5959
jaxen:jaxen:1.2.0=spotbugs
6060
jline:jline:2.14.6=testFixturesRuntimeClasspath,testRuntimeClasspath

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/Fingerprinter.java

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,31 @@
44

55
import com.datadog.debugger.util.ClassNameFiltering;
66
import java.security.MessageDigest;
7+
import java.security.NoSuchAlgorithmException;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
910

1011
/** Computes a fingerprint of an exception based on its stacktrace and exception type. */
1112
public class Fingerprinter {
1213
private static final Logger LOGGER = LoggerFactory.getLogger(Fingerprinter.class);
13-
private static MessageDigest digest;
14-
15-
static {
16-
try {
17-
digest = MessageDigest.getInstance("SHA-256");
18-
} catch (Throwable e) {
19-
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
20-
}
21-
}
2214

2315
// compute fingerprint of the Throwable based on the stacktrace and exception type
2416
public static String fingerprint(Throwable t, ClassNameFiltering classNameFiltering) {
25-
if (digest == null) {
26-
return null;
27-
}
2817
t = getInnerMostThrowable(t);
2918
if (t == null) {
3019
LOGGER.debug("Unable to find root cause of exception");
3120
return null;
3221
}
3322
Class<? extends Throwable> clazz = t.getClass();
23+
MessageDigest digest;
24+
try {
25+
// need to create a new instance each time to make it thread safe
26+
// Regarding performance, see the results of micro-benchmarks at the end of the file
27+
digest = MessageDigest.getInstance("SHA-256");
28+
} catch (NoSuchAlgorithmException e) {
29+
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
30+
return null;
31+
}
3432
String typeName = clazz.getTypeName();
3533
digest.update(typeName.getBytes());
3634
StackTraceElement[] stackTrace = t.getStackTrace();
@@ -45,11 +43,14 @@ public static String fingerprint(Throwable t, ClassNameFiltering classNameFilter
4543
}
4644

4745
public static String fingerprint(StackTraceElement element) {
48-
if (digest == null) {
46+
try {
47+
MessageDigest digest = MessageDigest.getInstance("SHA-256");
48+
digest.update(element.toString().getBytes());
49+
return bytesToHex(digest.digest());
50+
} catch (NoSuchAlgorithmException e) {
51+
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
4952
return null;
5053
}
51-
digest.update(element.toString().getBytes());
52-
return bytesToHex(digest.digest());
5354
}
5455

5556
// convert byte[] to hex string
@@ -61,3 +62,85 @@ private static String bytesToHex(byte[] bytes) {
6162
return result.toString();
6263
}
6364
}
65+
66+
/*
67+
Micro benchmark results:
68+
jdk8 arm64:
69+
Benchmark Mode Cnt Score Error Units
70+
MessageDigestBenchmark.md5NewInstance avgt 5 4.974 ± 0.069 us/op
71+
MessageDigestBenchmark.md5ReuseInstance avgt 5 4.787 ± 0.137 us/op
72+
MessageDigestBenchmark.sha1NewInstance avgt 5 6.131 ± 0.038 us/op
73+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 6.088 ± 0.016 us/op
74+
MessageDigestBenchmark.sha256NewInstance avgt 5 7.090 ± 0.091 us/op
75+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 7.048 ± 0.132 us/op
76+
77+
jdk11 arm64:
78+
Benchmark Mode Cnt Score Error Units
79+
MessageDigestBenchmark.md5NewInstance avgt 5 5.258 ± 0.166 us/op
80+
MessageDigestBenchmark.md5ReuseInstance avgt 5 5.196 ± 0.053 us/op
81+
MessageDigestBenchmark.sha1NewInstance avgt 5 6.639 ± 0.136 us/op
82+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 6.522 ± 0.096 us/op
83+
MessageDigestBenchmark.sha256NewInstance avgt 5 7.600 ± 0.130 us/op
84+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 7.605 ± 0.115 us/op
85+
86+
jdk17 arm64:
87+
Benchmark Mode Cnt Score Error Units
88+
MessageDigestBenchmark.md5NewInstance avgt 5 3.749 ± 0.054 us/op
89+
MessageDigestBenchmark.md5ReuseInstance avgt 5 3.713 ± 0.061 us/op
90+
MessageDigestBenchmark.sha1NewInstance avgt 5 5.708 ± 0.079 us/op
91+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 5.646 ± 0.070 us/op
92+
MessageDigestBenchmark.sha256NewInstance avgt 5 8.668 ± 0.073 us/op
93+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 8.651 ± 0.131 us/op
94+
95+
jdk21 arm64:
96+
Benchmark Mode Cnt Score Error Units
97+
MessageDigestBenchmark.md5NewInstance avgt 5 2.702 ± 0.023 us/op
98+
MessageDigestBenchmark.md5ReuseInstance avgt 5 2.675 ± 0.018 us/op
99+
MessageDigestBenchmark.sha1NewInstance avgt 5 0.818 ± 0.005 us/op
100+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 0.798 ± 0.035 us/op
101+
MessageDigestBenchmark.sha256NewInstance avgt 5 0.814 ± 0.018 us/op
102+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 0.792 ± 0.017 us/op
103+
104+
jdk21 arm64 -XX:+UnlockDiagnosticVMOptions -XX:-UseSHA1Intrinsics -XX:-UseSHA256Intrinsics
105+
Benchmark Mode Cnt Score Error Units
106+
MessageDigestBenchmark.sha1NewInstance avgt 5 5.030 ± 0.041 us/op
107+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 5.121 ± 0.090 us/op
108+
MessageDigestBenchmark.sha256NewInstance avgt 5 7.677 ± 0.089 us/op
109+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 7.627 ± 0.065 us/op
110+
111+
jdk8 x86_64:
112+
Benchmark Mode Cnt Score Error Units
113+
MessageDigestBenchmark.md5NewInstance avgt 5 4.435 ± 0.166 us/op
114+
MessageDigestBenchmark.md5ReuseInstance avgt 5 4.364 ± 0.206 us/op
115+
MessageDigestBenchmark.sha1NewInstance avgt 5 5.966 ± 0.224 us/op
116+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 5.901 ± 0.349 us/op
117+
MessageDigestBenchmark.sha256NewInstance avgt 5 9.220 ± 0.667 us/op
118+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 9.162 ± 0.860 us/op
119+
120+
jdk11 x86_64:
121+
Benchmark Mode Cnt Score Error Units
122+
MessageDigestBenchmark.md5NewInstance avgt 5 4.716 ± 0.233 us/op
123+
MessageDigestBenchmark.md5ReuseInstance avgt 5 4.662 ± 0.258 us/op
124+
MessageDigestBenchmark.sha1NewInstance avgt 5 1.444 ± 0.066 us/op
125+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 1.396 ± 0.060 us/op
126+
MessageDigestBenchmark.sha256NewInstance avgt 5 1.533 ± 0.054 us/op
127+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 1.494 ± 0.052 us/op
128+
129+
jdk17 x86_64:
130+
Benchmark Mode Cnt Score Error Units
131+
MessageDigestBenchmark.md5NewInstance avgt 5 2.852 ± 0.191 us/op
132+
MessageDigestBenchmark.md5ReuseInstance avgt 5 2.816 ± 0.086 us/op
133+
MessageDigestBenchmark.sha1NewInstance avgt 5 1.329 ± 0.051 us/op
134+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 1.363 ± 0.238 us/op
135+
MessageDigestBenchmark.sha256NewInstance avgt 5 1.397 ± 0.133 us/op
136+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 1.391 ± 0.047 us/op
137+
138+
jdk22 x86_64:
139+
Benchmark Mode Cnt Score Error Units
140+
MessageDigestBenchmark.md5NewInstance avgt 5 4.757 ± 0.179 us/op
141+
MessageDigestBenchmark.md5ReuseInstance avgt 5 4.689 ± 0.300 us/op
142+
MessageDigestBenchmark.sha1NewInstance avgt 5 1.460 ± 0.049 us/op
143+
MessageDigestBenchmark.sha1ReuseInstance avgt 5 1.423 ± 0.066 us/op
144+
MessageDigestBenchmark.sha256NewInstance avgt 5 1.567 ± 0.123 us/op
145+
MessageDigestBenchmark.sha256ReuseInstance avgt 5 1.521 ± 0.084 us/op
146+
*/

0 commit comments

Comments
 (0)