1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-07 13:31:42 +02:00

change trace.WithAttributes to append values instead of replacing (#315)

* change trace.WithAttributes to append values instead of replacing

* improve doc
This commit is contained in:
Gustavo Silva Paiva 2019-11-14 14:03:23 -04:00 committed by Liz Fong-Jones
parent a228bafec5
commit 1fd93b293c
2 changed files with 8 additions and 2 deletions

View File

@ -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...)
}
}

View File

@ -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)
@ -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,