Documentation
¶
Overview ¶
Package observe provides shared helpers for request observation code such as access logging and panic recovery.
Index ¶
- func AccessLogAttrs(method string, path string, status int, bytes int64, duration time.Duration, ...) ([9]slog.Attr, int)
- func EmitAccessLog(ctx context.Context, logger *slog.Logger, method string, path string, ...)
- func Level(status int) slog.Level
- func PanicAttrs(value any, method string, path string, requestID string, stack string) []slog.Attr
- func PanicError(v any) error
- func StackTrace(limit int) string
- func Status(status int, err error) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessLogAttrs ¶
func AccessLogAttrs( method string, path string, status int, bytes int64, duration time.Duration, remoteAddr string, userAgent string, originalPath string, requestID string, ) ([9]slog.Attr, int)
AccessLogAttrs builds the common structured attributes used by Credo's built-in access logger and the configurable middleware.AccessLog.
func EmitAccessLog ¶
func EmitAccessLog( ctx context.Context, logger *slog.Logger, method string, path string, status int, bytes int64, duration time.Duration, remoteAddr string, userAgent string, originalPath string, requestID string, )
EmitAccessLog assembles the standard access-log attributes and writes a single "request completed" entry at the status-derived level. It is the one source for the attribute set, message, and level shared by the built-in access logger and middleware.AccessLog; callers collect the per-request primitives (this package cannot import the root credo package).
func PanicAttrs ¶
PanicAttrs builds the common structured attributes used by Credo's built-in recovery and the configurable middleware.Recover.
func PanicError ¶
PanicError converts a recovered panic value into an error.
func StackTrace ¶
StackTrace returns the current goroutine stack. If limit is positive, the returned string is truncated to at most limit bytes without splitting UTF-8.
Types ¶
This section is empty.