nettrace

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package nettrace implements tracing of requests. Traces are created by nettrace.New, and can then be viewed over HTTP on /debug/traces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, tr Trace) context.Context

NewContext returns a new context with the given trace attached.

func RegisterHandler

func RegisterHandler(mux *http.ServeMux)

RegisterHandler registers a the trace handler in the given ServeMux, on `/debug/traces`.

func RenderTraces

func RenderTraces(w http.ResponseWriter, req *http.Request)

RenderTraces is an http.Handler that renders the tracing information.

Types

type Trace

type Trace interface {
	// NewChild creates a new trace, that is a child of this one.
	NewChild(family, title string) Trace

	// Link to another trace with the given message.
	Link(other Trace, msg string)

	// SetMaxEvents sets the maximum number of events that will be stored in
	// the trace. It must be called right after initialization.
	SetMaxEvents(n int)

	// SetError marks that the trace was for an error event.
	SetError()

	// Printf adds a message to the trace.
	Printf(format string, a ...interface{})

	// Errorf adds a message to the trace, marks it as an error, and returns
	// an error for it.
	Errorf(format string, a ...interface{}) error

	// Finish marks the trace as complete.
	// The trace should not be used after calling this method.
	Finish()
}

Trace represents a single request trace.

func ChildFromContext

func ChildFromContext(ctx context.Context, family, title string) Trace

ChildFromContext returns a new trace that is a child of the one attached to the context (if any).

func FromContext

func FromContext(ctx context.Context) (Trace, bool)

FromContext returns the trace attached to the given context (if any).

func FromContextOrNew

func FromContextOrNew(ctx context.Context, family, title string) (Trace, context.Context)

FromContextOrNew returns the trace attached to the given context, or a new trace if there is none.

func New

func New(family, title string) Trace

New creates a new trace with the given family and title.

Jump to

Keyboard shortcuts

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