private void processTraceObject( final Trace trace, Object target, Object[] args, Throwable throwable) { // end spanEvent try { SpanEventRecorder recorder = trace.currentSpanEventRecorder(); // TODO Might need a way to collect and record method arguments // trace.recordAttribute(...); recorder.recordException(throwable); recorder.recordApi(this.descriptor); } catch (Throwable t) { logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t); } finally { trace.traceBlockEnd(); } // end root span SpanRecorder recorder = trace.getSpanRecorder(); String methodUri = getMethodUri(target); recorder.recordRpcName(methodUri); // retrieve connection information String localIpPort = UNKNOWN_ADDRESS; String remoteAddress = UNKNOWN_ADDRESS; if (args.length == 2 && args[0] instanceof TProtocol) { TProtocol inputProtocol = (TProtocol) args[0]; if (this.socketAccessor.isApplicable(inputProtocol.getTransport())) { Socket socket = this.socketAccessor.get(inputProtocol.getTransport()); if (socket != null) { localIpPort = ThriftUtils.getHostPort(socket.getLocalSocketAddress()); remoteAddress = ThriftUtils.getHost(socket.getRemoteSocketAddress()); } } } if (localIpPort != UNKNOWN_ADDRESS) { recorder.recordEndPoint(localIpPort); } if (remoteAddress != UNKNOWN_ADDRESS) { recorder.recordRemoteAddress(remoteAddress); } }
private String getRemoteAddress(Object asyncMethodCallObj) { if (!this.nonblockingSocketAddressAccessor.isApplicable(asyncMethodCallObj)) { if (isDebug) { logger.debug( "Invalid TAsyncMethodCall object. Need metadata accessor({})", METADATA_NONBLOCKING_SOCKET_ADDRESS); } return UNKNOWN_ADDRESS; } Object socketAddress = this.nonblockingSocketAddressAccessor.get(asyncMethodCallObj); if (socketAddress instanceof SocketAddress) { return ThriftUtils.getHostPort((SocketAddress) socketAddress); } return UNKNOWN_ADDRESS; }
private String getMethodUri(Object target) { String methodUri = ThriftConstants.UNKNOWN_METHOD_URI; InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation(); Object attachment = currentTransaction.getAttachment(); if (attachment instanceof ThriftClientCallContext && target instanceof TBaseAsyncProcessor) { ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment; String methodName = clientCallContext.getMethodName(); methodUri = ThriftUtils.getAsyncProcessorNameAsUri((TBaseAsyncProcessor<?>) target); StringBuilder sb = new StringBuilder(methodUri); if (!methodUri.endsWith("/")) { sb.append("/"); } sb.append(methodName); methodUri = sb.toString(); } return methodUri; }