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
- func HardTimeoutEventFields(event timeoutmw.HardTimeoutEvent) []any
- func HardTimeoutEventLogHook(log ports.Logger) func(timeoutmw.HardTimeoutEvent)
- func IdempotencyOutcomeFields(event idempotencymw.OutcomeEvent) []any
- func IdempotencyOutcomeLogHook(log ports.Logger) idempotencymw.OutcomeHandler
- func IsSensitiveFieldName(name string) bool
- func RedactPayloadFields(fields map[string]any) map[string]any
- func RedactPayloadFieldsDeep(fields map[string]any) map[string]any
- func WebhookDeliveryFields(event webhookdelivery.DeliveryObservation) []any
- func WebhookDeliveryLogHook(log ports.Logger) webhookdelivery.MetricsRecorder
- type Middleware
- type Option
- func With5xxStackLogging(enabled bool) Option
- func WithClock(clock ports.Clock) Option
- func WithRedactedHeaders(headers ...string) Option
- func WithRequestHeaders() Option
- func WithResolver(resolver identity.Resolver) Option
- func WithResponseHeaders() Option
- func WithRoutePattern(fn func(*http.Request) string) Option
- type Options
Constants ¶
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 ¶
IsSensitiveFieldName reports whether the field name should be treated as sensitive for request log payloads.
func RedactPayloadFields ¶
RedactPayloadFields returns a copy of fields with common sensitive payload keys replaced by redactedValue.
func RedactPayloadFieldsDeep ¶
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 ¶
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 ¶
With5xxStackLogging controls whether handled 5xx responses include a stack trace.
func WithRedactedHeaders ¶
WithRedactedHeaders appends additional header names to redact.
func WithRequestHeaders ¶
func WithRequestHeaders() Option
WithRequestHeaders enables logging sanitized request headers.
func WithResolver ¶
WithResolver sets the trusted proxy resolver.
func WithResponseHeaders ¶
func WithResponseHeaders() Option
WithResponseHeaders enables logging sanitized response headers.