Skip to content

Commit

Permalink
Expose span data to custom reporters [fixes jaegertracing#394] (jaege…
Browse files Browse the repository at this point in the history
…rtracing#399)

* fixes jaegertracing#394

Signed-off-by: Curtis Allen <curtis.n.allen@gmail.com>

* use mutexs

Signed-off-by: Curtis Allen <callen@slack-corp.com>
  • Loading branch information
curtisallen authored and yurishkuro committed Jul 5, 2019
1 parent e66e072 commit 402bec9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,38 @@ func (s *Span) SetTag(key string, value interface{}) opentracing.Span {
return s
}

// SpanContext returns span context
func (s *Span) SpanContext() SpanContext {
s.Lock()
defer s.Unlock()
return s.context
}

// StartTime returns span start time
func (s *Span) StartTime() time.Time {
s.Lock()
defer s.Unlock()
return s.startTime
}

// Duration returns span duration
func (s *Span) Duration() time.Duration {
s.Lock()
defer s.Unlock()
return s.duration
}

// Tags returns tags for span
func (s *Span) Tags() opentracing.Tags {
s.Lock()
defer s.Unlock()
var result = make(opentracing.Tags)
for _, tag := range s.tags {
result[tag.key] = tag.value
}
return result
}

func (s *Span) setTagNoLocking(key string, value interface{}) {
s.tags = append(s.tags, Tag{key: key, value: value})
}
Expand Down
10 changes: 10 additions & 0 deletions span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ func TestSpanProperties(t *testing.T) {
defer closer.Close()

sp1 := tracer.StartSpan("s1").(*Span)
sp1.SetTag("foo", "bar")
var expectedTags = make(opentracing.Tags)
expectedTags["foo"] = "bar"
expectedTags["sampler.type"] = "const"
expectedTags["sampler.param"] = true

assert.Equal(t, tracer, sp1.Tracer())
assert.NotNil(t, sp1.Context())
assert.Equal(t, sp1.context, sp1.SpanContext())
assert.Equal(t, sp1.startTime, sp1.StartTime())
assert.Equal(t, sp1.duration, sp1.Duration())
assert.Equal(t, sp1.Tags(), expectedTags)
}

func TestSpanOperationName(t *testing.T) {
Expand Down

0 comments on commit 402bec9

Please sign in to comment.