Documentation
¶
Overview ¶
Package httplog centralizes HTTP request logging for the AgentBox API servers. It provides a request-ID middleware, structured error logging keyed off domain.AppError, and a gin log formatter that includes the request ID and any error attached via c.Error.
The design goal is that every 5xx response a client sees has a matching ERROR-level log line on the server, with enough context (method, path, request ID, underlying cause) to diagnose the failure without enabling request-body capture.
Index ¶
Constants ¶
const ( // RequestIDHeader is the HTTP header clients may send to set the request // ID. When absent a UUID v7 is generated server-side. RequestIDHeader = "X-Request-ID" )
Variables ¶
This section is empty.
Functions ¶
func GinLogFormatter ¶
func GinLogFormatter(prefix string) gin.LogFormatter
GinLogFormatter returns a gin.LogFormatter that prefixes each line with the given tag (e.g. "[RAW]" for the native API, "[E2B]" for the E2B compat API) and includes the request ID plus any errors attached to the request via c.Error (typically by LogAppError).
The request ID is taken from the X-Request-ID response header, which the RequestID middleware sets on every request.
func LogAppError ¶
LogAppError emits a klog entry for an AppError returned from the service layer. 5xx-class codes are logged at ERROR level with the underlying Cause; 4xx-class codes are logged at V(4) to avoid flooding production logs with client-side validation failures.
c may be nil (e.g. when called from a non-gin code path); the helper then falls back to logging without request metadata.
func LogServerError ¶
LogServerError logs an unexpected server-side error that did not go through the AppError abstraction (e.g. a JSON marshal failure inside a handler). Always logged at ERROR level. c may be nil.
func RequestID ¶
func RequestID() gin.HandlerFunc
RequestID returns a middleware that assigns each request a UUID v7 ID and echoes it back in the X-Request-ID response header. Existing inbound IDs (e.g. from an upstream gateway) are preserved so logs can be correlated across hops.
func RequestIDFromGin ¶
RequestIDFromGin returns the request ID attached to the gin context by RequestID middleware. Empty when the middleware was not installed.
Types ¶
This section is empty.