Logging invalid routes

So recently ran into an issue where I had a nginx k8s pod route traffic to a scala pod running tapir endpoints. We added a new endpoint that worked locally but when put into k8s was not being found and gave us 404s. We looked in the scala server pod logs for something and there was nothing there. The nginx logs showed it had received the request and got a 404 from the scala server. When we increased logging in the tapir server, we still saw nothing in the logs about the client making a request to the server. After many long hours we found out the issue was unrelated in our infrastructure deployment.

We had configured our server options as such:


but we didn’t see much more in terms of logging that would have shown us anything helpful in terms of that Tapir had received the request but did not have a matching endpoint that could handle it.

So do you know where the problem within tapir? Did the request reach tapir, and it responded with a 404, without logging anything? What was the problem? :slight_smile:

The problem was caused by us deploying the wrong docker container, so it was unrelated to tapir.

But the requests were reaching tapir, just that the above Http4sServerOptions seemed to do nothing add additional logging to help troubleshoot.

Is there a way for us to reproduce the problem? Then maybe we could fix something or at least explain what happened :slight_smile:

I think generating a project through tapir — tapir 1.x documentation using scala 3, http4s, cats io, circe and the abover server settings would work pretty easily. Then just curling a non existing endpoint?

If that doesn’t I can set something up locally and see if I can reproduce it.

Ah right, if the path doesn’t match any endpoint, then no endpoint will be ever decoded (which is an optimization on tapir’s side). So the tapir routes return a None, which is then handled by http4s’s .orNotFound.

You can log things in case tapir doesn’t handle the request as follows:

    "/" -> Kleisli { (req: Request[IO]) => routes.run(req).flatTapNone(IO.println(s"Not handled: ${req.pathInfo}")) }

I’ll see in tapir if we can log anything when logAllDecodeFailures is true if we don’t event attempt to decode any endpoint.

Actually there’s one more logging flag (for which an “enable” method has been missing), logWhenReceived. Currently it can be enabled using Http4sServerOptions.defaultServerLog[IO].copy(logWhenReceived = true). This will log all incoming requests, even if they are not handled later. Would that be sufficient to cover the request-not-handled-at-all case, or do you think we need another logging variant?