Remove muzzle dead code, doc cleanup, and better logging
This commit is contained in:
parent
2925df8de5
commit
23d0439b12
|
@ -4,7 +4,7 @@ import org.gradle.api.Project
|
||||||
import java.lang.reflect.Method
|
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
|
* <p/>TODO: merge this with version scan
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -90,15 +90,16 @@ public interface Instrumenter {
|
||||||
JavaModule module,
|
JavaModule module,
|
||||||
Class<?> classBeingRedefined,
|
Class<?> classBeingRedefined,
|
||||||
ProtectionDomain protectionDomain) {
|
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();
|
final ReferenceMatcher muzzle = getInstrumentationMuzzle();
|
||||||
if (null != muzzle) {
|
if (null != muzzle) {
|
||||||
List<Reference.Mismatch> mismatches =
|
List<Reference.Mismatch> mismatches =
|
||||||
muzzle.getMismatchedReferenceSources(classLoader);
|
muzzle.getMismatchedReferenceSources(classLoader);
|
||||||
if (mismatches.size() > 0) {
|
if (mismatches.size() > 0) {
|
||||||
log.debug(
|
log.debug(
|
||||||
"Instrumentation muzzled: {} on {}",
|
"Instrumentation muzzled: {} -- {} on {}",
|
||||||
instrumentationPrimaryName,
|
instrumentationPrimaryName,
|
||||||
|
this.getClass().getName(),
|
||||||
classLoader);
|
classLoader);
|
||||||
}
|
}
|
||||||
for (Reference.Mismatch mismatch : mismatches) {
|
for (Reference.Mismatch mismatch : mismatches) {
|
||||||
|
@ -149,6 +150,8 @@ public interface Instrumenter {
|
||||||
return getConfigEnabled("dd.integrations.enabled", true);
|
return getConfigEnabled("dd.integrations.enabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move common config helpers to Utils
|
||||||
|
|
||||||
public static String getPropOrEnv(final String name) {
|
public static String getPropOrEnv(final String name) {
|
||||||
return System.getProperty(name, System.getenv(propToEnvName(name)));
|
return System.getProperty(name, System.getenv(propToEnvName(name)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
package datadog.trace.agent.tooling.muzzle;
|
package datadog.trace.agent.tooling.muzzle;
|
||||||
|
|
||||||
import datadog.trace.agent.tooling.Instrumenter;
|
import datadog.trace.agent.tooling.Instrumenter;
|
||||||
import net.bytebuddy.asm.AsmVisitorWrapper;
|
|
||||||
import net.bytebuddy.build.Plugin;
|
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.TypeDefinition;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.dynamic.DynamicType.Builder;
|
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. */
|
/** Bytebuddy gradle plugin which creates muzzle-references at compile time. */
|
||||||
public class MuzzleGradlePlugin implements Plugin {
|
public class MuzzleGradlePlugin implements Plugin {
|
||||||
|
@ -52,58 +43,4 @@ public class MuzzleGradlePlugin implements Plugin {
|
||||||
return builder;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
|
||||||
public String[] helperClassNames() {
|
public String[] helperClassNames() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec",
|
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec",
|
||||||
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec$HttpHeadersInjectAdapter",
|
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec$HttpHeadersInjectAdapter"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue