Documentation ¶
Overview ¶
Package eztrc provides an easy-to-use API for common tracing use cases. Most applications should only need to import this package.
A global Collector maintains recent traces, grouped by category, in memory. Applications should call New to create a trace in that collector for each e.g. request they process. The Middleware helper provides a simple decorator for HTTP handlers which does this work.
Traces are always created within a context. Application code should "log" by adding events to the trace in that context. Callers can use Get to fetch the current trace from a context, or helpers like Tracef to log events directly to the trace in the context.
Traces are accessed via the Handler, which provides an HTTP interface to the global collector. Applications should install the handler to their internal or debug HTTP server.
See the examples directory for more complete example applications.
Index ¶
- func Collector() *trc.Collector
- func Errorf(ctx context.Context, format string, args ...any)
- func Get(ctx context.Context) trc.Trace
- func Handler() http.Handler
- func LazyErrorf(ctx context.Context, format string, args ...any)
- func LazyTracef(ctx context.Context, format string, args ...any)
- func MaybeGet(ctx context.Context) (trc.Trace, bool)
- func Middleware(categorize func(*http.Request) string) func(http.Handler) http.Handler
- func New(ctx context.Context, category string) (context.Context, trc.Trace)
- func Prefix(ctx context.Context, format string, args ...any) (context.Context, trc.Trace)
- func Region(ctx context.Context, name string) (context.Context, trc.Trace, func())
- func Tracef(ctx context.Context, format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶
Errorf adds a new error event to the trace in the context. Arguments are evaluated immediately.
func LazyErrorf ¶
LazyErrorf adds a new error event to the trace in the context. Arguments are evaluated lazily.
func LazyTracef ¶
LazyTracef adds a new normal event to the trace in the context. Arguments are evaluated lazily.
func Middleware ¶
Middleware returns an HTTP middleware which adds a trace to the global trace collector for each received request. The category is determined by the provided categorize function.
func New ¶
New creates a new trace in the global trace collector with the provided category, injects that trace into the provided context, and returns a derived context containing the new trace, as well as the new trace itself.
func Prefix ¶
Prefix calls trc.Prefix.
func Region ¶
Region calls trc.Region.
Types ¶
This section is empty.