reqtrace: Index | Files

package reqtrace

import ""

Package reqtrace contains a very simple request tracing framework.


Package Files

reqtrace.go trace_state.go

func Enabled Uses

func Enabled() (enabled bool)

Return false only if traces are disabled, i.e. Trace will never cause a trace to be initiated.

REQUIRES: flag.Parsed()

func StartSpan Uses

func StartSpan(
    parent context.Context,
    desc string) (ctx context.Context, report ReportFunc)

Begin a span within the current trace. Return a new context that should be used for operations that logically occur within the span, and a report function that must be called with the outcome of the logical operation represented by the span.

If no trace is active, no span will be created but ctx and report will still be valid.

func StartSpanWithError Uses

func StartSpanWithError(
    ctx *context.Context,
    err *error,
    desc string) (f func())

A wrapper around StartSpan that can be more convenient to use when the lifetime of a span matches the lifetime of a function. Intended to be used in a defer statement within a function using a named error return parameter.

Equivalent to calling StartSpan with *ctx, replacing *ctx with the resulting new context, then setting f to a function that will invoke the report function with the contents of *error at the time that it is called.


func DoSomething(ctx context.Context) (err error) {
  defer reqtrace.StartSpanWithError(&ctx, &err, "DoSomething")()

func Trace Uses

func Trace(
    parent context.Context,
    desc string) (ctx context.Context, report ReportFunc)

Like StartSpan, but begins a root span for a new trace if no trace is active in the supplied context and tracing is enabled for the process.

type ReportFunc Uses

type ReportFunc func(error)

A function that must be called exactly once to report the outcome of an operation represented by a span.

Package reqtrace imports 8 packages (graph) and is imported by 5 packages. Updated 2016-08-02. Refresh now. Tools for package owners.