Remove the over-design about methodMatcher, use byte-buddy judge instead. Add module ‘skywalking-toolkit-opentracing-activation’ ( no activation implementation ).

This commit is contained in:
wusheng 2017-01-03 15:25:17 +08:00
parent 3c92217b4d
commit a944427df8
34 changed files with 385 additions and 570 deletions

View File

@ -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}
* <p>
* Created by wusheng on 2017/1/3.
*/
public enum AllObjectDefaultMethodsMatch implements ElementMatcher<MethodDescription> {
INSTANCE;
private ElementMatcher.Junction<MethodDescription> matcher;
AllObjectDefaultMethodsMatch() {
ElementMatcher.Junction<MethodDescription>[] allDefaultMethods = new ElementMatcher.Junction[] {named("finalize").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("wait").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("wait").and(takesArguments(long.class, int.class)).and(ElementMatchers.<MethodDescription>isPublic()),
named("wait").and(takesArguments(long.class)).and(ElementMatchers.<MethodDescription>isPublic()),
named("equals").and(takesArguments(Object.class)).and(ElementMatchers.<MethodDescription>isPublic()),
named("toString").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("hashCode").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("getClass").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("clone").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("notify").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
named("notifyAll").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>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);
}
}

View File

@ -11,7 +11,7 @@ public class ArgumentTypeNameMatch implements ElementMatcher<MethodDescription>
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<MethodDescription>
return false;
}
public static ElementMatcher<MethodDescription> takesArgumentWithType(int index, String argumentTypeName){
return new ArgumentTypeNameMatch(index, argumentTypeName);
}
}

View File

@ -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<MethodDescription> getMethodsMatcher();
/**
*

View File

@ -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<MethodDescription> buildMatcher();
protected String getMethodMatchDescribe() {
return methodMatchDescribe;
}
protected ElementMatcher.Junction<MethodDescription> mergeArgumentsIfNecessary(ElementMatcher.Junction<MethodDescription> 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<MethodDescription> 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;
}
}

View File

@ -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<MethodDescription> getMethodsMatcher();
/**
*

View File

@ -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<MethodDescription> 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<MethodDescription> 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;

View File

@ -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<MethodDescription> match() {
return any();
}
@Override
public String toString() {
return getMethodMatchDescribe();
}
}

View File

@ -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<MethodDescription> buildMatcher() {
return this.match().and(excludeObjectDefaultMethod());
}
protected ElementMatcher.Junction<MethodDescription> excludeObjectDefaultMethod() {
ElementMatcher.Junction<MethodDescription> 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<MethodDescription> match();
}

View File

@ -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<MethodDescription> buildMatcher() {
ElementMatcher.Junction<MethodDescription> matcher = nameMatches(getMethodMatchDescribe());
return mergeArgumentsIfNecessary(matcher);
}
}

View File

@ -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<MethodMatcher> matchers = new ArrayList<MethodMatcher>();
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<MethodDescription> match() {
ElementMatcher.Junction<MethodDescription> 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();
}
}

View File

@ -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<MethodDescription> buildMatcher() {
return any().and(ElementMatchers.<MethodDescription>isPrivate());
}
@Override
public String toString() {
return getMethodMatchDescribe();
}
}

View File

@ -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<MethodDescription> buildMatcher() {
ElementMatcher.Junction<MethodDescription> matcher = named(getMethodMatchDescribe());
return mergeArgumentsIfNecessary(matcher);
}
}

View File

@ -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<MethodDescription> 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<MethodDescription> getMethodsMatcher() {
return named("call");
}
@Override
public String getMethodsInterceptor() {
return "TestStaticAroundInterceptor";
}
}};
}
@Override
public String getMethodsInterceptor() {
return "TestStaticAroundInterceptor";
}
}};
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("invoke");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("doExecute");
}
@Override

View File

@ -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.<br/>
* usually use in version 4.0-4.2<br/>
* since 4.3, this class is Deprecated.
*/
@Override
public String enhanceClassName() {
return "org.apache.http.impl.client.DefaultRequestDirector";
}
/**
* DefaultRequestDirector is default implement.<br/>
* usually use in version 4.0-4.2<br/>
* 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<MethodDescription> getMethodsMatcher() {
return named("execute");
}
@Override
public String getMethodsInterceptor() {
return getInstanceMethodsInterceptor();
}
}};
}
@Override
public String getMethodsInterceptor() {
return getInstanceMethodsInterceptor();
}
}};
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("doExecute");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("doExecute");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("connect");
}
@Override

View File

@ -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<MethodDescription> 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<MethodDescription> getMethodsMatcher() {
return any().and(not(AllObjectDefaultMethodsMatch.INSTANCE));
}
@Override

View File

@ -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<MethodDescription> 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<MethodDescription> getMethodsMatcher() {
return not(ElementMatchers.<MethodDescription>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

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("call");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("call");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("invoke");
}
@Override

View File

@ -14,6 +14,7 @@
<module>skywalking-toolkit-log4j-2.x-activation</module>
<module>skywalking-toolkit-logback-1.x-activation</module>
<module>skywalking-toolkit-trace-context-activation</module>
<module>skywalking-toolkit-opentracing-activation</module>
</modules>
<artifactId>skywalking-toolkit-activation</artifactId>

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("convert");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("append");
}
@Override

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("convert");
}
@Override

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skywalking-toolkit-activation</artifactId>
<groupId>com.a.eye</groupId>
<version>${skywalking.version}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-toolkit-opentracing-activation</artifactId>
</project>

View File

@ -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) {
}
}

View File

@ -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) {
}
}

View File

@ -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) {
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named("formatCrossProcessPropagationContextData");
}
@Override
public String getMethodsInterceptor() {
return "com.a.eye.skywalking.toolkit.activation.opentracing.FormatCrossProcessContextInterceptor";
}
}, new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> 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<MethodDescription> getMethodsMatcher() {
return named("extractCrossProcessPropagationContextData").and(takesArgument(0, ByteBuffer.class));
}
@Override
public String getMethodsInterceptor() {
return "com.a.eye.skywalking.toolkit.activation.opentracing.ExtractCrossProcessByteBufferContextInterceptor";
}
}};
}
}

View File

@ -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<MethodDescription> 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";
}
}};
}
}