Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Fix missing sampler tags when startSpan
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Xu <chen.x@uber.com>
  • Loading branch information
ChenX1993 committed Dec 20, 2022
1 parent 8d8e8fc commit 975df76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
3 changes: 0 additions & 3 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ func (t *Tracer) startSpanWithOptions(
sp.observer = t.observer.OnStartSpan(sp, operationName, options)

if tagsTotalLength := len(options.Tags) + len(internalTags); tagsTotalLength > 0 {
if sp.tags == nil || cap(sp.tags) < tagsTotalLength {
sp.tags = make([]Tag, 0, tagsTotalLength)
}
sp.tags = append(sp.tags, internalTags...)
for k, v := range options.Tags {
sp.setTagInternal(k, v, false)
Expand Down
34 changes: 33 additions & 1 deletion tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,42 @@ func (s *tracerSuite) TestBeginRootSpan() {

func (s *tracerSuite) TestStartRootSpanWithOptions() {
ts := time.Now()
sp := s.tracer.StartSpan("get_address", opentracing.StartTime(ts))
t := opentracing.Tags{
"testTag1": "test tag 1",
"testTag2": "test tag 2",
"testTag3": "test tag 3",
}
sp := s.tracer.StartSpan("get_address", opentracing.StartTime(ts), t)
ss := sp.(*Span)

s.Equal("get_address", ss.operationName)
s.Equal(ts, ss.startTime)
et := opentracing.Tags{
SamplerTypeTagKey: SamplerTypeConst,
SamplerParamTagKey: true,
"testTag1": "test tag 1",
"testTag2": "test tag 2",
"testTag3": "test tag 3",
}
s.Equal(et, ss.Tags())
}

func (s *tracerSuite) TestStartRootSpanWithDebugHeader() {
h := http.Header{}
h.Add(JaegerDebugHeader, "x")
ctx, err := s.tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(h))
require.NoError(s.T(), err)

sp := s.tracer.StartSpan("get_address", opentracing.ChildOf(ctx))
ss := sp.(*Span)

s.Equal("get_address", ss.operationName)
et := opentracing.Tags{
JaegerDebugHeader: "x",
SamplerTypeTagKey: SamplerTypeConst,
SamplerParamTagKey: true,
}
s.Equal(et, ss.Tags())
}

func (s *tracerSuite) TestStartChildSpan() {
Expand Down

0 comments on commit 975df76

Please sign in to comment.