dubbo插件中須要記錄當前調用的接口和方法,可是在泛化調用的場景下,記錄的接口和方法都變成了api
com.alibaba.dubbo.rpc.service.GenericService:$invoke,須要把它轉化爲真實的API和方法ide
@Override public void after(Object target, Object arg0, Object result, Throwable throwable) {
//插件開關 if(!traceContext.collectSwitch(traceContext.getApplicationName(),"dubbo",null)){ return ; } Trace trace = this.getTrace(target); if (trace == null) { return; } RpcInvocation invocation = (RpcInvocation) arg0; try { SpanEventRecorder recorder = trace.currentSpanEventRecorder(); String endPoint = RpcContext.getContext().getRemoteAddressString(); recorder.recordApi(descriptor,new Object[]{endPoint}); if (throwable == null) { // RPC client have to record end point (server address) recorder.recordEndPoint(endPoint); // Optionally, record the destination id (logical name of server. e.g. DB name) recorder.recordDestinationId(endPoint); URL url = invocation.getInvoker().getUrl(); // 2017/9/11 上午11:22 記錄調用的接口 String interfaceName = ((Invoker)target).getInterface().getName(); String methodName = invocation.getMethodName(); //泛化調用兼容 if (GENERIC_SERVICE.equals(interfaceName) && INVOKE.equals(methodName)) { interfaceName = invocation.getAttachment("interface"); methodName = (String) invocation.getArguments()[0]; } //記錄調用的api recorder.recordAttribute(DubboConstants.DUBBO_INTERFACE_ANNOTATION_KEY,interfaceName+":"+methodName); //記錄dubbo調用分組 recorder.recordAttribute(DubboConstants.DUBBO_GROUP_ANNOTATION_KEY,url.getParameter("group")); //記錄dubbo調用請求參數 recorder.recordAttribute(DubboConstants.DUBBO_ARGS_ANNOTATION_KEY, DubboUtils.getParam(invocation.getArguments(),traceContext)); if (result instanceof RpcResult && trace.isDebug()){ // if (result instanceof RpcResult ){ RpcResult rpcResult = (RpcResult)result; Object value = rpcResult.getValue(); recorder.recordAttribute(DubboConstants.DUBBO_RESULT_ANNOTATION_KEY, traceContext.toJsonString(value)); }else { // recorder.recordAttribute(DubboConstants.DUBBO_RESULT_ANNOTATION_KEY, result); } } else { recorder.recordException(throwable); } } finally { trace.traceBlockEnd(); } }