Skip to content

Commit

Permalink
Merge pull request #18 from jmacd/changes/exposebasicdetail
Browse files Browse the repository at this point in the history
Expose details for basictracer spans / tracers
  • Loading branch information
jmacd committed Mar 30, 2016
2 parents fe1253c + 67e572d commit f95feba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *spanImpl) maybeAssertSanityLocked() {
msg: fmt.Sprintf("span used after Finish()"),
})
}
if s.tracer.Options.DebugAssertSingleGoroutine {
if s.tracer.options.DebugAssertSingleGoroutine {
startID := curGoroutineID()
curID, ok := s.raw.Tags[debugGoroutineIDTag].(uint64)
if !ok {
Expand Down
34 changes: 31 additions & 3 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import (
"github.com/opentracing/opentracing-go/ext"
)

// Span provides access to the essential details of the span, for use
// by basictracer consumers. These methods may only be called prior
// to (*opentracing.Span).Finish().
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
}

// Implements the `Span` interface. Created via tracerImpl (see
// `basictracer.New()`).
type spanImpl struct {
Expand Down Expand Up @@ -50,7 +66,7 @@ func (s *spanImpl) SetOperationName(operationName string) opentracing.Span {
}

func (s *spanImpl) trim() bool {
return !s.raw.Sampled && s.tracer.TrimUnsampledSpans
return !s.raw.Sampled && s.tracer.options.TrimUnsampledSpans
}

func (s *spanImpl) SetTag(key string, value interface{}) opentracing.Span {
Expand Down Expand Up @@ -119,8 +135,8 @@ func (s *spanImpl) FinishWithOptions(opts opentracing.FinishOptions) {
s.raw.Duration = duration

s.onFinish(s.raw)
s.tracer.Recorder.RecordSpan(s.raw)
if s.tracer.Options.DebugAssertUseAfterFinish {
s.tracer.options.Recorder.RecordSpan(s.raw)
if s.tracer.options.DebugAssertUseAfterFinish {
// This makes it much more likely to catch a panic on any subsequent
// operation since s.tracer is accessed on every call to `Lock`.
s.reset()
Expand Down Expand Up @@ -163,3 +179,15 @@ func (s *spanImpl) BaggageItem(restrictedKey string) string {
func (s *spanImpl) Tracer() opentracing.Tracer {
return s.tracer
}

func (s *spanImpl) Context() Context {
return s.raw.Context
}

func (s *spanImpl) Operation() string {
return s.raw.Operation
}

func (s *spanImpl) Start() time.Time {
return s.raw.Start
}
23 changes: 18 additions & 5 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import (
opentracing "github.com/opentracing/opentracing-go"
)

// Tracer extends the opentracing.Tracer interface with methods to
// probe implementation state, for use by basictracer consumers.
type Tracer interface {
opentracing.Tracer

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

// Options allows creating a customized Tracer via NewWithOptions. The object
// must not be updated when there is an active tracer using it.
type Options struct {
Expand Down Expand Up @@ -78,7 +87,7 @@ func DefaultOptions() Options {

// NewWithOptions creates a customized Tracer.
func NewWithOptions(opts Options) opentracing.Tracer {
rval := &tracerImpl{Options: opts}
rval := &tracerImpl{options: opts}
rval.textPropagator = &textMapPropagator{rval}
rval.binaryPropagator = &binaryPropagator{rval}
rval.accessorPropagator = &accessorPropagator{rval}
Expand All @@ -97,7 +106,7 @@ func New(recorder SpanRecorder) opentracing.Tracer {

// Implements the `Tracer` interface.
type tracerImpl struct {
Options
options Options
textPropagator *textMapPropagator
binaryPropagator *binaryPropagator
accessorPropagator *accessorPropagator
Expand Down Expand Up @@ -135,7 +144,7 @@ func (t *tracerImpl) StartSpanWithOptions(
sp := t.getSpan()
if opts.Parent == nil {
sp.raw.TraceID, sp.raw.SpanID = randomID2()
sp.raw.Sampled = t.ShouldSample(sp.raw.TraceID)
sp.raw.Sampled = t.options.ShouldSample(sp.raw.TraceID)
} else {
pr := opts.Parent.(*spanImpl)
sp.raw.TraceID = pr.raw.TraceID
Expand Down Expand Up @@ -168,12 +177,12 @@ func (t *tracerImpl) startSpanInternal(
tags opentracing.Tags,
) opentracing.Span {
sp.tracer = t
sp.event = t.NewSpanEventListener()
sp.event = t.options.NewSpanEventListener()
sp.raw.Operation = operationName
sp.raw.Start = startTime
sp.raw.Duration = -1
sp.raw.Tags = tags
if t.Options.DebugAssertSingleGoroutine {
if t.options.DebugAssertSingleGoroutine {
sp.SetTag(debugGoroutineIDTag, curGoroutineID())
}
defer sp.onCreate(operationName)
Expand Down Expand Up @@ -210,3 +219,7 @@ func (t *tracerImpl) Join(operationName string, format interface{}, carrier inte
}
return nil, opentracing.ErrUnsupportedFormat
}

func (t *tracerImpl) Options() Options {
return t.options
}

0 comments on commit f95feba

Please sign in to comment.