Documentation
¶
Overview ¶
Package logctx provides shared context utilities for logger sub-packages.
This package exists to avoid import cycles between the parent logger package and its sub-packages (zap, stdlib). Both the parent and sub-packages import this package for context key definitions and PII redaction.
Index ¶
- Constants
- func CorrelationID(ctx context.Context) string
- func NewStacktraceHandler(inner slog.Handler, minLevel slog.Level) slog.Handler
- func RedactPII(s string) string
- func SpanID(ctx context.Context) string
- func TraceID(ctx context.Context) string
- func WithCorrelationID(ctx context.Context, id string) context.Context
Constants ¶
const StacktraceKey = "stacktrace"
StacktraceKey is the attribute key under which the captured stack is logged.
Variables ¶
This section is empty.
Functions ¶
func CorrelationID ¶
CorrelationID extracts the correlation ID from context. Returns empty string if no correlation ID is present.
func NewStacktraceHandler ¶
NewStacktraceHandler returns a handler that appends a captured stack trace to records logged at or above minLevel. Records below the threshold pass through unchanged.
func RedactPII ¶
RedactPII replaces PII (email, phone, SSN, IPv4, auth tokens) with "[REDACTED]" in a single pass.
func SpanID ¶
SpanID extracts the OpenTelemetry span ID from context. Returns the hex-encoded span ID string if a valid span context is present, empty string otherwise. This enables drill-down from log entries to specific spans within a trace.
Types ¶
This section is empty.