Documentation ¶
Overview ¶
Package tracer implements a Dapper-style tracing system. It is compatible with the OpenTracing specification.
Sampling ¶
To keep the overhead incurred by tracing low, only a subset of requests should be traced. This is achieved by a sampler. Each tracer has a sampler that may sample requests based on chance, a rate, or possibly other mechanisms. The default sampler samples all requests, which is useful for testing, and viable for low-traffic systems.
Only root spans make sampling decisions. Child spans will inherit the sampling decisions of the root spans.
Errors and logging ¶
The instrumentation is defensive and will never purposefully panic. At the same time, most functions do not return errors, because they'll be called by automatic instrumentation, hidden from the user. Instead, errors will be logged.
Index ¶
- Constants
- func RegisterExtracter(format interface{}, extracter Extracter)
- func RegisterInjecter(format interface{}, injecter Injecter)
- type Extracter
- type Flusher
- type GRPC
- type GRPCOptions
- type IDGenerator
- type Injecter
- type Logger
- type RandomID
- type RawRelation
- type RawSpan
- type RawTrace
- type Sampler
- type Span
- func (sp *Span) BaggageItem(key string) string
- func (sp *Span) Context() opentracing.SpanContext
- func (sp *Span) Finish()
- func (sp *Span) FinishWithOptions(opts opentracing.FinishOptions)
- func (sp *Span) Log(data opentracing.LogData)
- func (sp *Span) LogEvent(event string)
- func (sp *Span) LogEventWithPayload(event string, payload interface{})
- func (sp *Span) LogFields(fields ...tracinglog.Field)
- func (sp *Span) LogKV(keyValues ...interface{})
- func (sp *Span) RawSpan() RawSpan
- func (sp *Span) Sampled() bool
- func (sp *Span) SetBaggageItem(key, value string) opentracing.Span
- func (sp *Span) SetOperationName(name string) opentracing.Span
- func (sp *Span) SetTag(key string, value interface{}) opentracing.Span
- func (sp *Span) Tracer() opentracing.Tracer
- type SpanContext
- type Storer
- type Tracer
- func (tr *Tracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error)
- func (tr *Tracer) Flush() error
- func (tr *Tracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error
- func (tr *Tracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span
Constants ¶
const ( // The Span has been sampled. FlagSampled = 1 << iota )
The various flags of a Span.
Variables ¶
This section is empty.
Functions ¶
func RegisterExtracter ¶
func RegisterExtracter(format interface{}, extracter Extracter)
RegisterExtracter registers an Extracter.
func RegisterInjecter ¶
func RegisterInjecter(format interface{}, injecter Injecter)
RegisterInjecter registers an Injecter.
Types ¶
type Extracter ¶
type Extracter func(carrier interface{}) (SpanContext, error)
An Extracter extracts a SpanContext from carrier.
type Flusher ¶
type Flusher interface {
Flush() error
}
Flusher is an optional interface that when implemented allows a Storer to flush buffered spawns.
type GRPC ¶
type GRPC struct {
// contains filtered or unexported fields
}
GRPC is a gRPC-based transport for sending spans to a server.
type GRPCOptions ¶
type GRPCOptions struct { // How many spans to queue before sending them to the server. // Additionally, a buffer the size of 2*QueueSize will be used to // process new spans. If this buffer runs full, new spans will be // dropped. QueueSize int // How often to flush spans, even if the queue isn't full yet. FlushInterval time.Duration // Where to log errors. If nil, the default logger will be used. Logger Logger }
GRPCOptions are options for the GRPC storer.
type IDGenerator ¶
type IDGenerator interface {
GenerateID() uint64
}
IDGenerator generates IDs for traces and spans. The ID with value 0 is reserved to mean "no parent span" and should not be generated.
type Injecter ¶
type Injecter func(sm SpanContext, carrier interface{}) error
An Injecter injects a SpanContext into carrier.
type Logger ¶
type Logger interface { // Printf logs a single message, given a format and values. The // format is documented in the fmt package. Printf(format string, values ...interface{}) }
A Logger logs messages.
type RawRelation ¶
type RawRelation struct { ParentID uint64 `json:"parent_id"` ChildID uint64 `json:"child_id"` Kind string `json:"kind"` }
A RawRelation represents the relation between two spans.
type RawSpan ¶
type RawSpan struct { SpanContext ServiceName string `json:"service_name"` OperationName string `json:"operation_name"` StartTime time.Time `json:"start_time"` FinishTime time.Time `json:"finish_time"` Tags map[string]interface{} `json:"tags"` Logs []opentracing.LogData `json:"logs"` }
A RawSpan contains all the data associated with a span.
type RawTrace ¶
type RawTrace struct { TraceID uint64 `json:"trace_id"` Spans []RawSpan `json:"spans"` Relations []RawRelation `json:"relations"` }
A RawTrace contains all the data associated with a trace.
type Sampler ¶
A Sampler determines whether a span should be sampled or not by returning true or false.
func NewConstSampler ¶
NewConstSampler returns a constant sampler that always returns the same decision.
func NewProbabilisticSampler ¶
NewProbabilisticSampler returns a sampler that samples spans with a certain chance, which should be in [0, 1].
func NewRateSampler ¶
NewRateSampler returns a sampler that samples up to n samples per second.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span is an implementation of the OpenTracing Span interface.
func (*Span) BaggageItem ¶
BaggageItem implements the opentracing.Tracer interface.
func (*Span) Context ¶
func (sp *Span) Context() opentracing.SpanContext
Context implements the opentracing.Span interface.
func (*Span) FinishWithOptions ¶
func (sp *Span) FinishWithOptions(opts opentracing.FinishOptions)
FinishWithOptions implements the opentracing.Span interface.
func (*Span) Log ¶
func (sp *Span) Log(data opentracing.LogData)
Log implements the opentracing.Span interface.
func (*Span) LogEventWithPayload ¶
LogEventWithPayload implements the opentracing.Span interface.
func (*Span) LogFields ¶
func (sp *Span) LogFields(fields ...tracinglog.Field)
func (*Span) SetBaggageItem ¶
SetBaggageItem implements the opentracing.Tracer interface.
func (*Span) SetOperationName ¶
SetOperationName implements the opentracing.Span interface.
type SpanContext ¶
type SpanContext struct { TraceID uint64 `json:"trace_id"` ParentID uint64 `json:"parent_id"` SpanID uint64 `json:"span_id"` Flags uint64 `json:"flags"` Baggage map[string]string `json:"baggage"` }
SpanContext contains the parts of a span that will be sent to downstream services.
func (SpanContext) ForeachBaggageItem ¶
func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool)
ForeachBaggageItem implements the opentracing.Tracer interface.
type Storer ¶
A Storer stores a finished span. "Storing" a span may either mean saving it in a storage engine, or sending it to a remote collector.
If a span with the same ID and the same trace ID already exists, the existing and new spans should be merged into one span.
Because spans are only stored once they're done, children will be stored before their parents.
func NewGRPC ¶
func NewGRPC(address string, grpcOpts *GRPCOptions, opts ...grpc.DialOption) (Storer, error)
NewGRPC returns a new Storer that sends spans via gRPC to a server.
type Tracer ¶
type Tracer struct { ServiceName string Logger Logger Sampler Sampler // contains filtered or unexported fields }
Tracer is an implementation of the OpenTracing Tracer interface.
func NewTracer ¶
func NewTracer(serviceName string, storer Storer, idGenerator IDGenerator) *Tracer
NewTracer returns a new tracer.
Directories ¶
Path | Synopsis |
---|---|
Package client is a client for the HTTP query transport.
|
Package client is a client for the HTTP query transport. |
cmd
|
|
demo
Command demo creates an example trace.
|
Command demo creates an example trace. |
tracer
Command tracer is the Tracer query and storage server.
|
Command tracer is the Tracer query and storage server. |
tracer-cli
Command tracer-cli provides a CLI query client.
|
Command tracer-cli provides a CLI query client. |
tracer/config
Package config parses Tracer configuration files.
|
Package config parses Tracer configuration files. |
internal
|
|
Package pb is a generated protocol buffer package.
|
Package pb is a generated protocol buffer package. |
Package server implements the Tracer server.
|
Package server implements the Tracer server. |
storage
|
|
null
Package null is a null storage.
|
Package null is a null storage. |
postgres
Package postgres is a PostgreSQL storage.
|
Package postgres is a PostgreSQL storage. |
Package tracerutil provides helpers for tracing various components.
|
Package tracerutil provides helpers for tracing various components. |
transport
|
|
grpc
Package grpc is a gRPC-based storage transport.
|
Package grpc is a gRPC-based storage transport. |
http
Package http is an HTTP-based query transport.
|
Package http is an HTTP-based query transport. |
zipkinhttp
Package zipkinhttp is an HTTP-based query transport that implements the Zipkin v1 API.
|
Package zipkinhttp is an HTTP-based query transport that implements the Zipkin v1 API. |