Skip to content

Commit

Permalink
Rename kv.Infer to kv.Any (open-telemetry#969)
Browse files Browse the repository at this point in the history
* Consider renaming Infer to Any. Any is a commonly used concept in Go.
  • Loading branch information
u5surf committed Jul 26, 2020
1 parent c9c8137 commit 9a021b7
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Rename `kv.Infer` to `kv.Any`. (#969)
- Jaeger exporter helpers: added InstallNewPipeline and removed RegisterGlobal option instead. (#944)
- Zipkin exporter helpers: pipeline methods introduced, new exporter method adjusted. (#944)
- The trace (`go.opentelemetry.io/otel/exporters/trace/stdout`) and metric (`go.opentelemetry.io/otel/exporters/metric/stdout`) `stdout` exporters are now merged into a single exporter at `go.opentelemetry.io/otel/exporters/stdout`. (#956)
Expand Down
6 changes: 3 additions & 3 deletions api/kv/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func getSpan() trace.Span {
return sp
}

func BenchmarkKeyInfer(b *testing.B) {
func BenchmarkKeyAny(b *testing.B) {
for i := 0; i < b.N; i++ {
kv.Infer("Attr", int(256))
kv.Any("Attr", int(256))
}
}

Expand All @@ -58,7 +58,7 @@ func BenchmarkMultiWithKeyInference(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
sp.SetAttributes(kv.Infer("Attr", 1))
sp.SetAttributes(kv.Any("Attr", 1))
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func Array(k string, v interface{}) KeyValue {
return Key(k).Array(v)
}

// Infer creates a new key-value pair instance with a passed name and
// Any creates a new key-value pair instance with a passed name and
// automatic type inference. This is slower, and not type-safe.
func Infer(k string, value interface{}) KeyValue {
func Any(k string, value interface{}) KeyValue {
if value == nil {
return String(k, "<nil>")
}
Expand Down
4 changes: 2 additions & 2 deletions api/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestKeyValueConstructors(t *testing.T) {
}
}

func TestInfer(t *testing.T) {
func TestAny(t *testing.T) {
builder := &strings.Builder{}
builder.WriteString("foo")
jsonifyStruct := struct {
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestInfer(t *testing.T) {
},
} {
t.Logf("Running test case %s", testcase.key)
keyValue := kv.Infer(testcase.key, testcase.value)
keyValue := kv.Any(testcase.key, testcase.value)
if keyValue.Value.Type() != testcase.wantType {
t.Errorf("wrong value type, got %#v, expected %#v", keyValue.Value.Type(), testcase.wantType)
}
Expand Down
2 changes: 1 addition & 1 deletion api/trace/testtrace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *Span) SetAttributes(attrs ...kv.KeyValue) {
}

func (s *Span) SetAttribute(k string, v interface{}) {
s.SetAttributes(kv.Infer(k, v))
s.SetAttributes(kv.Any(k, v))
}

// Name returns the name most recently set on the Span, either at or after creation time.
Expand Down
2 changes: 1 addition & 1 deletion bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
}

func (s *MockSpan) SetAttribute(k string, v interface{}) {
s.SetAttributes(otelcore.Infer(k, v))
s.SetAttributes(otelcore.Any(k, v))
}

func (s *MockSpan) applyUpdate(update otelcorrelation.MapUpdate) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *span) SetAttributes(attributes ...kv.KeyValue) {
}

func (s *span) SetAttribute(k string, v interface{}) {
attr := kv.Infer(k, v)
attr := kv.Any(k, v)
if attr.Value.Type() != kv.INVALID {
s.SetAttributes(attr)
}
Expand Down

0 comments on commit 9a021b7

Please sign in to comment.