ddtracer

package module
v0.0.0-...-b1914c4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2017 License: MIT Imports: 12 Imported by: 0

README

dd-go-opentracing

Build Status GoDoc codecov

OpenTracing Tracer implementation for Datadog in Go

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

Examples

Constants

This section is empty.

Variables

View Source
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

type Span struct {
	*tracer.Span
	// contains filtered or unexported fields
}

func (*Span) BaggageItem

func (s *Span) BaggageItem(restrictedKey string) string

BaggageItem hasn't been implemented

func (*Span) Context

func (s *Span) Context() opentracing.SpanContext

func (*Span) Finish

func (s *Span) Finish()

func (*Span) FinishWithOptions

func (s *Span) FinishWithOptions(opts opentracing.FinishOptions)

func (*Span) Log

func (s *Span) Log(data opentracing.LogData)

func (*Span) LogEvent

func (s *Span) LogEvent(event string)

func (*Span) LogEventWithPayload

func (s *Span) LogEventWithPayload(event string, payload interface{})

func (*Span) LogFields

func (s *Span) LogFields(fields ...log.Field)

func (*Span) LogKV

func (s *Span) LogKV(alternatingKeyValues ...interface{})

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) SetTag

func (s *Span) SetTag(key string, value interface{}) 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

type Tracer struct {
	*tracer.Tracer
	// contains filtered or unexported fields
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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