官方开发指南
https://skywalking.apache.org/docs/skywalking-java/v8.8.0/en/setup/service-agent/java-agent/java-plugin-development-guide/
插件定义体系:
XXXInstrumentation
1.拦截实例方法/构造器 ClassInstanceMethodsEnhancePluginDefine
2.拦截静态方法ClassStaticMethodsEnhancePluginDefine
3.AbstractClassEnhancePluginDefine是自定义插件的基础抽象类
4.enhanceClass方法声明要拦截的类
5.getXXXMethodsInterceptPoints声明要拦截的方法
目标匹配 ClassMatch
1.按类名匹配NameMatch
2.模糊匹配 IndirectMatch
本文以dubbo插件为例
DubboInstrumentation是指定的对dubbo的一个插桩
private static final String ENHANCE_CLASS = "org.apache.dubbo.monitor.support.MonitorFilter";
@Override
protected ClassMatch enhanceClass() {
return NameMatch.byName(ENHANCE_CLASS);
}
指定了编写dubbo插件时拦截的具体的类,NameMatch.byName根据名称进行拦截匹配,具体拦截了org.apache.dubbo.monitor.support.MonitorFilter这个类(发起远程调)
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return null;
}
对构造方法进行拦截,这里没有用到
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {