Skip to content

Commit

Permalink
change trace.WithAttributes to append values instead of replacing (#315)
Browse files Browse the repository at this point in the history
* change trace.WithAttributes to append values instead of replacing

* improve doc
  • Loading branch information
paivagustavo authored and lizthegrey committed Nov 14, 2019
1 parent a228baf commit 1fd93b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ func WithStartTime(t time.Time) SpanOption {

// WithAttributes sets attributes to span. These attributes provides additional
// data about the span.
// Multiple `WithAttributes` options appends the attributes preserving the order.
func WithAttributes(attrs ...core.KeyValue) SpanOption {
return func(o *SpanOptions) {
o.Attributes = attrs
o.Attributes = append(o.Attributes, attrs...)
}
}

Expand Down
7 changes: 6 additions & 1 deletion sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ func TestStartSpanWithFollowsFrom(t *testing.T) {
func TestSetSpanAttributesOnStart(t *testing.T) {
te := &testExporter{}
tp, _ := NewProvider(WithSyncer(te))
span := startSpan(tp, "StartSpanAttribute", apitrace.WithAttributes(key.String("key1", "value1")))
span := startSpan(tp,
"StartSpanAttribute",
apitrace.WithAttributes(key.String("key1", "value1")),
apitrace.WithAttributes(key.String("key2", "value2")),
)
got, err := endSpan(te, span)
if err != nil {
t.Fatal(err)
Expand All @@ -310,6 +314,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) {
Name: "StartSpanAttribute/span0",
Attributes: []core.KeyValue{
key.String("key1", "value1"),
key.String("key2", "value2"),
},
SpanKind: apitrace.SpanKindInternal,
HasRemoteParent: true,
Expand Down

0 comments on commit 1fd93b2

Please sign in to comment.