httplog

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

View Source
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

func LogAppError(c *gin.Context, appErr *domain.AppError)

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

func LogServerError(c *gin.Context, err error, msg string, keysAndValues ...any)

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

func RequestIDFromGin(c *gin.Context) string

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.

Jump to

Keyboard shortcuts

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