Skip to content

Commit 75c2a20

Browse files
committed
fix: init StartSpanConfig tags map with empty map
1 parent 9d99c5c commit 75c2a20

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package http
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
10+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
11+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer"
12+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
13+
)
14+
15+
func TestSpanOptions(t *testing.T) {
16+
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("")) }))
17+
defer s.Close()
18+
19+
tagKey1, tagKey2 := "foo", "bar"
20+
tagValue1, tagValue2 := "bar", "baz"
21+
mt := mocktracer.Start()
22+
defer mt.Stop()
23+
rt := WrapRoundTripper(http.DefaultTransport, RTWithSpanOptions(
24+
func(cfg *ddtrace.StartSpanConfig) {
25+
cfg.Tags[tagKey1] = tagValue1
26+
},
27+
tracer.Tag(tagKey2, tagValue2),
28+
))
29+
client := &http.Client{Transport: rt}
30+
31+
resp, err := client.Get(s.URL)
32+
assert.Nil(t, err)
33+
defer resp.Body.Close()
34+
35+
spans := mt.FinishedSpans()
36+
assert.Len(t, spans, 1)
37+
assert.Equal(t, tagValue1, spans[0].Tag(tagKey1))
38+
assert.Equal(t, tagValue2, spans[0].Tag(tagKey2))
39+
}

ddtrace/internal/v2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ var (
7575
func ApplyV1Options(opts ...ddtrace.StartSpanOption) v2.StartSpanOption {
7676
return func(cfg *v2.StartSpanConfig) {
7777
ssc := startSpanConfigPool.Get().(*ddtrace.StartSpanConfig)
78+
ssc.Tags = make(map[string]interface{})
7879
defer releaseStartSpanConfig(ssc)
7980
for _, o := range opts {
8081
if o == nil {
@@ -97,7 +98,7 @@ func ApplyV1Options(opts ...ddtrace.StartSpanOption) v2.StartSpanOption {
9798
if !ssc.StartTime.IsZero() {
9899
cfg.StartTime = ssc.StartTime
99100
}
100-
if ssc.Tags == nil {
101+
if len(ssc.Tags) == 0 {
101102
return
102103
}
103104
if cfg.Tags == nil {

0 commit comments

Comments
 (0)