You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-13 01:00:22 +02:00
committed by
Liz Fong-Jones
parent
f25c84f35f
commit
eb9fe13a77
@ -310,9 +310,6 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) {
|
||||
"#SetName": func(span trace.Span) {
|
||||
span.SetName("new name")
|
||||
},
|
||||
"#SetAttribute": func(span trace.Span) {
|
||||
span.SetAttribute(core.Key("key").String("value"))
|
||||
},
|
||||
"#SetAttributes": func(span trace.Span) {
|
||||
span.SetAttributes(core.Key("key1").String("value"), core.Key("key2").Int(123))
|
||||
},
|
||||
|
@ -84,7 +84,6 @@ type Span interface {
|
||||
SetName(name string)
|
||||
|
||||
// Set span attributes
|
||||
SetAttribute(core.KeyValue)
|
||||
SetAttributes(...core.KeyValue)
|
||||
}
|
||||
|
||||
|
@ -79,10 +79,6 @@ func (mockSpan) SetName(name string) {
|
||||
func (mockSpan) SetError(v bool) {
|
||||
}
|
||||
|
||||
// SetAttribute does nothing.
|
||||
func (mockSpan) SetAttribute(attribute core.KeyValue) {
|
||||
}
|
||||
|
||||
// SetAttributes does nothing.
|
||||
func (mockSpan) SetAttributes(attributes ...core.KeyValue) {
|
||||
}
|
||||
|
@ -46,10 +46,6 @@ func (NoopSpan) SetStatus(status codes.Code) {
|
||||
func (NoopSpan) SetError(v bool) {
|
||||
}
|
||||
|
||||
// SetAttribute does nothing.
|
||||
func (NoopSpan) SetAttribute(attribute core.KeyValue) {
|
||||
}
|
||||
|
||||
// SetAttributes does nothing.
|
||||
func (NoopSpan) SetAttributes(attributes ...core.KeyValue) {
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func (s *bridgeSpan) SetTag(key string, value interface{}) ot.Span {
|
||||
s.otelSpan.SetStatus(status)
|
||||
}
|
||||
default:
|
||||
s.otelSpan.SetAttribute(otTagToOtelCoreKeyValue(key, value))
|
||||
s.otelSpan.SetAttributes(otTagToOtelCoreKeyValue(key, value))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -225,21 +225,15 @@ func (s *MockSpan) IsRecording() bool {
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetStatus(status codes.Code) {
|
||||
s.SetAttribute(NameKey.Uint32(uint32(status)))
|
||||
s.SetAttributes(NameKey.Uint32(uint32(status)))
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetName(name string) {
|
||||
s.SetAttribute(NameKey.String(name))
|
||||
s.SetAttributes(NameKey.String(name))
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetError(v bool) {
|
||||
s.SetAttribute(ErrorKey.Bool(v))
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetAttribute(attribute otelcore.KeyValue) {
|
||||
s.applyUpdate(oteldctx.MapUpdate{
|
||||
SingleKV: attribute,
|
||||
})
|
||||
s.SetAttributes(ErrorKey.Bool(v))
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
|
||||
|
@ -126,7 +126,7 @@ func main() {
|
||||
ctx,
|
||||
"Sub operation...",
|
||||
func(ctx context.Context) error {
|
||||
trace.CurrentSpan(ctx).SetAttribute(lemonsKey.String("five"))
|
||||
trace.CurrentSpan(ctx).SetAttributes(lemonsKey.String("five"))
|
||||
|
||||
trace.CurrentSpan(ctx).AddEvent(ctx, "Sub span event")
|
||||
|
||||
|
@ -37,7 +37,7 @@ func SubOperation(ctx context.Context) error {
|
||||
ctx,
|
||||
"Sub operation...",
|
||||
func(ctx context.Context) error {
|
||||
trace.CurrentSpan(ctx).SetAttribute(lemonsKey.String("five"))
|
||||
trace.CurrentSpan(ctx).SetAttributes(lemonsKey.String("five"))
|
||||
|
||||
trace.CurrentSpan(ctx).AddEvent(ctx, "Sub span event")
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (e *traceExporter) uploadSpans(ctx context.Context, spans []*tracepb.Span)
|
||||
// "go.opentelemetry.io/otel/exporter/stackdriver.uploadSpans",
|
||||
// )
|
||||
// defer span.End()
|
||||
// span.SetAttribute(key.New("num_spans").Int64(int64(len(spans))))
|
||||
// span.SetAttributes(key.New("num_spans").Int64(int64(len(spans))))
|
||||
|
||||
err := e.client.BatchWriteSpans(ctx, &req)
|
||||
if err != nil {
|
||||
|
@ -54,10 +54,6 @@ func (ms *MockSpan) SetStatus(status codes.Code) {
|
||||
func (ms *MockSpan) SetError(v bool) {
|
||||
}
|
||||
|
||||
// SetAttribute does nothing.
|
||||
func (ms *MockSpan) SetAttribute(attribute core.KeyValue) {
|
||||
}
|
||||
|
||||
// SetAttributes does nothing.
|
||||
func (ms *MockSpan) SetAttributes(attributes ...core.KeyValue) {
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func (ct *clientTracer) end(hook string, err error, attrs ...core.KeyValue) {
|
||||
if span, ok := ct.activeHooks[hook]; ok {
|
||||
if err != nil {
|
||||
span.SetStatus(codes.Unknown)
|
||||
span.SetAttribute(MessageKey.String(err.Error()))
|
||||
span.SetAttributes(MessageKey.String(err.Error()))
|
||||
}
|
||||
span.SetAttributes(attrs...)
|
||||
span.End()
|
||||
@ -164,7 +164,7 @@ func (ct *clientTracer) wroteHeaderField(k string, v []string) {
|
||||
if ct.span("http.headers") == nil {
|
||||
ct.start("http.headers", "http.headers")
|
||||
}
|
||||
ct.root.SetAttribute(key.String("http."+strings.ToLower(k), sliceToString(v)))
|
||||
ct.root.SetAttributes(key.String("http."+strings.ToLower(k), sliceToString(v)))
|
||||
}
|
||||
|
||||
func (ct *clientTracer) wroteHeaders() {
|
||||
@ -173,7 +173,7 @@ func (ct *clientTracer) wroteHeaders() {
|
||||
|
||||
func (ct *clientTracer) wroteRequest(info httptrace.WroteRequestInfo) {
|
||||
if info.Err != nil {
|
||||
ct.root.SetAttribute(MessageKey.String(info.Err.Error()))
|
||||
ct.root.SetAttributes(MessageKey.String(info.Err.Error()))
|
||||
ct.root.SetStatus(codes.Unknown)
|
||||
}
|
||||
ct.end("http.send", info.Err)
|
||||
|
@ -223,7 +223,7 @@ func WithRouteTag(route string, h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
span := trace.CurrentSpan(r.Context())
|
||||
//TODO: Why doesn't tag.Upsert work?
|
||||
span.SetAttribute(RouteKey.String(route))
|
||||
span.SetAttributes(RouteKey.String(route))
|
||||
h.ServeHTTP(w, r.WithContext(trace.SetCurrentSpan(r.Context(), span)))
|
||||
})
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func ExampleNewHandler() {
|
||||
case "":
|
||||
err = fmt.Errorf("expected /hello/:name in %q", s)
|
||||
default:
|
||||
trace.CurrentSpan(ctx).SetAttribute(core.Key("name").String(pp[1]))
|
||||
trace.CurrentSpan(ctx).SetAttributes(core.Key("name").String(pp[1]))
|
||||
}
|
||||
return pp[1], err
|
||||
}
|
||||
|
@ -53,39 +53,6 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) {
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkSpan_SetAttributes(b *testing.B) {
|
||||
b.Run("SetAttribute", func(b *testing.B) {
|
||||
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t apitrace.Tracer) {
|
||||
ctx := context.Background()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, span := t.Start(ctx, "/foo")
|
||||
span.SetAttribute(key.New("key1").Bool(false))
|
||||
span.SetAttribute(key.New("key2").String("hello"))
|
||||
span.SetAttribute(key.New("key3").Uint64(123))
|
||||
span.SetAttribute(key.New("key4").Float64(123.456))
|
||||
span.End()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
b.Run("SetAttributes", func(b *testing.B) {
|
||||
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t apitrace.Tracer) {
|
||||
ctx := context.Background()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, span := t.Start(ctx, "/foo")
|
||||
span.SetAttributes(key.New("key1").Bool(false))
|
||||
span.SetAttributes(key.New("key2").String("hello"))
|
||||
span.SetAttributes(key.New("key3").Uint64(123))
|
||||
span.SetAttributes(key.New("key4").Float64(123.456))
|
||||
span.End()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkSpanWithAttributes_8(b *testing.B) {
|
||||
traceBenchmark(b, "Benchmark Start With 8 Attributes", func(b *testing.B, t apitrace.Tracer) {
|
||||
ctx := context.Background()
|
||||
|
@ -84,13 +84,6 @@ func (s *span) SetStatus(status codes.Code) {
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *span) SetAttribute(attribute core.KeyValue) {
|
||||
if !s.IsRecording() {
|
||||
return
|
||||
}
|
||||
s.copyToCappedAttributes(attribute)
|
||||
}
|
||||
|
||||
func (s *span) SetAttributes(attributes ...core.KeyValue) {
|
||||
if !s.IsRecording() {
|
||||
return
|
||||
|
@ -328,7 +328,7 @@ func TestSetSpanAttributes(t *testing.T) {
|
||||
te := &testExporter{}
|
||||
tp, _ := NewProvider(WithSyncer(te))
|
||||
span := startSpan(tp, "SpanAttribute")
|
||||
span.SetAttribute(key.New("key1").String("value1"))
|
||||
span.SetAttributes(key.New("key1").String("value1"))
|
||||
got, err := endSpan(te, span)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -358,10 +358,12 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
|
||||
tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te))
|
||||
|
||||
span := startSpan(tp, "SpanAttributesOverLimit")
|
||||
span.SetAttribute(key.Bool("key1", true))
|
||||
span.SetAttribute(key.String("key2", "value2"))
|
||||
span.SetAttribute(key.Bool("key1", false)) // Replace key1.
|
||||
span.SetAttribute(key.Int64("key4", 4)) // Remove key2 and add key4
|
||||
span.SetAttributes(
|
||||
key.Bool("key1", true),
|
||||
key.String("key2", "value2"),
|
||||
key.Bool("key1", false), // Replace key1.
|
||||
key.Int64("key4", 4), // Remove key2 and add key4
|
||||
)
|
||||
got, err := endSpan(te, span)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
Reference in New Issue
Block a user