Documentation
¶
Index ¶
Constants ¶
const ( // RequestIDHeader is the HTTP header for request correlation. RequestIDHeader = "X-Request-ID" // RequestIDKey is the Gin context key for the request ID. RequestIDKey = "request_id" )
Variables ¶
This section is empty.
Functions ¶
func RequestID ¶
func RequestID() gin.HandlerFunc
RequestID injects a unique request ID into every request. If the client sends X-Request-ID, it is reused. Otherwise, the OTel TraceID from the active span is used (providing log↔trace correlation for free). Falls back to a new UUID when no trace context exists.
func UserSpanAttributes ¶
func UserSpanAttributes() gin.HandlerFunc
UserSpanAttributes reads the X-User-ID header injected by Oathkeeper and sets it as an attribute on the active OTel span. This allows filtering traces by authenticated user in Grafana Tempo.
func ZapLogger ¶
func ZapLogger(logger *zap.Logger) gin.HandlerFunc
ZapLogger returns a Gin middleware that logs every HTTP request using zap. Each log line includes method, path, sanitized query, status, latency, client IP, body size, and request ID.
func ZapRecovery ¶
func ZapRecovery(logger *zap.Logger) gin.HandlerFunc
ZapRecovery returns a Gin middleware that recovers from panics and logs them with zap. It returns a structured JSON error response so clients can handle the failure gracefully.
Types ¶
This section is empty.