Remove muzzle dead code, doc cleanup, and better logging
MODIFY
buildSrc/src/main/groovy/MuzzlePlugin.groovy
buildSrc/src/main/groovy/MuzzlePlugin.groovy
@@ -4,7 +4,7 @@ import org.gradle.api.Project
import java.lang.reflect.Method
/**
- * POC muzzle task plugin which runs muzzle validation against an instrumentation's compile-time dependencies.
+ * muzzle task plugin which runs muzzle validation against an instrumentation's compile-time dependencies.
*
* <p/>TODO: merge this with version scan
*/

MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java
@@ -90,15 +90,16 @@ public interface Instrumenter {
JavaModule module,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain) {
- // Optimization: calling getMuzzleReferenceMatcher() inside this method prevents unnecessary loading of muzzle references during agentBuilder setup.
+ // Optimization: calling getInstrumentationMuzzle() inside this method prevents unnecessary loading of muzzle references during agentBuilder setup.
final ReferenceMatcher muzzle = getInstrumentationMuzzle();
if (null != muzzle) {
List<Reference.Mismatch> mismatches =
muzzle.getMismatchedReferenceSources(classLoader);
if (mismatches.size() > 0) {
log.debug(
- "Instrumentation muzzled: {} on {}",
+ "Instrumentation muzzled: {} -- {} on {}",
instrumentationPrimaryName,
+ this.getClass().getName(),
classLoader);
}
for (Reference.Mismatch mismatch : mismatches) {
@@ -149,6 +150,8 @@ public interface Instrumenter {
return getConfigEnabled("dd.integrations.enabled", true);
}
+ // TODO: move common config helpers to Utils
+
public static String getPropOrEnv(final String name) {
return System.getProperty(name, System.getenv(propToEnvName(name)));
}

MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/MuzzleGradlePlugin.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/MuzzleGradlePlugin.java
package datadog.trace.agent.tooling.muzzle;
import datadog.trace.agent.tooling.Instrumenter;
-import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.build.Plugin;
-import net.bytebuddy.description.field.FieldDescription;
-import net.bytebuddy.description.field.FieldList;
-import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType.Builder;
-import net.bytebuddy.implementation.Implementation;
-import net.bytebuddy.jar.asm.ClassVisitor;
-import net.bytebuddy.jar.asm.MethodVisitor;
-import net.bytebuddy.jar.asm.Opcodes;
-import net.bytebuddy.pool.TypePool;
/** Bytebuddy gradle plugin which creates muzzle-references at compile time. */
public class MuzzleGradlePlugin implements Plugin {
@@ -52,58 +43,4 @@ public class MuzzleGradlePlugin implements Plugin {
return builder;
}
}
-
- private static class RemoveFinalFlagVisitor implements AsmVisitorWrapper {
- final String methodName;
-
- public RemoveFinalFlagVisitor(String methodName) {
- this.methodName = methodName;
- }
-
- @Override
- public int mergeWriter(int flags) {
- return flags;
- }
-
- @Override
- public int mergeReader(int flags) {
- return flags;
- }
-
- @Override
- public ClassVisitor wrap(
- TypeDescription instrumentedType,
- ClassVisitor classVisitor,
- Implementation.Context implementationContext,
- TypePool typePool,
- FieldList<FieldDescription.InDefinedShape> fields,
- MethodList<?> methods,
- int writerFlags,
- int readerFlags) {
- return new Visitor(classVisitor);
- }
-
- private class Visitor extends ClassVisitor {
- public Visitor(ClassVisitor cv) {
- super(Opcodes.ASM6, cv);
- }
-
- @Override
- public MethodVisitor visitMethod(
- final int access,
- final String name,
- final String descriptor,
- final String signature,
- final String[] exceptions) {
- MethodVisitor methodVisitor =
- super.visitMethod(access, name, descriptor, signature, exceptions);
- if (name.equals(methodName) && (access & Opcodes.ACC_FINAL) != 0) {
- return super.visitMethod(
- access ^ Opcodes.ACC_FINAL, name, descriptor, signature, exceptions);
- } else {
- return super.visitMethod(access, name, descriptor, signature, exceptions);
- }
- }
- }
- }
}

MODIFY
dd-java-agent/instrumentation/apache-httpclient-4.3/src/main/java/datadog/trace/instrumentation/apachehttpclient/ApacheHttpClientInstrumentation.java
dd-java-agent/instrumentation/apache-httpclient-4.3/src/main/java/datadog/trace/instrumentation/apachehttpclient/ApacheHttpClientInstrumentation.java
@@ -45,7 +45,7 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
public String[] helperClassNames() {
return new String[] {
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec",
- "datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec$HttpHeadersInjectAdapter",
+ "datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec$HttpHeadersInjectAdapter"
};
}

Remove muzzle dead code, doc cleanup, and better logging