Skip to content

Commit 13cf538

Browse files
committed
Merge branch 'master' of github.com:DataDog/dd-trace-java into labbati/jdbc-error-glasshfish
2 parents 0c52ba5 + 0ea2d74 commit 13cf538

24 files changed

Lines changed: 328 additions & 64 deletions

File tree

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Automatically assign the team as a reviewer.
2+
# https://help.github.com/en/articles/about-code-owners
3+
4+
* @DataDog/apm-java

dd-java-agent/agent-jmxfetch/agent-jmxfetch.gradle

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ plugins {
44
apply from: "${rootDir}/gradle/java.gradle"
55

66
dependencies {
7-
compile 'com.datadoghq:jmxfetch:0.27.0'
7+
compile('com.datadoghq:jmxfetch:0.29.0'){
8+
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
9+
exclude group: 'log4j', module: 'log4j'
10+
}
811
compile deps.slf4j
912
compile project(':dd-trace-api')
1013
}
@@ -32,12 +35,23 @@ tasks.register("submodulesUpdate", Exec) {
3235
group 'Build Setup'
3336
description 'Initializes and updates integrations-core git submodule'
3437
commandLine 'git', 'submodule', 'update', '--init', 'integrations-core'
38+
def submoduleHead = file("${project.rootDir}/.git/modules/dd-java-agent/agent-jmxfetch/integrations-core/HEAD")
39+
if (submoduleHead.exists()) {
40+
inputs.file "${project.rootDir}/.git/modules/dd-java-agent/agent-jmxfetch/integrations-core/HEAD"
41+
}
42+
def integrationsCore = file("$projectDir/integrations-core")
43+
outputs.dir integrationsCore
44+
if (integrationsCore.list().length == 0) {
45+
outputs.upToDateWhen { false }
46+
}
3547
}
3648

3749
tasks.register("copyMetricConfigs", Exec) {
3850
group 'Build Setup'
3951
description 'Copy metrics.yaml files from integrations-core into resources'
4052
commandLine './copy-metric-configs.sh', 'integrations-core', sourceSets.main.output.resourcesDir
53+
inputs.dir file("$projectDir/integrations-core")
54+
outputs.dir sourceSets.main.output.resourcesDir
4155
doFirst {
4256
// Ensure the resources directory is available.
4357
file(sourceSets.main.output.resourcesDir).mkdirs()
Submodule integrations-core updated 1416 files

dd-java-agent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JMXFetch.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.agent.jmxfetch;
22

3+
import static org.datadog.jmxfetch.AppConfig.ACTION_COLLECT;
4+
35
import com.google.common.collect.ImmutableList;
46
import datadog.trace.api.Config;
57
import java.io.IOException;
@@ -16,6 +18,7 @@
1618
import org.apache.commons.io.IOUtils;
1719
import org.datadog.jmxfetch.App;
1820
import org.datadog.jmxfetch.AppConfig;
21+
import org.datadog.jmxfetch.reporter.ReporterFactory;
1922

2023
@Slf4j
2124
public class JMXFetch {
@@ -38,6 +41,14 @@ private static void run(final Config config) {
3841
return;
3942
}
4043

44+
if (!log.isDebugEnabled()
45+
&& System.getProperty("org.slf4j.simpleLogger.log.org.datadog.jmxfetch") == null) {
46+
// Reduce noisiness of jmxfetch logging.
47+
System.setProperty("org.slf4j.simpleLogger.log.org.datadog.jmxfetch", "warn");
48+
}
49+
50+
final String jmxFetchConfigDir = config.getJmxFetchConfigDir();
51+
final List<String> jmxFetchConfigs = config.getJmxFetchConfigs();
4152
final List<String> internalMetricsConfigs = getInternalMetricFiles();
4253
final List<String> metricsConfigs = config.getJmxFetchMetricsConfigs();
4354
final Integer checkPeriod = config.getJmxFetchCheckPeriod();
@@ -48,7 +59,9 @@ private static void run(final Config config) {
4859
final String logLevel = getLogLevel();
4960

5061
log.info(
51-
"JMXFetch config: {} {} {} {} {} {} {} {}",
62+
"JMXFetch config: {} {} {} {} {} {} {} {} {} {}",
63+
jmxFetchConfigDir,
64+
jmxFetchConfigs,
5265
internalMetricsConfigs,
5366
metricsConfigs,
5467
checkPeriod,
@@ -57,17 +70,24 @@ private static void run(final Config config) {
5770
reporter,
5871
logLocation,
5972
logLevel);
60-
final AppConfig appConfig =
61-
AppConfig.create(
62-
DEFAULT_CONFIGS,
63-
internalMetricsConfigs,
64-
metricsConfigs,
65-
checkPeriod,
66-
refreshBeansPeriod,
67-
globalTags,
68-
reporter,
69-
logLocation,
70-
logLevel);
73+
74+
final AppConfig.AppConfigBuilder configBuilder =
75+
AppConfig.builder()
76+
.action(ImmutableList.of(ACTION_COLLECT))
77+
.confdDirectory(jmxFetchConfigDir)
78+
.yamlFileList(jmxFetchConfigs)
79+
.targetDirectInstances(true)
80+
.instanceConfigResources(DEFAULT_CONFIGS)
81+
.metricConfigResources(internalMetricsConfigs)
82+
.metricConfigFiles(metricsConfigs)
83+
.refreshBeansPeriod(refreshBeansPeriod)
84+
.globalTags(globalTags)
85+
.reporter(ReporterFactory.getReporter(reporter));
86+
87+
if (checkPeriod != null) {
88+
configBuilder.checkPeriod(checkPeriod);
89+
}
90+
final AppConfig appConfig = configBuilder.build();
7191

7292
final Thread thread =
7393
new Thread(
@@ -131,7 +151,7 @@ private static List<String> getInternalMetricFiles() {
131151
for (final String config : split) {
132152
integrationName.clear();
133153
integrationName.add(config.replace(".yaml", ""));
134-
if (Config.integrationEnabled(integrationName, false)) {
154+
if (Config.jmxFetchIntegrationEnabled(integrationName, false)) {
135155
final URL resource = JMXFetch.class.getResource("metricconfigs/" + config);
136156
result.add(resource.getPath().split("\\.jar!/")[1]);
137157
}

dd-java-agent/agent-jmxfetch/src/main/resources/jmxfetch-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ init_config:
33
new_gc_metrics: true
44

55
instances:
6-
- jmx_url: service:jmx:local:///
7-
conf:
8-
# Intentionally left empty for now
6+
- jvm_direct: true
7+
name: dd-java-agent default
8+
conf: [] # Intentionally left empty for now

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/AgentInstaller.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ public static ResettableClassFileTransformer installBytebuddyAgent(
121121
.or(nameStartsWith("com.intellij.rt.debugger."))
122122
.or(nameStartsWith("com.p6spy."))
123123
.or(nameStartsWith("com.newrelic."))
124+
.or(nameStartsWith("com.dynatrace."))
125+
.or(nameStartsWith("com.jloadtrace."))
126+
.or(nameStartsWith("com.appdynamics."))
127+
.or(nameStartsWith("com.singularity."))
128+
.or(nameStartsWith("com.jinspired."))
129+
.or(nameStartsWith("org.jinspired."))
130+
.or(nameStartsWith("org.apache.log4j."))
131+
.or(nameStartsWith("org.slf4j.").and(not(named("org.slf4j.MDC"))))
132+
.or(nameContains("$JaxbAccessor"))
133+
.or(nameContains("CGLIB$$"))
124134
.or(nameContains("javassist"))
125135
.or(nameContains(".asm."))
126136
.or(nameMatches("com\\.mchange\\.v2\\.c3p0\\..*Proxy"))

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ClassLoaderMatcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private static class SkipClassLoaderMatcher
5353
classesToSkip.add("sun.reflect.DelegatingClassLoader");
5454
classesToSkip.add("jdk.internal.reflect.DelegatingClassLoader");
5555
classesToSkip.add("clojure.lang.DynamicClassLoader");
56+
classesToSkip.add("org.apache.cxf.common.util.ASMHelper$TypeHelperClassLoader");
5657
classesToSkip.add(DatadogClassLoader.class.getName());
5758
CLASSLOADER_CLASSES_TO_SKIP = Collections.unmodifiableSet(classesToSkip);
5859
}

dd-java-agent/dd-java-agent.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ dependencies {
107107
}
108108

109109
tasks.withType(Test).configureEach {
110-
jvmArgs "-Ddd.writer.type=LogWriter", "-Ddd.service.name=java-app"
111-
jvmArgs "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"
112-
jvmArgs "-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
110+
jvmArgs "-Ddd.service.name=java-agent-tests"
111+
jvmArgs "-Ddd.writer.type=LoggingWriter"
112+
// Multi-threaded logging seems to be causing deadlocks with Gradle's log capture.
113+
// jvmArgs "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"
114+
// jvmArgs "-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
113115

114116
doFirst {
115117
// Defining here to allow jacoco to be first on the command line.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import datadog.opentracing.DDSpan
2+
import datadog.opentracing.scopemanager.ContinuableScope
3+
import datadog.trace.agent.test.AgentTestRunner
4+
import datadog.trace.api.Trace
5+
import io.opentracing.util.GlobalTracer
6+
7+
import java.util.concurrent.ArrayBlockingQueue
8+
import java.util.concurrent.CompletableFuture
9+
import java.util.concurrent.ThreadPoolExecutor
10+
import java.util.concurrent.TimeUnit
11+
import java.util.function.Function
12+
import java.util.function.Supplier
13+
14+
/**
15+
* Note: ideally this should live with the rest of ExecutorInstrumentationTest,
16+
* but this code needs java8 so we put it here for now.
17+
*/
18+
class CompletableFutureTest extends AgentTestRunner {
19+
20+
def "CompletableFuture test"() {
21+
setup:
22+
def pool = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.NANOSECONDS, new ArrayBlockingQueue<Runnable>(1))
23+
def differentPool = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.NANOSECONDS, new ArrayBlockingQueue<Runnable>(1))
24+
def supplier = new Supplier<String>() {
25+
@Override
26+
@Trace(operationName = "supplier")
27+
String get() {
28+
sleep(1000)
29+
return "a"
30+
}
31+
}
32+
33+
def function = new Function<String, String>() {
34+
@Override
35+
@Trace(operationName = "function")
36+
String apply(String s) {
37+
return s + "c"
38+
}
39+
}
40+
41+
def future = new Supplier<CompletableFuture<String>>() {
42+
@Override
43+
@Trace(operationName = "parent")
44+
CompletableFuture<String> get() {
45+
((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
46+
return CompletableFuture.supplyAsync(supplier, pool)
47+
.thenCompose({ s -> CompletableFuture.supplyAsync(new AppendingSupplier(s), differentPool) })
48+
.thenApply(function)
49+
}
50+
}.get()
51+
52+
def result = future.get()
53+
54+
TEST_WRITER.waitForTraces(1)
55+
List<DDSpan> trace = TEST_WRITER.get(0)
56+
57+
expect:
58+
result == "abc"
59+
60+
TEST_WRITER.size() == 1
61+
trace.size() == 4
62+
trace.get(0).operationName == "parent"
63+
trace.get(1).operationName == "function"
64+
trace.get(1).parentId == trace.get(0).spanId
65+
trace.get(2).operationName == "appendingSupplier"
66+
trace.get(2).parentId == trace.get(0).spanId
67+
trace.get(3).operationName == "supplier"
68+
trace.get(3).parentId == trace.get(0).spanId
69+
70+
cleanup:
71+
pool?.shutdown()
72+
differentPool?.shutdown()
73+
}
74+
75+
class AppendingSupplier implements Supplier<String> {
76+
String letter
77+
78+
AppendingSupplier(String letter) {
79+
this.letter = letter
80+
}
81+
82+
@Override
83+
@Trace(operationName = "appendingSupplier")
84+
String get() {
85+
return letter + "b"
86+
}
87+
}
88+
89+
}

dd-java-agent/instrumentation/kafka-clients-0.11/src/main/java/datadog/trace/instrumentation/kafka_clients/KafkaDecorator.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
public abstract class KafkaDecorator extends ClientDecorator {
1313
public static final KafkaDecorator PRODUCER_DECORATE =
1414
new KafkaDecorator() {
15+
@Override
16+
protected String service() {
17+
return "kafka";
18+
}
19+
1520
@Override
1621
protected String spanKind() {
1722
return Tags.SPAN_KIND_PRODUCER;
@@ -25,6 +30,16 @@ protected String spanType() {
2530

2631
public static final KafkaDecorator CONSUMER_DECORATE =
2732
new KafkaDecorator() {
33+
@Override
34+
protected String service() {
35+
/*
36+
Use default service name. Common use-case here is to have consumer span parent
37+
children spans in instrumented application. Since service name is inherited it makes
38+
sense to default that to application service name rather than 'kafka'.
39+
*/
40+
return null;
41+
}
42+
2843
@Override
2944
protected String spanKind() {
3045
return Tags.SPAN_KIND_CONSUMER;
@@ -41,11 +56,6 @@ protected String[] instrumentationNames() {
4156
return new String[] {"kafka"};
4257
}
4358

44-
@Override
45-
protected String service() {
46-
return "kafka";
47-
}
48-
4959
@Override
5060
protected String component() {
5161
return "java-kafka";

0 commit comments

Comments
 (0)