feat(v2/httpserver): add PanicRecoveryMiddleware

Summary

  • Adds PanicRecoveryMiddleware to v2/httpserver that recovers from application handler panics, logs a structured ERROR entry with the panic value, stack trace, HTTP method, and URI, records the error on the active OTel span, and returns 500 Internal Server Error to the client
  • Includes a panicResponseWriter sentinel that prevents a duplicate WriteHeader(500) when the handler began writing before panicking
  • Wires PanicRecoveryMiddleware unconditionally as the innermost middleware in NewWithConfig, so all LabKit HTTP servers get automatic panic recovery without any consumer-side changes

Test plan

  • TestPanicRecoveryMiddleware — 5 table-driven unit tests covering: no panic passthrough, string panic, error panic, nil panic, headers-already-written guard
  • TestNewWithConfig_PanicRecoveryMiddleware — integration test via s.ServeHTTP asserting NotPanics and 500 status
  • Run go test ./httpserver/... -v in v2/ — all tests pass
  • Run golangci-lint — clean

🤖 Generated with Claude Code

Merge request reports

Loading
Loading