diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java index b024ff9f2..ce00118df 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java @@ -1,12 +1,9 @@ package com.ai.cloud.skywalking.plugin.interceptor; -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; - -import java.util.List; - +import com.ai.cloud.skywalking.plugin.PluginCfg; +import com.ai.cloud.skywalking.util.StringUtil; import net.bytebuddy.ByteBuddy; +import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; @@ -16,146 +13,131 @@ import net.bytebuddy.implementation.SuperMethodCall; import net.bytebuddy.implementation.bind.annotation.FieldProxy; import net.bytebuddy.pool.TypePool; import net.bytebuddy.pool.TypePool.Resolution; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.ai.cloud.skywalking.plugin.PluginCfg; -import com.ai.cloud.skywalking.util.StringUtil; +import java.util.List; + +import static net.bytebuddy.matcher.ElementMatchers.any; public class EnhanceClazz4Interceptor { - private static Logger logger = LogManager - .getLogger(EnhanceClazz4Interceptor.class); + private static Logger logger = LogManager + .getLogger(EnhanceClazz4Interceptor.class); - private TypePool typePool; + private TypePool typePool; - public static final String contextAttrName = "_$EnhancedClassInstanceContext"; + public static final String contextAttrName = "_$EnhancedClassInstanceContext"; - public EnhanceClazz4Interceptor() { - typePool = TypePool.Default.ofClassPath(); - } + public EnhanceClazz4Interceptor() { + typePool = TypePool.Default.ofClassPath(); + } - public void enhance() { - List interceptorClassList = PluginCfg.CFG - .getInterceptorClassList(); + public void enhance() { + List interceptorClassList = PluginCfg.CFG + .getInterceptorClassList(); - for (String interceptorClassName : interceptorClassList) { - try { - enhance0(interceptorClassName); - } catch (Throwable t) { - logger.error("enhance class [{}] for intercept failure.", - interceptorClassName, t); - } - } - } + for (String interceptorClassName : interceptorClassList) { + try { + enhance0(interceptorClassName); + } catch (Throwable t) { + logger.error("enhance class [{}] for intercept failure.", + interceptorClassName, t); + } + } + } - private void enhance0(String interceptorDefineClassName) - throws InstantiationException, IllegalAccessException, - ClassNotFoundException, EnhanceException { - logger.debug("prepare to enhance class by {}.", - interceptorDefineClassName); - InterceptorDefine define = (InterceptorDefine) Class.forName( - interceptorDefineClassName).newInstance(); + private void enhance0(String interceptorDefineClassName) + throws InstantiationException, IllegalAccessException, + ClassNotFoundException, EnhanceException { + logger.debug("prepare to enhance class by {}.", + interceptorDefineClassName); + InterceptorDefine define = (InterceptorDefine) Class.forName( + interceptorDefineClassName).newInstance(); - String enhanceOriginClassName = define.getBeInterceptedClassName(); - if(StringUtil.isEmpty(enhanceOriginClassName)){ - logger.warn("classname of being intercepted is not defined by {}.", - interceptorDefineClassName); - return; - } + String enhanceOriginClassName = define.getBeInterceptedClassName(); + if (StringUtil.isEmpty(enhanceOriginClassName)) { + logger.warn("classname of being intercepted is not defined by {}.", + interceptorDefineClassName); + return; + } - logger.debug("prepare to enhance class {} by {}.", - enhanceOriginClassName, interceptorDefineClassName); - - Resolution resolution = typePool.describe(enhanceOriginClassName); - if(!resolution.isResolved()){ - logger.warn("class {} can't be resolved, enhance by {} failue.", - enhanceOriginClassName, interceptorDefineClassName); - return; - } - - /** - * rename origin class
- * add '$$Origin' at the end of be enhanced classname
- * such as: class com.ai.cloud.TestClass to class - * com.ai.cloud.TestClass$$Origin - */ - String renameClassName = enhanceOriginClassName + "$$Origin"; - Class originClass = new ByteBuddy() - .redefine(resolution.resolve(), - ClassFileLocator.ForClassLoader.ofClassPath()) - .name(renameClassName) - .make() - .load(ClassLoader.getSystemClassLoader(), - ClassLoadingStrategy.Default.INJECTION).getLoaded(); + logger.debug("prepare to enhance class {} by {}.", + enhanceOriginClassName, interceptorDefineClassName); - /** - * create a new class using origin classname.
- * - * new class need:
- * 1.add field '_$EnhancedClassInstanceContext' of type - * EnhancedClassInstanceContext
- * - * 2.intercept constructor by default, and intercept method which it's - * required by interceptorDefineClass.
- */ - IAroundInterceptor interceptor = define.instance(); - if(interceptor == null){ - throw new EnhanceException("no IAroundInterceptor instance. "); - } + Resolution resolution = typePool.describe(enhanceOriginClassName); + if (!resolution.isResolved()) { + logger.warn("class {} can't be resolved, enhance by {} failue.", + enhanceOriginClassName, interceptorDefineClassName); + return; + } - DynamicType.Builder newClassBuilder = new ByteBuddy().subclass( - originClass, ConstructorStrategy.Default.IMITATE_SUPER_CLASS); - newClassBuilder = newClassBuilder - .defineField(contextAttrName, - EnhancedClassInstanceContext.class) - .constructor(any()) - .intercept( - SuperMethodCall.INSTANCE.andThen(MethodDelegation.to( - new ClassConstructorInterceptor(interceptor)) - .appendParameterBinder( - FieldProxy.Binder.install( - FieldGetter.class, - FieldSetter.class)))); + /** + * rename origin class
+ * add '$$Origin' at the end of be enhanced classname
+ * such as: class com.ai.cloud.TestClass to class + * com.ai.cloud.TestClass$$Origin + */ + String renameClassName = enhanceOriginClassName + "$$Origin"; + Class originClass = new ByteBuddy() + .redefine(resolution.resolve(), + ClassFileLocator.ForClassLoader.ofClassPath()) + .name(renameClassName) + .make() + .load(ClassLoader.getSystemClassLoader(), + ClassLoadingStrategy.Default.INJECTION).getLoaded(); - InterceptPoint[] methodNameList = define.getBeInterceptedMethods(); - ClassMethodInterceptor classMethodInterceptor = new ClassMethodInterceptor( - interceptor); - - for (InterceptPoint method : methodNameList) { - logger.debug("prepare to enhance class {} method [{}] ", - enhanceOriginClassName, method.getMethodName()); - if (method.getArgTypeArray() != null) { - newClassBuilder = newClassBuilder.method( - named(method.getMethodName()).and( - takesArguments(method.getArgTypeArray()))).intercept( - MethodDelegation.to(classMethodInterceptor)); - } else if (method.getArgNum() > -1) { - newClassBuilder = newClassBuilder.method( - named(method.getMethodName()).and( - takesArguments(method.getArgNum()))).intercept( - MethodDelegation.to(classMethodInterceptor)); - } else if("*".equals(method.getMethodName())){ - newClassBuilder = newClassBuilder.method(any()).intercept( - MethodDelegation.to(classMethodInterceptor)); - } else { - newClassBuilder = newClassBuilder.method( - named(method.getMethodName())).intercept( - MethodDelegation.to(classMethodInterceptor)); - } - } + /** + * create a new class using origin classname.
+ * + * new class need:
+ * 1.add field '_$EnhancedClassInstanceContext' of type + * EnhancedClassInstanceContext
+ * + * 2.intercept constructor by default, and intercept method which it's + * required by interceptorDefineClass.
+ */ + IAroundInterceptor interceptor = define.instance(); + if (interceptor == null) { + throw new EnhanceException("no IAroundInterceptor instance. "); + } - /** - * naming class as origin class name, make and load class to - * classloader. - */ - newClassBuilder - .name(enhanceOriginClassName) - .make() - .load(ClassLoader.getSystemClassLoader(), - ClassLoadingStrategy.Default.INJECTION).getLoaded(); + DynamicType.Builder newClassBuilder = new ByteBuddy().subclass( + originClass, ConstructorStrategy.Default.IMITATE_SUPER_CLASS); + newClassBuilder = newClassBuilder + .defineField(contextAttrName, + EnhancedClassInstanceContext.class) + .constructor(any()) + .intercept( + SuperMethodCall.INSTANCE.andThen(MethodDelegation.to( + new ClassConstructorInterceptor(interceptor)) + .appendParameterBinder( + FieldProxy.Binder.install( + FieldGetter.class, + FieldSetter.class)))); - logger.debug("enhance class {} by {} completely.", - enhanceOriginClassName, interceptorDefineClassName); - } + MethodNameMatcher[] methodNameList = define.getBeInterceptedMethods(); + ClassMethodInterceptor classMethodInterceptor = new ClassMethodInterceptor( + interceptor); + + for (MethodNameMatcher method : methodNameList) { + logger.debug("prepare to enhance class {} method [{}] ", + enhanceOriginClassName, method.getMethodMatchDescribe()); + newClassBuilder = newClassBuilder.method( + method.builderMatcher()).intercept( + MethodDelegation.to(classMethodInterceptor)); + } + + /** + * naming class as origin class name, make and load class to + * classloader. + */ + newClassBuilder + .name(enhanceOriginClassName) + .make() + .load(ClassLoader.getSystemClassLoader(), + ClassLoadingStrategy.Default.INJECTION).getLoaded(); + + logger.debug("enhance class {} by {} completely.", + enhanceOriginClassName, interceptorDefineClassName); + } } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorDefine.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorDefine.java index 0953c50d3..69e5d6fab 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorDefine.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorDefine.java @@ -13,7 +13,7 @@ public interface InterceptorDefine { * * @return */ - public InterceptPoint[] getBeInterceptedMethods(); + public MethodNameMatcher[] getBeInterceptedMethods(); /** * 返回增强拦截器的实现
diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodNameMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodNameMatcher.java new file mode 100644 index 000000000..42bd86e6c --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodNameMatcher.java @@ -0,0 +1,40 @@ +package com.ai.cloud.skywalking.plugin.interceptor; + +import net.bytebuddy.matcher.ElementMatcher; + +public abstract class MethodNameMatcher { + + private String methodMatchDescribe; + + private int argNum = -1; + + private Class[] argTypeArray; + + public MethodNameMatcher(String methodMatchDescribe) { + this.methodMatchDescribe = methodMatchDescribe; + } + + public MethodNameMatcher(String methodMatchDescribe, int argNum) { + this.methodMatchDescribe = methodMatchDescribe; + this.argNum = argNum; + } + + public MethodNameMatcher(String methodMatchDescribe, Class[] argTypeArray) { + this.argTypeArray = argTypeArray; + this.methodMatchDescribe = methodMatchDescribe; + } + + public abstract ElementMatcher builderMatcher(); + + protected String getMethodMatchDescribe() { + return methodMatchDescribe; + } + + protected int getArgNum() { + return argNum; + } + + protected Class[] getArgTypeArray() { + return argTypeArray; + } +} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodMatcher.java new file mode 100644 index 000000000..741125c47 --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodMatcher.java @@ -0,0 +1,18 @@ +package com.ai.cloud.skywalking.plugin.interceptor.matcher; + +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.any; + +public class AnyMethodMatcher extends MethodNameMatcher { + + public AnyMethodMatcher() { + super("*"); + } + + @Override + public ElementMatcher builderMatcher() { + return any(); + } +} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusionNameMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusionNameMatcher.java new file mode 100644 index 000000000..487fa4a06 --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusionNameMatcher.java @@ -0,0 +1,36 @@ +package com.ai.cloud.skywalking.plugin.interceptor.matcher; + +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.*; + +public class ExclusionNameMatcher extends MethodNameMatcher { + + public ExclusionNameMatcher(String methodMatchDescribe) { + super(methodMatchDescribe); + } + + public ExclusionNameMatcher(String methodMatchDescribe, int argNum) { + super(methodMatchDescribe, argNum); + } + + public ExclusionNameMatcher(String methodMatchDescribe, Class[] argTypeArray) { + super(methodMatchDescribe, argTypeArray); + } + + @Override + public ElementMatcher builderMatcher() { + ElementMatcher.Junction matcher = not(named(getMethodMatchDescribe())); + + if (getArgTypeArray() != null) { + matcher.and(takesArguments(getArgTypeArray())); + } + + if (getArgNum() > -1) { + matcher.and(takesArguments(getArgNum())); + } + + return matcher; + } +} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/FullNameMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/FullNameMatcher.java new file mode 100644 index 000000000..80324b474 --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/FullNameMatcher.java @@ -0,0 +1,37 @@ +package com.ai.cloud.skywalking.plugin.interceptor.matcher; + +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +public class FullNameMatcher extends MethodNameMatcher { + + public FullNameMatcher(String methodName) { + super(methodName); + } + + public FullNameMatcher(String methodName, int argNum) { + super(methodName, argNum); + } + + public FullNameMatcher(String methodName, Class... args) { + super(methodName, args); + } + + @Override + public ElementMatcher builderMatcher() { + ElementMatcher.Junction matcher = named(getMethodMatchDescribe()); + + if (getArgTypeArray() != null) { + matcher.and(takesArguments(getArgTypeArray())); + } + + if (getArgNum() > -1) { + matcher.and(takesArguments(getArgNum())); + } + + return matcher; + } +} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/RegexNameMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/RegexNameMatcher.java new file mode 100644 index 000000000..1cba7b2ad --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/RegexNameMatcher.java @@ -0,0 +1,37 @@ +package com.ai.cloud.skywalking.plugin.interceptor.matcher; + +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.nameMatches; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +public class RegexNameMatcher extends MethodNameMatcher { + + public RegexNameMatcher(String methodMatchDescribe) { + super(methodMatchDescribe); + } + + public RegexNameMatcher(String methodMatchDescribe, int argNum) { + super(methodMatchDescribe, argNum); + } + + public RegexNameMatcher(String methodMatchDescribe, Class[] argTypeArray) { + super(methodMatchDescribe, argTypeArray); + } + + @Override + public ElementMatcher builderMatcher() { + ElementMatcher.Junction matcher = nameMatches(getMethodMatchDescribe()); + + if (getArgTypeArray() != null) { + matcher.and(takesArguments(getArgTypeArray())); + } + + if (getArgNum() > -1) { + matcher.and(takesArguments(getArgNum())); + } + + return matcher; + } +} diff --git a/skywalking-api/src/test/java/test/ai/cloud/plugin/TestInterceptorDefine.java b/skywalking-api/src/test/java/test/ai/cloud/plugin/TestInterceptorDefine.java index 14b863daa..97f71e731 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/plugin/TestInterceptorDefine.java +++ b/skywalking-api/src/test/java/test/ai/cloud/plugin/TestInterceptorDefine.java @@ -3,6 +3,8 @@ package test.ai.cloud.plugin; import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor; import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher; public class TestInterceptorDefine implements InterceptorDefine { @@ -12,8 +14,8 @@ public class TestInterceptorDefine implements InterceptorDefine { } @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[] { new InterceptPoint("printabc") }; + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[] { new FullNameMatcher("printabc") }; } @Override diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java b/skywalking-sdk-plugin/httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java index 6f46e7cf6..c0d71738d 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java @@ -1,5 +1,6 @@ package org.skywalking.httpClient.v4.plugin.dubbox.rest.attachment; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; import org.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor; import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor; @@ -20,7 +21,7 @@ public class DubboxRestHeadSetterAttachment implements InterceptorDefine { } @Override - public InterceptPoint[] getBeInterceptedMethods() { + public MethodNameMatcher[] getBeInterceptedMethods() { return null; } diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java index 42fca394d..f9c09b1da 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java @@ -1,6 +1,8 @@ package org.skywalking.httpClient.v4.plugin.define; import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher; public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { @@ -16,8 +18,8 @@ public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { * */ @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[] { - new InterceptPoint("doExecute")}; + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[] { + new FullNameMatcher("doExecute")}; } } diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java index b80c7f309..953383cd2 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java @@ -1,6 +1,8 @@ package org.skywalking.httpClient.v4.plugin.define; import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher; public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine { /** @@ -14,9 +16,9 @@ public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine { } @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[] { - new InterceptPoint("execute")}; + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[] { + new FullNameMatcher("execute")}; } } diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java index 8ad3a754d..5b296e962 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java @@ -1,16 +1,17 @@ package org.skywalking.httpClient.v4.plugin.define; -import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher; public class InternalHttpClientPluginDefine extends HttpClientPluginDefine { - @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[]{new InterceptPoint("doExecute")}; - } - - @Override - public String getBeInterceptedClassName() { - return "org.apache.http.impl.client.InternalHttpClient"; - } + @Override + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[]{new FullNameMatcher("doExecute")}; + } + + @Override + public String getBeInterceptedClassName() { + return "org.apache.http.impl.client.InternalHttpClient"; + } } diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java index 32479cb38..1b91130ab 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java @@ -1,16 +1,17 @@ package org.skywalking.httpClient.v4.plugin.define; -import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher; public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine { - @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[]{new InterceptPoint("doExecute")}; - } - - @Override - public String getBeInterceptedClassName() { - return "org.apache.http.impl.client.MinimalHttpClient"; - } + @Override + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[]{new FullNameMatcher("doExecute")}; + } + + @Override + public String getBeInterceptedClassName() { + return "org.apache.http.impl.client.MinimalHttpClient"; + } } diff --git a/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/jedis/v2/plugin/define/JedisPluginDefine.java b/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/jedis/v2/plugin/define/JedisPluginDefine.java index 7c54cad3b..821d3331e 100644 --- a/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/jedis/v2/plugin/define/JedisPluginDefine.java +++ b/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/jedis/v2/plugin/define/JedisPluginDefine.java @@ -1,26 +1,29 @@ package org.skywalking.jedis.v2.plugin.define; -import org.skywalking.jedis.v2.plugin.JedisInterceptor; - import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor; import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.ExclusionNameMatcher; +import org.skywalking.jedis.v2.plugin.JedisInterceptor; public class JedisPluginDefine implements InterceptorDefine { - @Override - public String getBeInterceptedClassName() { - return "redis.clients.jedis.Jedis"; - } + @Override + public String getBeInterceptedClassName() { + return "redis.clients.jedis.Jedis"; + } - @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[] { new InterceptPoint("*") }; - } + @Override + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[]{ + new ExclusionNameMatcher("set"), + }; + } - @Override - public IAroundInterceptor instance() { - return new JedisInterceptor(); - } + @Override + public IAroundInterceptor instance() { + return new JedisInterceptor(); + } } diff --git a/skywalking-sdk-plugin/mysql-plugin/src/main/java/com/ai/cloud/skywalking/plugin/mysql/ConnectionPluginDefine.java b/skywalking-sdk-plugin/mysql-plugin/src/main/java/com/ai/cloud/skywalking/plugin/mysql/ConnectionPluginDefine.java index e03561f57..12cc2a36f 100644 --- a/skywalking-sdk-plugin/mysql-plugin/src/main/java/com/ai/cloud/skywalking/plugin/mysql/ConnectionPluginDefine.java +++ b/skywalking-sdk-plugin/mysql-plugin/src/main/java/com/ai/cloud/skywalking/plugin/mysql/ConnectionPluginDefine.java @@ -3,6 +3,8 @@ package com.ai.cloud.skywalking.plugin.mysql; import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor; import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine; +import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher; +import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher; public class ConnectionPluginDefine implements InterceptorDefine { @@ -12,12 +14,12 @@ public class ConnectionPluginDefine implements InterceptorDefine { } @Override - public InterceptPoint[] getBeInterceptedMethods() { - return new InterceptPoint[] { new InterceptPoint("createStatement", 2), - new InterceptPoint("prepareStatement", 3), - new InterceptPoint("prepareCall", 3), - new InterceptPoint("commit"), new InterceptPoint("rollback"), - new InterceptPoint("close") }; + public MethodNameMatcher[] getBeInterceptedMethods() { + return new MethodNameMatcher[] { new FullNameMatcher("createStatement", 2), + new FullNameMatcher("prepareStatement", 3), + new FullNameMatcher("prepareCall", 3), + new FullNameMatcher("commit"), new FullNameMatcher("rollback"), + new FullNameMatcher("close") }; } @Override