traceutil

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicRecoveryError

func PanicRecoveryError(err any) (bool, string, []string)

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) Write

func (w *CustomResponseWriter) Write(b []byte) (int, error)

func (*CustomResponseWriter) WriteHeader

func (w *CustomResponseWriter) WriteHeader(code int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL