Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecoverMiddleware ¶
func RecoverMiddleware(next http.HandlerFunc, logger *zap.Logger, debug bool) http.HandlerFunc
func TraceMiddleware ¶
func TraceMiddleware(next http.HandlerFunc, logger *zap.Logger, debug bool) http.HandlerFunc
TraceMiddleware provides OpenTelemetry tracing and structured logging for HTTP handlers. It creates a new span for each request, linking it to any upstream traces, and enriches the logger with trace and span IDs for context propagation.
The middleware logs request completion with varying severity levels (Info, Warn, Error) based on the HTTP status code. When the debug flag is enabled, it enhances error logs for 4xx and 5xx responses by including full request/response headers and bodies.
Note: Enabling debug mode causes the entire request body to be read into memory. This can lead to high memory consumption for large payloads, such as file uploads, and is a known limitation. Use with caution in environments that handle large requests.
Types ¶
type CustomResponseWriter ¶
type CustomResponseWriter struct {
http.ResponseWriter
StatusCode int
Body *bytes.Buffer
}
func (*CustomResponseWriter) WriteHeader ¶
func (w *CustomResponseWriter) WriteHeader(code int)