Package trace implements tracing of requests and long-lived objects. It exports HTTP interfaces on /debug/requests and /debug/events.

A trace.Trace provides tracing for short-lived objects, usually requests. A request handler might be implemented like this:

func fooHandler(w http.ResponseWriter, req *http.Request) {
	tr := trace.New("mypkg.Foo", req.URL.Path)
	defer tr.Finish()
	tr.LazyPrintf("some event %q happened", str)
	if err := somethingImportant(); err != nil {
		tr.LazyPrintf("somethingImportant failed: %v", err)

The /debug/requests HTTP endpoint organizes the traces by family, errors, and duration. It also provides histogram of request duration for each family.

A trace.EventLog provides tracing for long-lived objects, such as RPC connections.

// A Fetcher fetches URL paths for a single domain.
type Fetcher struct {
	domain string
	events trace.EventLog

func NewFetcher(domain string) *Fetcher {
	return &Fetcher{
		trace.NewEventLog("mypkg.Fetcher", domain),

func (f *Fetcher) Fetch(path string) (string, error) {
	resp, err := http.Get("http://" + f.domain + "/" + path)
	if err != nil {"Get(%q) = %v", path, err)
		return "", err
	}"Get(%q) = %s", path, resp.Status)

func (f *Fetcher) Close() error {
	return nil

The /debug/events HTTP endpoint organizes the event logs by family and by time since the last error. The expanded view displays recent log entries and the log's call stack.

trace is referenced in 0 repositories