eztrc

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collector

func Collector() *trc.Collector

Collector returns the global trc.Collector.

func Errorf

func Errorf(ctx context.Context, format string, args ...any)

Errorf adds a new error event to the trace in the context. Arguments are evaluated immediately.

func Get

func Get(ctx context.Context) trc.Trace

Get calls trc.Get.

func Handler

func Handler() http.Handler

Handler returns an HTTP handler for the global trace collector.

func LazyErrorf

func LazyErrorf(ctx context.Context, format string, args ...any)

LazyErrorf adds a new error event to the trace in the context. Arguments are evaluated lazily.

func LazyTracef

func LazyTracef(ctx context.Context, format string, args ...any)

LazyTracef adds a new normal event to the trace in the context. Arguments are evaluated lazily.

func MaybeGet

func MaybeGet(ctx context.Context) (trc.Trace, bool)

MaybeGet calls trc.MaybeGet.

func Middleware

func Middleware(categorize func(*http.Request) string) func(http.Handler) http.Handler

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

func New(ctx context.Context, category string) (context.Context, trc.Trace)

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

func Prefix(ctx context.Context, format string, args ...any) (context.Context, trc.Trace)

Prefix calls trc.Prefix.

func Region

func Region(ctx context.Context, name string) (context.Context, trc.Trace, func())

Region calls trc.Region.

func Tracef

func Tracef(ctx context.Context, format string, args ...any)

Tracef adds a new normal event to the trace in the context. Arguments are evaluated immediately.

Types

This section is empty.

Jump to

Keyboard shortcuts

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