libtracker

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKeyRequestID = contextKey("request_id")
View Source
var ContextKeySpanID = contextKey("span_id")
View Source
var ContextKeyTraceID = contextKey("trace_id")

Functions

func CopyTrackingValues

func CopyTrackingValues(src context.Context, dst context.Context) context.Context

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, so a caller can extend rather than replace the defaults.

func WithNewRequestID

func WithNewRequestID(ctx context.Context) context.Context

WithNewRequestID stamps a fresh random request ID into ctx. Request IDs are correlation keys only: do not reuse one as a token, nonce or idempotency key.

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 without coupling core logic to a monitoring backend. Start returns reportErr, reportChange and end; end must be called exactly once, the other two at most once each.

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 returns an ActivityTracker over logger. Values are scrubbed by field name before being logged.

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.

type ChainedTracker

type ChainedTracker []ActivityTracker

ChainedTracker wraps multiple ActivityTrackers into one, broadcasting every event to all of them.

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 across every chained tracker.

type LogOption added in v0.37.0

type LogOption func(*logActivityTracker)

LogOption customizes a log-backed ActivityTracker.

func WithRedactedFields added in v0.37.0

func WithRedactedFields(names ...string) LogOption

WithRedactedFields replaces the built-in sensitive field-name list (see DefaultRedactedFields). Names are matched case-insensitively as substrings, and passing none disables redaction entirely.

type NoopTracker

type NoopTracker struct{}

NoopTracker is a null-object ActivityTracker.

func (NoopTracker) Start

func (NoopTracker) Start(
	ctx context.Context,
	operation string,
	subject string,
	kvArgs ...any,
) (
	func(error),
	func(string, any),
	func(),
)

Jump to

Keyboard shortcuts

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