Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ContextKeyRequestID = contextKey("request_id")
var ContextKeySpanID = contextKey("span_id")
var ContextKeyTraceID = contextKey("trace_id")
Functions ¶
func CopyTrackingValues ¶
CopyTrackingValues copies the tracking values from src to dst.
func DefaultRedactedFields ¶ added in v0.37.0
func DefaultRedactedFields() []string
DefaultRedactedFields returns a copy of the built-in sensitive field-name list. It exists so a caller can extend rather than replace the defaults:
WithRedactedFields(append(DefaultRedactedFields(), "ssn")...)
func WithNewRequestID ¶
WithNewRequestID stamps a fresh random request ID into ctx. Call this at any entry point lacking one so the tracker never logs SERVERBUG.
Uses math/rand/v2, not crypto/rand, deliberately: request IDs are correlation keys only, never authenticated or authorized on, so the only requirement is collision avoidance. Do not reuse these as tokens, nonces, or idempotency keys — mint those with crypto/rand.
Types ¶
type ActivityTracker ¶
type ActivityTracker interface {
Start(
ctx context.Context,
operation string,
subject string,
kvArgs ...any,
) (
reportErr func(err error),
reportChange func(id string, data any),
end func(),
)
}
ActivityTracker instruments an operation's lifecycle (start, optional error, optional state change, end) without coupling core logic to a specific monitoring backend. Start returns reportErr, reportChange, and end: end must be called exactly once, typically via defer; reportErr and reportChange are called at most once each, depending on outcome.
func NewChainedTracker ¶
func NewChainedTracker(trackers ...ActivityTracker) ActivityTracker
NewChainedTracker creates a new ActivityTracker that chains multiple trackers.
func NewLogActivityTracker ¶
func NewLogActivityTracker(logger *slog.Logger, opts ...LogOption) ActivityTracker
NewLogActivityTracker creates a new instance of logActivityTracker.
Values are scrubbed by field name before being logged (see redact.go): this tracker is the shared instrumentation point for packages that handle tokens and keys, so redaction is on by default rather than something each caller has to remember.
func NewTextActivityTracker ¶ added in v0.37.0
func NewTextActivityTracker(w io.Writer, opts ...LogOption) ActivityTracker
NewTextActivityTracker returns an ActivityTracker that emits structured text logs to w at Info level. It owns its slog wiring so callers (e.g. command entrypoints) don't have to import log/slog just to obtain a tracker.
type ChainedTracker ¶
type ChainedTracker []ActivityTracker
ChainedTracker wraps multiple ActivityTrackers into one. All events are broadcasted to all trackers in the chain.
func (ChainedTracker) Start ¶
func (ct ChainedTracker) Start( ctx context.Context, operation string, subject string, kvArgs ...any, ) ( reportErr func(err error), reportChange func(id string, data any), end func(), )
Start implements ActivityTracker.Start by calling Start on all chained trackers. It returns combined reportErr, reportChange, and end functions that call the respective functions from all trackers.
type LogOption ¶ added in v0.37.0
type LogOption func(*logActivityTracker)
LogOption customizes a log-backed ActivityTracker.
func WithRedactedFields ¶ added in v0.37.0
WithRedactedFields REPLACES the built-in sensitive field-name list (see DefaultRedactedFields) used to scrub values before they are logged. Names are matched case-insensitively as substrings, so "key" would scrub "api_key" and "keyring" alike. Passing no names disables redaction entirely, which is only appropriate where the caller can prove no credential ever reaches the tracker.
type NoopTracker ¶
type NoopTracker struct{}
NoopTracker is a null-object ActivityTracker for tests and environments where tracking is disabled.