Hello,
I’m using a logging directive within akka-http service interop-ed with gRPC endpoints:
def requestAsInfoLogging(route: Route): Route = {
def loggingFunction(loggingAdapter: LoggingAdapter, requestTimestamp: Long)(req: HttpRequest)(res: Any): Unit = {
val entry = res match {
case Complete(resp) =>
val elapsedTime: Long = System.currentTimeMillis() - requestTimestamp
if (req.uri.toString().contains("/some.grpc.Message/")) {
// gRPC access log
} else {
// REST access log
}
None
case anythingElse => Some(LogEntry(s"Failure: $anythingElse", Logging.ErrorLevel))
}
if (entry.isDefined) entry.get.logTo(loggingAdapter)
}
DebuggingDirectives.logRequestResult(LoggingMagnet(log => {
loggingFunction(log, System.currentTimeMillis())
}))(route)
}
private def startHttpServer(routes: Route)(implicit system: ActorSystem[_]): Unit = {
import system.executionContext
val loggedRoutes = requestAsInfoLogging(routes)
val futureBinding = Http().newServerAt(config.mcr.server.address, config.mcr.server.port).bind(loggedRoutes)
// ...
and I’m looking for a way to access gRPC response status codes from HttpResponse
, to leave them in the logs. Is there a way like generating and passing a gRPC Metadata
or Trailer
to HttpResponse
, other than unmarshaling the response entity?