mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-05-13 21:56:48 +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
|
// WithAttributes sets attributes to span. These attributes provides additional
|
||||||
// data about the span.
|
// data about the span.
|
||||||
|
// Multiple `WithAttributes` options appends the attributes preserving the order.
|
||||||
func WithAttributes(attrs ...core.KeyValue) SpanOption {
|
func WithAttributes(attrs ...core.KeyValue) SpanOption {
|
||||||
return func(o *SpanOptions) {
|
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) {
|
func TestSetSpanAttributesOnStart(t *testing.T) {
|
||||||
te := &testExporter{}
|
te := &testExporter{}
|
||||||
tp, _ := NewProvider(WithSyncer(te))
|
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)
|
got, err := endSpan(te, span)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -310,6 +314,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) {
|
|||||||
Name: "StartSpanAttribute/span0",
|
Name: "StartSpanAttribute/span0",
|
||||||
Attributes: []core.KeyValue{
|
Attributes: []core.KeyValue{
|
||||||
key.String("key1", "value1"),
|
key.String("key1", "value1"),
|
||||||
|
key.String("key2", "value2"),
|
||||||
},
|
},
|
||||||
SpanKind: apitrace.SpanKindInternal,
|
SpanKind: apitrace.SpanKindInternal,
|
||||||
HasRemoteParent: true,
|
HasRemoteParent: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user