/** * Constructs {@link ThriftStructuredLog} from {@link RequestContext} and {@link RequestLog}. * Can be used as {@link StructuredLogBuilder}. */ public ThriftStructuredLog(RequestLog reqLog) { super(reqLog); final Object requestContent = reqLog.rawRequestContent(); if (requestContent == null) { // Request might be responded as error before reading arguments. thriftServiceName = null; thriftMethodName = null; thriftCall = null; thriftReply = null; return; } if (!(requestContent instanceof ThriftCall)) { throw new IllegalArgumentException( "expected ApacheThriftCall instance for RequestLog.requestContent() but was " + requestContent); } final ThriftCall thriftCall = (ThriftCall) requestContent; // Get the service name from the args class name. final String argsTypeName = thriftCall.args().getClass().getName(); thriftServiceName = argsTypeName.substring(0, argsTypeName.indexOf('$')); thriftMethodName = thriftCall.header().name; this.thriftCall = thriftCall; thriftReply = (ThriftReply) reqLog.rawResponseContent(); }
@Test(timeout = 10000) public void testMessageLogsForException() throws Exception { final HelloService.Iface client = Clients.newClient(clientFactory(), getURI(Handlers.EXCEPTION), Handlers.EXCEPTION.iface(), clientOptions); recordMessageLogs = true; assertThatThrownBy(() -> client.hello("trustin")).isInstanceOf(TApplicationException.class); final RequestLog log = requestLogs.take(); assertThat(log.requestHeaders()).isInstanceOf(HttpHeaders.class); assertThat(log.requestContent()).isInstanceOf(RpcRequest.class); assertThat(log.rawRequestContent()).isInstanceOf(ThriftCall.class); final RpcRequest request = (RpcRequest) log.requestContent(); assertThat(request.serviceType()).isEqualTo(HelloService.Iface.class); assertThat(request.method()).isEqualTo("hello"); assertThat(request.params()).containsExactly("trustin"); final ThriftCall rawRequest = (ThriftCall) log.rawRequestContent(); assertThat(rawRequest.header().type).isEqualTo(TMessageType.CALL); assertThat(rawRequest.header().name).isEqualTo("hello"); assertThat(rawRequest.args()).isInstanceOf(HelloService.hello_args.class); assertThat(((HelloService.hello_args) rawRequest.args()).getName()).isEqualTo("trustin"); assertThat(log.responseHeaders()).isInstanceOf(HttpHeaders.class); assertThat(log.responseContent()).isInstanceOf(RpcResponse.class); assertThat(log.rawResponseContent()).isInstanceOf(ThriftReply.class); final RpcResponse response = (RpcResponse) log.responseContent(); assertThat(response.cause()).isNotNull(); final ThriftReply rawResponse = (ThriftReply) log.rawResponseContent(); assertThat(rawResponse.header().type).isEqualTo(TMessageType.EXCEPTION); assertThat(rawResponse.header().name).isEqualTo("hello"); assertThat(rawResponse.exception()).isNotNull(); }
assertThat(log.rawResponseContent()).isInstanceOf(ThriftReply.class); final ThriftReply rawResponse = (ThriftReply) log.rawResponseContent(); assertThat(rawResponse.header().type).isEqualTo(TMessageType.REPLY); assertThat(rawResponse.header().name).isEqualTo("hello");
assertThat(log.rawResponseContent()).isInstanceOf(ThriftReply.class); final ThriftReply rawResponse = (ThriftReply) log.rawResponseContent(); assertThat(rawResponse.header().type).isEqualTo(TMessageType.EXCEPTION); assertThat(rawResponse.header().name).isEqualTo("hello");
@Test(timeout = 10000) public void testMessageLogsForOneWay() throws Exception { final OnewayHelloService.Iface client = Clients.newClient(clientFactory(), getURI(Handlers.HELLO), Handlers.ONEWAYHELLO.iface(), clientOptions); recordMessageLogs = true; client.hello("trustin"); final RequestLog log = requestLogs.take(); assertThat(log.requestHeaders()).isInstanceOf(HttpHeaders.class); assertThat(log.requestContent()).isInstanceOf(RpcRequest.class); assertThat(log.rawRequestContent()).isInstanceOf(ThriftCall.class); final RpcRequest request = (RpcRequest) log.requestContent(); assertThat(request.serviceType()).isEqualTo(OnewayHelloService.Iface.class); assertThat(request.method()).isEqualTo("hello"); assertThat(request.params()).containsExactly("trustin"); final ThriftCall rawRequest = (ThriftCall) log.rawRequestContent(); assertThat(rawRequest.header().type).isEqualTo(TMessageType.ONEWAY); assertThat(rawRequest.header().name).isEqualTo("hello"); assertThat(rawRequest.args()).isInstanceOf(OnewayHelloService.hello_args.class); assertThat(((OnewayHelloService.hello_args) rawRequest.args()).getName()).isEqualTo("trustin"); assertThat(log.responseHeaders()).isInstanceOf(HttpHeaders.class); assertThat(log.responseContent()).isInstanceOf(RpcResponse.class); assertThat(log.rawResponseContent()).isNull(); final RpcResponse response = (RpcResponse) log.responseContent(); assertThat(response.get()).isNull(); }
assertThat(log.rawResponseContent()).isInstanceOf(ThriftReply.class); final ThriftReply rawResponse = (ThriftReply) log.rawResponseContent(); assertThat(rawResponse.header().type).isEqualTo(TMessageType.REPLY); assertThat(rawResponse.header().name).isEqualTo("hello");
private void propagateResponseSideLog(RequestLog lastChild) { // update the available logs if the lastChild already has them if (lastChild.isAvailable(RESPONSE_START)) { startResponse0(lastChild.responseStartTimeNanos(), lastChild.responseStartTimeMicros(), true); } if (lastChild.isAvailable(RESPONSE_FIRST_BYTES_TRANSFERRED)) { responseFirstBytesTransferred(lastChild.responseFirstBytesTransferredTimeNanos()); } if (lastChild.isAvailable(RESPONSE_HEADERS)) { responseHeaders(lastChild.responseHeaders()); } if (lastChild.isAvailable(RESPONSE_CONTENT)) { responseContent(lastChild.responseContent(), lastChild.rawResponseContent()); } if (lastChild.isAvailable(RESPONSE_END)) { endResponse0(lastChild.responseCause(), lastChild.responseEndTimeNanos()); } lastChild.addListener(log -> startResponse0( log.responseStartTimeNanos(), log.responseStartTimeMicros(), true), RESPONSE_START); lastChild.addListener(log -> responseFirstBytesTransferred( log.responseFirstBytesTransferredTimeNanos()), RESPONSE_FIRST_BYTES_TRANSFERRED); lastChild.addListener(log -> responseHeaders(log.responseHeaders()), RESPONSE_HEADERS); lastChild.addListener(log -> responseContent( log.responseContent(), log.rawResponseContent()), RESPONSE_CONTENT); lastChild.addListener(log -> endResponse0( log.responseCause(), log.responseEndTimeNanos()), RESPONSE_END); }
/** * Constructs {@link ThriftStructuredLog} from {@link RequestContext} and {@link RequestLog}. * Can be used as {@link StructuredLogBuilder}. */ public ThriftStructuredLog(RequestLog reqLog) { super(reqLog); final Object requestContent = reqLog.rawRequestContent(); if (requestContent == null) { // Request might be responded as error before reading arguments. thriftServiceName = null; thriftMethodName = null; thriftCall = null; thriftReply = null; return; } if (!(requestContent instanceof ThriftCall)) { throw new IllegalArgumentException( "expected ApacheThriftCall instance for RequestLog.requestContent() but was " + requestContent); } final ThriftCall thriftCall = (ThriftCall) requestContent; // Get the service name from the args class name. final String argsTypeName = thriftCall.args().getClass().getName(); thriftServiceName = argsTypeName.substring(0, argsTypeName.indexOf('$')); thriftMethodName = thriftCall.header().name; this.thriftCall = thriftCall; thriftReply = (ThriftReply) reqLog.rawResponseContent(); }
/** * Constructs {@link ThriftStructuredLog} from {@link RequestContext} and {@link RequestLog}. * Can be used as {@link StructuredLogBuilder}. */ public ThriftStructuredLog(RequestLog reqLog) { super(reqLog); final Object requestContent = reqLog.rawRequestContent(); if (requestContent == null) { // Request might be responded as error before reading arguments. thriftServiceName = null; thriftMethodName = null; thriftCall = null; thriftReply = null; return; } if (!(requestContent instanceof ThriftCall)) { throw new IllegalArgumentException( "expected ApacheThriftCall instance for RequestLog.requestContent() but was " + requestContent); } final ThriftCall thriftCall = (ThriftCall) requestContent; // Get the service name from the args class name. final String argsTypeName = thriftCall.args().getClass().getName(); thriftServiceName = argsTypeName.substring(0, argsTypeName.indexOf('$')); thriftMethodName = thriftCall.header().name; this.thriftCall = thriftCall; thriftReply = (ThriftReply) reqLog.rawResponseContent(); }
/** * Constructs {@link ThriftStructuredLog} from {@link RequestContext} and {@link RequestLog}. * Can be used as {@link StructuredLogBuilder}. */ public ThriftStructuredLog(RequestLog reqLog) { super(reqLog); final Object requestContent = reqLog.rawRequestContent(); if (requestContent == null) { // Request might be responded as error before reading arguments. thriftServiceName = null; thriftMethodName = null; thriftCall = null; thriftReply = null; return; } if (!(requestContent instanceof ThriftCall)) { throw new IllegalArgumentException( "expected ApacheThriftCall instance for RequestLog.requestContent() but was " + requestContent); } final ThriftCall thriftCall = (ThriftCall) requestContent; // Get the service name from the args class name. final String argsTypeName = thriftCall.args().getClass().getName(); thriftServiceName = argsTypeName.substring(0, argsTypeName.indexOf('$')); thriftMethodName = thriftCall.header().name; this.thriftCall = thriftCall; thriftReply = (ThriftReply) reqLog.rawResponseContent(); }