Documentation ¶
Overview ¶
span is a very simple implementation of ideas presented in Google's Dapper paper (http://research.google.com/pubs/pub36356.html). The basic idea is that every request has a Span object associated with it which allows for registering subspans (used for timing subroutines), attributes (arbitrary metadata) and counts (incrementers ala StatsD). At the end of a request, this span is turned into JSON and logged to logger as well as the timings and counters sent through the supplied StatsRecorder.
Index ¶
- func DefaultUUIDGenerator() string
- type AtomicCounter
- type DebugStatsRecorder
- func (s *DebugStatsRecorder) Counter(stat string, amount int64)
- func (s *DebugStatsRecorder) DurationTimer(stat string, begin time.Time, end time.Time)
- func (s *DebugStatsRecorder) Gauge(stat string, amount int64)
- func (s *DebugStatsRecorder) Increment(stat string)
- func (s *DebugStatsRecorder) Timer(stat string, amount int64)
- type Span
- func (s *Span) Add(name string, val int64) int64
- func (s *Span) Attr(k, v string)
- func (s *Span) CollectMemStats()
- func (s *Span) Duration(name string) int64
- func (s *Span) Finish(name string) (duration int64)
- func (s *Span) Increment(name string) int64
- func (s *Span) JSON() string
- func (s *Span) MergeJSON(span string) (err error)
- func (s *Span) MillisecondDuration(name string) float64
- func (s *Span) Record()
- func (s *Span) Start(name string)
- func (s *Span) String() string
- func (s *Span) SubSpan(name string) (sub *SubSpan)
- func (s *Span) SubSpanWithDuration(name string, msduration float64)
- type SpanJSON
- type StatsRecorder
- type SubSpan
- type UUIDGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultUUIDGenerator ¶
func DefaultUUIDGenerator() string
The DefaultUUIDGenerator uses "github.com/satori/go.uuid"/V1 to generate RFC 4122 compatible uuids
Types ¶
type AtomicCounter ¶
type AtomicCounter struct {
// contains filtered or unexported fields
}
func (*AtomicCounter) Decrement ¶
func (counter *AtomicCounter) Decrement() int64
func (*AtomicCounter) Increment ¶
func (counter *AtomicCounter) Increment() int64
func (*AtomicCounter) Load ¶
func (counter *AtomicCounter) Load() int64
func (*AtomicCounter) LoadFast ¶
func (counter *AtomicCounter) LoadFast() int64
func (*AtomicCounter) Store ¶
func (counter *AtomicCounter) Store(val int64)
type DebugStatsRecorder ¶
type DebugStatsRecorder struct{}
func (*DebugStatsRecorder) Counter ¶
func (s *DebugStatsRecorder) Counter(stat string, amount int64)
func (*DebugStatsRecorder) DurationTimer ¶
func (*DebugStatsRecorder) Gauge ¶
func (s *DebugStatsRecorder) Gauge(stat string, amount int64)
func (*DebugStatsRecorder) Increment ¶
func (s *DebugStatsRecorder) Increment(stat string)
func (*DebugStatsRecorder) Timer ¶
func (s *DebugStatsRecorder) Timer(stat string, amount int64)
type Span ¶
type Span struct { sync.Mutex Stats StatsRecorder Id string ParentId string SubSpans map[string]*SubSpan Counters map[string]int64 Attrs map[string]string }
Span is the main object passed through a RequestHandler that stores all the metadata about a request. It should be initialized with a UUID through NewSpan().
func NewSpan ¶
Initialize a Span for a unique request with a UUID. This also initializes all of the substructures/maps for storing the metadata.
func (*Span) Add ¶
Add increments the counter at name by val. names for counters also are unique per-Span.
func (*Span) CollectMemStats ¶
func (s *Span) CollectMemStats()
CollectMemStats populates the span with a number of memory statistics from runtime.MemStats. Call this before logging your span for info about your applications memory usage
func (*Span) Finish ¶
Finish marks the subspan at name as finished, returning the duration (useful for debug logging). This does not have to be called in the same goroutine or location as the .Start() for the SubSpan, in fact, you can call Finish on an unstarted SubSpan without error (the duration will be 0).
func (*Span) JSON ¶
JSON marshalls the Span into a JSON formatted string with all the subspans turned into their millisecond durations. This is the default for what is logged by the tcpez server.
func (*Span) MergeJSON ¶
MergeJSON imports values from a wellformed json that looks like {"subspans": {}, "attrs": {}, "counters": {}}
func (*Span) MillisecondDuration ¶
MillisecondDuration() returns a float64 of the duration with millisecond prescision.
func (*Span) Record ¶
func (s *Span) Record()
Record flushes the counters and SubSpan durations to the provider StatsRecorder. By default this goes to /dev/null, but using the StatsdStatsdRecorder this can be flushed to Statsd (or any other service that conforms to the StatsRecorder interface)
func (*Span) Start ¶
Start a subspan with name. names need to be unique per-Span as these are stored in a map of name->SubSpan. If you have multiple recouring calls to a subroutine in a request, consider naming them with `method-newuuid`
func (*Span) String ¶
String turns the Span into a k=v formatted string with the subspans turned into their millisecond durations.
func (*Span) SubSpan ¶
SubSpan returns the SubSpan at name. If the SubSpan does not exist, it initializes a new one with name.
func (*Span) SubSpanWithDuration ¶
SubSpanWithDuration creates a new subspan with the duration expressed as a float64 of milliseconds.
type StatsRecorder ¶
type SubSpan ¶
A SubSpan represents an unique subroutine and its start/end times. These are coallated at the end of a Span and turned into Durations.
func (*SubSpan) MillisecondDuration ¶
The Duration of the subspan as a millisecond prescision float64
type UUIDGenerator ¶
type UUIDGenerator func() string
A UUIDGenerator is a func that returns a unique id as a string