v.io: v.io/v23/vtrace Index | Files

package vtrace

import "v.io/v23/vtrace"

Package vtrace defines a system for collecting debugging information about operations that span a distributed system. We call the debugging information attached to one operation a Trace. A Trace may span many processes on many machines.

Traces are composed of a hierarchy of Spans. A span is a named timespan, that is, it has a name, a start time, and an end time. For example, imagine we are making a new blog post. We may have to first authentiate with an auth server, then write the new post to a database, and finally notify subscribers of the new content. The trace might look like this:

Trace:
<---------------- Make a new blog post ----------->
|                  |                   |
<- Authenticate -> |                   |
                   |                   |
                   <-- Write to DB --> |
                                       <- Notify ->
0s                      1.5s                      3s

Here we have a single trace with four Spans. Note that some Spans are children of other Spans. Vtrace works by attaching data to a Context, and this hierarchical structure falls directly out of our building off of the tree of Contexts. When you derive a new context using WithNewSpan(), you create a Span thats a child of the currently active span in the context. Note that spans that share a parent may overlap in time.

In this case the tree would have been created with code like this:

function MakeBlogPost(ctx *context.T) {
    authCtx, _ := vtrace.WithNewSpan(ctx, "Authenticate")
    Authenticate(authCtx)
    writeCtx, _ := vtrace.WithNewSpan(ctx, "Write To DB")
    Write(writeCtx)
    notifyCtx, _ := vtrace.WithNewSpan(ctx, "Notify")
    Notify(notifyCtx)
}

Just as we have Spans to represent time spans we have Annotations to attach debugging information that is relevant to the current moment. You can add an annotation to the current span by calling the Span's Annotate method:

span := vtrace.GetSpan(ctx)
span.Annotate("Just got an error")

When you make an annotation we record the annotation and the time when it was attached.

Traces can be composed of large numbers of spans containing data collected from large numbers of different processes. Always collecting this information would have a negative impact on performance. By default we don't collect any data. If a particular operation is of special importance you can force it to be collected by calling ForceCollect. You can also use the --v23.vtrace.collect-regexp flag to set a regular expression which will force us to record any matching trace.

If your trace has collected information you can retrieve the data collected so far with the Store's TraceRecord and TraceRecords methods.

By default contexts obtained from v23.Init or in rpc server implementations already have an initialized Trace. The functions in this package allow you to add data to existing traces or start new ones.

nolint:golint

Index

Package Files

format.go model.go vtrace.vdl.go

Constants

const CollectInMemory = TraceFlags(1)
const Empty = TraceFlags(0)

func ForceCollect Uses

func ForceCollect(ctx *context.T, level int)

ForceCollect forces the store to collect all information about the current trace.

func FormatTrace Uses

func FormatTrace(w io.Writer, record *TraceRecord, loc *time.Location)

FormatTrace writes a text description of the given trace to the given writer. Times will be formatted according to the given location, if loc is nil local times will be used.

func FormatTraces Uses

func FormatTraces(w io.Writer, records []TraceRecord, loc *time.Location)

FormatTraces writes a text description of all the given traces to the given writer. Times will be formatted according to the given location, if loc is nil local times will be used.

func WithManager Uses

func WithManager(ctx *context.T, manager Manager) *context.T

WithManager returns a new context with a Vtrace manager attached.

type Annotation Uses

type Annotation struct {
    // When the annotation was added.
    When time.Time
    // The annotation message.
    // TODO(mattr): Allow richer annotations.
    Message string
}

An Annotation represents data that is relevant at a specific moment. They can be attached to spans to add useful debugging information.

func (Annotation) VDLIsZero Uses

func (x Annotation) VDLIsZero() bool

func (*Annotation) VDLRead Uses

func (x *Annotation) VDLRead(dec vdl.Decoder) error

func (Annotation) VDLReflect Uses

func (Annotation) VDLReflect(struct {
    Name string `vdl:"v.io/v23/vtrace.Annotation"`
})

func (Annotation) VDLWrite Uses

func (x Annotation) VDLWrite(enc vdl.Encoder) error

type Manager Uses

type Manager interface {
    // WithNewTrace creates a new vtrace context that is not the child of any
    // other span.  This is useful when starting operations that are
    // disconnected from the activity ctx is performing.  For example
    // this might be used to start background tasks.
    WithNewTrace(ctx *context.T) (*context.T, Span)

    // WithContinuedTrace creates a span that represents a continuation of
    // a trace from a remote server.  name is the name of the new span and
    // req contains the parameters needed to connect this span with it's
    // trace.
    WithContinuedTrace(ctx *context.T, name string, req Request) (*context.T, Span)

    // WithNewSpan derives a context with a new Span that can be used to
    // trace and annotate operations across process boundaries.
    WithNewSpan(ctx *context.T, name string) (*context.T, Span)

    // Span finds the currently active span.
    GetSpan(ctx *context.T) Span

    // Store returns the current Store.
    GetStore(ctx *context.T) Store

    // Generate a Request from the current context.
    GetRequest(ctx *context.T) Request

    // Generate a Response from the current context.
    GetResponse(ctx *context.T) Response
}

type Node Uses

type Node struct {
    Span     *SpanRecord
    Children []*Node
}

func BuildTree Uses

func BuildTree(trace *TraceRecord) *Node

TODO(mattr): It is useful in general to make a tree of spans for analysis as well as formatting. This interface should be cleaned up and exported.

type Request Uses

type Request struct {
    SpanId   uniqueid.Id // The Id of the span that originated the RPC call.
    TraceId  uniqueid.Id // The Id of the trace this call is a part of.
    Flags    TraceFlags
    LogLevel int32
}

Request is the object that carries trace information between processes.

func GetRequest Uses

func GetRequest(ctx *context.T) Request

Generate a Request from the current context.

func (Request) VDLIsZero Uses

func (x Request) VDLIsZero() bool

func (*Request) VDLRead Uses

func (x *Request) VDLRead(dec vdl.Decoder) error

func (Request) VDLReflect Uses

func (Request) VDLReflect(struct {
    Name string `vdl:"v.io/v23/vtrace.Request"`
})

func (Request) VDLWrite Uses

func (x Request) VDLWrite(enc vdl.Encoder) error

type Response Uses

type Response struct {
    // Flags give options for trace collection, the client should alter its
    // collection for this trace according to the flags sent back from the
    // server.
    Flags TraceFlags
    // Trace is collected trace data.  This may be empty.
    Trace TraceRecord
}

func GetResponse Uses

func GetResponse(ctx *context.T) Response

Generate a Response from the current context.

func (Response) VDLIsZero Uses

func (x Response) VDLIsZero() bool

func (*Response) VDLRead Uses

func (x *Response) VDLRead(dec vdl.Decoder) error

func (Response) VDLReflect Uses

func (Response) VDLReflect(struct {
    Name string `vdl:"v.io/v23/vtrace.Response"`
})

func (Response) VDLWrite Uses

func (x Response) VDLWrite(enc vdl.Encoder) error

type Span Uses

type Span interface {
    // Name returns the name of the span.
    Name() string

    // ID returns the uniqueid.ID of the span.
    ID() uniqueid.Id

    // Parent returns the uniqueid.ID of this spans parent span.
    Parent() uniqueid.Id

    // Annotate adds a string annotation to the trace.  Where Spans
    // represent time periods Annotations represent data thats relevant
    // at a specific moment.
    Annotate(s string)

    // Annotatef adds an annotation to the trace.  Where Spans represent
    // time periods Annotations represent data thats relevant at a
    // specific moment.
    // format and a are interpreted as with fmt.Printf.
    Annotatef(format string, a ...interface{})

    // Finish ends the span, marking the end time.  The span should
    // not be used after Finish is called.
    Finish()

    // Trace returns the id of the trace this Span is a member of.
    Trace() uniqueid.Id
}

Spans represent a named time period. You can create new spans to represent new parts of your computation. Spans are safe to use from multiple goroutines simultaneously.

func GetSpan Uses

func GetSpan(ctx *context.T) Span

Span finds the currently active span.

func WithContinuedTrace Uses

func WithContinuedTrace(ctx *context.T, name string, req Request) (*context.T, Span)

WithContinuedTrace creates a span that represents a continuation of a trace from a remote server. name is the name of the new span and req contains the parameters needed to connect this span with it's trace.

func WithNewSpan Uses

func WithNewSpan(ctx *context.T, name string) (*context.T, Span)

WithNewSpan derives a context with a new Span that can be used to trace and annotate operations across process boundaries.

func WithNewTrace Uses

func WithNewTrace(ctx *context.T) (*context.T, Span)

WithNewTrace creates a new vtrace context that is not the child of any other span. This is useful when starting operations that are disconnected from the activity ctx is performing. For example this might be used to start background tasks.

type SpanRecord Uses

type SpanRecord struct {
    Id     uniqueid.Id // The Id of the Span.
    Parent uniqueid.Id // The Id of this Span's parent.
    Name   string      // The Name of this span.
    Start  time.Time   // The start time of this span.
    End    time.Time   // The end time of this span.
    // A series of annotations.
    Annotations []Annotation
}

A SpanRecord is the wire format for a Span.

func (SpanRecord) VDLIsZero Uses

func (x SpanRecord) VDLIsZero() bool

func (*SpanRecord) VDLRead Uses

func (x *SpanRecord) VDLRead(dec vdl.Decoder) error

func (SpanRecord) VDLReflect Uses

func (SpanRecord) VDLReflect(struct {
    Name string `vdl:"v.io/v23/vtrace.SpanRecord"`
})

func (SpanRecord) VDLWrite Uses

func (x SpanRecord) VDLWrite(enc vdl.Encoder) error

type Store Uses

type Store interface {
    // TraceRecords returns TraceRecords for all traces saved in the store.
    TraceRecords() []TraceRecord

    // TraceRecord returns a TraceRecord for a given ID.  Returns
    // nil if the given id is not present.
    TraceRecord(traceid uniqueid.Id) *TraceRecord

    // ForceCollect forces the store to collect all information about a given trace and to capture
    // the log messages at the given log level.
    ForceCollect(traceid uniqueid.Id, level int)

    // Merge merges a vtrace.Response into the current store.
    Merge(response Response)
}

Store selectively collects information about traces in the system.

func GetStore Uses

func GetStore(ctx *context.T) Store

VtraceStore returns the current Store.

type TraceFlags Uses

type TraceFlags int32

func (TraceFlags) VDLIsZero Uses

func (x TraceFlags) VDLIsZero() bool

func (*TraceFlags) VDLRead Uses

func (x *TraceFlags) VDLRead(dec vdl.Decoder) error

func (TraceFlags) VDLReflect Uses

func (TraceFlags) VDLReflect(struct {
    Name string `vdl:"v.io/v23/vtrace.TraceFlags"`
})

func (TraceFlags) VDLWrite Uses

func (x TraceFlags) VDLWrite(enc vdl.Encoder) error

type TraceRecord Uses

type TraceRecord struct {
    Id    uniqueid.Id
    Spans []SpanRecord
}

func (TraceRecord) VDLIsZero Uses

func (x TraceRecord) VDLIsZero() bool

func (*TraceRecord) VDLRead Uses

func (x *TraceRecord) VDLRead(dec vdl.Decoder) error

func (TraceRecord) VDLReflect Uses

func (TraceRecord) VDLReflect(struct {
    Name string `vdl:"v.io/v23/vtrace.TraceRecord"`
})

func (TraceRecord) VDLWrite Uses

func (x TraceRecord) VDLWrite(enc vdl.Encoder) error

Package vtrace imports 8 packages (graph) and is imported by 55 packages. Updated 2020-10-29. Refresh now. Tools for package owners.