akka-http 没有堆栈跟踪或错误详细信息

akka-http no stack trace or details on error

我得到的结构基本上可以概括为:

有时我从 akka 收到一个错误,它几乎没有告诉我任何信息。这个错误发生在 asynchttpclient returns 我得到一些结果之后。 (事实上​​我现在可以在日志上打印结果,它们是从 json 等解析的。但是 akka 已经出错了)

即使在调试日志记录级别,我也没有从 akka 或堆栈跟踪中收到可破译的错误消息。

我收到的唯一消息是:

2017-03-24 17:22:55 INFO  CompanyRepository:111 - search company with name:"somecompanyname"
2017-03-24 17:22:55 INFO  CompanyRepository:73 - [QUERY TIME]: 527ms
[ERROR] [03/24/2017 17:22:55.951] [company-api-system-akka.actor.default-dispatcher-3] [akka.actor.ActorSystemImpl(company-api-system)] Error during processing of request: 'requirement failed'. Completing with 500 Internal Server Error response.

这条错误消息是我唯一得到的。我配置的相关部分:

akka {
  loglevel = "DEBUG"
  # edit --  tested with sl4jlogger with no change
  #loggers = ["akka.event.slf4j.Slf4jLogger"]
  #logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

  parsing {
    max-content-length = 800m
    max-chunk-size             = 100m
  }
  server {
    server-header = akka-http/${akka.http.version}
    idle-timeout = 120 s
    request-timeout = 120 s
    bind-timeout = 10s
    max-connections = 1024
    pipelining-limit = 32

    verbose-error-messages = on
  }

  client {
    user-agent-header = akka-http/${akka.http.version}
  }

  host-connection-pool {
    max-connections = 4
  }
}

akka.http.routing {
  verbose-error-messages = on
}

任何人都知道我是否可以让 akka 吐出更多关于 what/where 错误发生的细节?

编辑:我意识到我在较小的结果集上没有得到同样的错误。 <- 忽略

编辑 2:

编辑 3:在两次调用之间用 sleep 记录

编辑4和解决方案!

这意味着这数千行响应中的一个字符串为空。特别感谢在没有消息的情况下使用 "require" 的懒惰。调试哪个字符串为空将是一场噩梦,但我仍然认为 akka 应该以更好的方式失败。

也尝试设置记录器 - 从您的配置来看,它们似乎没有设置。类似于:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

此外,考虑使用 akka-slf4j along with their recommended logging backend logback

这应该会让 akka 吐出更多细节。

akka-http no stack trace or details on error

好吧,默认的 akka-http ExceptionHandler 不打印堆栈跟踪,只打印错误消息或其 class 名称(如果消息为空),但您可以提供将打印的自定义异常处理程序你想要的任何东西(即你的例子中的堆栈跟踪)。

GitHub ExceptionHandlerExamplesSpec.spec

提供了一些如何制作自定义异常处理程序的示例

在您的案例中,最简单的方法似乎是定义您自己的自定义隐式异常处理程序

  import akka.http.scaladsl.model._
  import akka.http.scaladsl.server._
  import StatusCodes._
  import Directives._

  implicit def myExceptionHandler: ExceptionHandler =
    ExceptionHandler {
      case NonFatal(e) =>
          logger.error(s"Exception $e at\n${e.getStackTraceString}")
          complete(HttpResponse(InternalServerError, entity = "Internal Server Error"))
        }
    }