zipkintracer

package module
v0.0.0-...-7bb13b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2016 License: MIT Imports: 24 Imported by: 0

README

zipkin-go-opentracing

Travis CI GoDoc

OpenTracing Tracer implementation for Zipkin in Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Delegator delegatorType

Delegator is the format to use for DelegatingCarrier.

View Source
var ErrInvalidEndpoint = errors.New("Invalid Endpoint. Please check hostPort parameter")

ErrInvalidEndpoint will be thrown if hostPort parameter is corrupted or host can't be resolved

View Source
var ErrMissingValue = errors.New("(MISSING)")

ErrMissingValue adds a Missing Value Error when the Logging Parameters are not even in number

View Source
var NetTraceIntegrator = func() func(SpanEvent) {
	var tr trace.Trace
	return func(e SpanEvent) {
		switch t := e.(type) {
		case EventCreate:
			tr = trace.New("tracing", t.OperationName)
		case EventFinish:
			tr.Finish()
		case EventLog:
			if t.Payload != nil {
				tr.LazyPrintf("%s (payload %v)", t.Event, t.Payload)
			} else {
				tr.LazyPrintf("%s", t.Event)
			}
		}
	}
}

NetTraceIntegrator can be passed into a zipkintracer as NewSpanEventListener and causes all traces to be registered with the net/trace endpoint.

View Source
var (
	// SpanKindResource will be regarded as a SA annotation by Zipkin.
	SpanKindResource = otext.SpanKindEnum("resource")
)

Functions

func NewTracer

func NewTracer(recorder SpanRecorder, options ...TracerOption) (opentracing.Tracer, error)

NewTracer creates a new OpenTracing compatible Zipkin Tracer.

Types

type CollectionError

type CollectionError interface {
	Error() string
	GetErrors() []error
}

CollectionError represents an array of errors returned by one or more failed Collector methods.

type Collector

type Collector interface {
	Collect(*zipkincore.Span) error
	Close() error
}

Collector represents a Zipkin trace collector, which is probably a set of remote endpoints.

func NewKafkaCollector

func NewKafkaCollector(addrs []string, options ...KafkaOption) (Collector, error)

NewKafkaCollector returns a new Kafka-backed Collector. addrs should be a slice of TCP endpoints of the form "host:port".

func NewScribeCollector

func NewScribeCollector(addr string, timeout time.Duration, options ...ScribeOption) (Collector, error)

NewScribeCollector returns a new Scribe-backed Collector. addr should be a TCP endpoint of the form "host:port". timeout is passed to the Thrift dial function NewTSocketFromAddrTimeout. batchSize and batchInterval control the maximum size and interval of a batch of spans; as soon as either limit is reached, the batch is sent. The logger is used to log errors, such as batch send failures; users should provide an appropriate context, if desired.

type Context

type Context struct {
	// A probabilistically unique identifier for a [multi-span] trace.
	TraceID uint64

	// A probabilistically unique identifier for a span.
	SpanID uint64

	// The SpanID of this Context's parent, or 0 if there is no parent.
	ParentSpanID uint64

	// Whether the trace is sampled.
	Sampled bool
}

Context holds the basic Span metadata.

type DelegatingCarrier

type DelegatingCarrier interface {
	SetState(traceID, spanID, parentSpanID uint64, sampled bool)
	State() (traceID, spanID, parentSpanID uint64, sampled bool)
	SetBaggageItem(key, value string)
	GetBaggage(func(key, value string))
}

DelegatingCarrier is a flexible carrier interface which can be implemented by types which have a means of storing the trace metadata and already know how to serialize themselves (for example, protocol buffers).

type EventBaggage

type EventBaggage struct {
	Key, Value string
}

EventBaggage is received when SetBaggageItem is called.

type EventCreate

type EventCreate struct{ OperationName string }

EventCreate is emitted when a Span is created.

type EventFinish

type EventFinish RawSpan

EventFinish is received when Finish is called.

type EventLog

type EventLog opentracing.LogData

EventLog is received when Log (or one of its derivatives) is called.

type EventTag

type EventTag struct {
	Key   string
	Value interface{}
}

EventTag is received when SetTag is called.

type KafkaCollector

type KafkaCollector struct {
	// contains filtered or unexported fields
}

KafkaCollector implements Collector by publishing spans to a Kafka broker.

func (*KafkaCollector) Close

func (c *KafkaCollector) Close() error

Close implements Collector.

func (*KafkaCollector) Collect

func (c *KafkaCollector) Collect(s *zipkincore.Span) error

Collect implements Collector.

type KafkaOption

type KafkaOption func(c *KafkaCollector)

KafkaOption sets a parameter for the KafkaCollector

func KafkaLogger

func KafkaLogger(logger Logger) KafkaOption

KafkaLogger sets the logger used to report errors in the collection process. By default, a no-op logger is used, i.e. no errors are logged anywhere. It's important to set this option.

func KafkaProducer

func KafkaProducer(p sarama.AsyncProducer) KafkaOption

KafkaProducer sets the producer used to produce to Kafka.

func KafkaTopic

func KafkaTopic(t string) KafkaOption

KafkaTopic sets the kafka topic to attach the collector producer on.

type Logger

type Logger interface {
	Log(keyvals ...interface{}) error
}

Logger interface used by this package. This means that we accept Go kit Log compatible loggers

func LogWrapper

func LogWrapper(l *log.Logger) Logger

LogWrapper wraps a standard library logger into a Logger compatible with this package.

func NewNopLogger

func NewNopLogger() Logger

NewNopLogger provides a Logger that discards all Log data sent to it.

type LoggerFunc

type LoggerFunc func(...interface{}) error

LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If f is a function with the appropriate signature, LoggerFunc(f) is a Logger object that calls f.

func (LoggerFunc) Log

func (f LoggerFunc) Log(keyvals ...interface{}) error

Log implements Logger by calling f(keyvals...).

type MultiCollector

type MultiCollector []Collector

MultiCollector implements Collector by sending spans to all collectors.

func (MultiCollector) Close

func (c MultiCollector) Close() error

Close implements Collector.

func (MultiCollector) Collect

func (c MultiCollector) Collect(s *zipkincore.Span) error

Collect implements Collector.

type NopCollector

type NopCollector struct{}

NopCollector implements Collector but performs no work.

func (NopCollector) Close

func (NopCollector) Close() error

Close implements Collector.

func (NopCollector) Collect

func (NopCollector) Collect(*zipkincore.Span) error

Collect implements Collector.

type RawSpan

type RawSpan struct {
	// The RawSpan embeds its Context. Those recording the RawSpan
	// should also record the contents of its Context.
	Context

	// The name of the "operation" this span is an instance of. (Called a "span
	// name" in some implementations)
	Operation string

	// We store <start, duration> rather than <start, end> so that only
	// one of the timestamps has global clock uncertainty issues.
	Start    time.Time
	Duration time.Duration

	// Essentially an extension mechanism. Can be used for many purposes,
	// not to be enumerated here.
	Tags opentracing.Tags

	// The span's "microlog".
	Logs []opentracing.LogData

	// The span's associated baggage.
	Baggage map[string]string // initialized on first use
}

RawSpan encapsulates all state associated with a (finished) Span.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder implements the SpanRecorder interface.

func (*Recorder) RecordSpan

func (r *Recorder) RecordSpan(sp RawSpan)

RecordSpan converts a RawSpan into the Zipkin representation of a span and records it to the underlying collector.

type Sampler

type Sampler func(id uint64) bool

Sampler functions return if a Zipkin span should be sampled, based on its traceID.

func ModuloSampler

func ModuloSampler(mod uint64) Sampler

ModuloSampler provides a typical OpenTracing type Sampler.

func NewBoundarySampler

func NewBoundarySampler(rate float64, salt int64) Sampler

NewBoundarySampler is appropriate for high-traffic instrumentation who provision random trace ids, and make the sampling decision only once. It defends against nodes in the cluster selecting exactly the same ids.

func NewCountingSampler

func NewCountingSampler(rate float64) Sampler

NewCountingSampler is appropriate for low-traffic instrumentation or those who do not provision random trace ids. It is not appropriate for collectors as the sampling decision isn't idempotent (consistent based on trace id).

type ScribeCollector

type ScribeCollector struct {
	// contains filtered or unexported fields
}

ScribeCollector implements Collector by forwarding spans to a Scribe service, in batches.

func (*ScribeCollector) Close

func (c *ScribeCollector) Close() error

Close implements Collector.

func (*ScribeCollector) Collect

func (c *ScribeCollector) Collect(s *zipkincore.Span) error

Collect implements Collector.

type ScribeOption

type ScribeOption func(s *ScribeCollector)

ScribeOption sets a parameter for the StdlibAdapter.

func ScribeBatchInterval

func ScribeBatchInterval(d time.Duration) ScribeOption

ScribeBatchInterval sets the maximum duration we will buffer traces before emitting them to the collector. The default batch interval is 1 second.

func ScribeBatchSize

func ScribeBatchSize(n int) ScribeOption

ScribeBatchSize sets the maximum batch size, after which a collect will be triggered. The default batch size is 100 traces.

func ScribeCategory

func ScribeCategory(category string) ScribeOption

ScribeCategory sets the Scribe category used to transmit the spans.

func ScribeLogger

func ScribeLogger(logger Logger) ScribeOption

ScribeLogger sets the logger used to report errors in the collection process. By default, a no-op logger is used, i.e. no errors are logged anywhere. It's important to set this option in a production service.

type Span

type Span interface {
	opentracing.Span

	// Context contains trace identifiers
	Context() Context

	// Operation names the work done by this span instance
	Operation() string

	// Start indicates when the span began
	Start() time.Time
}

Span provides access to the essential details of the span, for use by zipkintracer consumers. These methods may only be called prior to (*opentracing.Span).Finish().

type SpanEvent

type SpanEvent interface{}

A SpanEvent is emitted when a mutating command is called on a Span.

type SpanRecorder

type SpanRecorder interface {
	// Implementations must determine whether and where to store `span`.
	RecordSpan(span RawSpan)
}

A SpanRecorder handles all of the `RawSpan` data generated via an associated `Tracer` (see `NewStandardTracer`) instance. It also names the containing process and provides access to a straightforward tag map.

func NewRecorder

func NewRecorder(c Collector, debug bool, hostPort, serviceName string) SpanRecorder

NewRecorder creates a new Zipkin Recorder backed by the provided Collector.

type Tracer

type Tracer interface {
	opentracing.Tracer

	// Options gets the Options used in New() or NewWithOptions().
	Options() TracerOptions
}

Tracer extends the opentracing.Tracer interface with methods to probe implementation state, for use by zipkintracer consumers.

type TracerOption

type TracerOption func(opts *TracerOptions) error

TracerOption allows for functional options. See: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

func ClientServerSameSpan

func ClientServerSameSpan(val bool) TracerOption

ClientServerSameSpan allows to place client-side and server-side annotations for a RPC call in the same span (Zipkin V1 behavior). By default this Tracer uses single host spans (so client-side and server-side in separate spans).

func DebugAssertSingleGoroutine

func DebugAssertSingleGoroutine(val bool) TracerOption

DebugAssertSingleGoroutine option

func DebugAssertUseAfterFinish

func DebugAssertUseAfterFinish(val bool) TracerOption

DebugAssertUseAfterFinish option

func TrimUnsampledSpans

func TrimUnsampledSpans(trim bool) TracerOption

TrimUnsampledSpans option

func WithLogger

func WithLogger(logger Logger) TracerOption

WithLogger option

func WithSampler

func WithSampler(sampler Sampler) TracerOption

WithSampler allows one to add a Sampler function

type TracerOptions

type TracerOptions struct {
	// contains filtered or unexported fields
}

TracerOptions allows creating a customized Tracer.

Directories

Path Synopsis
_thrift
Package wire is a generated protocol buffer package.
Package wire is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL