use of com.nike.riposte.util.asynchelperwrapper.ChannelFutureListenerWithTracingAndMdc in project riposte by Nike-Inc.
the class AccessLogEndHandler method doAccessLogging.
protected void doAccessLogging(ChannelHandlerContext ctx) throws Exception {
if (accessLogger == null)
return;
HttpProcessingState httpProcessingState = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
if (httpProcessingState == null) {
runnableWithTracingAndMdc(() -> logger.warn("HttpProcessingState is null. This shouldn't happen."), ctx).run();
}
// logging for this request, so make sure we only do it if appropriate
if (httpProcessingState != null && !httpProcessingState.isAccessLogCompletedOrScheduled()) {
Instant startTime = httpProcessingState.getRequestStartTime();
ResponseInfo responseInfo = httpProcessingState.getResponseInfo();
HttpResponse actualResponseObject = httpProcessingState.getActualResponseObject();
RequestInfo requestInfo = httpProcessingState.getRequestInfo();
ChannelFutureListener doTheAccessLoggingOperation = new ChannelFutureListenerWithTracingAndMdc((channelFuture) -> accessLogger.log(requestInfo, actualResponseObject, responseInfo, Instant.now().minusMillis(startTime.toEpochMilli()).toEpochMilli()), ctx);
// conditions), otherwise do it when the response finishes.
if (!httpProcessingState.isResponseSendingLastChunkSent())
doTheAccessLoggingOperation.operationComplete(null);
else
httpProcessingState.getResponseWriterFinalChunkChannelFuture().addListener(doTheAccessLoggingOperation);
httpProcessingState.setAccessLogCompletedOrScheduled(true);
}
}
Aggregations