/// <summary> /// Handles the logging of asynchronous unary calls. /// </summary> /// <typeparam name="TRequest">The type of the request.</typeparam> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The request.</param> /// <param name="context">The context.</param> /// <param name="oldTask">The old task.</param> /// <param name="call">The call.</param> internal void HandleAsyncUnaryLogging <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, Task <TResponse> oldTask, AsyncUnaryCall <TResponse> call) where TRequest : class where TResponse : class { // Generating log entry is expensive, so let's do that only if the log source // has been configured to do so. if (TraceUtilities.ShouldGenerateRequestLogs()) { LogEntry logEntry = new LogEntry() { Host = config.ServerUrl, Method = context.Method.FullName, RequestHeaders = context.Options.Headers, Request = request, ResponseHeaders = Merge(GetResponseHeader(call.ResponseHeadersAsync), call.GetTrailers()), Response = (oldTask.IsFaulted) ? default : oldTask.Result, Exception = UnaryRpcInterceptor.ParseTaskException(oldTask.Exception), IsFailure = oldTask.IsFaulted, CustomerId = GetCustomerId(request), PartialFailures = (oldTask.IsFaulted) ? "" : GetPartialFailures(oldTask.Result) }; WriteLogs(logEntry); } }
/// <summary> /// Handles the logging of asynchronous server streaming calls. /// </summary> /// <typeparam name="TRequest">The type of the request.</typeparam> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="context">The context.</param> /// <param name="rpcException">The RPC exception.</param> /// <param name="call">The call.</param> internal void HandleAsyncServerStreamingLogging <TRequest, TResponse>(TRequest request, TResponse response, ClientInterceptorContext <TRequest, TResponse> context, AggregateException rpcException, AsyncServerStreamingCall <TResponse> call) where TRequest : class where TResponse : class { // Generating log entry is expensive, so let's do that only if the log source // has been configured to do so. if (TraceUtilities.ShouldGenerateRequestLogs()) { LogEntry logEntry = new LogEntry() { Host = config.ServerUrl, Method = context.Method.FullName, RequestHeaders = context.Options.Headers, Request = request, ResponseHeaders = Merge(GetResponseHeader(call.ResponseHeadersAsync), TryGetCallTrailers(call)), Response = response, Exception = UnaryRpcInterceptor.ParseTaskException(rpcException), IsFailure = (rpcException != null), CustomerId = GetCustomerId(request), PartialFailures = (rpcException != null) ? "" : GetPartialFailures(response) }; WriteLogs(logEntry); } }
public void TestParseTaskException() { Assert.NotNull(UnaryRpcInterceptor.ParseTaskException <HelloException>( new AggregateException(TEST_EXCEPTION))); }