pinpoint 插件开发实战
资源文件pinpoint agent在启动的时候,会加载plugin文件夹下所有的插件。它会扫描插件jar包中META-INF/services目录下的两个配置文件来确认ProfilerPlugin和TraceMetadataProvider的实现类。META-INF/services/com.naercorp.pinpoint.bootstrap.plugin.ProfilerPlugin: 1com.isuwang.dapeng.pinpoint.plugin.DapengPinpintPlugin META-INF/services/com.navercorp.pinpoint.common.trace.TraceMetadataProvider: 1com.isuwang.dapeng.pinpoint.plugin.DapengTraceMetadataProvider TraceMetadataProvider只需要实现setup方法,添加ServiceType和AnnotationKey, 主要用于服务类型和记录的数据的标识,agent上送给collector, collector和web通过它们区分不同的服务节点类型。 12345678910111213141516public class DapengTraceMetadataProvider implements TraceMetadataProvider { public static ServiceType DAPENG_PROVIDER_SERVICE_TYPE = ServiceTypeFactory.of(1999, "DAPENG_PROVIDER", RECORD_STATISTICS); public static ServiceType DAPENG_CONSUMER_SERVICE_TYPE = ServiceTypeFactory.of(9999, "DAPENG_CONSUMER", RECORD_STATISTICS); public static AnnotationKey DAPENG_ARGS_ANNOTATION_KEY = AnnotationKeyFactory.of(900, "dapeng.args", VIEW_IN_RECORD_SET); public static AnnotationKey DAPENG_RESULT_ANNOTATION_KEY = AnnotationKeyFactory.of(999, "dapeng.result", VIEW_IN_RECORD_SET); @Override public void setup(TraceMetadataSetupContext context) { context.addServiceType(DAPENG_PROVIDER_SERVICE_TYPE); context.addServiceType(DAPENG_CONSUMER_SERVICE_TYPE); context.addAnnotationKey(DAPENG_ARGS_ANNOTATION_KEY); context.addAnnotationKey(DAPENG_RESULT_ANNOTATION_KEY); }} 注意这里的ServiceType和AnnotationKey的code是有范围的.RECORD_STATICSTICS类型的ServiceType, agent会统计它的耗时。VIEW_IN_RECORD_SET属性的AnnotationKey将会在调用树状图中行显示。