mtrudel / bandit

Bandit is a pure Elixir HTTP server for Plug & WebSock applications
MIT License
1.7k stars 86 forks source link

No telemetry when client hangs up #406

Closed joladev closed 2 weeks ago

joladev commented 1 month ago

As expected, the [:bandit, :request, :start] event happens when a request starts, the [:bandit, :request, :exception] event happens when the request raises, and [:bandit, :request, :stop] happens when the request ends normally, but no event is emitted in the case where a request starts but then the client hangs up.

As an example use case, let's say you've got long running requests where you log them starting and ending. With longer running requests it's more likely that you'll have clients occasionally hanging up, and it's a bit confusing that you've got a telemetry event saying the request started but then nothing letting you know it has stopped.

For Cowboy I know you can use a stream handlers to hook into terminate and get that event, does Bandit have some method of notifying you that the client hung up?

mtrudel commented 2 weeks ago

Apologies for the tardy response.

This is essentially the same issue as #408; Bandit doesn't see the connection as being 'done' until the Plug.call/2 call completes (either normally or by raising an exception). If that never happens (because, say, you have super Process.sleep calls or whatever else) then the connection isn't complete from Bandit's perspective and so we don't emit a closing telemetry span.

There are a few paths forward for this that I'm writing up over on #408. In the meantime I'll close this issue for hygiene considering it's the same underlying issue.

Thanks again!