diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/AllObjectDefaultMethodsMatch.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/AllObjectDefaultMethodsMatch.java new file mode 100644 index 000000000..da1cd1c05 --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/AllObjectDefaultMethodsMatch.java @@ -0,0 +1,46 @@ +package com.a.eye.skywalking.plugin.bytebuddy; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import net.bytebuddy.matcher.ElementMatchers; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * match all methods, which inherits from {@link Object} + *

+ * Created by wusheng on 2017/1/3. + */ +public enum AllObjectDefaultMethodsMatch implements ElementMatcher { + INSTANCE; + + private ElementMatcher.Junction matcher; + + AllObjectDefaultMethodsMatch() { + ElementMatcher.Junction[] allDefaultMethods = new ElementMatcher.Junction[] {named("finalize").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("wait").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("wait").and(takesArguments(long.class, int.class)).and(ElementMatchers.isPublic()), + named("wait").and(takesArguments(long.class)).and(ElementMatchers.isPublic()), + named("equals").and(takesArguments(Object.class)).and(ElementMatchers.isPublic()), + named("toString").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("hashCode").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("getClass").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("clone").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("notify").and(takesArguments(0)).and(ElementMatchers.isPublic()), + named("notifyAll").and(takesArguments(0)).and(ElementMatchers.isPublic())}; + + for (int i = 0; i < allDefaultMethods.length; i++) { + if(i == 0){ + matcher = allDefaultMethods[i]; + }else{ + matcher.or(allDefaultMethods[i]); + } + } + } + + @Override + public boolean matches(MethodDescription target) { + return matcher.matches(target); + } +} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/ArgumentTypeNameMatch.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/ArgumentTypeNameMatch.java index 8106f5437..a80a2610c 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/ArgumentTypeNameMatch.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/bytebuddy/ArgumentTypeNameMatch.java @@ -11,7 +11,7 @@ public class ArgumentTypeNameMatch implements ElementMatcher private String argumentTypeName; - public ArgumentTypeNameMatch(int index, String argumentTypeName) { + private ArgumentTypeNameMatch(int index, String argumentTypeName) { this.index = index; this.argumentTypeName = argumentTypeName; } @@ -24,4 +24,8 @@ public class ArgumentTypeNameMatch implements ElementMatcher return false; } + + public static ElementMatcher takesArgumentWithType(int index, String argumentTypeName){ + return new ArgumentTypeNameMatch(index, argumentTypeName); + } } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/InstanceMethodsInterceptPoint.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/InstanceMethodsInterceptPoint.java index 48e1609f5..faa640e6e 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/InstanceMethodsInterceptPoint.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/InstanceMethodsInterceptPoint.java @@ -1,5 +1,8 @@ package com.a.eye.skywalking.plugin.interceptor; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + /** * Created by wusheng on 2016/11/29. */ @@ -9,7 +12,7 @@ public interface InstanceMethodsInterceptPoint { * * @return */ - MethodMatcher[] getMethodsMatchers(); + ElementMatcher getMethodsMatcher(); /** * diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/MethodMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/MethodMatcher.java deleted file mode 100644 index 765fb899f..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/MethodMatcher.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.*; - -public abstract class MethodMatcher { - - private String methodMatchDescribe; - - private int argNum = -1; - - private Class[] argTypeArray; - - private Modifier modifier; - - public MethodMatcher(String methodMatchDescribe) { - this(null, methodMatchDescribe); - } - - public MethodMatcher(Modifier modifier, String methodMatchDescribe) { - this.methodMatchDescribe = methodMatchDescribe; - this.modifier = modifier; - } - - - public MethodMatcher(String methodMatchDescribe, int argNum) { - this(null, methodMatchDescribe, argNum); - } - - public MethodMatcher(Modifier modifier, String methodMatchDescribe, int argNum) { - this.methodMatchDescribe = methodMatchDescribe; - this.argNum = argNum; - this.modifier = modifier; - } - - public MethodMatcher(String methodMatchDescribe, Class[] argTypeArray) { - this(null, methodMatchDescribe, argTypeArray); - } - - public MethodMatcher(Modifier modifier, String methodMatchDescribe, Class[] argTypeArray) { - this.argTypeArray = argTypeArray; - this.methodMatchDescribe = methodMatchDescribe; - this.modifier = modifier; - } - - public abstract ElementMatcher.Junction buildMatcher(); - - protected String getMethodMatchDescribe() { - return methodMatchDescribe; - } - - protected ElementMatcher.Junction mergeArgumentsIfNecessary(ElementMatcher.Junction matcher) { - if (argTypeArray != null) { - matcher = matcher.and(takesArguments(argTypeArray)); - } - - if (argNum > -1) { - matcher = matcher.and(takesArguments(argNum)); - } - - if (modifier != null) { - matcher = matcher.and(modifier.elementMatcher()); - } - - return matcher; - } - - public enum Modifier { - Public, Default, Private, Protected; - - private ElementMatcher.Junction elementMatcher() { - switch (this) { - case Private: { - return isPrivate(); - } - case Default: { - return isPackagePrivate(); - } - case Public: { - return isPublic(); - } - case Protected: { - return isProtected(); - } - default: - return isPublic(); - } - } - } - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder("method name=" + getMethodMatchDescribe()); - if (getModifier() != null) { - stringBuilder.insert(0, getModifier() + " "); - } - - if (getArgNum() > -1) { - stringBuilder.append(", argnum=" + getArgNum()); - } - - if (getArgTypeArray() != null) { - stringBuilder.append(", types of arguments are "); - boolean isFirst = true; - for (Class argType : getArgTypeArray()) { - if(isFirst){ - isFirst = false; - }else{ - stringBuilder.append(","); - } - stringBuilder.append(argType.getName()); - } - } - return stringBuilder.toString(); - } - - protected int getArgNum() { - return argNum; - } - - protected Class[] getArgTypeArray() { - return argTypeArray; - } - - protected Modifier getModifier() { - return modifier; - } -} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/StaticMethodsInterceptPoint.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/StaticMethodsInterceptPoint.java index e7b46d39e..0685c9946 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/StaticMethodsInterceptPoint.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/StaticMethodsInterceptPoint.java @@ -1,5 +1,8 @@ package com.a.eye.skywalking.plugin.interceptor; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + /** * Created by wusheng on 2016/11/29. */ @@ -9,7 +12,7 @@ public interface StaticMethodsInterceptPoint { * * @return */ - MethodMatcher[] getMethodsMatchers(); + ElementMatcher getMethodsMatcher(); /** * diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/enhance/ClassEnhancePluginDefine.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/enhance/ClassEnhancePluginDefine.java index ebeaee623..7250b57c1 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/enhance/ClassEnhancePluginDefine.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/enhance/ClassEnhancePluginDefine.java @@ -11,10 +11,10 @@ import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.implementation.MethodDelegation; import net.bytebuddy.implementation.SuperMethodCall; import net.bytebuddy.implementation.bind.annotation.FieldProxy; -import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatchers; import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE; +import static net.bytebuddy.matcher.ElementMatchers.isStatic; import static net.bytebuddy.matcher.ElementMatchers.not; public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePluginDefine { @@ -88,35 +88,13 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi String interceptor = instanceMethodsInterceptPoint.getMethodsInterceptor(); if (StringUtil.isEmpty(interceptor)) { - throw new EnhanceException("no InstanceMethodsAroundInterceptor define. "); + throw new EnhanceException("no InstanceMethodsAroundInterceptor define to enhance class " + enhanceOriginClassName); } ClassInstanceMethodsInterceptor classMethodInterceptor = new ClassInstanceMethodsInterceptor(interceptor); - MethodMatcher[] methodMatchers = instanceMethodsInterceptPoint.getMethodsMatchers(); - - StringBuilder enhanceRules = new StringBuilder("\nprepare to enhance class [" + enhanceOriginClassName + "] instance methods as following rules:\n"); - int ruleIdx = 1; - for (MethodMatcher methodMatcher : methodMatchers) { - enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n"); - } - logger.debug(enhanceRules.toString()); - ElementMatcher.Junction matcher = null; - for (MethodMatcher methodMatcher : methodMatchers) { - logger.debug("enhance class {} instance methods by rule: {}", enhanceOriginClassName, methodMatcher); - if (matcher == null) { - matcher = methodMatcher.buildMatcher(); - continue; - } - - matcher = matcher.or(methodMatcher.buildMatcher()); - - } - - /** - * exclude static methods. - */ - matcher = matcher.and(not(ElementMatchers.isStatic())); - newClassBuilder = newClassBuilder.method(matcher).intercept(MethodDelegation.to(classMethodInterceptor)); + newClassBuilder = newClassBuilder + .method(not(isStatic()).and(instanceMethodsInterceptPoint.getMethodsMatcher())) + .intercept(MethodDelegation.to(classMethodInterceptor)); } } @@ -136,38 +114,16 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi } for (StaticMethodsInterceptPoint staticMethodsInterceptPoint : staticMethodsInterceptPoints) { - MethodMatcher[] methodMatchers = staticMethodsInterceptPoint.getMethodsMatchers(); - String interceptor = staticMethodsInterceptPoint.getMethodsInterceptor(); if (StringUtil.isEmpty(interceptor)) { - throw new EnhanceException("no StaticMethodsAroundInterceptor define. "); + throw new EnhanceException("no StaticMethodsAroundInterceptor define to enhance class " + enhanceOriginClassName); } ClassStaticMethodsInterceptor classMethodInterceptor = new ClassStaticMethodsInterceptor(interceptor); - StringBuilder enhanceRules = new StringBuilder("\nprepare to enhance class [" + enhanceOriginClassName + "] static methods as following rules:\n"); - int ruleIdx = 1; - for (MethodMatcher methodMatcher : methodMatchers) { - enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n"); - } - logger.debug(enhanceRules.toString()); - ElementMatcher.Junction matcher = null; - for (MethodMatcher methodMatcher : methodMatchers) { - logger.debug("enhance class {} static methods by rule: {}", enhanceOriginClassName, methodMatcher); - if (matcher == null) { - matcher = methodMatcher.buildMatcher(); - continue; - } - - matcher = matcher.or(methodMatcher.buildMatcher()); - - } - - /** - * restrict static methods. - */ - matcher = matcher.and(ElementMatchers.isStatic()); - newClassBuilder = newClassBuilder.method(matcher).intercept(MethodDelegation.to(classMethodInterceptor)); + newClassBuilder = newClassBuilder + .method(isStatic().and(staticMethodsInterceptPoint.getMethodsMatcher())) + .intercept(MethodDelegation.to(classMethodInterceptor)); } return newClassBuilder; diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/AnyMethodsMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/AnyMethodsMatcher.java deleted file mode 100644 index 4c19620e2..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/AnyMethodsMatcher.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor.matcher; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.any; - -public class AnyMethodsMatcher extends ExclusiveObjectDefaultMethodsMatcher { - - public AnyMethodsMatcher() { - super("any method"); - } - - @Override - public ElementMatcher.Junction match() { - return any(); - } - - @Override - public String toString() { - return getMethodMatchDescribe(); - } -} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodsMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodsMatcher.java deleted file mode 100644 index 43d010887..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodsMatcher.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor.matcher; - -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.not; - -public abstract class ExclusiveObjectDefaultMethodsMatcher extends MethodMatcher { - - private static final MethodMatcher[] EXCLUSIVE_DEFAULT_METHOD_NAME = new MethodMatcher[]{ - new SimpleMethodMatcher(Modifier.Public, "finalize", 0), - new SimpleMethodMatcher(Modifier.Public, "wait", long.class, int.class), - new SimpleMethodMatcher(Modifier.Public, "wait", long.class), - new SimpleMethodMatcher(Modifier.Public, "wait", 0), - new SimpleMethodMatcher(Modifier.Public, "equals", Object.class), - new SimpleMethodMatcher(Modifier.Public, "toString", 0), - new SimpleMethodMatcher(Modifier.Public, "hashCode", 0), - new SimpleMethodMatcher(Modifier.Public, "getClass", 0), - new SimpleMethodMatcher(Modifier.Public, "clone", 0), - new SimpleMethodMatcher(Modifier.Public, "notify", 0), - new SimpleMethodMatcher(Modifier.Public, "notifyAll", 0) - }; - - public ExclusiveObjectDefaultMethodsMatcher(String methodMatchDescribe) { - super(methodMatchDescribe); - } - - @Override - public ElementMatcher.Junction buildMatcher() { - return this.match().and(excludeObjectDefaultMethod()); - } - - protected ElementMatcher.Junction excludeObjectDefaultMethod() { - ElementMatcher.Junction exclusiveMatcher = null; - for (MethodMatcher methodMatcher : EXCLUSIVE_DEFAULT_METHOD_NAME) { - if (exclusiveMatcher == null) { - exclusiveMatcher = methodMatcher.buildMatcher(); - continue; - } - - exclusiveMatcher = exclusiveMatcher.or(methodMatcher.buildMatcher()); - - } - return not(exclusiveMatcher); - } - - public abstract ElementMatcher.Junction match(); - - -} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java deleted file mode 100644 index 54ebfa41a..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor.matcher; - -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.nameMatches; - -public class MethodRegexMatcher extends MethodMatcher { - - public MethodRegexMatcher(String methodMatchDescribe) { - super(methodMatchDescribe); - } - - public MethodRegexMatcher(String methodMatchDescribe, int argNum) { - super(methodMatchDescribe, argNum); - } - - public MethodRegexMatcher(String methodMatchDescribe, Class... argTypeArray) { - super(methodMatchDescribe, argTypeArray); - } - - public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe) { - super(modifier, methodMatchDescribe); - } - - public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe, int argNum) { - super(modifier, methodMatchDescribe, argNum); - } - - public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe, Class... argTypeArray) { - super(modifier, methodMatchDescribe, argTypeArray); - } - - - @Override - public ElementMatcher.Junction buildMatcher() { - ElementMatcher.Junction matcher = nameMatches(getMethodMatchDescribe()); - return mergeArgumentsIfNecessary(matcher); - } - -} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java deleted file mode 100644 index 5dbca070a..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor.matcher; - -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static net.bytebuddy.matcher.ElementMatchers.not; - -public class MethodsExclusiveMatcher extends ExclusiveObjectDefaultMethodsMatcher { - - private List matchers = new ArrayList(); - - public MethodsExclusiveMatcher(String... methodNames) { - super("exclude method name: " + methodNames.toString()); - for (String methodName : methodNames) { - matchers.add(new SimpleMethodMatcher(methodName)); - } - } - - public MethodsExclusiveMatcher(MethodMatcher... matchers) { - super("exclude methods description :" + matchers.toString()); - this.matchers.addAll(Arrays.asList(matchers)); - } - - @Override - public ElementMatcher.Junction match() { - ElementMatcher.Junction result = null; - - for (MethodMatcher matcher : matchers) { - if (result == null) { - result = matcher.buildMatcher(); - continue; - } - - result = result.or(matcher.buildMatcher()); - } - - return not(result); - } - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder("exclude following method(s): "); - int idx = 1; - for (MethodMatcher methodMatcher : matchers) { - stringBuilder.append(idx++ + "." + methodMatcher.toString() + ". "); - } - - return stringBuilder.toString(); - } -} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/PrivateMethodMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/PrivateMethodMatcher.java deleted file mode 100644 index 097cc3366..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/PrivateMethodMatcher.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor.matcher; - -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import net.bytebuddy.matcher.ElementMatchers; - -import static net.bytebuddy.matcher.ElementMatchers.any; - -public class PrivateMethodMatcher extends MethodMatcher { - public PrivateMethodMatcher() { - super("any private method"); - } - - @Override - public ElementMatcher.Junction buildMatcher() { - return any().and(ElementMatchers.isPrivate()); - } - - @Override - public String toString() { - return getMethodMatchDescribe(); - } -} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java deleted file mode 100644 index 786dabffe..000000000 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.a.eye.skywalking.plugin.interceptor.matcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; - -public class SimpleMethodMatcher extends MethodMatcher { - - public SimpleMethodMatcher(String methodName) { - super(methodName); - } - - public SimpleMethodMatcher(String methodName, int argNum) { - super(methodName, argNum); - } - - public SimpleMethodMatcher(String methodName, Class... args) { - super(methodName, args); - } - - - public SimpleMethodMatcher(Modifier modifier, String methodMatchDescribe) { - super(modifier, methodMatchDescribe); - } - - public SimpleMethodMatcher(Modifier modifier, String methodMatchDescribe, int argNum) { - super(modifier, methodMatchDescribe, argNum); - } - - public SimpleMethodMatcher(Modifier modifier, String methodMatchDescribe, Class... argTypeArray) { - super(modifier, methodMatchDescribe, argTypeArray); - } - - - @Override - public ElementMatcher.Junction buildMatcher() { - ElementMatcher.Junction matcher = named(getMethodMatchDescribe()); - return mergeArgumentsIfNecessary(matcher); - } -} diff --git a/skywalking-sniffer/skywalking-api/src/test/java/test/a/eye/cloud/plugin/TestInterceptorDefine.java b/skywalking-sniffer/skywalking-api/src/test/java/test/a/eye/cloud/plugin/TestInterceptorDefine.java index dba4bc8cf..dfe4d1ecf 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/test/a/eye/cloud/plugin/TestInterceptorDefine.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/test/a/eye/cloud/plugin/TestInterceptorDefine.java @@ -2,50 +2,52 @@ package test.a.eye.cloud.plugin; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class TestInterceptorDefine extends ClassEnhancePluginDefine { - @Override - public String enhanceClassName() { - return "BeInterceptedClass"; - } + @Override + public String enhanceClassName() { + return "BeInterceptedClass"; + } - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("printabc")}; - } + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("printabc"); + } - @Override - public String getMethodsInterceptor() { - return "TestAroundInterceptor"; - } - }}; - } + @Override + public String getMethodsInterceptor() { + return "TestAroundInterceptor"; + } + }}; + } - @Override - protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return new StaticMethodsInterceptPoint[]{new StaticMethodsInterceptPoint() { - @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("call")}; - } + @Override + protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[] {new StaticMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("call"); + } - @Override - public String getMethodsInterceptor() { - return "TestStaticAroundInterceptor"; - } - }}; - } + @Override + public String getMethodsInterceptor() { + return "TestStaticAroundInterceptor"; + } + }}; + } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboPluginDefine.java index d0e22d93d..5d04f87c5 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboPluginDefine.java @@ -2,9 +2,11 @@ package com.a.eye.skywalking.plugin.dubbo; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class DubboPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { @Override @@ -21,8 +23,8 @@ public class DubboPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("invoke")}; + public ElementMatcher getMethodsMatcher() { + return named("invoke"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java index 7b0ccfa9f..c507ab152 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java @@ -1,8 +1,10 @@ package com.a.eye.skywalking.plugin.httpClient.v4.define; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { @@ -21,9 +23,8 @@ public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[] { - new SimpleMethodMatcher("doExecute")}; + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java index e953369f0..5e2c6cca9 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java @@ -1,33 +1,34 @@ package com.a.eye.skywalking.plugin.httpClient.v4.define; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine { - /** - * DefaultRequestDirector is default implement.
- * usually use in version 4.0-4.2
- * since 4.3, this class is Deprecated. - */ - @Override - public String enhanceClassName() { - return "org.apache.http.impl.client.DefaultRequestDirector"; - } + /** + * DefaultRequestDirector is default implement.
+ * usually use in version 4.0-4.2
+ * since 4.3, this class is Deprecated. + */ + @Override + public String enhanceClassName() { + return "org.apache.http.impl.client.DefaultRequestDirector"; + } - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[] { - new SimpleMethodMatcher("execute")}; - } + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("execute"); + } - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + }}; + } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java index c70fe5078..28e510372 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java @@ -1,8 +1,10 @@ package com.a.eye.skywalking.plugin.httpClient.v4.define; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class InternalHttpClientPluginDefine extends HttpClientPluginDefine { @Override @@ -14,8 +16,8 @@ public class InternalHttpClientPluginDefine extends HttpClientPluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("doExecute")}; + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java index 379dc675c..69213af59 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java @@ -1,8 +1,10 @@ package com.a.eye.skywalking.plugin.httpClient.v4.define; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine { @Override @@ -14,8 +16,8 @@ public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("doExecute")}; + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabasePluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabasePluginDefine.java index 8cbd28861..db029464d 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabasePluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabasePluginDefine.java @@ -2,9 +2,11 @@ package com.a.eye.skywalking.plugin.jdbc.define; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public abstract class AbstractDatabasePluginDefine extends ClassInstanceMethodsEnhancePluginDefine { @Override @@ -16,8 +18,8 @@ public abstract class AbstractDatabasePluginDefine extends ClassInstanceMethodsE protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("connect")}; + public ElementMatcher getMethodsMatcher() { + return named("connect"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterPluginDefine.java index 97558beb5..d55821875 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterPluginDefine.java @@ -1,18 +1,17 @@ package com.a.eye.skywalking.plugin.jedis.v2.define; +import com.a.eye.skywalking.plugin.bytebuddy.AllObjectDefaultMethodsMatch; import com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import java.util.Set; -import static net.bytebuddy.matcher.ElementMatchers.not; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.*; public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { @@ -36,7 +35,7 @@ public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginD }, new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return new ArgumentTypeNameMatch(0, "redis.clients.jedis.HostAndPort"); + return takesArgumentWithType(0, "redis.clients.jedis.HostAndPort"); } @Override @@ -50,8 +49,8 @@ public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginD protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[] {new AnyMethodsMatcher()}; + public ElementMatcher getMethodsMatcher() { + return any().and(not(AllObjectDefaultMethodsMatch.INSTANCE)); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisPluginDefine.java index 9a5b88d30..24b847a0a 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisPluginDefine.java @@ -1,20 +1,18 @@ package com.a.eye.skywalking.plugin.jedis.v2.define; +import com.a.eye.skywalking.plugin.bytebuddy.AllObjectDefaultMethodsMatch; import com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.MethodsExclusiveMatcher; -import com.a.eye.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; +import net.bytebuddy.matcher.ElementMatchers; import java.net.URI; -import static net.bytebuddy.matcher.ElementMatchers.not; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.*; public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { @@ -38,7 +36,7 @@ public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { }, new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return new ArgumentTypeNameMatch(0, "redis.clients.jedis.HostAndPort"); + return takesArgumentWithType(0, "redis.clients.jedis.HostAndPort"); } @Override @@ -62,10 +60,16 @@ public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[] {new MethodsExclusiveMatcher(new PrivateMethodMatcher(), new SimpleMethodMatcher("close"), new SimpleMethodMatcher("getDB"), - new SimpleMethodMatcher("connect"), new SimpleMethodMatcher("setDataSource"), new SimpleMethodMatcher("resetState"), - new SimpleMethodMatcher("clusterSlots"), new SimpleMethodMatcher("checkIsInMultiOrPipeline"))}; + public ElementMatcher getMethodsMatcher() { + return not(ElementMatchers.isPrivate() + .or(AllObjectDefaultMethodsMatch.INSTANCE) + .or(named("close")) + .or(named("getDB")) + .or(named("connect")) + .or(named("setDataSource")) + .or(named("resetState")) + .or(named("clusterSlots")) + .or(named("checkIsInMultiOrPipeline"))); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanClientDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanClientDefine.java index 235b58d01..d96f8cfe0 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanClientDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanClientDefine.java @@ -2,13 +2,12 @@ package com.a.eye.skywalking.plugin.motan.define; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine { @Override @@ -35,8 +34,8 @@ public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[] {new SimpleMethodMatcher("call")}; + public ElementMatcher getMethodsMatcher() { + return named("call"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanServerDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanServerDefine.java index 91b847005..aec3aeca8 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanServerDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanServerDefine.java @@ -2,13 +2,12 @@ package com.a.eye.skywalking.plugin.motan.define; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine { @@ -36,8 +35,8 @@ public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine { protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[] {new SimpleMethodMatcher("call")}; + public ElementMatcher getMethodsMatcher() { + return named("call"); } @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatPluginDefine.java index 8f77846f6..6e26528cd 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatPluginDefine.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatPluginDefine.java @@ -2,9 +2,11 @@ package com.a.eye.skywalking.plugin.tomcat78x.define; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { @Override @@ -21,8 +23,8 @@ public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("invoke")}; + public ElementMatcher getMethodsMatcher() { + return named("invoke"); } @Override diff --git a/skywalking-sniffer/skywalking-toolkit-activation/pom.xml b/skywalking-sniffer/skywalking-toolkit-activation/pom.xml index d4061ee5b..f1b808e8e 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/pom.xml +++ b/skywalking-sniffer/skywalking-toolkit-activation/pom.xml @@ -14,6 +14,7 @@ skywalking-toolkit-log4j-2.x-activation skywalking-toolkit-logback-1.x-activation skywalking-toolkit-trace-context-activation + skywalking-toolkit-opentracing-activation skywalking-toolkit-activation diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java index c6513597c..72fcb6c61 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java @@ -2,9 +2,11 @@ package com.a.eye.skywalking.toolkit.activation.log.log4j.v1.x; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; /** * Created by wusheng on 2016/12/7. @@ -24,8 +26,8 @@ public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhan protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("convert")}; + public ElementMatcher getMethodsMatcher() { + return named("convert"); } @Override diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java index 68e113fec..4ce673c66 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java @@ -1,9 +1,11 @@ package com.a.eye.skywalking.toolkit.activation.log.log4j.v2.x; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; /** * Created by wusheng on 2016/12/7. @@ -18,8 +20,8 @@ public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePlu protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { return new StaticMethodsInterceptPoint[]{new StaticMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("append")}; + public ElementMatcher getMethodsMatcher() { + return named("append"); } @Override diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java index 57638c7b3..b1bf6b0df 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java @@ -2,9 +2,11 @@ package com.a.eye.skywalking.toolkit.activation.log.logback.v1.x; import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; /** * Created by wusheng on 2016/12/7. @@ -24,8 +26,8 @@ public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhan protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{new SimpleMethodMatcher("convert")}; + public ElementMatcher getMethodsMatcher() { + return named("convert"); } @Override diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml new file mode 100644 index 000000000..531f15c9b --- /dev/null +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml @@ -0,0 +1,15 @@ + + + + skywalking-toolkit-activation + com.a.eye + ${skywalking.version} + + 4.0.0 + + skywalking-toolkit-opentracing-activation + + + diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/ExtractCrossProcessByteBufferContextInterceptor.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/ExtractCrossProcessByteBufferContextInterceptor.java new file mode 100644 index 000000000..658af9a35 --- /dev/null +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/ExtractCrossProcessByteBufferContextInterceptor.java @@ -0,0 +1,26 @@ +package com.a.eye.skywalking.toolkit.activation.opentracing; + +import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * Created by wusheng on 2017/1/3. + */ +public class ExtractCrossProcessByteBufferContextInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { + return null; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { + + } +} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/ExtractCrossProcessTextMapContextInterceptor.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/ExtractCrossProcessTextMapContextInterceptor.java new file mode 100644 index 000000000..ad5fa3ff7 --- /dev/null +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/ExtractCrossProcessTextMapContextInterceptor.java @@ -0,0 +1,26 @@ +package com.a.eye.skywalking.toolkit.activation.opentracing; + +import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * Created by wusheng on 2017/1/3. + */ +public class ExtractCrossProcessTextMapContextInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { + return null; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { + + } +} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/FormatCrossProcessContextInterceptor.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/FormatCrossProcessContextInterceptor.java new file mode 100644 index 000000000..c419f195a --- /dev/null +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/FormatCrossProcessContextInterceptor.java @@ -0,0 +1,26 @@ +package com.a.eye.skywalking.toolkit.activation.opentracing; + +import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * Created by wusheng on 2017/1/3. + */ +public class FormatCrossProcessContextInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { + return null; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { + + } +} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/SkyWalkingTracerActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/SkyWalkingTracerActivation.java new file mode 100644 index 000000000..f3c8fb891 --- /dev/null +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/SkyWalkingTracerActivation.java @@ -0,0 +1,64 @@ +package com.a.eye.skywalking.toolkit.activation.opentracing; + +import com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch; +import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; +import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; +import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import java.nio.ByteBuffer; + +import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; + +/** + * Created by wusheng on 2017/1/3. + */ +public class SkyWalkingTracerActivation extends ClassInstanceMethodsEnhancePluginDefine { + @Override + protected String enhanceClassName() { + return "com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer"; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("formatCrossProcessPropagationContextData"); + } + + @Override + public String getMethodsInterceptor() { + return "com.a.eye.skywalking.toolkit.activation.opentracing.FormatCrossProcessContextInterceptor"; + } + }, new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("extractCrossProcessPropagationContextData").and(takesArgumentWithType(0, "io.opentracing.propagation.TextMap")); + } + + @Override + public String getMethodsInterceptor() { + return "com.a.eye.skywalking.toolkit.activation.opentracing.ExtractCrossProcessTextMapContextInterceptor"; + } + }, new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("extractCrossProcessPropagationContextData").and(takesArgument(0, ByteBuffer.class)); + } + + @Override + public String getMethodsInterceptor() { + return "com.a.eye.skywalking.toolkit.activation.opentracing.ExtractCrossProcessByteBufferContextInterceptor"; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextActivation.java index dc9aa307a..7af599337 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextActivation.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextActivation.java @@ -1,11 +1,11 @@ package com.a.eye.skywalking.toolkit.activation.trace; -import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.MethodMatcher; import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint; import com.a.eye.skywalking.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; -import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; /** * Created by xin on 2016/12/15. @@ -16,27 +16,18 @@ public class TraceContextActivation extends ClassStaticMethodsEnhancePluginDefin return "com.a.eye.skywalking.toolkit.trace.TraceContext"; } - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - @Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return new StaticMethodsInterceptPoint[]{ - new StaticMethodsInterceptPoint() { - @Override - public MethodMatcher[] getMethodsMatchers() { - return new MethodMatcher[]{ - new SimpleMethodMatcher("traceId") - }; - } + return new StaticMethodsInterceptPoint[] {new StaticMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("traceId"); + } - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.toolkit.activation.trace.TraceContextInterceptor"; - } - } - }; + @Override + public String getMethodsInterceptor() { + return "com.a.eye.skywalking.toolkit.activation.trace.TraceContextInterceptor"; + } + }}; } }