未验证 提交 7d3e699e 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Adjust agent setting (#1682)

* Add ignore to bytebuddy agent.

* Fix a wrong name.

* Make sure toolkits are excluded.

* Fix CI

* Format codes.

* Remove MethodGraph compiler
上级 7c619e3c
...@@ -16,16 +16,21 @@ ...@@ -16,16 +16,21 @@
* *
*/ */
package org.apache.skywalking.apm.agent; package org.apache.skywalking.apm.agent;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.util.List; import java.util.List;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.utility.JavaModule; import net.bytebuddy.utility.JavaModule;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager; import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine;
...@@ -33,11 +38,13 @@ import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext; ...@@ -33,11 +38,13 @@ import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext;
import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap; import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.apache.skywalking.apm.agent.core.plugin.PluginException; import org.apache.skywalking.apm.agent.core.plugin.PluginException;
import org.apache.skywalking.apm.agent.core.plugin.PluginFinder; import org.apache.skywalking.apm.agent.core.plugin.PluginFinder;
import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import static net.bytebuddy.matcher.ElementMatchers.nameContains;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.not;
/** /**
* The main entrance of sky-waking agent, * The main entrance of sky-waking agent, based on javaagent mechanism.
* based on javaagent mechanism.
* *
* @author wusheng * @author wusheng
*/ */
...@@ -45,8 +52,7 @@ public class SkyWalkingAgent { ...@@ -45,8 +52,7 @@ public class SkyWalkingAgent {
private static final ILog logger = LogManager.getLogger(SkyWalkingAgent.class); private static final ILog logger = LogManager.getLogger(SkyWalkingAgent.class);
/** /**
* Main entrance. * Main entrance. Use byte-buddy transform to enhance all classes, which define in plugins.
* Use byte-buddy transform to enhance all classes, which define in plugins.
* *
* @param agentArgs * @param agentArgs
* @param instrumentation * @param instrumentation
...@@ -64,11 +70,21 @@ public class SkyWalkingAgent { ...@@ -64,11 +70,21 @@ public class SkyWalkingAgent {
return; return;
} }
new AgentBuilder.Default() final ByteBuddy byteBuddy = new ByteBuddy()
.type(pluginFinder.buildMatch()) .with(TypeValidation.of(Config.Agent.IS_OPEN_DEBUGGING_CLASS));
.transform(new Transformer(pluginFinder))
.with(new Listener()) new AgentBuilder.Default(byteBuddy)
.installOn(instrumentation); .ignore(nameStartsWith("net.bytebuddy."))
.ignore(nameStartsWith("org.slf4j."))
.ignore(nameStartsWith("org.apache.logging."))
.ignore(nameStartsWith("org.groovy."))
.ignore(nameContains("javassist"))
.ignore(nameContains(".asm."))
.ignore(allSkyWalkingAgentExcludeToolkit())
.type(pluginFinder.buildMatch())
.transform(new Transformer(pluginFinder))
.with(new Listener())
.installOn(instrumentation);
try { try {
ServiceManager.INSTANCE.boot(); ServiceManager.INSTANCE.boot();
...@@ -91,7 +107,8 @@ public class SkyWalkingAgent { ...@@ -91,7 +107,8 @@ public class SkyWalkingAgent {
} }
@Override @Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module) {
List<AbstractClassEnhancePluginDefine> pluginDefines = pluginFinder.find(typeDescription, classLoader); List<AbstractClassEnhancePluginDefine> pluginDefines = pluginFinder.find(typeDescription, classLoader);
if (pluginDefines.size() > 0) { if (pluginDefines.size() > 0) {
DynamicType.Builder<?> newBuilder = builder; DynamicType.Builder<?> newBuilder = builder;
...@@ -114,6 +131,10 @@ public class SkyWalkingAgent { ...@@ -114,6 +131,10 @@ public class SkyWalkingAgent {
} }
} }
private static ElementMatcher.Junction<NamedElement> allSkyWalkingAgentExcludeToolkit() {
return nameStartsWith("org.apache.skywalking.").and(not(nameStartsWith("org.apache.skywalking.apm.toolkit.")));
}
private static class Listener implements AgentBuilder.Listener { private static class Listener implements AgentBuilder.Listener {
@Override @Override
public void onDiscovery(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) { public void onDiscovery(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {
...@@ -122,7 +143,7 @@ public class SkyWalkingAgent { ...@@ -122,7 +143,7 @@ public class SkyWalkingAgent {
@Override @Override
public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module,
boolean loaded, DynamicType dynamicType) { boolean loaded, DynamicType dynamicType) {
if (logger.isDebugEnable()) { if (logger.isDebugEnable()) {
logger.debug("On Transformation class {}.", typeDescription.getName()); logger.debug("On Transformation class {}.", typeDescription.getName());
} }
...@@ -132,13 +153,13 @@ public class SkyWalkingAgent { ...@@ -132,13 +153,13 @@ public class SkyWalkingAgent {
@Override @Override
public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module,
boolean loaded) { boolean loaded) {
} }
@Override @Override
public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded, public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded,
Throwable throwable) { Throwable throwable) {
logger.error("Enhance class " + typeName + " error.", throwable); logger.error("Enhance class " + typeName + " error.", throwable);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册