observe

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package observe provides shared helpers for request observation code such as access logging and panic recovery.

Index

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 Level

func Level(status int) slog.Level

Level maps an HTTP status code to the structured log level Credo uses.

func PanicAttrs

func PanicAttrs(value any, method string, path string, requestID string, stack string) []slog.Attr

PanicAttrs builds the common structured attributes used by Credo's built-in recovery and the configurable middleware.Recover.

func PanicError

func PanicError(v any) error

PanicError converts a recovered panic value into an error.

func StackTrace

func StackTrace(limit int) string

StackTrace returns the current goroutine stack. If limit is positive, the returned string is truncated to at most limit bytes without splitting UTF-8.

func Status

func Status(status int, err error) int

Status resolves the final HTTP status from a tracked response status and an optional returned error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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