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

Commit 975df76

Browse files
committed
Fix missing sampler tags when startSpan
Signed-off-by: Chen Xu <chen.x@uber.com>
1 parent 8d8e8fc commit 975df76

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

tracer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ func (t *Tracer) startSpanWithOptions(
327327
sp.observer = t.observer.OnStartSpan(sp, operationName, options)
328328

329329
if tagsTotalLength := len(options.Tags) + len(internalTags); tagsTotalLength > 0 {
330-
if sp.tags == nil || cap(sp.tags) < tagsTotalLength {
331-
sp.tags = make([]Tag, 0, tagsTotalLength)
332-
}
333330
sp.tags = append(sp.tags, internalTags...)
334331
for k, v := range options.Tags {
335332
sp.setTagInternal(k, v, false)

tracer_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,42 @@ func (s *tracerSuite) TestBeginRootSpan() {
101101

102102
func (s *tracerSuite) TestStartRootSpanWithOptions() {
103103
ts := time.Now()
104-
sp := s.tracer.StartSpan("get_address", opentracing.StartTime(ts))
104+
t := opentracing.Tags{
105+
"testTag1": "test tag 1",
106+
"testTag2": "test tag 2",
107+
"testTag3": "test tag 3",
108+
}
109+
sp := s.tracer.StartSpan("get_address", opentracing.StartTime(ts), t)
105110
ss := sp.(*Span)
111+
106112
s.Equal("get_address", ss.operationName)
107113
s.Equal(ts, ss.startTime)
114+
et := opentracing.Tags{
115+
SamplerTypeTagKey: SamplerTypeConst,
116+
SamplerParamTagKey: true,
117+
"testTag1": "test tag 1",
118+
"testTag2": "test tag 2",
119+
"testTag3": "test tag 3",
120+
}
121+
s.Equal(et, ss.Tags())
122+
}
123+
124+
func (s *tracerSuite) TestStartRootSpanWithDebugHeader() {
125+
h := http.Header{}
126+
h.Add(JaegerDebugHeader, "x")
127+
ctx, err := s.tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(h))
128+
require.NoError(s.T(), err)
129+
130+
sp := s.tracer.StartSpan("get_address", opentracing.ChildOf(ctx))
131+
ss := sp.(*Span)
132+
133+
s.Equal("get_address", ss.operationName)
134+
et := opentracing.Tags{
135+
JaegerDebugHeader: "x",
136+
SamplerTypeTagKey: SamplerTypeConst,
137+
SamplerParamTagKey: true,
138+
}
139+
s.Equal(et, ss.Tags())
108140
}
109141

110142
func (s *tracerSuite) TestStartChildSpan() {

0 commit comments

Comments
 (0)