Package zipkintracer
Overview ▹
Index ▹
Variables
Delegator is the format to use for DelegatingCarrier.
var Delegator delegatorType
ErrInvalidEndpoint will be thrown if hostPort parameter is corrupted or host can't be resolved
var ErrInvalidEndpoint = errors.New("Invalid Endpoint. Please check hostPort parameter")
ErrMissingValue adds a Missing Value Error when the Logging Parameters are not even in number
var ErrMissingValue = errors.New("(MISSING)")
var (
// SpanKindResource will be regarded as a SA annotation by Zipkin.
SpanKindResource = otext.SpanKindEnum("resource")
)
func MaterializeWithJSON ¶
func MaterializeWithJSON(logFields []log.Field) ([]byte, error)
MaterializeWithJSON converts log Fields into JSON string
func MaterializeWithLogFmt ¶
func MaterializeWithLogFmt(logFields []log.Field) ([]byte, error)
MaterializeWithLogFmt converts log Fields into LogFmt string
func NewTracer ¶
func NewTracer(recorder SpanRecorder, options ...TracerOption) (opentracing.Tracer, error)
NewTracer creates a new OpenTracing compatible Zipkin Tracer.
func StrictZipkinMaterializer ¶
func StrictZipkinMaterializer(logFields []log.Field) ([]byte, error)
StrictZipkinMaterializer will only record a log.Field of type "event".
type CollectionError ¶
CollectionError represents an array of errors returned by one or more failed Collector methods.
type CollectionError interface { Error() string GetErrors() []error }
type Collector ¶
Collector represents a Zipkin trace collector, which is probably a set of remote endpoints.
type Collector interface { Collect(*zipkincore.Span) error Close() error }
func NewHTTPCollector ¶
func NewHTTPCollector(url string, options ...HTTPOption) (Collector, error)
NewHTTPCollector returns a new HTTP-backend Collector. url should be a http url for handle post request. timeout is passed to http client. queueSize control the maximum size of buffer of async queue. The logger is used to log errors, such as send failures;
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 DelegatingCarrier ¶
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 DelegatingCarrier interface { SetState(traceID types.TraceID, spanID uint64, parentSpanID *uint64, sampled bool, flags flag.Flags) State() (traceID types.TraceID, spanID uint64, parentSpanID *uint64, sampled bool, flags flag.Flags) SetBaggageItem(key, value string) GetBaggage(func(key, value string)) }
type EventBaggage ¶
EventBaggage is received when SetBaggageItem is called.
type EventBaggage struct { Key, Value string }
type EventCreate ¶
EventCreate is emitted when a Span is created.
type EventCreate struct{ OperationName string }
type EventFinish ¶
EventFinish is received when Finish is called.
type EventFinish RawSpan
type EventLog ¶
EventLog is received when Log (or one of its derivatives) is called.
DEPRECATED
type EventLog opentracing.LogData
type EventLogFields ¶
EventLogFields is received when LogFields or LogKV is called.
type EventLogFields opentracing.LogRecord
type EventTag ¶
EventTag is received when SetTag is called.
type EventTag struct { Key string Value interface{} }
type HTTPCollector ¶
HTTPCollector implements Collector by forwarding spans to a http server.
type HTTPCollector struct {
// contains filtered or unexported fields
}
func (*HTTPCollector) Close ¶
func (c *HTTPCollector) Close() error
Close implements Collector.
func (*HTTPCollector) Collect ¶
func (c *HTTPCollector) Collect(s *zipkincore.Span) error
Collect implements Collector.
type HTTPOption ¶
HTTPOption sets a parameter for the HttpCollector
type HTTPOption func(c *HTTPCollector)
func HTTPBatchInterval ¶
func HTTPBatchInterval(d time.Duration) HTTPOption
HTTPBatchInterval sets the maximum duration we will buffer traces before emitting them to the collector. The default batch interval is 1 second.
func HTTPBatchSize ¶
func HTTPBatchSize(n int) HTTPOption
HTTPBatchSize sets the maximum batch size, after which a collect will be triggered. The default batch size is 100 traces.
func HTTPLogger ¶
func HTTPLogger(logger Logger) HTTPOption
HTTPLogger 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.
func HTTPMaxBacklog ¶
func HTTPMaxBacklog(n int) HTTPOption
HTTPMaxBacklog sets the maximum backlog size, when batch size reaches this threshold, spans from the beginning of the batch will be disposed
func HTTPTimeout ¶
func HTTPTimeout(duration time.Duration) HTTPOption
HTTPTimeout sets maximum timeout for http request.
type InMemorySpanRecorder ¶
InMemorySpanRecorder is a simple thread-safe implementation of SpanRecorder that stores all reported spans in memory, accessible via reporter.GetSpans(). It is primarily intended for testing purposes.
type InMemorySpanRecorder struct {
sync.RWMutex
// contains filtered or unexported fields
}
func NewInMemoryRecorder ¶
func NewInMemoryRecorder() *InMemorySpanRecorder
NewInMemoryRecorder creates new InMemorySpanRecorder
func (*InMemorySpanRecorder) GetSampledSpans ¶
func (r *InMemorySpanRecorder) GetSampledSpans() []RawSpan
GetSampledSpans returns a slice of spans accumulated so far which were sampled.
func (*InMemorySpanRecorder) GetSpans ¶
func (r *InMemorySpanRecorder) GetSpans() []RawSpan
GetSpans returns a copy of the array of spans accumulated so far.
func (*InMemorySpanRecorder) RecordSpan ¶
func (r *InMemorySpanRecorder) RecordSpan(span RawSpan)
RecordSpan implements the respective method of SpanRecorder.
func (*InMemorySpanRecorder) Reset ¶
func (r *InMemorySpanRecorder) Reset()
Reset clears the internal array of spans.
type KafkaCollector ¶
KafkaCollector implements Collector by publishing spans to a Kafka broker.
type KafkaCollector struct {
// contains filtered or unexported fields
}
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 ¶
KafkaOption sets a parameter for the KafkaCollector
type KafkaOption func(c *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 ¶
Logger interface used by this package. This means that we accept Go kit Log compatible loggers
type Logger interface { Log(keyvals ...interface{}) error }
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 ¶
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.
type LoggerFunc func(...interface{}) error
func (LoggerFunc) Log ¶
func (f LoggerFunc) Log(keyvals ...interface{}) error
Log implements Logger by calling f(keyvals...).
type MultiCollector ¶
MultiCollector implements Collector by sending spans to all collectors.
type MultiCollector []Collector
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 ¶
NopCollector implements Collector but performs no work.
type NopCollector struct{}
func (NopCollector) Close ¶
func (NopCollector) Close() error
Close implements Collector.
func (NopCollector) Collect ¶
func (NopCollector) Collect(*zipkincore.Span) error
Collect implements Collector.
type RawSpan ¶
RawSpan encapsulates all state associated with a (finished) Span.
type RawSpan struct { // Those recording the RawSpan should also record the contents of its // SpanContext. Context SpanContext // 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.LogRecord }
type Recorder ¶
Recorder implements the SpanRecorder interface.
type Recorder struct {
// contains filtered or unexported fields
}
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 RecorderOption ¶
RecorderOption allows for functional options.
type RecorderOption func(r *Recorder)
func WithJSONMaterializer ¶
func WithJSONMaterializer() RecorderOption
WithJSONMaterializer will convert OpenTracing Log fields to a JSON representation.
func WithLogFmtMaterializer ¶
func WithLogFmtMaterializer() RecorderOption
WithLogFmtMaterializer will convert OpenTracing Log fields to a LogFmt representation.
func WithStrictMaterializer ¶
func WithStrictMaterializer() RecorderOption
WithStrictMaterializer will only record event Log fields and discard the rest.
type Sampler ¶
Sampler functions return if a Zipkin span should be sampled, based on its traceID.
type Sampler func(id uint64) bool
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 ¶
ScribeCollector implements Collector by forwarding spans to a Scribe service, in batches.
type ScribeCollector struct {
// contains filtered or unexported fields
}
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 ¶
ScribeOption sets a parameter for the StdlibAdapter.
type ScribeOption func(s *ScribeCollector)
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.
func ScribeMaxBacklog ¶
func ScribeMaxBacklog(n int) ScribeOption
ScribeMaxBacklog sets the maximum backlog size, when batch size reaches this threshold, spans from the beginning of the batch will be disposed
type Span ¶
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 Span interface { opentracing.Span // Operation names the work done by this span instance Operation() string // Start indicates when the span began Start() time.Time }
type SpanContext ¶
SpanContext holds the basic Span metadata.
type SpanContext struct { // A probabilistically unique identifier for a [multi-span] trace. TraceID types.TraceID // A probabilistically unique identifier for a span. SpanID uint64 // Whether the trace is sampled. Sampled bool // The span's associated baggage. Baggage map[string]string // initialized on first use // The SpanID of this Context's parent, or nil if there is no parent. ParentSpanID *uint64 // Flags provides the ability to create and communicate feature flags. Flags flag.Flags // Whether the span is owned by the current process Owner bool }
func (SpanContext) ForeachBaggageItem ¶
func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool)
ForeachBaggageItem belongs to the opentracing.SpanContext interface
func (SpanContext) WithBaggageItem ¶
func (c SpanContext) WithBaggageItem(key, val string) SpanContext
WithBaggageItem returns an entirely new basictracer SpanContext with the given key:value baggage pair set.
type SpanEvent ¶
A SpanEvent is emitted when a mutating command is called on a Span.
type SpanEvent interface{}
type SpanRecorder ¶
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.
type SpanRecorder interface {
// Implementations must determine whether and where to store `span`.
RecordSpan(span RawSpan)
}
func NewRecorder ¶
func NewRecorder(c Collector, debug bool, hostPort, serviceName string, options ...RecorderOption) SpanRecorder
NewRecorder creates a new Zipkin Recorder backed by the provided Collector.
hostPort and serviceName allow you to set the default Zipkin endpoint information which will be added to the application's standard core annotations. hostPort will be resolved into an IPv4 and/or IPv6 address and Port number, serviceName will be used as the application's service identifier.
If application does not listen for incoming requests or an endpoint Context does not involve network address and/or port these cases can be solved like this:
# port is not applicable: NewRecorder(c, debug, "192.168.1.12:0", "ServiceA") # network address and port are not applicable: NewRecorder(c, debug, "0.0.0.0:0", "ServiceB")
type Tracer ¶
Tracer extends the opentracing.Tracer interface with methods to probe implementation state, for use by zipkintracer consumers.
type Tracer interface {
opentracing.Tracer
// Options gets the Options used in New() or NewWithOptions().
Options() TracerOptions
}
type TracerOption ¶
TracerOption allows for functional options. See: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
type TracerOption func(opts *TracerOptions) error
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 DebugMode ¶
func DebugMode(val bool) TracerOption
DebugMode allows to set the tracer to Zipkin debug mode
func DropAllLogs ¶
func DropAllLogs(dropAllLogs bool) TracerOption
DropAllLogs option
func EnableSpanPool ¶
func EnableSpanPool(val bool) TracerOption
EnableSpanPool ...
func NewSpanEventListener ¶
func NewSpanEventListener(f func() func(SpanEvent)) TracerOption
NewSpanEventListener option
func TraceID128Bit ¶
func TraceID128Bit(val bool) TracerOption
TraceID128Bit option
func TrimUnsampledSpans ¶
func TrimUnsampledSpans(trim bool) TracerOption
TrimUnsampledSpans option
func WithLogger ¶
func WithLogger(logger Logger) TracerOption
WithLogger option
func WithMaxLogsPerSpan ¶
func WithMaxLogsPerSpan(limit int) TracerOption
WithMaxLogsPerSpan option
func WithSampler ¶
func WithSampler(sampler Sampler) TracerOption
WithSampler allows one to add a Sampler function
type TracerOptions ¶
TracerOptions allows creating a customized Tracer.
type TracerOptions struct {
// contains filtered or unexported fields
}