Remove classloaders instrumentation
This is dead code that is not used
DELETE
dd-java-agent/instrumentation/classloaders/classloaders.gradle
-apply from: "${rootDir}/gradle/java.gradle"
-
-dependencies {
- compile project(':dd-trace-ot')
- compile project(':dd-java-agent:agent-tooling')
-
- compile deps.bytebuddy
- compile deps.opentracing
- annotationProcessor deps.autoservice
- implementation deps.autoservice
-
- testCompile project(':dd-java-agent:testing')
-}

DELETE
dd-java-agent/instrumentation/classloaders/src/main/java/datadog/trace/instrumentation/classloaders/ClassLoaderInstrumentation.java
-package datadog.trace.instrumentation.classloaders;
-
-import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
-
-import com.google.auto.service.AutoService;
-import datadog.opentracing.DDTracer;
-import datadog.trace.agent.tooling.Instrumenter;
-import datadog.trace.bootstrap.CallDepthThreadLocalMap;
-import io.opentracing.util.GlobalTracer;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-import net.bytebuddy.asm.Advice;
-import net.bytebuddy.matcher.ElementMatcher;
-
-@AutoService(Instrumenter.class)
-public final class ClassLoaderInstrumentation extends Instrumenter.Default {
-
- public ClassLoaderInstrumentation() {
- super("classloader");
- }
-
- @Override
- protected boolean defaultEnabled() {
- return false;
- }
-
- @Override
- public ElementMatcher<TypeDescription> typeMatcher() {
- return safeHasSuperType(named("java.lang.ClassLoader"));
- }
-
- @Override
- public Map<ElementMatcher, String> transformers() {
- final Map<ElementMatcher, String> transformers = new HashMap<>();
- transformers.put(isConstructor(), ClassloaderAdvice.class.getName());
- return transformers;
- }
-
- public static class ClassloaderAdvice {
-
- @Advice.OnMethodEnter
- public static int constructorEnter() {
- // We use this to make sure we only apply the exit instrumentation
- // after the constructors are done calling their super constructors.
- return CallDepthThreadLocalMap.incrementCallDepth(ClassLoader.class);
- }
-
- // Not sure why, but adding suppress causes a verify error.
- @Advice.OnMethodExit // (suppress = Throwable.class)
- public static void constructorExit(
- @Advice.This final ClassLoader cl, @Advice.Enter final int depth) {
- if (depth == 0) {
- CallDepthThreadLocalMap.reset(ClassLoader.class);
-
- try {
- final Field field = GlobalTracer.class.getDeclaredField("tracer");
- field.setAccessible(true);
-
- final Object o = field.get(null);
- // FIXME: This instrumentation will never work. Referencing class DDTracer will throw an
- // exception.
- if (o instanceof DDTracer) {
- final DDTracer tracer = (DDTracer) o;
- tracer.registerClassLoader(cl);
- }
- } catch (final Throwable e) {
- }
- }
- }
- }
-}

DELETE
dd-java-agent/instrumentation/classloaders/src/test/groovy/ClassLoaderInstrumentationTest.groovy
-import datadog.opentracing.DDTracer
-import datadog.trace.agent.test.AgentTestRunner
-import datadog.trace.agent.test.TestUtils
-
-import java.security.SecureClassLoader
-
-class ClassLoaderInstrumentationTest extends AgentTestRunner {
- static {
- System.setProperty("dd.integration.classloader.enabled", "true")
- }
-
- DDTracer tracer = Mock()
-
- def setup() {
- TestUtils.registerOrReplaceGlobalTracer(tracer)
- }
-
- def "creating classloader calls register on tracer"() {
- when:
- new EmptyNonDelegatingLoader()
-
- then:
- 1 * tracer.registerClassLoader(_ as EmptyNonDelegatingLoader)
- 0 * _
- }
-
- def "creating anonymous classloader calls register on tracer"() {
- when:
- new EmptyNonDelegatingLoader() {}
-
- then:
- 1 * tracer.registerClassLoader(_ as EmptyNonDelegatingLoader)
- 0 * _
- }
-
- def "bootstrap classloaders aren't instrumented"() {
- // (Because they don't have access to GlobalTracer)
- when:
- new SecureClassLoader()
- new SecureClassLoader(null) {}
- new URLClassLoader(new URL[0], ClassLoader.systemClassLoader)
-
- then:
- 0 * tracer.registerClassLoader(_)
- 0 * _
- }
-
- class EmptyNonDelegatingLoader extends SecureClassLoader {
- EmptyNonDelegatingLoader() {
- super(null)
- }
- }
-}

Remove classloaders instrumentation

This is dead code that is not used