Documentation ¶
Overview ¶
Package ddtracer is a DataDog's tracer (https://github.com/DataDog/dd-trace-go) wrapper for the OpenTracing API. The goal of the wrapper is to exploit all the functionalities provided by DataDog witout leaving the OpenTracing API nor having to deal with reflecion/type casting. Although both API have similar semantics, there's some concepts in DataDog which doesn't fit with OpenTracing specs.
Service and Resource has been implemented through opentracing-go/ext.{PeerService,Component}, to invoke Span.SetError, opentracing-go/log.Error() has been used (see examples below).
This is an OpenTracing API wrapper, all the methods implementing the specifications are described in detail on official documentation.
Index ¶
- Variables
- func NewTracer() opentracing.Tracer
- func NewTracerTransport(tr tracer.Transport) opentracing.Tracer
- type Span
- func (s *Span) BaggageItem(restrictedKey string) string
- func (s *Span) Context() opentracing.SpanContext
- func (s *Span) Finish()
- func (s *Span) FinishWithOptions(opts opentracing.FinishOptions)
- func (s *Span) Log(data opentracing.LogData)
- func (s *Span) LogEvent(event string)
- func (s *Span) LogEventWithPayload(event string, payload interface{})
- func (s *Span) LogFields(fields ...log.Field)
- func (s *Span) LogKV(alternatingKeyValues ...interface{})
- func (s *Span) SetBaggageItem(restrictedKey string, value string) opentracing.Span
- func (s *Span) SetOperationName(operationName string) opentracing.Span
- func (s *Span) SetTag(key string, value interface{}) opentracing.Span
- func (s *Span) Tracer() opentracing.Tracer
- type SpanContext
- type Tracer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultService = defaultHostname() DefaultResource = "/" // EnvTag set's the environment for a given span // i.e EnvTag.Set(span, "development") EnvTag = stringTagName("env") )
Functions ¶
func NewTracer ¶
func NewTracer() opentracing.Tracer
NewTracer creates a new Tracer.
Example ¶
t := NewTracer() // To access DataDog tracer's you will need to type cast // Let's enable Debug Log t.(*Tracer).DebugLoggingEnabled = true // And flush all the remaining traces t.(*Tracer).FlushTraces()
Output:
func NewTracerTransport ¶
func NewTracerTransport(tr tracer.Transport) opentracing.Tracer
NewTracerTransport create a new Tracer with the given transport.
Types ¶
type Span ¶
func (*Span) BaggageItem ¶
BaggageItem hasn't been implemented
func (*Span) Context ¶
func (s *Span) Context() opentracing.SpanContext
func (*Span) FinishWithOptions ¶
func (s *Span) FinishWithOptions(opts opentracing.FinishOptions)
func (*Span) Log ¶
func (s *Span) Log(data opentracing.LogData)
func (*Span) LogEventWithPayload ¶
func (*Span) SetBaggageItem ¶
func (s *Span) SetBaggageItem(restrictedKey string, value string) opentracing.Span
SetBaggageItem hasn't been implemented
func (*Span) SetOperationName ¶
func (s *Span) SetOperationName(operationName string) opentracing.Span
func (*Span) Tracer ¶
func (s *Span) Tracer() opentracing.Tracer
type SpanContext ¶
type SpanContext struct {
// contains filtered or unexported fields
}
func (*SpanContext) ForeachBaggageItem ¶
func (ctx *SpanContext) ForeachBaggageItem(handler func(k, v string) bool)
ForeachBaggageItem hasn't been implemented
type Tracer ¶
func (*Tracer) Extract ¶
func (t *Tracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error)
func (*Tracer) Inject ¶
func (t *Tracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error
func (*Tracer) StartSpan ¶
func (t *Tracer) StartSpan(op string, opts ...opentracing.StartSpanOption) opentracing.Span
Example ¶
span := NewTracer().StartSpan("span") // Let set DataDog's specific attrs Service and Resource ext.PeerService.Set(span, "test-service") ext.Component.Set(span, "/user/{id}") // To Set metrics, we need to pass a float64 value type span.LogKV("elapsed", 0.1234) // Everything else, is going to be treated as Meta span.LogKV("query", "SELECT data FROM dogs") span.Finish() ddspan := span.(*Span) fmt.Println("service =", ddspan.Service) fmt.Println("resource =", ddspan.Resource) fmt.Println("elapsed =", ddspan.Metrics["elapsed"]) fmt.Println("query =", ddspan.GetMeta("query"))
Output: service = test-service resource = /user/{id} elapsed = 0.1234 query = SELECT data FROM dogs