Bootstrap delegation for wildfly/jboss
ADD
dd-java-agent/instrumentation/jboss-classloading/jboss-classloading.gradle
+apply from: "${rootDir}/gradle/java.gradle"
+
+dependencies {
+ compile project(':dd-java-agent:agent-tooling')
+ compile deps.bytebuddy
+ compile deps.autoservice
+
+ testCompile group: 'org.jboss.modules', name: 'jboss-modules', version: '1.3.10.Final'
+ testCompile project(':dd-java-agent:testing')
+}

ADD
dd-java-agent/instrumentation/jboss-classloading/src/main/java/datadog/trace/instrumentation/jboss/JBossClassloadingInstrumentation.java
+package datadog.trace.instrumentation.jboss;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+import com.google.auto.service.AutoService;
+import datadog.trace.agent.tooling.Instrumenter;
+import net.bytebuddy.agent.builder.AgentBuilder;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.dynamic.DynamicType;
+import net.bytebuddy.utility.JavaModule;
+
+@AutoService(Instrumenter.class)
+public final class JBossClassloadingInstrumentation extends Instrumenter.Configurable {
+ private static final String[] BOOTSTRAP_PACKAGE_PREFIXES = {
+ "io.opentracing", "datadog.slf4j", "datadog.trace"
+ };
+
+ public JBossClassloadingInstrumentation() {
+ super("jboss-classloading");
+ }
+
+ @Override
+ public AgentBuilder apply(final AgentBuilder agentBuilder) {
+ return agentBuilder
+ // Jboss Module class loads the sys prop which defines bootstrap classes
+ .type(named("org.jboss.modules.Module"))
+ .transform(
+ new AgentBuilder.Transformer() {
+ @Override
+ public DynamicType.Builder<?> transform(
+ DynamicType.Builder<?> builder,
+ TypeDescription typeDescription,
+ ClassLoader classLoader,
+ JavaModule javaModule) {
+ // This instrumentation modifies no bytes.
+ // Instead it sets a system prop to tell jboss to delegate
+ // classloads for datadog bootstrap classes
+ StringBuilder ddPrefixes = new StringBuilder("");
+ for (int i = 0; i < BOOTSTRAP_PACKAGE_PREFIXES.length; ++i) {
+ if (i > 0) {
+ ddPrefixes.append(",");
+ }
+ ddPrefixes.append(BOOTSTRAP_PACKAGE_PREFIXES[i]);
+ }
+ final String existing = System.getProperty("jboss.modules.system.pkgs");
+ if (null == existing) {
+ System.setProperty("jboss.modules.system.pkgs", ddPrefixes.toString());
+ } else if (!existing.contains(ddPrefixes)) {
+ System.setProperty(
+ "jboss.modules.system.pkgs", existing + "," + ddPrefixes.toString());
+ }
+ return builder;
+ }
+ })
+ .asDecorator();
+ }
+}

ADD
dd-java-agent/instrumentation/jboss-classloading/src/test/groovy/JBossClassloadingTest.groovy
+import datadog.trace.agent.test.AgentTestRunner
+
+class JBossClassloadingTest extends AgentTestRunner {
+ def "delegation property set on module load"() {
+ setup:
+ org.jboss.modules.Module.getName()
+
+ expect:
+ System.getProperty("jboss.modules.system.pkgs") == "io.opentracing,datadog.slf4j,datadog.trace"
+ }
+}

MODIFY
settings.gradle
settings.gradle
@@ -14,6 +14,7 @@ include ':dd-java-agent:instrumentation:apache-httpclient-4.3'
include ':dd-java-agent:instrumentation:aws-sdk'
include ':dd-java-agent:instrumentation:datastax-cassandra-3.2'
include ':dd-java-agent:instrumentation:jax-rs'
+include ':dd-java-agent:instrumentation:jboss-classloading'
include ':dd-java-agent:instrumentation:jdbc'
include ':dd-java-agent:instrumentation:jms-1'
include ':dd-java-agent:instrumentation:jms-2'

Bootstrap delegation for wildfly/jboss