requestlog

package
v3.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Panic logging ------------

Recovered panics are always emitted at error level. Panic observations use failure status metadata (5xx) in log fields while preserving the committed status in `committed_status` when a response had already started. Enable `With5xxStackLogging(true)` to capture stack traces for recovered panics.

Index

Constants

View Source
const (
	FieldRequestID              = "request_id"
	FieldTraceID                = "trace_id"
	FieldSpanID                 = "span_id"
	FieldRoute                  = "route"
	FieldStatus                 = "status"
	FieldCommittedStatus        = "committed_status"
	FieldLatencyMS              = "latency_ms"
	FieldMethod                 = "method"
	FieldPath                   = "path"
	FieldBytes                  = "bytes"
	FieldClientIP               = "client_ip"
	FieldUserAgent              = "user_agent"
	FieldRequestHeaders         = "req_headers"
	FieldResponseHeaders        = "resp_headers"
	FieldStack                  = "stack"
	FieldPanicRecovered         = "panic_recovered"
	FieldPolicyAuth             = "policy_auth"
	FieldPolicyTenant           = "policy_tenant"
	FieldPolicyIdempotency      = "policy_idempotency"
	FieldPolicyRateLimit        = "policy_rate_limit"
	FieldPolicyAdmin            = "policy_admin"
	FieldPolicyDeprecated       = "policy_deprecated"
	FieldIdempotencyMethod      = "idempotency_method"
	FieldIdempotencyStoreClass  = "idempotency_store_class"
	FieldIdempotencyOutcome     = "idempotency_outcome"
	FieldIdempotencyStatusClass = "idempotency_status_class"
	FieldIdempotencyFailOpen    = "idempotency_fail_open"

	FieldHardTimeoutMethod          = "hard_timeout_method"
	FieldHardTimeoutOutcome         = "hard_timeout_outcome"
	FieldHardTimeoutStatusClass     = "hard_timeout_status_class"
	FieldHardTimeoutTimedOut        = "hard_timeout_timed_out"
	FieldHardTimeoutPanicked        = "hard_timeout_panicked"
	FieldHardTimeoutCaptureOverflow = "hard_timeout_capture_overflow"

	FieldWebhookDeliveryEventType   = "webhook_delivery_event_type"
	FieldWebhookDeliveryOutcome     = "webhook_delivery_outcome"
	FieldWebhookDeliveryStatusClass = "webhook_delivery_status_class"
)

Variables

This section is empty.

Functions

func HardTimeoutEventFields

func HardTimeoutEventFields(event timeoutmw.HardTimeoutEvent) []any

HardTimeoutEventFields returns bounded log fields for a hard-timeout event. It intentionally omits request paths, tenant IDs, request IDs, headers, bodies, panic values, and raw error strings.

func HardTimeoutEventLogHook

func HardTimeoutEventLogHook(log ports.Logger) func(timeoutmw.HardTimeoutEvent)

HardTimeoutEventLogHook returns a hard-timeout middleware event hook that writes bounded timeout fields to the configured logger.

func IdempotencyOutcomeFields

func IdempotencyOutcomeFields(event idempotencymw.OutcomeEvent) []any

IdempotencyOutcomeFields returns bounded log fields for an idempotency outcome. It intentionally omits request paths, tenant IDs, idempotency keys, request IDs, bodies, and raw error strings.

func IdempotencyOutcomeLogHook

func IdempotencyOutcomeLogHook(log ports.Logger) idempotencymw.OutcomeHandler

IdempotencyOutcomeLogHook returns an idempotency middleware outcome hook that writes bounded outcome fields to the configured logger.

func IsSensitiveFieldName

func IsSensitiveFieldName(name string) bool

IsSensitiveFieldName reports whether the field name should be treated as sensitive for request log payloads.

func RedactPayloadFields

func RedactPayloadFields(fields map[string]any) map[string]any

RedactPayloadFields returns a copy of fields with common sensitive payload keys replaced by redactedValue.

func RedactPayloadFieldsDeep

func RedactPayloadFieldsDeep(fields map[string]any) map[string]any

RedactPayloadFieldsDeep returns a copy of fields with sensitive payload keys replaced by redactedValue. Nested maps and slices are sanitized recursively.

func WebhookDeliveryFields

func WebhookDeliveryFields(event webhookdelivery.DeliveryObservation) []any

WebhookDeliveryFields returns bounded log fields for an outbound webhook delivery observation. It intentionally omits tenant IDs, endpoint IDs, delivery IDs, URLs, payloads, secrets, and raw error strings.

func WebhookDeliveryLogHook

func WebhookDeliveryLogHook(log ports.Logger) webhookdelivery.MetricsRecorder

WebhookDeliveryLogHook returns a webhook delivery observation hook that writes bounded delivery fields to the configured logger.

Types

type Middleware

type Middleware struct {
	Log ports.Logger
	// contains filtered or unexported fields
}

Middleware logs structured request summaries.

func New

func New(log ports.Logger, opts ...Option) (*Middleware, error)

New constructs a request logging middleware.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler with request logging. It is intended to emit exactly one request log entry on both normal and panic paths. For panic paths, it should infer the final visible status before re-panicking so outer recovery can still produce the response contract.

func (*Middleware) Middleware

func (m *Middleware) Middleware() func(http.Handler) http.Handler

Middleware implements ports.Middleware via Handler adapter.

type Option

type Option func(*Options)

Option mutates request log options.

func With5xxStackLogging

func With5xxStackLogging(enabled bool) Option

With5xxStackLogging controls whether handled 5xx responses include a stack trace.

func WithClock

func WithClock(clock ports.Clock) Option

WithClock overrides the time source used for latency measurement.

func WithRedactedHeaders

func WithRedactedHeaders(headers ...string) Option

WithRedactedHeaders appends additional header names to redact.

func WithRequestHeaders

func WithRequestHeaders() Option

WithRequestHeaders enables logging sanitized request headers.

func WithResolver

func WithResolver(resolver identity.Resolver) Option

WithResolver sets the trusted proxy resolver.

func WithResponseHeaders

func WithResponseHeaders() Option

WithResponseHeaders enables logging sanitized response headers.

func WithRoutePattern

func WithRoutePattern(fn func(*http.Request) string) Option

WithRoutePattern sets the route pattern function for logging.

type Options

type Options struct {
	Resolver           identity.Resolver
	RoutePattern       func(*http.Request) string
	LogRequestHeaders  bool
	LogResponseHeaders bool
	Log5xxStacks       bool
	RedactHeaders      []string
	Clock              ports.Clock
}

Options configures request logging behavior.

Jump to

Keyboard shortcuts

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