Skip to content

Commit eb9fe13

Browse files
ferhatelmaslizthegrey
authored andcommitted
Drop SetAttribute from Span (#361)
fixes #302
1 parent f25c84f commit eb9fe13

File tree

16 files changed

+19
-79
lines changed

16 files changed

+19
-79
lines changed

api/testharness/harness.go

-3
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,6 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) {
310310
"#SetName": func(span trace.Span) {
311311
span.SetName("new name")
312312
},
313-
"#SetAttribute": func(span trace.Span) {
314-
span.SetAttribute(core.Key("key").String("value"))
315-
},
316313
"#SetAttributes": func(span trace.Span) {
317314
span.SetAttributes(core.Key("key1").String("value"), core.Key("key2").Int(123))
318315
},

api/trace/api.go

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ type Span interface {
8484
SetName(name string)
8585

8686
// Set span attributes
87-
SetAttribute(core.KeyValue)
8887
SetAttributes(...core.KeyValue)
8988
}
9089

api/trace/current_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ func (mockSpan) SetName(name string) {
7979
func (mockSpan) SetError(v bool) {
8080
}
8181

82-
// SetAttribute does nothing.
83-
func (mockSpan) SetAttribute(attribute core.KeyValue) {
84-
}
85-
8682
// SetAttributes does nothing.
8783
func (mockSpan) SetAttributes(attributes ...core.KeyValue) {
8884
}

api/trace/noop_span.go

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ func (NoopSpan) SetStatus(status codes.Code) {
4646
func (NoopSpan) SetError(v bool) {
4747
}
4848

49-
// SetAttribute does nothing.
50-
func (NoopSpan) SetAttribute(attribute core.KeyValue) {
51-
}
52-
5349
// SetAttributes does nothing.
5450
func (NoopSpan) SetAttributes(attributes ...core.KeyValue) {
5551
}

bridge/opentracing/bridge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (s *bridgeSpan) SetTag(key string, value interface{}) ot.Span {
131131
s.otelSpan.SetStatus(status)
132132
}
133133
default:
134-
s.otelSpan.SetAttribute(otTagToOtelCoreKeyValue(key, value))
134+
s.otelSpan.SetAttributes(otTagToOtelCoreKeyValue(key, value))
135135
}
136136
return s
137137
}

bridge/opentracing/internal/mock.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,15 @@ func (s *MockSpan) IsRecording() bool {
225225
}
226226

227227
func (s *MockSpan) SetStatus(status codes.Code) {
228-
s.SetAttribute(NameKey.Uint32(uint32(status)))
228+
s.SetAttributes(NameKey.Uint32(uint32(status)))
229229
}
230230

231231
func (s *MockSpan) SetName(name string) {
232-
s.SetAttribute(NameKey.String(name))
232+
s.SetAttributes(NameKey.String(name))
233233
}
234234

235235
func (s *MockSpan) SetError(v bool) {
236-
s.SetAttribute(ErrorKey.Bool(v))
237-
}
238-
239-
func (s *MockSpan) SetAttribute(attribute otelcore.KeyValue) {
240-
s.applyUpdate(oteldctx.MapUpdate{
241-
SingleKV: attribute,
242-
})
236+
s.SetAttributes(ErrorKey.Bool(v))
243237
}
244238

245239
func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {

example/basic/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func main() {
126126
ctx,
127127
"Sub operation...",
128128
func(ctx context.Context) error {
129-
trace.CurrentSpan(ctx).SetAttribute(lemonsKey.String("five"))
129+
trace.CurrentSpan(ctx).SetAttributes(lemonsKey.String("five"))
130130

131131
trace.CurrentSpan(ctx).AddEvent(ctx, "Sub span event")
132132

example/namedtracer/foo/foo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func SubOperation(ctx context.Context) error {
3737
ctx,
3838
"Sub operation...",
3939
func(ctx context.Context) error {
40-
trace.CurrentSpan(ctx).SetAttribute(lemonsKey.String("five"))
40+
trace.CurrentSpan(ctx).SetAttributes(lemonsKey.String("five"))
4141

4242
trace.CurrentSpan(ctx).AddEvent(ctx, "Sub span event")
4343

exporter/trace/stackdriver/trace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (e *traceExporter) uploadSpans(ctx context.Context, spans []*tracepb.Span)
8383
// "go.opentelemetry.io/otel/exporter/stackdriver.uploadSpans",
8484
// )
8585
// defer span.End()
86-
// span.SetAttribute(key.New("num_spans").Int64(int64(len(spans))))
86+
// span.SetAttributes(key.New("num_spans").Int64(int64(len(spans))))
8787

8888
err := e.client.BatchWriteSpans(ctx, &req)
8989
if err != nil {

internal/trace/mock_span.go

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ func (ms *MockSpan) SetStatus(status codes.Code) {
5454
func (ms *MockSpan) SetError(v bool) {
5555
}
5656

57-
// SetAttribute does nothing.
58-
func (ms *MockSpan) SetAttribute(attribute core.KeyValue) {
59-
}
60-
6157
// SetAttributes does nothing.
6258
func (ms *MockSpan) SetAttributes(attributes ...core.KeyValue) {
6359
}

plugin/httptrace/clienttrace.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (ct *clientTracer) end(hook string, err error, attrs ...core.KeyValue) {
9999
if span, ok := ct.activeHooks[hook]; ok {
100100
if err != nil {
101101
span.SetStatus(codes.Unknown)
102-
span.SetAttribute(MessageKey.String(err.Error()))
102+
span.SetAttributes(MessageKey.String(err.Error()))
103103
}
104104
span.SetAttributes(attrs...)
105105
span.End()
@@ -164,7 +164,7 @@ func (ct *clientTracer) wroteHeaderField(k string, v []string) {
164164
if ct.span("http.headers") == nil {
165165
ct.start("http.headers", "http.headers")
166166
}
167-
ct.root.SetAttribute(key.String("http."+strings.ToLower(k), sliceToString(v)))
167+
ct.root.SetAttributes(key.String("http."+strings.ToLower(k), sliceToString(v)))
168168
}
169169

170170
func (ct *clientTracer) wroteHeaders() {
@@ -173,7 +173,7 @@ func (ct *clientTracer) wroteHeaders() {
173173

174174
func (ct *clientTracer) wroteRequest(info httptrace.WroteRequestInfo) {
175175
if info.Err != nil {
176-
ct.root.SetAttribute(MessageKey.String(info.Err.Error()))
176+
ct.root.SetAttributes(MessageKey.String(info.Err.Error()))
177177
ct.root.SetStatus(codes.Unknown)
178178
}
179179
ct.end("http.send", info.Err)

plugin/othttp/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func WithRouteTag(route string, h http.Handler) http.Handler {
223223
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
224224
span := trace.CurrentSpan(r.Context())
225225
//TODO: Why doesn't tag.Upsert work?
226-
span.SetAttribute(RouteKey.String(route))
226+
span.SetAttributes(RouteKey.String(route))
227227
h.ServeHTTP(w, r.WithContext(trace.SetCurrentSpan(r.Context(), span)))
228228
})
229229
}

plugin/othttp/handler_example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func ExampleNewHandler() {
6565
case "":
6666
err = fmt.Errorf("expected /hello/:name in %q", s)
6767
default:
68-
trace.CurrentSpan(ctx).SetAttribute(core.Key("name").String(pp[1]))
68+
trace.CurrentSpan(ctx).SetAttributes(core.Key("name").String(pp[1]))
6969
}
7070
return pp[1], err
7171
}

sdk/trace/benchmark_test.go

-33
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,6 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) {
5353
})
5454
}
5555

56-
func BenchmarkSpan_SetAttributes(b *testing.B) {
57-
b.Run("SetAttribute", func(b *testing.B) {
58-
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t apitrace.Tracer) {
59-
ctx := context.Background()
60-
b.ResetTimer()
61-
62-
for i := 0; i < b.N; i++ {
63-
_, span := t.Start(ctx, "/foo")
64-
span.SetAttribute(key.New("key1").Bool(false))
65-
span.SetAttribute(key.New("key2").String("hello"))
66-
span.SetAttribute(key.New("key3").Uint64(123))
67-
span.SetAttribute(key.New("key4").Float64(123.456))
68-
span.End()
69-
}
70-
})
71-
})
72-
73-
b.Run("SetAttributes", func(b *testing.B) {
74-
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t apitrace.Tracer) {
75-
ctx := context.Background()
76-
b.ResetTimer()
77-
for i := 0; i < b.N; i++ {
78-
_, span := t.Start(ctx, "/foo")
79-
span.SetAttributes(key.New("key1").Bool(false))
80-
span.SetAttributes(key.New("key2").String("hello"))
81-
span.SetAttributes(key.New("key3").Uint64(123))
82-
span.SetAttributes(key.New("key4").Float64(123.456))
83-
span.End()
84-
}
85-
})
86-
})
87-
}
88-
8956
func BenchmarkSpanWithAttributes_8(b *testing.B) {
9057
traceBenchmark(b, "Benchmark Start With 8 Attributes", func(b *testing.B, t apitrace.Tracer) {
9158
ctx := context.Background()

sdk/trace/span.go

-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ func (s *span) SetStatus(status codes.Code) {
8484
s.mu.Unlock()
8585
}
8686

87-
func (s *span) SetAttribute(attribute core.KeyValue) {
88-
if !s.IsRecording() {
89-
return
90-
}
91-
s.copyToCappedAttributes(attribute)
92-
}
93-
9487
func (s *span) SetAttributes(attributes ...core.KeyValue) {
9588
if !s.IsRecording() {
9689
return

sdk/trace/trace_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func TestSetSpanAttributes(t *testing.T) {
328328
te := &testExporter{}
329329
tp, _ := NewProvider(WithSyncer(te))
330330
span := startSpan(tp, "SpanAttribute")
331-
span.SetAttribute(key.New("key1").String("value1"))
331+
span.SetAttributes(key.New("key1").String("value1"))
332332
got, err := endSpan(te, span)
333333
if err != nil {
334334
t.Fatal(err)
@@ -358,10 +358,12 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
358358
tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te))
359359

360360
span := startSpan(tp, "SpanAttributesOverLimit")
361-
span.SetAttribute(key.Bool("key1", true))
362-
span.SetAttribute(key.String("key2", "value2"))
363-
span.SetAttribute(key.Bool("key1", false)) // Replace key1.
364-
span.SetAttribute(key.Int64("key4", 4)) // Remove key2 and add key4
361+
span.SetAttributes(
362+
key.Bool("key1", true),
363+
key.String("key2", "value2"),
364+
key.Bool("key1", false), // Replace key1.
365+
key.Int64("key4", 4), // Remove key2 and add key4
366+
)
365367
got, err := endSpan(te, span)
366368
if err != nil {
367369
t.Fatal(err)

0 commit comments

Comments
 (0)