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:
parent
a228bafec5
commit
1fd93b293c
@ -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...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user