diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f0a6141328..9decc17f33a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The environment variable used for resource detection has been changed from `OTEL_RESOURCE_LABELS` to `OTEL_RESOURCE_ATTRIBUTES` (#1042) - Replace `WithSyncer` with `WithBatcher` in examples. (#1044) - Replace the `google.golang.org/grpc/codes` dependency in the API with an equivalent `go.opentelemetry.io/otel/codes` package. (#1046) +- Merge the `go.opentelemetry.io/otel/api/label` and `go.opentelemetry.io/otel/api/kv` into the new `go.opentelemetry.io/otel/label` package. (#1060) - Unify Callback Function Naming. Rename `*Callback` with `*Func`. (#1061) diff --git a/api/apitest/harness.go b/api/apitest/harness.go index 6237264ee7b..981fccd2581 100644 --- a/api/apitest/harness.go +++ b/api/apitest/harness.go @@ -20,10 +20,10 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/internal/matchers" + "go.opentelemetry.io/otel/label" ) type Harness struct { @@ -195,7 +195,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { span.SetName("new name") }, "#SetAttributes": func(span trace.Span) { - span.SetAttributes(kv.String("key1", "value"), kv.Int("key2", 123)) + span.SetAttributes(label.String("key1", "value"), label.Int("key2", 123)) }, } var mechanisms = map[string]func() trace.Span{ diff --git a/api/correlation/context.go b/api/correlation/context.go index 15545206372..ee384198481 100644 --- a/api/correlation/context.go +++ b/api/correlation/context.go @@ -17,7 +17,7 @@ package correlation import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) type correlationsType struct{} @@ -150,7 +150,7 @@ func ContextWithMap(ctx context.Context, m Map) context.Context { // NewContext returns a context with the map from passed context // updated with the passed key-value pairs. -func NewContext(ctx context.Context, keyvalues ...kv.KeyValue) context.Context { +func NewContext(ctx context.Context, keyvalues ...label.KeyValue) context.Context { return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{ MultiKV: keyvalues, })) diff --git a/api/correlation/correlation_context_propagator.go b/api/correlation/correlation_context_propagator.go index fec83ed1416..bf93e701fe1 100644 --- a/api/correlation/correlation_context_propagator.go +++ b/api/correlation/correlation_context_propagator.go @@ -19,8 +19,8 @@ import ( "net/url" "strings" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/propagation" + "go.opentelemetry.io/otel/label" ) // Temporary header name until W3C finalizes format. @@ -45,7 +45,7 @@ func (CorrelationContext) Inject(ctx context.Context, supplier propagation.HTTPS correlationCtx := MapFromContext(ctx) firstIter := true var headerValueBuilder strings.Builder - correlationCtx.Foreach(func(kv kv.KeyValue) bool { + correlationCtx.Foreach(func(kv label.KeyValue) bool { if !firstIter { headerValueBuilder.WriteRune(',') } @@ -69,7 +69,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP } contextValues := strings.Split(correlationContext, ",") - keyValues := make([]kv.KeyValue, 0, len(contextValues)) + keyValues := make([]label.KeyValue, 0, len(contextValues)) for _, contextValue := range contextValues { valueAndProps := strings.Split(contextValue, ";") if len(valueAndProps) < 1 { @@ -99,7 +99,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP trimmedValueWithProps.WriteString(prop) } - keyValues = append(keyValues, kv.Key(trimmedName).String(trimmedValueWithProps.String())) + keyValues = append(keyValues, label.String(trimmedName, trimmedValueWithProps.String())) } if len(keyValues) > 0 { diff --git a/api/correlation/correlation_context_propagator_test.go b/api/correlation/correlation_context_propagator_test.go index e6d7804b88a..f7d21a6fc31 100644 --- a/api/correlation/correlation_context_propagator_test.go +++ b/api/correlation/correlation_context_propagator_test.go @@ -23,8 +23,8 @@ import ( "github.com/google/go-cmp/cmp" "go.opentelemetry.io/otel/api/correlation" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/propagation" + "go.opentelemetry.io/otel/label" ) func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) { @@ -32,54 +32,54 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) { tests := []struct { name string header string - wantKVs []kv.KeyValue + wantKVs []label.KeyValue }{ { name: "valid w3cHeader", header: "key1=val1,key2=val2", - wantKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2"), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2"), }, }, { name: "valid w3cHeader with spaces", header: "key1 = val1, key2 =val2 ", - wantKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2"), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2"), }, }, { name: "valid w3cHeader with properties", header: "key1=val1,key2=val2;prop=1", - wantKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2;prop=1"), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2;prop=1"), }, }, { name: "valid header with url-escaped comma", header: "key1=val1,key2=val2%2Cval3", - wantKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2,val3"), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2,val3"), }, }, { name: "valid header with an invalid header", header: "key1=val1,key2=val2,a,val3", - wantKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2"), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2"), }, }, { name: "valid header with no value", header: "key1=,key2=val2", - wantKVs: []kv.KeyValue{ - kv.Key("key1").String(""), - kv.Key("key2").String("val2"), + wantKVs: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), }, }, } @@ -101,9 +101,9 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) { ) } totalDiff := "" - wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool { + wantCorCtx.Foreach(func(keyValue label.KeyValue) bool { val, _ := gotCorCtx.Value(keyValue.Key) - diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(kv.Value{})) + diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{})) if diff != "" { totalDiff += diff + "\n" } @@ -121,7 +121,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { tests := []struct { name string header string - hasKVs []kv.KeyValue + hasKVs []label.KeyValue }{ { name: "no key values", @@ -130,17 +130,17 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { { name: "invalid header with existing context", header: "header2", - hasKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2"), + hasKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2"), }, }, { name: "empty header value", header: "", - hasKVs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2"), + hasKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2"), }, }, } @@ -162,9 +162,9 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { ) } totalDiff := "" - wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool { + wantCorCtx.Foreach(func(keyValue label.KeyValue) bool { val, _ := gotCorCtx.Value(keyValue.Key) - diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(kv.Value{})) + diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{})) if diff != "" { totalDiff += diff + "\n" } @@ -179,38 +179,38 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) { props := propagation.New(propagation.WithInjectors(propagator)) tests := []struct { name string - kvs []kv.KeyValue + kvs []label.KeyValue wantInHeader []string wantedLen int }{ { name: "two simple values", - kvs: []kv.KeyValue{ - kv.Key("key1").String("val1"), - kv.Key("key2").String("val2"), + kvs: []label.KeyValue{ + label.String("key1", "val1"), + label.String("key2", "val2"), }, wantInHeader: []string{"key1=val1", "key2=val2"}, }, { name: "two values with escaped chars", - kvs: []kv.KeyValue{ - kv.Key("key1").String("val1,val2"), - kv.Key("key2").String("val3=4"), + kvs: []label.KeyValue{ + label.String("key1", "val1,val2"), + label.String("key2", "val3=4"), }, wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"}, }, { name: "values of non-string types", - kvs: []kv.KeyValue{ - kv.Key("key1").Bool(true), - kv.Key("key2").Int(123), - kv.Key("key3").Int64(123), - kv.Key("key4").Int32(123), - kv.Key("key5").Uint(123), - kv.Key("key6").Uint32(123), - kv.Key("key7").Uint64(123), - kv.Key("key8").Float64(123.567), - kv.Key("key9").Float32(123.567), + kvs: []label.KeyValue{ + label.Bool("key1", true), + label.Int("key2", 123), + label.Int64("key3", 123), + label.Int32("key4", 123), + label.Uint("key5", 123), + label.Uint32("key6", 123), + label.Uint64("key7", 123), + label.Float64("key8", 123.567), + label.Float32("key9", 123.567), }, wantInHeader: []string{ "key1=true", diff --git a/api/correlation/map.go b/api/correlation/map.go index 2bbb0435611..df517da4986 100644 --- a/api/correlation/map.go +++ b/api/correlation/map.go @@ -14,12 +14,10 @@ package correlation -import ( - "go.opentelemetry.io/otel/api/kv" -) +import "go.opentelemetry.io/otel/label" -type rawMap map[kv.Key]kv.Value -type keySet map[kv.Key]struct{} +type rawMap map[label.Key]label.Value +type keySet map[label.Key]struct{} // Map is an immutable storage for correlations. type Map struct { @@ -32,18 +30,18 @@ type MapUpdate struct { // DropSingleK contains a single key to be dropped from // correlations. Use this to avoid an overhead of a slice // allocation if there is only one key to drop. - DropSingleK kv.Key + DropSingleK label.Key // DropMultiK contains all the keys to be dropped from // correlations. - DropMultiK []kv.Key + DropMultiK []label.Key // SingleKV contains a single key-value pair to be added to // correlations. Use this to avoid an overhead of a slice // allocation if there is only one key-value pair to add. - SingleKV kv.KeyValue + SingleKV label.KeyValue // MultiKV contains all the key-value pairs to be added to // correlations. - MultiKV []kv.KeyValue + MultiKV []label.KeyValue } func newMap(raw rawMap) Map { @@ -101,7 +99,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) { deletionsCount++ } if deletionsCount > 0 { - delSet = make(map[kv.Key]struct{}, deletionsCount) + delSet = make(map[label.Key]struct{}, deletionsCount) for _, k := range update.DropMultiK { delSet[k] = struct{}{} } @@ -115,7 +113,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) { additionsCount++ } if additionsCount > 0 { - addSet = make(map[kv.Key]struct{}, additionsCount) + addSet = make(map[label.Key]struct{}, additionsCount) for _, k := range update.MultiKV { addSet[k.Key] = struct{}{} } @@ -146,14 +144,14 @@ func getNewMapSize(m rawMap, delSet, addSet keySet) int { // Value gets a value from correlations map and returns a boolean // value indicating whether the key exist in the map. -func (m Map) Value(k kv.Key) (kv.Value, bool) { +func (m Map) Value(k label.Key) (label.Value, bool) { value, ok := m.m[k] return value, ok } // HasValue returns a boolean value indicating whether the key exist // in the map. -func (m Map) HasValue(k kv.Key) bool { +func (m Map) HasValue(k label.Key) bool { _, has := m.Value(k) return has } @@ -166,9 +164,9 @@ func (m Map) Len() int { // Foreach calls a passed callback once on each key-value pair until // all the key-value pairs of the map were iterated or the callback // returns false, whichever happens first. -func (m Map) Foreach(f func(kv kv.KeyValue) bool) { +func (m Map) Foreach(f func(label.KeyValue) bool) { for k, v := range m.m { - if !f(kv.KeyValue{ + if !f(label.KeyValue{ Key: k, Value: v, }) { diff --git a/api/correlation/map_test.go b/api/correlation/map_test.go index f2eb2abc960..18a037ba4ae 100644 --- a/api/correlation/map_test.go +++ b/api/correlation/map_test.go @@ -18,14 +18,14 @@ import ( "fmt" "testing" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) type testCase struct { name string value MapUpdate init []int - wantKVs []kv.KeyValue + wantKVs []label.KeyValue } func TestMap(t *testing.T) { @@ -46,13 +46,13 @@ func TestMap(t *testing.T) { } } // test Foreach() - got.Foreach(func(kv kv.KeyValue) bool { + got.Foreach(func(kv label.KeyValue) bool { for _, want := range testcase.wantKVs { if kv == want { return false } } - t.Errorf("Expected kv %v, but not found", kv) + t.Errorf("Expected label %v, but not found", kv) return true }) if l, exp := got.Len(), len(testcase.wantKVs); l != exp { @@ -85,192 +85,192 @@ func getTestCases() []testCase { return []testCase{ { name: "map with MultiKV", - value: MapUpdate{MultiKV: []kv.KeyValue{ - kv.Int64("key1", 1), - kv.String("key2", "val2")}, + value: MapUpdate{MultiKV: []label.KeyValue{ + label.Int64("key1", 1), + label.String("key2", "val2")}, }, init: []int{}, - wantKVs: []kv.KeyValue{ - kv.Int64("key1", 1), - kv.String("key2", "val2"), + wantKVs: []label.KeyValue{ + label.Int64("key1", 1), + label.String("key2", "val2"), }, }, { name: "map with SingleKV", - value: MapUpdate{SingleKV: kv.String("key1", "val1")}, + value: MapUpdate{SingleKV: label.String("key1", "val1")}, init: []int{}, - wantKVs: []kv.KeyValue{ - kv.String("key1", "val1"), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), }, }, { name: "map with both add fields", - value: MapUpdate{SingleKV: kv.Int64("key1", 3), - MultiKV: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2")}, + value: MapUpdate{SingleKV: label.Int64("key1", 3), + MultiKV: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2")}, }, init: []int{}, - wantKVs: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2"), + wantKVs: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), }, }, { name: "map with empty MapUpdate", value: MapUpdate{}, init: []int{}, - wantKVs: []kv.KeyValue{}, + wantKVs: []label.KeyValue{}, }, { name: "map with DropSingleK", - value: MapUpdate{DropSingleK: kv.Key("key1")}, + value: MapUpdate{DropSingleK: label.Key("key1")}, init: []int{}, - wantKVs: []kv.KeyValue{}, + wantKVs: []label.KeyValue{}, }, { name: "map with DropMultiK", - value: MapUpdate{DropMultiK: []kv.Key{ - kv.Key("key1"), kv.Key("key2"), + value: MapUpdate{DropMultiK: []label.Key{ + label.Key("key1"), label.Key("key2"), }}, init: []int{}, - wantKVs: []kv.KeyValue{}, + wantKVs: []label.KeyValue{}, }, { name: "map with both drop fields", value: MapUpdate{ - DropSingleK: kv.Key("key1"), - DropMultiK: []kv.Key{ - kv.Key("key1"), - kv.Key("key2"), + DropSingleK: label.Key("key1"), + DropMultiK: []label.Key{ + label.Key("key1"), + label.Key("key2"), }, }, init: []int{}, - wantKVs: []kv.KeyValue{}, + wantKVs: []label.KeyValue{}, }, { name: "map with all fields", value: MapUpdate{ - DropSingleK: kv.Key("key1"), - DropMultiK: []kv.Key{ - kv.Key("key1"), - kv.Key("key2"), + DropSingleK: label.Key("key1"), + DropMultiK: []label.Key{ + label.Key("key1"), + label.Key("key2"), }, - SingleKV: kv.String("key4", "val4"), - MultiKV: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2"), - kv.String("key3", "val3"), + SingleKV: label.String("key4", "val4"), + MultiKV: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), + label.String("key3", "val3"), }, }, init: []int{}, - wantKVs: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2"), - kv.String("key3", "val3"), - kv.String("key4", "val4"), + wantKVs: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), + label.String("key3", "val3"), + label.String("key4", "val4"), }, }, { name: "Existing map with MultiKV", - value: MapUpdate{MultiKV: []kv.KeyValue{ - kv.Int64("key1", 1), - kv.String("key2", "val2")}, + value: MapUpdate{MultiKV: []label.KeyValue{ + label.Int64("key1", 1), + label.String("key2", "val2")}, }, init: []int{5}, - wantKVs: []kv.KeyValue{ - kv.Int64("key1", 1), - kv.String("key2", "val2"), - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.Int64("key1", 1), + label.String("key2", "val2"), + label.Int("key5", 5), }, }, { name: "Existing map with SingleKV", - value: MapUpdate{SingleKV: kv.String("key1", "val1")}, + value: MapUpdate{SingleKV: label.String("key1", "val1")}, init: []int{5}, - wantKVs: []kv.KeyValue{ - kv.String("key1", "val1"), - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.String("key1", "val1"), + label.Int("key5", 5), }, }, { name: "Existing map with both add fields", - value: MapUpdate{SingleKV: kv.Int64("key1", 3), - MultiKV: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2")}, + value: MapUpdate{SingleKV: label.Int64("key1", 3), + MultiKV: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2")}, }, init: []int{5}, - wantKVs: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2"), - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), + label.Int("key5", 5), }, }, { name: "Existing map with empty MapUpdate", value: MapUpdate{}, init: []int{5}, - wantKVs: []kv.KeyValue{ - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.Int("key5", 5), }, }, { name: "Existing map with DropSingleK", - value: MapUpdate{DropSingleK: kv.Key("key1")}, + value: MapUpdate{DropSingleK: label.Key("key1")}, init: []int{1, 5}, - wantKVs: []kv.KeyValue{ - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.Int("key5", 5), }, }, { name: "Existing map with DropMultiK", - value: MapUpdate{DropMultiK: []kv.Key{ - kv.Key("key1"), kv.Key("key2"), + value: MapUpdate{DropMultiK: []label.Key{ + label.Key("key1"), label.Key("key2"), }}, init: []int{1, 5}, - wantKVs: []kv.KeyValue{ - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.Int("key5", 5), }, }, { name: "Existing map with both drop fields", value: MapUpdate{ - DropSingleK: kv.Key("key1"), - DropMultiK: []kv.Key{ - kv.Key("key1"), - kv.Key("key2"), + DropSingleK: label.Key("key1"), + DropMultiK: []label.Key{ + label.Key("key1"), + label.Key("key2"), }, }, init: []int{1, 2, 5}, - wantKVs: []kv.KeyValue{ - kv.Int("key5", 5), + wantKVs: []label.KeyValue{ + label.Int("key5", 5), }, }, { name: "Existing map with all the fields", value: MapUpdate{ - DropSingleK: kv.Key("key1"), - DropMultiK: []kv.Key{ - kv.Key("key1"), - kv.Key("key2"), - kv.Key("key5"), - kv.Key("key6"), + DropSingleK: label.Key("key1"), + DropMultiK: []label.Key{ + label.Key("key1"), + label.Key("key2"), + label.Key("key5"), + label.Key("key6"), }, - SingleKV: kv.String("key4", "val4"), - MultiKV: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2"), - kv.String("key3", "val3"), + SingleKV: label.String("key4", "val4"), + MultiKV: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), + label.String("key3", "val3"), }, }, init: []int{5, 6, 7}, - wantKVs: []kv.KeyValue{ - kv.String("key1", ""), - kv.String("key2", "val2"), - kv.String("key3", "val3"), - kv.String("key4", "val4"), - kv.Int("key7", 7), + wantKVs: []label.KeyValue{ + label.String("key1", ""), + label.String("key2", "val2"), + label.String("key3", "val3"), + label.String("key4", "val4"), + label.Int("key7", 7), }, }, } @@ -279,7 +279,7 @@ func getTestCases() []testCase { func makeTestMap(ints []int) Map { r := make(rawMap, len(ints)) for _, v := range ints { - r[kv.Key(fmt.Sprintf("key%d", v))] = kv.IntValue(v) + r[label.Key(fmt.Sprintf("key%d", v))] = label.IntValue(v) } return newMap(r) } diff --git a/api/global/internal/benchmark_test.go b/api/global/internal/benchmark_test.go index d8e4ca932c4..4abada40d75 100644 --- a/api/global/internal/benchmark_test.go +++ b/api/global/internal/benchmark_test.go @@ -20,7 +20,7 @@ import ( "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/global/internal" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { @@ -30,7 +30,7 @@ func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { internal.ResetForTest() ctx := context.Background() sdk := global.Meter("test") - labs := []kv.KeyValue{kv.String("A", "B")} + labs := []label.KeyValue{label.String("A", "B")} cnt := Must(sdk).NewInt64Counter("int64.counter") b.ResetTimer() diff --git a/api/global/internal/meter.go b/api/global/internal/meter.go index 43f28227c6d..ce3ed20996c 100644 --- a/api/global/internal/meter.go +++ b/api/global/internal/meter.go @@ -20,9 +20,9 @@ import ( "sync/atomic" "unsafe" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/metric/registry" + "go.opentelemetry.io/otel/label" ) // This file contains the forwarding implementation of metric.Provider @@ -108,7 +108,7 @@ type syncHandle struct { delegate unsafe.Pointer // (*metric.HandleImpl) inst *syncImpl - labels []kv.KeyValue + labels []label.KeyValue initialize sync.Once } @@ -227,7 +227,7 @@ func (inst *syncImpl) Implementation() interface{} { return inst } -func (inst *syncImpl) Bind(labels []kv.KeyValue) metric.BoundSyncImpl { +func (inst *syncImpl) Bind(labels []label.KeyValue) metric.BoundSyncImpl { if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil { return (*implPtr).Bind(labels) } @@ -299,13 +299,13 @@ func (obs *asyncImpl) setDelegate(d metric.MeterImpl) { // Metric updates -func (m *meterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measurements ...metric.Measurement) { +func (m *meterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) { if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil { (*delegatePtr).RecordBatch(ctx, labels, measurements...) } } -func (inst *syncImpl) RecordOne(ctx context.Context, number metric.Number, labels []kv.KeyValue) { +func (inst *syncImpl) RecordOne(ctx context.Context, number metric.Number, labels []label.KeyValue) { if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil { (*instPtr).RecordOne(ctx, number, labels) } diff --git a/api/global/internal/meter_test.go b/api/global/internal/meter_test.go index aa962ba0188..0ebc09b55f3 100644 --- a/api/global/internal/meter_test.go +++ b/api/global/internal/meter_test.go @@ -23,9 +23,9 @@ import ( "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/global/internal" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" metrictest "go.opentelemetry.io/otel/internal/metric" + "go.opentelemetry.io/otel/label" ) var Must = metric.Must @@ -35,7 +35,7 @@ type measured struct { Name string InstrumentationName string InstrumentationVersion string - Labels map[kv.Key]kv.Value + Labels map[label.Key]label.Value Number metric.Number } @@ -55,10 +55,10 @@ func asStructs(batches []metrictest.Batch) []measured { return r } -func asMap(kvs ...kv.KeyValue) map[kv.Key]kv.Value { - m := map[kv.Key]kv.Value{} - for _, kv := range kvs { - m[kv.Key] = kv.Value +func asMap(kvs ...label.KeyValue) map[label.Key]label.Value { + m := map[label.Key]label.Value{} + for _, label := range kvs { + m[label.Key] = label.Value } return m } @@ -72,9 +72,9 @@ func TestDirect(t *testing.T) { ctx := context.Background() meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0")) meter2 := global.Meter("test2") - labels1 := []kv.KeyValue{kv.String("A", "B")} - labels2 := []kv.KeyValue{kv.String("C", "D")} - labels3 := []kv.KeyValue{kv.String("E", "F")} + labels1 := []label.KeyValue{label.String("A", "B")} + labels2 := []label.KeyValue{label.String("C", "D")} + labels3 := []label.KeyValue{label.String("E", "F")} counter := Must(meter1).NewInt64Counter("test.counter") counter.Add(ctx, 1, labels1...) @@ -171,7 +171,7 @@ func TestBound(t *testing.T) { // vs. the above, to cover all the instruments. ctx := context.Background() glob := global.Meter("test") - labels1 := []kv.KeyValue{kv.String("A", "B")} + labels1 := []label.KeyValue{label.String("A", "B")} counter := Must(glob).NewFloat64Counter("test.counter") boundC := counter.Bind(labels1...) @@ -215,7 +215,7 @@ func TestUnbind(t *testing.T) { internal.ResetForTest() glob := global.Meter("test") - labels1 := []kv.KeyValue{kv.String("A", "B")} + labels1 := []label.KeyValue{label.String("A", "B")} counter := Must(glob).NewFloat64Counter("test.counter") boundC := counter.Bind(labels1...) diff --git a/api/metric/api_test.go b/api/metric/api_test.go index 66c6758eedd..459e9a92591 100644 --- a/api/metric/api_test.go +++ b/api/metric/api_test.go @@ -20,10 +20,10 @@ import ( "fmt" "testing" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/unit" mockTest "go.opentelemetry.io/otel/internal/metric" + "go.opentelemetry.io/otel/label" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -99,7 +99,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := mockTest.NewMeter() c := Must(meter).NewFloat64Counter("test.counter.float") ctx := context.Background() - labels := []kv.KeyValue{kv.String("A", "B")} + labels := []label.KeyValue{label.String("A", "B")} c.Add(ctx, 1994.1, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -742) @@ -112,7 +112,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := mockTest.NewMeter() c := Must(meter).NewInt64Counter("test.counter.int") ctx := context.Background() - labels := []kv.KeyValue{kv.String("A", "B"), kv.String("C", "D")} + labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")} c.Add(ctx, 42, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, 4200) @@ -126,7 +126,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := mockTest.NewMeter() c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int") ctx := context.Background() - labels := []kv.KeyValue{kv.String("A", "B"), kv.String("C", "D")} + labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")} c.Add(ctx, 100, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -100) @@ -139,7 +139,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := mockTest.NewMeter() c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float") ctx := context.Background() - labels := []kv.KeyValue{kv.String("A", "B"), kv.String("C", "D")} + labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")} c.Add(ctx, 100.1, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -76) @@ -155,7 +155,7 @@ func TestValueRecorder(t *testing.T) { mockSDK, meter := mockTest.NewMeter() m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float") ctx := context.Background() - labels := []kv.KeyValue{} + labels := []label.KeyValue{} m.Record(ctx, 42, labels...) boundInstrument := m.Bind(labels...) boundInstrument.Record(ctx, 0) @@ -168,7 +168,7 @@ func TestValueRecorder(t *testing.T) { mockSDK, meter := mockTest.NewMeter() m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int") ctx := context.Background() - labels := []kv.KeyValue{kv.Int("I", 1)} + labels := []label.KeyValue{label.Int("I", 1)} m.Record(ctx, 173, labels...) boundInstrument := m.Bind(labels...) boundInstrument.Record(ctx, 80) @@ -181,7 +181,7 @@ func TestValueRecorder(t *testing.T) { func TestObserverInstruments(t *testing.T) { t.Run("float valueobserver", func(t *testing.T) { - labels := []kv.KeyValue{kv.String("O", "P")} + labels := []label.KeyValue{label.String("O", "P")} mockSDK, meter := mockTest.NewMeter() o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) @@ -192,7 +192,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("int valueobserver", func(t *testing.T) { - labels := []kv.KeyValue{} + labels := []label.KeyValue{} mockSDK, meter := mockTest.NewMeter() o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) @@ -203,7 +203,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("float sumobserver", func(t *testing.T) { - labels := []kv.KeyValue{kv.String("O", "P")} + labels := []label.KeyValue{label.String("O", "P")} mockSDK, meter := mockTest.NewMeter() o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) @@ -214,7 +214,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("int sumobserver", func(t *testing.T) { - labels := []kv.KeyValue{} + labels := []label.KeyValue{} mockSDK, meter := mockTest.NewMeter() o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) @@ -225,7 +225,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("float updownsumobserver", func(t *testing.T) { - labels := []kv.KeyValue{kv.String("O", "P")} + labels := []label.KeyValue{label.String("O", "P")} mockSDK, meter := mockTest.NewMeter() o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) @@ -236,7 +236,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("int updownsumobserver", func(t *testing.T) { - labels := []kv.KeyValue{} + labels := []label.KeyValue{} mockSDK, meter := mockTest.NewMeter() o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) @@ -248,7 +248,7 @@ func TestObserverInstruments(t *testing.T) { }) } -func checkSyncBatches(t *testing.T, ctx context.Context, labels []kv.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, instrument metric.InstrumentImpl, expected ...float64) { +func checkSyncBatches(t *testing.T, ctx context.Context, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, instrument metric.InstrumentImpl, expected ...float64) { t.Helper() if len(mock.MeasurementBatches) != 3 { t.Errorf("Expected 3 recorded measurement batches, got %d", len(mock.MeasurementBatches)) @@ -296,9 +296,9 @@ func TestBatchObserverInstruments(t *testing.T) { var obs1 metric.Int64ValueObserver var obs2 metric.Float64ValueObserver - labels := []kv.KeyValue{ - kv.String("A", "B"), - kv.String("C", "D"), + labels := []label.KeyValue{ + label.String("A", "B"), + label.String("C", "D"), } cb := Must(meter).NewBatchObserver( @@ -335,7 +335,7 @@ func TestBatchObserverInstruments(t *testing.T) { require.Equal(t, 0, m2.Number.CompareNumber(metric.Float64NumberKind, number(t, metric.Float64NumberKind, 42))) } -func checkObserverBatch(t *testing.T, labels []kv.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, observer metric.AsyncImpl, expected float64) { +func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, observer metric.AsyncImpl, expected float64) { t.Helper() assert.Len(t, mock.MeasurementBatches, 1) if len(mock.MeasurementBatches) < 1 { @@ -374,7 +374,7 @@ type testWrappedMeter struct { var _ metric.MeterImpl = testWrappedMeter{} -func (testWrappedMeter) RecordBatch(context.Context, []kv.KeyValue, ...metric.Measurement) { +func (testWrappedMeter) RecordBatch(context.Context, []label.KeyValue, ...metric.Measurement) { } func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { diff --git a/api/metric/async.go b/api/metric/async.go index 3f5a946adb8..d0d488df130 100644 --- a/api/metric/async.go +++ b/api/metric/async.go @@ -17,7 +17,7 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // The file is organized as follows: @@ -57,25 +57,25 @@ type BatchObserverFunc func(context.Context, BatchObserverResult) // observations for one asynchronous integer metric instrument. type Int64ObserverResult struct { instrument AsyncImpl - function func([]kv.KeyValue, ...Observation) + function func([]label.KeyValue, ...Observation) } // Float64ObserverResult is passed to an observer callback to capture // observations for one asynchronous floating point metric instrument. type Float64ObserverResult struct { instrument AsyncImpl - function func([]kv.KeyValue, ...Observation) + function func([]label.KeyValue, ...Observation) } // BatchObserverResult is passed to a batch observer callback to // capture observations for multiple asynchronous instruments. type BatchObserverResult struct { - function func([]kv.KeyValue, ...Observation) + function func([]label.KeyValue, ...Observation) } // Observe captures a single integer value from the associated // instrument callback, with the given labels. -func (ir Int64ObserverResult) Observe(value int64, labels ...kv.KeyValue) { +func (ir Int64ObserverResult) Observe(value int64, labels ...label.KeyValue) { ir.function(labels, Observation{ instrument: ir.instrument, number: NewInt64Number(value), @@ -84,7 +84,7 @@ func (ir Int64ObserverResult) Observe(value int64, labels ...kv.KeyValue) { // Observe captures a single floating point value from the associated // instrument callback, with the given labels. -func (fr Float64ObserverResult) Observe(value float64, labels ...kv.KeyValue) { +func (fr Float64ObserverResult) Observe(value float64, labels ...label.KeyValue) { fr.function(labels, Observation{ instrument: fr.instrument, number: NewFloat64Number(value), @@ -93,7 +93,7 @@ func (fr Float64ObserverResult) Observe(value float64, labels ...kv.KeyValue) { // Observe captures a multiple observations from the associated batch // instrument callback, with the given labels. -func (br BatchObserverResult) Observe(labels []kv.KeyValue, obs ...Observation) { +func (br BatchObserverResult) Observe(labels []label.KeyValue, obs ...Observation) { br.function(labels, obs...) } @@ -114,7 +114,7 @@ type AsyncSingleRunner interface { // receives one captured observation. (The function accepts // multiple observations so the same implementation can be // used for batch runners.) - Run(ctx context.Context, single AsyncImpl, capture func([]kv.KeyValue, ...Observation)) + Run(ctx context.Context, single AsyncImpl, capture func([]label.KeyValue, ...Observation)) AsyncRunner } @@ -124,7 +124,7 @@ type AsyncSingleRunner interface { type AsyncBatchRunner interface { // Run accepts a function for capturing observations of // multiple instruments. - Run(ctx context.Context, capture func([]kv.KeyValue, ...Observation)) + Run(ctx context.Context, capture func([]label.KeyValue, ...Observation)) AsyncRunner } @@ -158,7 +158,7 @@ func (*Float64ObserverFunc) AnyRunner() {} func (*BatchObserverFunc) AnyRunner() {} // Run implements AsyncSingleRunner. -func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) { +func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) { (*i)(ctx, Int64ObserverResult{ instrument: impl, function: function, @@ -166,7 +166,7 @@ func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function fu } // Run implements AsyncSingleRunner. -func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) { +func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) { (*f)(ctx, Float64ObserverResult{ instrument: impl, function: function, @@ -174,7 +174,7 @@ func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function } // Run implements AsyncBatchRunner. -func (b *BatchObserverFunc) Run(ctx context.Context, function func([]kv.KeyValue, ...Observation)) { +func (b *BatchObserverFunc) Run(ctx context.Context, function func([]label.KeyValue, ...Observation)) { (*b)(ctx, BatchObserverResult{ function: function, }) diff --git a/api/metric/counter.go b/api/metric/counter.go index e9e73a35877..c03421d2a3f 100644 --- a/api/metric/counter.go +++ b/api/metric/counter.go @@ -17,7 +17,7 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // Float64Counter is a metric that accumulates float64 values. @@ -46,14 +46,14 @@ type BoundInt64Counter struct { // Bind creates a bound instrument for this counter. The labels are // associated with values recorded via subsequent calls to Record. -func (c Float64Counter) Bind(labels ...kv.KeyValue) (h BoundFloat64Counter) { +func (c Float64Counter) Bind(labels ...label.KeyValue) (h BoundFloat64Counter) { h.syncBoundInstrument = c.bind(labels) return } // Bind creates a bound instrument for this counter. The labels are // associated with values recorded via subsequent calls to Record. -func (c Int64Counter) Bind(labels ...kv.KeyValue) (h BoundInt64Counter) { +func (c Int64Counter) Bind(labels ...label.KeyValue) (h BoundInt64Counter) { h.syncBoundInstrument = c.bind(labels) return } @@ -72,13 +72,13 @@ func (c Int64Counter) Measurement(value int64) Measurement { // Add adds the value to the counter's sum. The labels should contain // the keys and values to be associated with this value. -func (c Float64Counter) Add(ctx context.Context, value float64, labels ...kv.KeyValue) { +func (c Float64Counter) Add(ctx context.Context, value float64, labels ...label.KeyValue) { c.directRecord(ctx, NewFloat64Number(value), labels) } // Add adds the value to the counter's sum. The labels should contain // the keys and values to be associated with this value. -func (c Int64Counter) Add(ctx context.Context, value int64, labels ...kv.KeyValue) { +func (c Int64Counter) Add(ctx context.Context, value int64, labels ...label.KeyValue) { c.directRecord(ctx, NewInt64Number(value), labels) } diff --git a/api/metric/meter.go b/api/metric/meter.go index cec2c72153c..079c294776f 100644 --- a/api/metric/meter.go +++ b/api/metric/meter.go @@ -17,7 +17,7 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // The file is organized as follows: @@ -52,7 +52,7 @@ type Meter struct { } // RecordBatch atomically records a batch of measurements. -func (m Meter) RecordBatch(ctx context.Context, ls []kv.KeyValue, ms ...Measurement) { +func (m Meter) RecordBatch(ctx context.Context, ls []label.KeyValue, ms ...Measurement) { if m.impl == nil { return } diff --git a/api/metric/noop.go b/api/metric/noop.go index 9a54ebc5b00..de2c5681a9f 100644 --- a/api/metric/noop.go +++ b/api/metric/noop.go @@ -17,7 +17,7 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) type NoopProvider struct{} @@ -50,9 +50,9 @@ func (noopBoundInstrument) RecordOne(context.Context, Number) { func (noopBoundInstrument) Unbind() { } -func (NoopSync) Bind([]kv.KeyValue) BoundSyncImpl { +func (NoopSync) Bind([]label.KeyValue) BoundSyncImpl { return noopBoundInstrument{} } -func (NoopSync) RecordOne(context.Context, Number, []kv.KeyValue) { +func (NoopSync) RecordOne(context.Context, Number, []label.KeyValue) { } diff --git a/api/metric/number.go b/api/metric/number.go index 1e04a0009f0..c3ca0ed7923 100644 --- a/api/metric/number.go +++ b/api/metric/number.go @@ -21,7 +21,7 @@ import ( "math" "sync/atomic" - "go.opentelemetry.io/otel/api/internal" + "go.opentelemetry.io/otel/internal" ) // NumberKind describes the data type of the Number. diff --git a/api/metric/registry/registry.go b/api/metric/registry/registry.go index dfcd1fbc28e..16b6883a9a6 100644 --- a/api/metric/registry/registry.go +++ b/api/metric/registry/registry.go @@ -19,8 +19,8 @@ import ( "fmt" "sync" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" ) // Provider is a standard metric.Provider for wrapping `MeterImpl` @@ -75,7 +75,7 @@ func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl { } // RecordBatch implements metric.MeterImpl. -func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, ms ...metric.Measurement) { +func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, ms ...metric.Measurement) { u.impl.RecordBatch(ctx, labels, ms...) } diff --git a/api/metric/sdkapi.go b/api/metric/sdkapi.go index 1d255d56c41..3c4e11ee4fb 100644 --- a/api/metric/sdkapi.go +++ b/api/metric/sdkapi.go @@ -17,14 +17,14 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // MeterImpl is the interface an SDK must implement to supply a Meter // implementation. type MeterImpl interface { // RecordBatch atomically records a batch of measurements. - RecordBatch(context.Context, []kv.KeyValue, ...Measurement) + RecordBatch(context.Context, []label.KeyValue, ...Measurement) // NewSyncInstrument returns a newly constructed // synchronous instrument implementation or an error, should @@ -59,10 +59,10 @@ type SyncImpl interface { // Bind creates an implementation-level bound instrument, // binding a label set with this instrument implementation. - Bind(labels []kv.KeyValue) BoundSyncImpl + Bind(labels []label.KeyValue) BoundSyncImpl // RecordOne captures a single synchronous metric event. - RecordOne(ctx context.Context, number Number, labels []kv.KeyValue) + RecordOne(ctx context.Context, number Number, labels []label.KeyValue) } // BoundSyncImpl is the implementation-level interface to a diff --git a/api/metric/sync.go b/api/metric/sync.go index e98def2d2b4..a08a65ba127 100644 --- a/api/metric/sync.go +++ b/api/metric/sync.go @@ -18,7 +18,7 @@ import ( "context" "errors" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil. @@ -82,7 +82,7 @@ func (s syncInstrument) SyncImpl() SyncImpl { return s.instrument } -func (s syncInstrument) bind(labels []kv.KeyValue) syncBoundInstrument { +func (s syncInstrument) bind(labels []label.KeyValue) syncBoundInstrument { return newSyncBoundInstrument(s.instrument.Bind(labels)) } @@ -94,7 +94,7 @@ func (s syncInstrument) int64Measurement(value int64) Measurement { return newMeasurement(s.instrument, NewInt64Number(value)) } -func (s syncInstrument) directRecord(ctx context.Context, number Number, labels []kv.KeyValue) { +func (s syncInstrument) directRecord(ctx context.Context, number Number, labels []label.KeyValue) { s.instrument.RecordOne(ctx, number, labels) } diff --git a/api/metric/updowncounter.go b/api/metric/updowncounter.go index 26366c3d805..10182460aaf 100644 --- a/api/metric/updowncounter.go +++ b/api/metric/updowncounter.go @@ -17,7 +17,7 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // Float64UpDownCounter is a metric instrument that sums floating @@ -47,14 +47,14 @@ type BoundInt64UpDownCounter struct { // Bind creates a bound instrument for this counter. The labels are // associated with values recorded via subsequent calls to Record. -func (c Float64UpDownCounter) Bind(labels ...kv.KeyValue) (h BoundFloat64UpDownCounter) { +func (c Float64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundFloat64UpDownCounter) { h.syncBoundInstrument = c.bind(labels) return } // Bind creates a bound instrument for this counter. The labels are // associated with values recorded via subsequent calls to Record. -func (c Int64UpDownCounter) Bind(labels ...kv.KeyValue) (h BoundInt64UpDownCounter) { +func (c Int64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundInt64UpDownCounter) { h.syncBoundInstrument = c.bind(labels) return } @@ -73,13 +73,13 @@ func (c Int64UpDownCounter) Measurement(value int64) Measurement { // Add adds the value to the counter's sum. The labels should contain // the keys and values to be associated with this value. -func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...kv.KeyValue) { +func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...label.KeyValue) { c.directRecord(ctx, NewFloat64Number(value), labels) } // Add adds the value to the counter's sum. The labels should contain // the keys and values to be associated with this value. -func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...kv.KeyValue) { +func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...label.KeyValue) { c.directRecord(ctx, NewInt64Number(value), labels) } diff --git a/api/metric/valuerecorder.go b/api/metric/valuerecorder.go index f4723fb98f4..fa7e2d4f8a5 100644 --- a/api/metric/valuerecorder.go +++ b/api/metric/valuerecorder.go @@ -17,7 +17,7 @@ package metric import ( "context" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // Float64ValueRecorder is a metric that records float64 values. @@ -46,14 +46,14 @@ type BoundInt64ValueRecorder struct { // Bind creates a bound instrument for this ValueRecorder. The labels are // associated with values recorded via subsequent calls to Record. -func (c Float64ValueRecorder) Bind(labels ...kv.KeyValue) (h BoundFloat64ValueRecorder) { +func (c Float64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundFloat64ValueRecorder) { h.syncBoundInstrument = c.bind(labels) return } // Bind creates a bound instrument for this ValueRecorder. The labels are // associated with values recorded via subsequent calls to Record. -func (c Int64ValueRecorder) Bind(labels ...kv.KeyValue) (h BoundInt64ValueRecorder) { +func (c Int64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundInt64ValueRecorder) { h.syncBoundInstrument = c.bind(labels) return } @@ -73,14 +73,14 @@ func (c Int64ValueRecorder) Measurement(value int64) Measurement { // Record adds a new value to the list of ValueRecorder's records. The // labels should contain the keys and values to be associated with // this value. -func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...kv.KeyValue) { +func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...label.KeyValue) { c.directRecord(ctx, NewFloat64Number(value), labels) } // Record adds a new value to the ValueRecorder's distribution. The // labels should contain the keys and values to be associated with // this value. -func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...kv.KeyValue) { +func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...label.KeyValue) { c.directRecord(ctx, NewInt64Number(value), labels) } diff --git a/api/trace/api.go b/api/trace/api.go index a0e11e5fcff..19528d43bda 100644 --- a/api/trace/api.go +++ b/api/trace/api.go @@ -18,8 +18,8 @@ import ( "context" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) type Provider interface { @@ -103,10 +103,10 @@ type Span interface { End(options ...EndOption) // AddEvent adds an event to the span. - AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) + AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) // AddEventWithTimestamp adds an event with a custom timestamp // to the span. - AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) + AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) // IsRecording returns true if the span is active and recording events is enabled. IsRecording() bool @@ -131,7 +131,7 @@ type Span interface { SetName(name string) // Set span attributes - SetAttributes(...kv.KeyValue) + SetAttributes(...label.KeyValue) // Set singular span attribute, with type inference. SetAttribute(string, interface{}) @@ -143,7 +143,7 @@ type StartOption func(*StartConfig) // StartConfig provides options to set properties of span at the time of starting // a new span. type StartConfig struct { - Attributes []kv.KeyValue + Attributes []label.KeyValue StartTime time.Time Links []Link Record bool @@ -164,7 +164,7 @@ type StartConfig struct { // be correlated. type Link struct { SpanContext - Attributes []kv.KeyValue + Attributes []label.KeyValue } // SpanKind represents the role of a Span inside a Trace. Often, this defines how a Span @@ -232,7 +232,7 @@ func WithStartTime(t time.Time) StartOption { // 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 ...kv.KeyValue) StartOption { +func WithAttributes(attrs ...label.KeyValue) StartOption { return func(c *StartConfig) { c.Attributes = append(c.Attributes, attrs...) } @@ -259,7 +259,7 @@ func WithNewRoot() StartOption { } // LinkedTo allows instantiating a Span with initial Links. -func LinkedTo(sc SpanContext, attrs ...kv.KeyValue) StartOption { +func LinkedTo(sc SpanContext, attrs ...label.KeyValue) StartOption { return func(c *StartConfig) { c.Links = append(c.Links, Link{sc, attrs}) } diff --git a/api/trace/context_test.go b/api/trace/context_test.go index 7e4891e66d5..57c1b0a04d0 100644 --- a/api/trace/context_test.go +++ b/api/trace/context_test.go @@ -19,9 +19,9 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) func TestSetCurrentSpanOverridesPreviouslySetSpan(t *testing.T) { @@ -93,7 +93,7 @@ func (mockSpan) SetError(v bool) { } // SetAttributes does nothing. -func (mockSpan) SetAttributes(attributes ...kv.KeyValue) { +func (mockSpan) SetAttributes(attributes ...label.KeyValue) { } // SetAttribute does nothing. @@ -114,9 +114,9 @@ func (mockSpan) Tracer() trace.Tracer { } // Event does nothing. -func (mockSpan) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) { +func (mockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) { } // AddEventWithTimestamp does nothing. -func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) { +func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) { } diff --git a/api/trace/noop_span.go b/api/trace/noop_span.go index b35e9ce6439..27f0d319f3d 100644 --- a/api/trace/noop_span.go +++ b/api/trace/noop_span.go @@ -18,8 +18,8 @@ import ( "context" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) type NoopSpan struct { @@ -46,7 +46,7 @@ func (NoopSpan) SetError(v bool) { } // SetAttributes does nothing. -func (NoopSpan) SetAttributes(attributes ...kv.KeyValue) { +func (NoopSpan) SetAttributes(attributes ...label.KeyValue) { } // SetAttribute does nothing. @@ -67,11 +67,11 @@ func (NoopSpan) Tracer() Tracer { } // AddEvent does nothing. -func (NoopSpan) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) { +func (NoopSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) { } // AddEventWithTimestamp does nothing. -func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) { +func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) { } // SetName does nothing. diff --git a/api/trace/tracetest/event.go b/api/trace/tracetest/event.go index 4e58d33cb4a..e62b8c8cbbf 100644 --- a/api/trace/tracetest/event.go +++ b/api/trace/tracetest/event.go @@ -17,12 +17,12 @@ package tracetest import ( "time" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp. type Event struct { Timestamp time.Time Name string - Attributes map[kv.Key]kv.Value + Attributes map[label.Key]label.Value } diff --git a/api/trace/tracetest/span.go b/api/trace/tracetest/span.go index c161f5951e4..c60e8525c83 100644 --- a/api/trace/tracetest/span.go +++ b/api/trace/tracetest/span.go @@ -21,14 +21,14 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) const ( - errorTypeKey = kv.Key("error.type") - errorMessageKey = kv.Key("error.message") + errorTypeKey = label.Key("error.type") + errorMessageKey = label.Key("error.message") errorEventName = "error" ) @@ -45,9 +45,9 @@ type Span struct { endTime time.Time statusCode codes.Code statusMessage string - attributes map[kv.Key]kv.Value + attributes map[label.Key]label.Value events []Event - links map[trace.SpanContext][]kv.KeyValue + links map[trace.SpanContext][]label.KeyValue spanKind trace.SpanKind } @@ -110,11 +110,11 @@ func (s *Span) RecordError(ctx context.Context, err error, opts ...trace.ErrorOp ) } -func (s *Span) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) { +func (s *Span) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) { s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...) } -func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) { +func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) { s.lock.Lock() defer s.lock.Unlock() @@ -122,7 +122,7 @@ func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, n return } - attributes := make(map[kv.Key]kv.Value) + attributes := make(map[label.Key]label.Value) for _, attr := range attrs { attributes[attr.Key] = attr.Value @@ -166,7 +166,7 @@ func (s *Span) SetName(name string) { s.name = name } -func (s *Span) SetAttributes(attrs ...kv.KeyValue) { +func (s *Span) SetAttributes(attrs ...label.KeyValue) { s.lock.Lock() defer s.lock.Unlock() @@ -180,7 +180,7 @@ func (s *Span) SetAttributes(attrs ...kv.KeyValue) { } func (s *Span) SetAttribute(k string, v interface{}) { - s.SetAttributes(kv.Any(k, v)) + s.SetAttributes(label.Any(k, v)) } // Name returns the name most recently set on the Span, either at or after creation time. @@ -199,11 +199,11 @@ func (s *Span) ParentSpanID() trace.SpanID { // Attributes returns the attributes set on the Span, either at or after creation time. // If the same attribute key was set multiple times, the last call will be used. // Attributes cannot be changed after End has been called on the Span. -func (s *Span) Attributes() map[kv.Key]kv.Value { +func (s *Span) Attributes() map[label.Key]label.Value { s.lock.RLock() defer s.lock.RUnlock() - attributes := make(map[kv.Key]kv.Value) + attributes := make(map[label.Key]label.Value) for k, v := range s.attributes { attributes[k] = v @@ -220,11 +220,11 @@ func (s *Span) Events() []Event { // Links returns the links set on the Span at creation time. // If multiple links for the same SpanContext were set, the last link will be used. -func (s *Span) Links() map[trace.SpanContext][]kv.KeyValue { - links := make(map[trace.SpanContext][]kv.KeyValue) +func (s *Span) Links() map[trace.SpanContext][]label.KeyValue { + links := make(map[trace.SpanContext][]label.KeyValue) for sc, attributes := range s.links { - links[sc] = append([]kv.KeyValue{}, attributes...) + links[sc] = append([]label.KeyValue{}, attributes...) } return links diff --git a/api/trace/tracetest/span_test.go b/api/trace/tracetest/span_test.go index 433e5a71219..11fa68b988e 100644 --- a/api/trace/tracetest/span_test.go +++ b/api/trace/tracetest/span_test.go @@ -22,12 +22,12 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace/tracetest" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/internal/matchers" ottest "go.opentelemetry.io/otel/internal/testing" + "go.opentelemetry.io/otel/label" ) func TestSpan(t *testing.T) { @@ -161,9 +161,9 @@ func TestSpan(t *testing.T) { expectedEvents := []tracetest.Event{{ Timestamp: testTime, Name: "error", - Attributes: map[kv.Key]kv.Value{ - kv.Key("error.type"): kv.StringValue(s.typ), - kv.Key("error.message"): kv.StringValue(s.msg), + Attributes: map[label.Key]label.Value{ + label.Key("error.type"): label.StringValue(s.typ), + label.Key("error.message"): label.StringValue(s.msg), }, }} e.Expect(subject.Events()).ToEqual(expectedEvents) @@ -192,9 +192,9 @@ func TestSpan(t *testing.T) { expectedEvents := []tracetest.Event{{ Timestamp: testTime, Name: "error", - Attributes: map[kv.Key]kv.Value{ - kv.Key("error.type"): kv.StringValue("go.opentelemetry.io/otel/internal/testing.TestError"), - kv.Key("error.message"): kv.StringValue(errMsg), + Attributes: map[label.Key]label.Value{ + label.Key("error.type"): label.StringValue("go.opentelemetry.io/otel/internal/testing.TestError"), + label.Key("error.message"): label.StringValue(errMsg), }, }} e.Expect(subject.Events()).ToEqual(expectedEvents) @@ -331,7 +331,7 @@ func TestSpan(t *testing.T) { subject, ok := span.(*tracetest.Span) e.Expect(ok).ToBeTrue() - e.Expect(subject.Attributes()).ToEqual(map[kv.Key]kv.Value{}) + e.Expect(subject.Attributes()).ToEqual(map[label.Key]label.Value{}) }) t.Run("returns the most recently set attributes", func(t *testing.T) { @@ -345,9 +345,9 @@ func TestSpan(t *testing.T) { subject, ok := span.(*tracetest.Span) e.Expect(ok).ToBeTrue() - attr1 := kv.String("key1", "value1") - attr2 := kv.String("key2", "value2") - attr3 := kv.String("key3", "value3") + attr1 := label.String("key1", "value1") + attr2 := label.String("key2", "value2") + attr3 := label.String("key3", "value3") unexpectedAttr := attr2.Key.String("unexpected") subject.SetAttributes(attr1, unexpectedAttr, attr3) @@ -371,7 +371,7 @@ func TestSpan(t *testing.T) { subject, ok := span.(*tracetest.Span) e.Expect(ok).ToBeTrue() - expectedAttr := kv.String("key", "value") + expectedAttr := label.String("key", "value") subject.SetAttributes(expectedAttr) subject.End() @@ -401,7 +401,7 @@ func TestSpan(t *testing.T) { go func() { defer wg.Done() - subject.SetAttributes(kv.String("key", "value")) + subject.SetAttributes(label.String("key", "value")) }() go func() { @@ -459,9 +459,9 @@ func TestSpan(t *testing.T) { e.Expect(ok).ToBeTrue() event1Name := "event1" - event1Attributes := []kv.KeyValue{ - kv.String("event1Attr1", "foo"), - kv.String("event1Attr2", "bar"), + event1Attributes := []label.KeyValue{ + label.String("event1Attr1", "foo"), + label.String("event1Attr2", "bar"), } event1Start := time.Now() @@ -470,8 +470,8 @@ func TestSpan(t *testing.T) { event2Timestamp := time.Now().AddDate(5, 0, 0) event2Name := "event1" - event2Attributes := []kv.KeyValue{ - kv.String("event2Attr", "abc"), + event2Attributes := []label.KeyValue{ + label.String("event2Attr", "abc"), } subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Name, event2Attributes...) diff --git a/api/trace/tracetest/tracer.go b/api/trace/tracetest/tracer.go index c8d06adebdf..9662c106898 100644 --- a/api/trace/tracetest/tracer.go +++ b/api/trace/tracetest/tracer.go @@ -18,8 +18,8 @@ import ( "context" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" ) var _ trace.Tracer = (*Tracer)(nil) @@ -48,20 +48,20 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti span := &Span{ tracer: t, startTime: startTime, - attributes: make(map[kv.Key]kv.Value), - links: make(map[trace.SpanContext][]kv.KeyValue), + attributes: make(map[label.Key]label.Value), + links: make(map[trace.SpanContext][]label.KeyValue), spanKind: c.SpanKind, } if c.NewRoot { span.spanContext = trace.EmptySpanContext() - iodKey := kv.Key("ignored-on-demand") + iodKey := label.Key("ignored-on-demand") if lsc := trace.SpanFromContext(ctx).SpanContext(); lsc.IsValid() { - span.links[lsc] = []kv.KeyValue{iodKey.String("current")} + span.links[lsc] = []label.KeyValue{iodKey.String("current")} } if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() { - span.links[rsc] = []kv.KeyValue{iodKey.String("remote")} + span.links[rsc] = []label.KeyValue{iodKey.String("remote")} } } else { span.spanContext = t.config.SpanContextFunc(ctx) diff --git a/api/trace/tracetest/tracer_test.go b/api/trace/tracetest/tracer_test.go index 4af442b3972..f2999e2c515 100644 --- a/api/trace/tracetest/tracer_test.go +++ b/api/trace/tracetest/tracer_test.go @@ -23,10 +23,10 @@ import ( "time" "go.opentelemetry.io/otel/api/apitest" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace/tracetest" "go.opentelemetry.io/otel/internal/matchers" + "go.opentelemetry.io/otel/label" ) func TestTracer(t *testing.T) { @@ -68,8 +68,8 @@ func TestTracer(t *testing.T) { e := matchers.NewExpecter(t) - attr1 := kv.String("a", "1") - attr2 := kv.String("b", "2") + attr1 := label.String("a", "1") + attr2 := label.String("b", "2") subject := tp.Tracer(t.Name()) _, span := subject.Start(context.Background(), "test", trace.WithAttributes(attr1, attr2)) @@ -201,14 +201,14 @@ func TestTracer(t *testing.T) { expectedLinks := []trace.Link{ { SpanContext: parentSpanContext, - Attributes: []kv.KeyValue{ - kv.String("ignored-on-demand", "current"), + Attributes: []label.KeyValue{ + label.String("ignored-on-demand", "current"), }, }, { SpanContext: remoteParentSpanContext, - Attributes: []kv.KeyValue{ - kv.String("ignored-on-demand", "remote"), + Attributes: []label.KeyValue{ + label.String("ignored-on-demand", "remote"), }, }, } @@ -233,16 +233,16 @@ func TestTracer(t *testing.T) { _, span := subject.Start(context.Background(), "link1") link1 := trace.Link{ SpanContext: span.SpanContext(), - Attributes: []kv.KeyValue{ - kv.String("a", "1"), + Attributes: []label.KeyValue{ + label.String("a", "1"), }, } _, span = subject.Start(context.Background(), "link2") link2 := trace.Link{ SpanContext: span.SpanContext(), - Attributes: []kv.KeyValue{ - kv.String("b", "2"), + Attributes: []label.KeyValue{ + label.String("b", "2"), }, } diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 7f5866c5cda..97d6786ee33 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -27,11 +27,11 @@ import ( otelcorrelation "go.opentelemetry.io/otel/api/correlation" otelglobal "go.opentelemetry.io/otel/api/global" - otelcore "go.opentelemetry.io/otel/api/kv" otelpropagation "go.opentelemetry.io/otel/api/propagation" oteltrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" otelparent "go.opentelemetry.io/otel/internal/trace/parent" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/bridge/opentracing/migration" ) @@ -58,19 +58,19 @@ func newBridgeSpanContext(otelSpanContext oteltrace.SpanContext, parentOtSpanCon } func (c *bridgeSpanContext) ForeachBaggageItem(handler func(k, v string) bool) { - c.baggageItems.Foreach(func(kv otelcore.KeyValue) bool { + c.baggageItems.Foreach(func(kv label.KeyValue) bool { return handler(string(kv.Key), kv.Value.Emit()) }) } func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) { crk := http.CanonicalHeaderKey(restrictedKey) - c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: otelcore.Key(crk).String(value)}) + c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: label.String(crk, value)}) } func (c *bridgeSpanContext) baggageItem(restrictedKey string) string { crk := http.CanonicalHeaderKey(restrictedKey) - val, _ := c.baggageItems.Value(otelcore.Key(crk)) + val, _ := c.baggageItems.Value(label.Key(crk)) return val.Emit() } @@ -114,7 +114,7 @@ func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) { } func (s *bridgeSpan) logRecord(record ot.LogRecord) { - s.otelSpan.AddEventWithTimestamp(context.Background(), record.Timestamp, "", otLogFieldsToOtelCoreKeyValues(record.Fields)...) + s.otelSpan.AddEventWithTimestamp(context.Background(), record.Timestamp, "", otLogFieldsToOTelLabels(record.Fields)...) } func (s *bridgeSpan) Context() ot.SpanContext { @@ -135,17 +135,17 @@ func (s *bridgeSpan) SetTag(key string, value interface{}) ot.Span { s.otelSpan.SetStatus(codes.Unknown, "") } default: - s.otelSpan.SetAttributes(otTagToOtelCoreKeyValue(key, value)) + s.otelSpan.SetAttributes(otTagToOTelLabel(key, value)) } return s } func (s *bridgeSpan) LogFields(fields ...otlog.Field) { - s.otelSpan.AddEvent(context.Background(), "", otLogFieldsToOtelCoreKeyValues(fields)...) + s.otelSpan.AddEvent(context.Background(), "", otLogFieldsToOTelLabels(fields)...) } type bridgeFieldEncoder struct { - pairs []otelcore.KeyValue + pairs []label.KeyValue } var _ otlog.Encoder = &bridgeFieldEncoder{} @@ -195,10 +195,10 @@ func (e *bridgeFieldEncoder) EmitLazyLogger(value otlog.LazyLogger) { } func (e *bridgeFieldEncoder) emitCommon(key string, value interface{}) { - e.pairs = append(e.pairs, otTagToOtelCoreKeyValue(key, value)) + e.pairs = append(e.pairs, otTagToOTelLabel(key, value)) } -func otLogFieldsToOtelCoreKeyValues(fields []otlog.Field) []otelcore.KeyValue { +func otLogFieldsToOTelLabels(fields []otlog.Field) []label.KeyValue { encoder := &bridgeFieldEncoder{} for _, field := range fields { field.Marshal(encoder) @@ -215,7 +215,7 @@ func (s *bridgeSpan) LogKV(alternatingKeyValues ...interface{}) { } func (s *bridgeSpan) SetBaggageItem(restrictedKey, value string) ot.Span { - s.updateOtelContext(restrictedKey, value) + s.updateOTelContext(restrictedKey, value) s.setBaggageItemOnly(restrictedKey, value) return s } @@ -224,7 +224,7 @@ func (s *bridgeSpan) setBaggageItemOnly(restrictedKey, value string) { s.ctx.setBaggageItem(restrictedKey, value) } -func (s *bridgeSpan) updateOtelContext(restrictedKey, value string) { +func (s *bridgeSpan) updateOTelContext(restrictedKey, value string) { if s.extraBaggageItems == nil { s.extraBaggageItems = make(map[string]string) } @@ -347,7 +347,7 @@ func (t *BridgeTracer) correlationSetHook(ctx context.Context) context.Context { // context, so we don't care about the old hooks. clearCtx, _, _ := otelcorrelation.ContextWithNoHooks(ctx) m := otelcorrelation.MapFromContext(clearCtx) - m.Foreach(func(kv otelcore.KeyValue) bool { + m.Foreach(func(kv label.KeyValue) bool { bSpan.setBaggageItemOnly(string(kv.Key), kv.Value.Emit()) return true }) @@ -369,9 +369,9 @@ func (t *BridgeTracer) correlationGetHook(ctx context.Context, m otelcorrelation if len(items) == 0 { return m } - kv := make([]otelcore.KeyValue, 0, len(items)) + kv := make([]label.KeyValue, 0, len(items)) for k, v := range items { - kv = append(kv, otelcore.String(k, v)) + kv = append(kv, label.String(k, v)) } return m.Apply(otelcorrelation.MapUpdate{MultiKV: kv}) } @@ -384,7 +384,7 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio opt.Apply(&sso) } parentBridgeSC, links := otSpanReferencesToParentAndLinks(sso.References) - attributes, kind, hadTrueErrorTag := otTagsToOtelAttributesKindAndError(sso.Tags) + attributes, kind, hadTrueErrorTag := otTagsToOTelAttributesKindAndError(sso.Tags) checkCtx := migration.WithDeferredSetup(context.Background()) if parentBridgeSC != nil { checkCtx = oteltrace.ContextWithRemoteSpanContext(checkCtx, parentBridgeSC.otelSpanContext) @@ -457,10 +457,10 @@ func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) co return ctx } -func otTagsToOtelAttributesKindAndError(tags map[string]interface{}) ([]otelcore.KeyValue, oteltrace.SpanKind, bool) { +func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.KeyValue, oteltrace.SpanKind, bool) { kind := oteltrace.SpanKindInternal err := false - var pairs []otelcore.KeyValue + var pairs []label.KeyValue for k, v := range tags { switch k { case string(otext.SpanKind): @@ -481,14 +481,14 @@ func otTagsToOtelAttributesKindAndError(tags map[string]interface{}) ([]otelcore err = true } default: - pairs = append(pairs, otTagToOtelCoreKeyValue(k, v)) + pairs = append(pairs, otTagToOTelLabel(k, v)) } } return pairs, kind, err } -func otTagToOtelCoreKeyValue(k string, v interface{}) otelcore.KeyValue { - key := otTagToOtelCoreKey(k) +func otTagToOTelLabel(k string, v interface{}) label.KeyValue { + key := otTagToOTelLabelKey(k) switch val := v.(type) { case bool: return key.Bool(val) @@ -515,8 +515,8 @@ func otTagToOtelCoreKeyValue(k string, v interface{}) otelcore.KeyValue { } } -func otTagToOtelCoreKey(k string) otelcore.Key { - return otelcore.Key(k) +func otTagToOTelLabelKey(k string) label.Key { + return label.Key(k) } func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpanContext, []oteltrace.Link) { @@ -530,34 +530,34 @@ func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpa // We ignore foreign ot span contexts, // sorry. We have no way of getting any // TraceID and SpanID out of it for form a - // otelcore.SpanContext for otelcore.Link. And + // OTel SpanContext for OTel Link. And // we can't make it a parent - it also needs a - // valid otelcore.SpanContext. + // valid OTel SpanContext. continue } if parent != nil { - links = append(links, otSpanReferenceToOtelLink(bridgeSC, reference.Type)) + links = append(links, otSpanReferenceToOTelLink(bridgeSC, reference.Type)) } else { if reference.Type == ot.ChildOfRef { parent = bridgeSC } else { - links = append(links, otSpanReferenceToOtelLink(bridgeSC, reference.Type)) + links = append(links, otSpanReferenceToOTelLink(bridgeSC, reference.Type)) } } } return parent, links } -func otSpanReferenceToOtelLink(bridgeSC *bridgeSpanContext, refType ot.SpanReferenceType) oteltrace.Link { +func otSpanReferenceToOTelLink(bridgeSC *bridgeSpanContext, refType ot.SpanReferenceType) oteltrace.Link { return oteltrace.Link{ SpanContext: bridgeSC.otelSpanContext, - Attributes: otSpanReferenceTypeToOtelLinkAttributes(refType), + Attributes: otSpanReferenceTypeToOTelLinkAttributes(refType), } } -func otSpanReferenceTypeToOtelLinkAttributes(refType ot.SpanReferenceType) []otelcore.KeyValue { - return []otelcore.KeyValue{ - otelcore.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)), +func otSpanReferenceTypeToOTelLinkAttributes(refType ot.SpanReferenceType) []label.KeyValue { + return []label.KeyValue{ + label.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)), } } diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index cdd6568fe14..f346ffa33ac 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -22,21 +22,21 @@ import ( "time" otelcorrelation "go.opentelemetry.io/otel/api/correlation" - otelcore "go.opentelemetry.io/otel/api/kv" oteltrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" otelparent "go.opentelemetry.io/otel/internal/trace/parent" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/bridge/opentracing/migration" ) var ( - ComponentKey = otelcore.Key("component") - ServiceKey = otelcore.Key("service") - StatusCodeKey = otelcore.Key("status.code") - StatusMessageKey = otelcore.Key("status.message") - ErrorKey = otelcore.Key("error") - NameKey = otelcore.Key("name") + ComponentKey = label.Key("component") + ServiceKey = label.Key("service") + StatusCodeKey = label.Key("status.code") + StatusMessageKey = label.Key("status.message") + ErrorKey = label.Key("error") + NameKey = label.Key("name") ) type MockContextKeyValue struct { @@ -225,14 +225,14 @@ func (s *MockSpan) SetError(v bool) { s.SetAttributes(ErrorKey.Bool(v)) } -func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) { +func (s *MockSpan) SetAttributes(attributes ...label.KeyValue) { s.applyUpdate(otelcorrelation.MapUpdate{ MultiKV: attributes, }) } func (s *MockSpan) SetAttribute(k string, v interface{}) { - s.SetAttributes(otelcore.Any(k, v)) + s.SetAttributes(label.Any(k, v)) } func (s *MockSpan) applyUpdate(update otelcorrelation.MapUpdate) { @@ -281,8 +281,8 @@ func (s *MockSpan) RecordError(ctx context.Context, err error, opts ...oteltrace } s.AddEventWithTimestamp(ctx, cfg.Timestamp, "error", - otelcore.String("error.type", reflect.TypeOf(err).String()), - otelcore.String("error.message", err.Error()), + label.String("error.type", reflect.TypeOf(err).String()), + label.String("error.message", err.Error()), ) } @@ -290,11 +290,11 @@ func (s *MockSpan) Tracer() oteltrace.Tracer { return s.officialTracer } -func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...otelcore.KeyValue) { +func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) { s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...) } -func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...otelcore.KeyValue) { +func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) { s.Events = append(s.Events, MockEvent{ CtxAttributes: otelcorrelation.MapFromContext(ctx), Timestamp: timestamp, diff --git a/bridge/opentracing/mix_test.go b/bridge/opentracing/mix_test.go index 4fb67e43c4d..70d805375a6 100644 --- a/bridge/opentracing/mix_test.go +++ b/bridge/opentracing/mix_test.go @@ -23,8 +23,8 @@ import ( otelcorrelation "go.opentelemetry.io/otel/api/correlation" otelglobal "go.opentelemetry.io/otel/api/global" - otelcore "go.opentelemetry.io/otel/api/kv" oteltrace "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/bridge/opentracing/internal" ) @@ -589,7 +589,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont value := bio.baggageItems[idx].value otSpan.SetBaggageItem(otKey, value) - ctx = otelcorrelation.NewContext(ctx, otelcore.String(otelKey, value)) + ctx = otelcorrelation.NewContext(ctx, label.String(otelKey, value)) otRecording := make(map[string]string) otSpan.Context().ForeachBaggageItem(func(key, value string) bool { @@ -597,7 +597,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont return true }) otelRecording := make(map[string]string) - otelcorrelation.MapFromContext(ctx).Foreach(func(kv otelcore.KeyValue) bool { + otelcorrelation.MapFromContext(ctx).Foreach(func(kv label.KeyValue) bool { otelRecording[string(kv.Key)] = kv.Value.Emit() return true }) diff --git a/example/basic/main.go b/example/basic/main.go index f00c4c015d8..3fb8d13deb7 100644 --- a/example/basic/main.go +++ b/example/basic/main.go @@ -20,17 +20,17 @@ import ( "go.opentelemetry.io/otel/api/correlation" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/exporters/stdout" + "go.opentelemetry.io/otel/label" ) var ( - fooKey = kv.Key("ex.com/foo") - barKey = kv.Key("ex.com/bar") - lemonsKey = kv.Key("ex.com/lemons") - anotherKey = kv.Key("ex.com/another") + fooKey = label.Key("ex.com/foo") + barKey = label.Key("ex.com/bar") + lemonsKey = label.Key("ex.com/lemons") + anotherKey = label.Key("ex.com/another") ) func main() { @@ -46,7 +46,7 @@ func main() { tracer := global.Tracer("ex.com/basic") meter := global.Meter("ex.com/basic") - commonLabels := []kv.KeyValue{lemonsKey.Int(10), kv.String("A", "1"), kv.String("B", "2"), kv.String("C", "3")} + commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")} oneMetricCB := func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(1, commonLabels...) @@ -72,7 +72,7 @@ func main() { ctx, span = tracer.Start(ctx, "operation") defer span.End() - span.AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100)) + span.AddEvent(ctx, "Nice operation!", label.Int("bogons", 100)) span.SetAttributes(anotherKey.String("yes")) meter.RecordBatch( diff --git a/example/jaeger/main.go b/example/jaeger/main.go index e28592e0f60..80a6857fc31 100644 --- a/example/jaeger/main.go +++ b/example/jaeger/main.go @@ -21,7 +21,7 @@ import ( "log" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/exporters/trace/jaeger" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -34,9 +34,9 @@ func initTracer() func() { jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"), jaeger.WithProcess(jaeger.Process{ ServiceName: "trace-demo", - Tags: []kv.KeyValue{ - kv.String("exporter", "jaeger"), - kv.Float64("float", 312.23), + Tags: []label.KeyValue{ + label.String("exporter", "jaeger"), + label.Float64("float", 312.23), }, }), jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), diff --git a/example/namedtracer/foo/foo.go b/example/namedtracer/foo/foo.go index 88dd709f70e..12ab8261c54 100644 --- a/example/namedtracer/foo/foo.go +++ b/example/namedtracer/foo/foo.go @@ -18,12 +18,12 @@ import ( "context" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" ) var ( - lemonsKey = kv.Key("ex.com/lemons") + lemonsKey = label.Key("ex.com/lemons") ) // SubOperation is an example to demonstrate the use of named tracer. diff --git a/example/namedtracer/main.go b/example/namedtracer/main.go index 961275de639..942961dd7be 100644 --- a/example/namedtracer/main.go +++ b/example/namedtracer/main.go @@ -18,20 +18,19 @@ import ( "context" "log" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/correlation" "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/example/namedtracer/foo" "go.opentelemetry.io/otel/exporters/stdout" + "go.opentelemetry.io/otel/label" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) var ( - fooKey = kv.Key("ex.com/foo") - barKey = kv.Key("ex.com/bar") - anotherKey = kv.Key("ex.com/another") + fooKey = label.Key("ex.com/foo") + barKey = label.Key("ex.com/bar") + anotherKey = label.Key("ex.com/another") ) var tp *sdktrace.Provider @@ -68,7 +67,7 @@ func main() { var span trace.Span ctx, span = tracer.Start(ctx, "operation") defer span.End() - span.AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100)) + span.AddEvent(ctx, "Nice operation!", label.Int("bogons", 100)) span.SetAttributes(anotherKey.String("yes")) if err := foo.SubOperation(ctx); err != nil { panic(err) diff --git a/example/otel-collector/main.go b/example/otel-collector/main.go index bd0100483a7..0512984c435 100644 --- a/example/otel-collector/main.go +++ b/example/otel-collector/main.go @@ -26,10 +26,10 @@ import ( "google.golang.org/grpc" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" apitrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/exporters/otlp" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/metric/controller/push" "go.opentelemetry.io/otel/sdk/metric/processor/basic" "go.opentelemetry.io/otel/sdk/metric/selector/simple" @@ -58,7 +58,7 @@ func initProvider() (*otlp.Exporter, *push.Controller) { sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithResource(resource.New( // the service name used to display traces in backends - kv.Key(semconv.ServiceNameKey).String("test-service"), + semconv.ServiceNameKey.String("test-service"), )), sdktrace.WithBatcher(exp), ) @@ -92,10 +92,10 @@ func main() { // labels represent additional key-value descriptors that can be bound to a // metric observer or recorder. - commonLabels := []kv.KeyValue{ - kv.String("labelA", "chocolate"), - kv.String("labelB", "raspberry"), - kv.String("labelC", "vanilla"), + commonLabels := []label.KeyValue{ + label.String("labelA", "chocolate"), + label.String("labelB", "raspberry"), + label.String("labelC", "vanilla"), } // Recorder metric example diff --git a/example/prometheus/main.go b/example/prometheus/main.go index 65474917ff8..3f095ae4dc6 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -23,13 +23,13 @@ import ( "time" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/exporters/metric/prometheus" + "go.opentelemetry.io/otel/label" ) var ( - lemonsKey = kv.Key("ex.com/lemons") + lemonsKey = label.Key("ex.com/lemons") ) func initMeter() { @@ -51,7 +51,7 @@ func main() { meter := global.Meter("ex.com/basic") observerLock := new(sync.RWMutex) observerValueToReport := new(float64) - observerLabelsToReport := new([]kv.KeyValue) + observerLabelsToReport := new([]label.KeyValue) cb := func(_ context.Context, result metric.Float64ObserverResult) { (*observerLock).RLock() value := *observerValueToReport @@ -66,8 +66,8 @@ func main() { valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two") counter := metric.Must(meter).NewFloat64Counter("ex.com.three") - commonLabels := []kv.KeyValue{lemonsKey.Int(10), kv.String("A", "1"), kv.String("B", "2"), kv.String("C", "3")} - notSoCommonLabels := []kv.KeyValue{lemonsKey.Int(13)} + commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")} + notSoCommonLabels := []label.KeyValue{lemonsKey.Int(13)} ctx := context.Background() diff --git a/exporters/metric/prometheus/example_test.go b/exporters/metric/prometheus/example_test.go index 14714bf100c..441e1addd78 100644 --- a/exporters/metric/prometheus/example_test.go +++ b/exporters/metric/prometheus/example_test.go @@ -22,9 +22,9 @@ import ( "net/http" "net/http/httptest" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/exporters/metric/prometheus" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/metric/controller/pull" "go.opentelemetry.io/otel/sdk/resource" ) @@ -40,7 +40,7 @@ func ExampleNewExportPipeline() { // Create a meter exporter, err := prometheus.NewExportPipeline( prometheus.Config{}, - pull.WithResource(resource.New(kv.String("R", "V"))), + pull.WithResource(resource.New(label.String("R", "V"))), ) if err != nil { panic(err) @@ -58,8 +58,8 @@ func ExampleNewExportPipeline() { metric.WithDescription("Records values"), ) - counter.Add(ctx, 100, kv.String("key", "value")) - recorder.Record(ctx, 100, kv.String("key", "value")) + counter.Add(ctx, 100, label.String("key", "value")) + recorder.Record(ctx, 100, label.String("key", "value")) // GET the HTTP endpoint var input bytes.Buffer diff --git a/exporters/metric/prometheus/prometheus.go b/exporters/metric/prometheus/prometheus.go index 80f1c2721a7..77b428ce014 100644 --- a/exporters/metric/prometheus/prometheus.go +++ b/exporters/metric/prometheus/prometheus.go @@ -24,8 +24,8 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/controller/pull" diff --git a/exporters/metric/prometheus/prometheus_test.go b/exporters/metric/prometheus/prometheus_test.go index ecfef6da3b6..ba09e2240dc 100644 --- a/exporters/metric/prometheus/prometheus_test.go +++ b/exporters/metric/prometheus/prometheus_test.go @@ -26,9 +26,9 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/exporters/metric/prometheus" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/metric/controller/pull" "go.opentelemetry.io/otel/sdk/resource" ) @@ -39,7 +39,7 @@ func TestPrometheusExporter(t *testing.T) { DefaultHistogramBoundaries: []float64{-0.5, 1}, }, pull.WithCachePeriod(0), - pull.WithResource(resource.New(kv.String("R", "V"))), + pull.WithResource(resource.New(label.String("R", "V"))), ) require.NoError(t, err) @@ -48,9 +48,9 @@ func TestPrometheusExporter(t *testing.T) { counter := metric.Must(meter).NewFloat64Counter("counter") valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder") - labels := []kv.KeyValue{ - kv.Key("A").String("B"), - kv.Key("C").String("D"), + labels := []label.KeyValue{ + label.Key("A").String("B"), + label.Key("C").String("D"), } ctx := context.Background() @@ -128,14 +128,14 @@ func TestPrometheusStatefulness(t *testing.T) { metric.WithDescription("Counts things"), ) - counter.Add(ctx, 100, kv.String("key", "value")) + counter.Add(ctx, 100, label.String("key", "value")) require.Equal(t, `# HELP a_counter Counts things # TYPE a_counter counter a_counter{key="value"} 100 `, scrape()) - counter.Add(ctx, 100, kv.String("key", "value")) + counter.Add(ctx, 100, label.String("key", "value")) require.Equal(t, `# HELP a_counter Counts things # TYPE a_counter counter diff --git a/exporters/otlp/internal/transform/attribute.go b/exporters/otlp/internal/transform/attribute.go index 3f10e7f3537..b50ff25c071 100644 --- a/exporters/otlp/internal/transform/attribute.go +++ b/exporters/otlp/internal/transform/attribute.go @@ -16,13 +16,13 @@ package transform import ( commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" + "go.opentelemetry.io/otel/label" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/sdk/resource" ) // Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values. -func Attributes(attrs []kv.KeyValue) []*commonpb.KeyValue { +func Attributes(attrs []label.KeyValue) []*commonpb.KeyValue { if len(attrs) == 0 { return nil } @@ -48,33 +48,33 @@ func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue { return out } -func toAttribute(v kv.KeyValue) *commonpb.KeyValue { +func toAttribute(v label.KeyValue) *commonpb.KeyValue { result := &commonpb.KeyValue{ Key: string(v.Key), Value: new(commonpb.AnyValue), } switch v.Value.Type() { - case kv.BOOL: + case label.BOOL: result.Value.Value = &commonpb.AnyValue_BoolValue{ BoolValue: v.Value.AsBool(), } - case kv.INT64, kv.INT32, kv.UINT32, kv.UINT64: + case label.INT64, label.INT32, label.UINT32, label.UINT64: result.Value.Value = &commonpb.AnyValue_IntValue{ IntValue: v.Value.AsInt64(), } - case kv.FLOAT32: + case label.FLOAT32: result.Value.Value = &commonpb.AnyValue_DoubleValue{ DoubleValue: float64(v.Value.AsFloat32()), } - case kv.FLOAT64: + case label.FLOAT64: result.Value.Value = &commonpb.AnyValue_DoubleValue{ DoubleValue: v.Value.AsFloat64(), } - case kv.STRING: + case label.STRING: result.Value.Value = &commonpb.AnyValue_StringValue{ StringValue: v.Value.AsString(), } - case kv.ARRAY: + case label.ARRAY: result.Value.Value = toArrayAttribute(v) default: result.Value.Value = &commonpb.AnyValue_StringValue{ @@ -84,7 +84,7 @@ func toAttribute(v kv.KeyValue) *commonpb.KeyValue { return result } -func toArrayAttribute(v kv.KeyValue) *commonpb.AnyValue_ArrayValue { +func toArrayAttribute(v label.KeyValue) *commonpb.AnyValue_ArrayValue { array := v.Value.AsArray() var resultValues []*commonpb.AnyValue diff --git a/exporters/otlp/internal/transform/attribute_test.go b/exporters/otlp/internal/transform/attribute_test.go index 7623f3ac20f..7cb2a56d430 100644 --- a/exporters/otlp/internal/transform/attribute_test.go +++ b/exporters/otlp/internal/transform/attribute_test.go @@ -19,12 +19,12 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/otel/api/kv" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" + "go.opentelemetry.io/otel/label" ) type attributeTest struct { - attrs []kv.KeyValue + attrs []label.KeyValue expected []*commonpb.KeyValue } @@ -32,17 +32,17 @@ func TestAttributes(t *testing.T) { for _, test := range []attributeTest{ {nil, nil}, { - []kv.KeyValue{ - kv.Int("int to int", 123), - kv.Uint("uint to int", 1234), - kv.Int32("int32 to int", 12345), - kv.Uint32("uint32 to int", 123456), - kv.Int64("int64 to int64", 1234567), - kv.Uint64("uint64 to int64", 12345678), - kv.Float32("float32 to double", 3.14), - kv.Float32("float64 to double", 1.61), - kv.String("string to string", "string"), - kv.Bool("bool to bool", true), + []label.KeyValue{ + label.Int("int to int", 123), + label.Uint("uint to int", 1234), + label.Int32("int32 to int", 12345), + label.Uint32("uint32 to int", 123456), + label.Int64("int64 to int64", 1234567), + label.Uint64("uint64 to int64", 12345678), + label.Float32("float32 to double", 3.14), + label.Float32("float64 to double", 1.61), + label.String("string to string", "string"), + label.Bool("bool to bool", true), }, []*commonpb.KeyValue{ { @@ -157,17 +157,17 @@ func TestArrayAttributes(t *testing.T) { for _, test := range []attributeTest{ {nil, nil}, { - []kv.KeyValue{ - kv.Array("bool array to bool array", []bool{true, false}), - kv.Array("int array to int64 array", []int{1, 2, 3}), - kv.Array("uint array to int64 array", []uint{1, 2, 3}), - kv.Array("int32 array to int64 array", []int32{1, 2, 3}), - kv.Array("uint32 array to int64 array", []uint32{1, 2, 3}), - kv.Array("int64 array to int64 array", []int64{1, 2, 3}), - kv.Array("uint64 array to int64 array", []uint64{1, 2, 3}), - kv.Array("float32 array to double array", []float32{1.11, 2.22, 3.33}), - kv.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}), - kv.Array("string array to string array", []string{"foo", "bar", "baz"}), + []label.KeyValue{ + label.Array("bool array to bool array", []bool{true, false}), + label.Array("int array to int64 array", []int{1, 2, 3}), + label.Array("uint array to int64 array", []uint{1, 2, 3}), + label.Array("int32 array to int64 array", []int32{1, 2, 3}), + label.Array("uint32 array to int64 array", []uint32{1, 2, 3}), + label.Array("int64 array to int64 array", []int64{1, 2, 3}), + label.Array("uint64 array to int64 array", []uint64{1, 2, 3}), + label.Array("float32 array to double array", []float32{1.11, 2.22, 3.33}), + label.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}), + label.Array("string array to string array", []string{"foo", "bar", "baz"}), }, []*commonpb.KeyValue{ newOTelBoolArray("bool array to bool array", []bool{true, false}), diff --git a/exporters/otlp/internal/transform/metric.go b/exporters/otlp/internal/transform/metric.go index a5b417c04ea..c76164aa277 100644 --- a/exporters/otlp/internal/transform/metric.go +++ b/exporters/otlp/internal/transform/metric.go @@ -27,8 +27,8 @@ import ( metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1" resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/instrumentation" diff --git a/exporters/otlp/internal/transform/metric_test.go b/exporters/otlp/internal/transform/metric_test.go index 7a09e432648..d3024e0d213 100644 --- a/exporters/otlp/internal/transform/metric_test.go +++ b/exporters/otlp/internal/transform/metric_test.go @@ -26,10 +26,9 @@ import ( commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/unit" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/metrictest" @@ -46,7 +45,7 @@ var ( func TestStringKeyValues(t *testing.T) { tests := []struct { - kvs []kv.KeyValue + kvs []label.KeyValue expected []*commonpb.StringKeyValue }{ { @@ -54,21 +53,21 @@ func TestStringKeyValues(t *testing.T) { nil, }, { - []kv.KeyValue{}, + []label.KeyValue{}, nil, }, { - []kv.KeyValue{ - kv.Bool("true", true), - kv.Int64("one", 1), - kv.Uint64("two", 2), - kv.Float64("three", 3), - kv.Int32("four", 4), - kv.Uint32("five", 5), - kv.Float32("six", 6), - kv.Int("seven", 7), - kv.Uint("eight", 8), - kv.String("the", "final word"), + []label.KeyValue{ + label.Bool("true", true), + label.Int64("one", 1), + label.Uint64("two", 2), + label.Float64("three", 3), + label.Int32("four", 4), + label.Uint32("five", 5), + label.Float32("six", 6), + label.Int("seven", 7), + label.Uint("eight", 8), + label.String("the", "final word"), }, []*commonpb.StringKeyValue{ {Key: "eight", Value: "8"}, @@ -119,7 +118,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) { description string unit unit.Unit numberKind metric.NumberKind - labels []kv.KeyValue + labels []label.KeyValue expected *metricpb.MetricDescriptor }{ { @@ -128,7 +127,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) { "test-a-description", unit.Dimensionless, metric.Int64NumberKind, - []kv.KeyValue{}, + []label.KeyValue{}, &metricpb.MetricDescriptor{ Name: "mmsc-test-a", Description: "test-a-description", @@ -142,7 +141,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) { "test-b-description", unit.Bytes, metric.Float64NumberKind, // This shouldn't change anything. - []kv.KeyValue{kv.String("A", "1")}, + []label.KeyValue{label.String("A", "1")}, &metricpb.MetricDescriptor{ Name: "mmsc-test-b", Description: "test-b-description", @@ -224,7 +223,7 @@ func TestSumMetricDescriptor(t *testing.T) { description string unit unit.Unit numberKind metric.NumberKind - labels []kv.KeyValue + labels []label.KeyValue expected *metricpb.MetricDescriptor }{ { @@ -233,7 +232,7 @@ func TestSumMetricDescriptor(t *testing.T) { "test-a-description", unit.Dimensionless, metric.Int64NumberKind, - []kv.KeyValue{}, + []label.KeyValue{}, &metricpb.MetricDescriptor{ Name: "sum-test-a", Description: "test-a-description", @@ -247,7 +246,7 @@ func TestSumMetricDescriptor(t *testing.T) { "test-b-description", unit.Milliseconds, metric.Float64NumberKind, - []kv.KeyValue{kv.String("A", "1")}, + []label.KeyValue{label.String("A", "1")}, &metricpb.MetricDescriptor{ Name: "sum-test-b", Description: "test-b-description", diff --git a/exporters/otlp/internal/transform/resource_test.go b/exporters/otlp/internal/transform/resource_test.go index 34c1d52c991..3d73150d52e 100644 --- a/exporters/otlp/internal/transform/resource_test.go +++ b/exporters/otlp/internal/transform/resource_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/resource" ) @@ -38,7 +38,7 @@ func TestEmptyResource(t *testing.T) { */ func TestResourceAttributes(t *testing.T) { - attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)} + attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)} got := Resource(resource.New(attrs...)).GetAttributes() if !assert.Len(t, attrs, 2) { diff --git a/exporters/otlp/internal/transform/span.go b/exporters/otlp/internal/transform/span.go index 7248eb12212..63c303e024c 100644 --- a/exporters/otlp/internal/transform/span.go +++ b/exporters/otlp/internal/transform/span.go @@ -19,8 +19,8 @@ import ( tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" - "go.opentelemetry.io/otel/api/label" apitrace "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/instrumentation" ) diff --git a/exporters/otlp/internal/transform/span_test.go b/exporters/otlp/internal/transform/span_test.go index d04778610d3..50ea6698c3f 100644 --- a/exporters/otlp/internal/transform/span_test.go +++ b/exporters/otlp/internal/transform/span_test.go @@ -26,8 +26,8 @@ import ( "google.golang.org/grpc/codes" tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" + "go.opentelemetry.io/otel/label" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -77,12 +77,12 @@ func TestEmptySpanEvent(t *testing.T) { } func TestSpanEvent(t *testing.T) { - attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)} + attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)} eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC) got := spanEvents([]export.Event{ { Name: "test 1", - Attributes: []kv.KeyValue{}, + Attributes: []label.KeyValue{}, Time: eventTime, }, { @@ -121,7 +121,7 @@ func TestEmptyLinks(t *testing.T) { } func TestLinks(t *testing.T) { - attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)} + attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)} l := []apitrace.Link{ {}, { @@ -283,13 +283,13 @@ func TestSpanData(t *testing.T) { EndTime: endTime, MessageEvents: []export.Event{ {Time: startTime, - Attributes: []kv.KeyValue{ - kv.Uint64("CompressedByteSize", 512), + Attributes: []label.KeyValue{ + label.Uint64("CompressedByteSize", 512), }, }, {Time: endTime, - Attributes: []kv.KeyValue{ - kv.String("MessageEventType", "Recv"), + Attributes: []label.KeyValue{ + label.String("MessageEventType", "Recv"), }, }, }, @@ -300,8 +300,8 @@ func TestSpanData(t *testing.T) { SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, TraceFlags: 0, }, - Attributes: []kv.KeyValue{ - kv.String("LinkType", "Parent"), + Attributes: []label.KeyValue{ + label.String("LinkType", "Parent"), }, }, { @@ -310,21 +310,21 @@ func TestSpanData(t *testing.T) { SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, TraceFlags: 0, }, - Attributes: []kv.KeyValue{ - kv.String("LinkType", "Child"), + Attributes: []label.KeyValue{ + label.String("LinkType", "Child"), }, }, }, StatusCode: codes.Internal, StatusMessage: "utterly unrecognized", HasRemoteParent: true, - Attributes: []kv.KeyValue{ - kv.Int64("timeout_ns", 12e9), + Attributes: []label.KeyValue{ + label.Int64("timeout_ns", 12e9), }, DroppedAttributeCount: 1, DroppedMessageEventCount: 2, DroppedLinkCount: 3, - Resource: resource.New(kv.String("rk1", "rv1"), kv.Int64("rk2", 5)), + Resource: resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5)), InstrumentationLibrary: instrumentation.Library{ Name: "go.opentelemetry.io/test/otel", Version: "v0.0.1", diff --git a/exporters/otlp/otlp_integration_test.go b/exporters/otlp/otlp_integration_test.go index 8731b060520..5af4f7306a6 100644 --- a/exporters/otlp/otlp_integration_test.go +++ b/exporters/otlp/otlp_integration_test.go @@ -27,8 +27,8 @@ import ( commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1" + "go.opentelemetry.io/otel/label" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" metricapi "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/exporters/otlp" @@ -91,15 +91,15 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) } tp1, err := sdktrace.NewProvider(append(pOpts, sdktrace.WithResource(resource.New( - kv.String("rk1", "rv11)"), - kv.Int64("rk2", 5), + label.String("rk1", "rv11)"), + label.Int64("rk2", 5), )))...) assert.NoError(t, err) tp2, err := sdktrace.NewProvider(append(pOpts, sdktrace.WithResource(resource.New( - kv.String("rk1", "rv12)"), - kv.Float32("rk3", 6.5), + label.String("rk1", "rv12)"), + label.Float32("rk3", 6.5), )))...) assert.NoError(t, err) @@ -109,11 +109,11 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) m := 4 for i := 0; i < m; i++ { _, span := tr1.Start(context.Background(), "AlwaysSample") - span.SetAttributes(kv.Int64("i", int64(i))) + span.SetAttributes(label.Int64("i", int64(i))) span.End() _, span = tr2.Start(context.Background(), "AlwaysSample") - span.SetAttributes(kv.Int64("i", int64(i))) + span.SetAttributes(label.Int64("i", int64(i))) span.End() } @@ -124,7 +124,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) ctx := context.Background() meter := pusher.Provider().Meter("test-meter") - labels := []kv.KeyValue{kv.Bool("test", true)} + labels := []label.KeyValue{label.Bool("test", true)} type data struct { iKind metric.Kind diff --git a/exporters/otlp/otlp_metric_test.go b/exporters/otlp/otlp_metric_test.go index f2b23055506..8c1ff81f291 100644 --- a/exporters/otlp/otlp_metric_test.go +++ b/exporters/otlp/otlp_metric_test.go @@ -28,9 +28,8 @@ import ( metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1" resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" metricsdk "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/metrictest" @@ -98,15 +97,15 @@ type record struct { nKind metric.NumberKind resource *resource.Resource opts []metric.InstrumentOption - labels []kv.KeyValue + labels []label.KeyValue } var ( - baseKeyValues = []kv.KeyValue{kv.String("host", "test.com")} - cpuKey = kv.Key("CPU") + baseKeyValues = []label.KeyValue{label.String("host", "test.com")} + cpuKey = label.Key("CPU") - testInstA = resource.New(kv.String("instance", "tester-a")) - testInstB = resource.New(kv.String("instance", "tester-b")) + testInstA = resource.New(label.String("instance", "tester-a")) + testInstB = resource.New(label.String("instance", "tester-b")) md = &metricpb.MetricDescriptor{ Name: "int64-count", diff --git a/exporters/otlp/otlp_span_test.go b/exporters/otlp/otlp_span_test.go index 5e521c3eeed..f38d832f7cc 100644 --- a/exporters/otlp/otlp_span_test.go +++ b/exporters/otlp/otlp_span_test.go @@ -27,8 +27,8 @@ import ( commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1" tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" + "go.opentelemetry.io/otel/label" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" tracesdk "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -91,13 +91,13 @@ func TestExportSpans(t *testing.T) { Name: "parent process", StartTime: startTime, EndTime: endTime, - Attributes: []kv.KeyValue{ - kv.String("user", "alice"), - kv.Bool("authenticated", true), + Attributes: []label.KeyValue{ + label.String("user", "alice"), + label.Bool("authenticated", true), }, StatusCode: codes.OK, StatusMessage: "Ok", - Resource: resource.New(kv.String("instance", "tester-a")), + Resource: resource.New(label.String("instance", "tester-a")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-a", Version: "v0.1.0", @@ -113,13 +113,13 @@ func TestExportSpans(t *testing.T) { Name: "secondary parent process", StartTime: startTime, EndTime: endTime, - Attributes: []kv.KeyValue{ - kv.String("user", "alice"), - kv.Bool("authenticated", true), + Attributes: []label.KeyValue{ + label.String("user", "alice"), + label.Bool("authenticated", true), }, StatusCode: codes.OK, StatusMessage: "Ok", - Resource: resource.New(kv.String("instance", "tester-a")), + Resource: resource.New(label.String("instance", "tester-a")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-b", Version: "v0.1.0", @@ -136,13 +136,13 @@ func TestExportSpans(t *testing.T) { Name: "internal process", StartTime: startTime, EndTime: endTime, - Attributes: []kv.KeyValue{ - kv.String("user", "alice"), - kv.Bool("authenticated", true), + Attributes: []label.KeyValue{ + label.String("user", "alice"), + label.Bool("authenticated", true), }, StatusCode: codes.OK, StatusMessage: "Ok", - Resource: resource.New(kv.String("instance", "tester-a")), + Resource: resource.New(label.String("instance", "tester-a")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-a", Version: "v0.1.0", @@ -158,13 +158,13 @@ func TestExportSpans(t *testing.T) { Name: "parent process", StartTime: startTime, EndTime: endTime, - Attributes: []kv.KeyValue{ - kv.String("user", "bob"), - kv.Bool("authenticated", false), + Attributes: []label.KeyValue{ + label.String("user", "bob"), + label.Bool("authenticated", false), }, StatusCode: codes.Unauthenticated, StatusMessage: "Unauthenticated", - Resource: resource.New(kv.String("instance", "tester-b")), + Resource: resource.New(label.String("instance", "tester-b")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-a", Version: "v1.1.0", diff --git a/exporters/stdout/config.go b/exporters/stdout/config.go index 2255b560958..39549ea117c 100644 --- a/exporters/stdout/config.go +++ b/exporters/stdout/config.go @@ -18,7 +18,7 @@ import ( "io" "os" - "go.opentelemetry.io/otel/api/label" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" ) diff --git a/exporters/stdout/example_test.go b/exporters/stdout/example_test.go index fa4a3015e7c..ff7c0144b60 100644 --- a/exporters/stdout/example_test.go +++ b/exporters/stdout/example_test.go @@ -19,10 +19,10 @@ import ( "log" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/exporters/stdout" + "go.opentelemetry.io/otel/label" ) const ( @@ -44,7 +44,7 @@ var ( loopCounter = metric.Must(meter).NewInt64Counter("function.loops") paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param") - nameKey = kv.Key("function.name") + nameKey = label.Key("function.name") ) func add(ctx context.Context, x, y int64) int64 { diff --git a/exporters/stdout/metric.go b/exporters/stdout/metric.go index a809809a0ae..fd25f62556b 100644 --- a/exporters/stdout/metric.go +++ b/exporters/stdout/metric.go @@ -21,9 +21,8 @@ import ( "strings" "time" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" apimetric "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" ) @@ -69,11 +68,11 @@ func (e *metricExporter) Export(_ context.Context, checkpointSet metric.Checkpoi kind := desc.NumberKind() encodedResource := record.Resource().Encoded(e.config.LabelEncoder) - var instLabels []kv.KeyValue + var instLabels []label.KeyValue if name := desc.InstrumentationName(); name != "" { - instLabels = append(instLabels, kv.String("instrumentation.name", name)) + instLabels = append(instLabels, label.String("instrumentation.name", name)) if version := desc.InstrumentationVersion(); version != "" { - instLabels = append(instLabels, kv.String("instrumentation.version", version)) + instLabels = append(instLabels, label.String("instrumentation.version", version)) } } instSet := label.NewSet(instLabels...) diff --git a/exporters/stdout/metric_test.go b/exporters/stdout/metric_test.go index 31fd86d166c..1a6e11000b3 100644 --- a/exporters/stdout/metric_test.go +++ b/exporters/stdout/metric_test.go @@ -26,9 +26,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/exporters/stdout" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/metrictest" @@ -48,7 +48,7 @@ type testFixture struct { output *bytes.Buffer } -var testResource = resource.New(kv.String("R", "V")) +var testResource = resource.New(label.String("R", "V")) func newFixture(t *testing.T, opts ...stdout.Option) testFixture { buf := &bytes.Buffer{} @@ -145,7 +145,7 @@ func TestStdoutCounterFormat(t *testing.T) { aggregatortest.CheckedUpdate(fix.t, cagg, metric.NewInt64Number(123), &desc) require.NoError(t, cagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D")) + checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) fix.Export(checkpointSet) @@ -163,7 +163,7 @@ func TestStdoutLastValueFormat(t *testing.T) { aggregatortest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc) require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D")) + checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) fix.Export(checkpointSet) @@ -183,7 +183,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) { aggregatortest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(876.543), &desc) require.NoError(t, magg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D")) + checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) fix.Export(checkpointSet) @@ -204,7 +204,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) { require.NoError(t, aagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D")) + checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) fix.Export(checkpointSet) @@ -268,7 +268,7 @@ func TestStdoutLastValueNotSet(t *testing.T) { lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, lvagg, kv.String("A", "B"), kv.String("C", "D")) + checkpointSet.Add(&desc, lvagg, label.String("A", "B"), label.String("C", "D")) fix.Export(checkpointSet) @@ -279,9 +279,9 @@ func TestStdoutResource(t *testing.T) { type testCase struct { expect string res *resource.Resource - attrs []kv.KeyValue + attrs []label.KeyValue } - newCase := func(expect string, res *resource.Resource, attrs ...kv.KeyValue) testCase { + newCase := func(expect string, res *resource.Resource, attrs ...label.KeyValue) testCase { return testCase{ expect: expect, res: res, @@ -290,23 +290,23 @@ func TestStdoutResource(t *testing.T) { } testCases := []testCase{ newCase("R1=V1,R2=V2,A=B,C=D", - resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")), - kv.String("A", "B"), - kv.String("C", "D")), + resource.New(label.String("R1", "V1"), label.String("R2", "V2")), + label.String("A", "B"), + label.String("C", "D")), newCase("R1=V1,R2=V2", - resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")), + resource.New(label.String("R1", "V1"), label.String("R2", "V2")), ), newCase("A=B,C=D", nil, - kv.String("A", "B"), - kv.String("C", "D"), + label.String("A", "B"), + label.String("C", "D"), ), // We explicitly do not de-duplicate between resources // and metric labels in this exporter. newCase("R1=V1,R2=V2,R1=V3,R2=V4", - resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")), - kv.String("R1", "V3"), - kv.String("R2", "V4")), + resource.New(label.String("R1", "V1"), label.String("R2", "V2")), + label.String("R1", "V3"), + label.String("R2", "V4")), } for _, tc := range testCases { diff --git a/exporters/stdout/trace_test.go b/exporters/stdout/trace_test.go index 03078d25f33..5b133ed0784 100644 --- a/exporters/stdout/trace_test.go +++ b/exporters/stdout/trace_test.go @@ -23,9 +23,9 @@ import ( "google.golang.org/grpc/codes" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/exporters/stdout" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/resource" ) @@ -44,7 +44,7 @@ func TestExporter_ExportSpan(t *testing.T) { spanID, _ := trace.SpanIDFromHex("0102030405060708") keyValue := "value" doubleValue := 123.456 - resource := resource.New(kv.String("rk1", "rv11")) + resource := resource.New(label.String("rk1", "rv11")) testSpan := &export.SpanData{ SpanContext: trace.SpanContext{ @@ -54,13 +54,13 @@ func TestExporter_ExportSpan(t *testing.T) { Name: "/foo", StartTime: now, EndTime: now, - Attributes: []kv.KeyValue{ - kv.String("key", keyValue), - kv.Float64("double", doubleValue), + Attributes: []label.KeyValue{ + label.String("key", keyValue), + label.Float64("double", doubleValue), }, MessageEvents: []export.Event{ - {Name: "foo", Attributes: []kv.KeyValue{kv.String("key", keyValue)}, Time: now}, - {Name: "bar", Attributes: []kv.KeyValue{kv.Float64("double", doubleValue)}, Time: now}, + {Name: "foo", Attributes: []label.KeyValue{label.String("key", keyValue)}, Time: now}, + {Name: "bar", Attributes: []label.KeyValue{label.Float64("double", doubleValue)}, Time: now}, }, SpanKind: trace.SpanKindInternal, StatusCode: codes.Unknown, diff --git a/exporters/trace/jaeger/env.go b/exporters/trace/jaeger/env.go index abff351a7c3..e4aa4d00924 100644 --- a/exporters/trace/jaeger/env.go +++ b/exporters/trace/jaeger/env.go @@ -21,7 +21,7 @@ import ( "strings" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // Environment variable names @@ -111,9 +111,9 @@ var errTagEnvironmentDefaultValueNotFound = errors.New("missing default value fo // - comma separated list of key=value // - value can be specified using the notation ${envVar:defaultValue}, where `envVar` // is an environment variable and `defaultValue` is the value to use in case the env var is not set -func parseTags(sTags string) ([]kv.KeyValue, error) { +func parseTags(sTags string) ([]label.KeyValue, error) { pairs := strings.Split(sTags, ",") - tags := make([]kv.KeyValue, len(pairs)) + tags := make([]label.KeyValue, len(pairs)) for i, p := range pairs { field := strings.SplitN(p, "=", 2) if len(field) != 2 { @@ -139,24 +139,24 @@ func parseTags(sTags string) ([]kv.KeyValue, error) { return tags, nil } -func parseKeyValue(k, v string) kv.KeyValue { - return kv.KeyValue{ - Key: kv.Key(k), +func parseKeyValue(k, v string) label.KeyValue { + return label.KeyValue{ + Key: label.Key(k), Value: parseValue(v), } } -func parseValue(str string) kv.Value { +func parseValue(str string) label.Value { if v, err := strconv.ParseInt(str, 10, 64); err == nil { - return kv.Int64Value(v) + return label.Int64Value(v) } if v, err := strconv.ParseFloat(str, 64); err == nil { - return kv.Float64Value(v) + return label.Float64Value(v) } if v, err := strconv.ParseBool(str); err == nil { - return kv.BoolValue(v) + return label.BoolValue(v) } // Fallback - return kv.StringValue(str) + return label.StringValue(str) } diff --git a/exporters/trace/jaeger/env_test.go b/exporters/trace/jaeger/env_test.go index 51b459c4ddc..69cc847de8a 100644 --- a/exporters/trace/jaeger/env_test.go +++ b/exporters/trace/jaeger/env_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" ottest "go.opentelemetry.io/otel/internal/testing" + "go.opentelemetry.io/otel/label" ) func Test_parseTags(t *testing.T) { @@ -38,78 +38,78 @@ func Test_parseTags(t *testing.T) { testCases := []struct { name string tagStr string - expectedTags []kv.KeyValue + expectedTags []label.KeyValue expectedError error }{ { name: "string", tagStr: "key=value", - expectedTags: []kv.KeyValue{ + expectedTags: []label.KeyValue{ { Key: "key", - Value: kv.StringValue("value"), + Value: label.StringValue("value"), }, }, }, { name: "int64", tagStr: "k=9223372036854775807,k2=-9223372036854775808", - expectedTags: []kv.KeyValue{ + expectedTags: []label.KeyValue{ { Key: "k", - Value: kv.Int64Value(math.MaxInt64), + Value: label.Int64Value(math.MaxInt64), }, { Key: "k2", - Value: kv.Int64Value(math.MinInt64), + Value: label.Int64Value(math.MinInt64), }, }, }, { name: "float64", tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2", - expectedTags: []kv.KeyValue{ + expectedTags: []label.KeyValue{ { Key: "k", - Value: kv.Float64Value(math.MaxFloat64), + Value: label.Float64Value(math.MaxFloat64), }, { Key: "k2", - Value: kv.Float64Value(math.SmallestNonzeroFloat64), + Value: label.Float64Value(math.SmallestNonzeroFloat64), }, { Key: "k3", - Value: kv.Float64Value(-1.2), + Value: label.Float64Value(-1.2), }, }, }, { name: "multiple type values", tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}", - expectedTags: []kv.KeyValue{ + expectedTags: []label.KeyValue{ { Key: "k", - Value: kv.StringValue("v"), + Value: label.StringValue("v"), }, { Key: "k2", - Value: kv.Int64Value(123), + Value: label.Int64Value(123), }, { Key: "k3", - Value: kv.StringValue("v3"), + Value: label.StringValue("v3"), }, { Key: "k4", - Value: kv.Float64Value(-1.2), + Value: label.Float64Value(-1.2), }, { Key: "k5", - Value: kv.StringValue("not-default"), + Value: label.StringValue("not-default"), }, { Key: "k6", - Value: kv.StringValue("default"), + Value: label.StringValue("default"), }, }, }, @@ -144,52 +144,52 @@ func Test_parseValue(t *testing.T) { testCases := []struct { name string str string - expected kv.Value + expected label.Value }{ { name: "bool: true", str: "true", - expected: kv.BoolValue(true), + expected: label.BoolValue(true), }, { name: "bool: false", str: "false", - expected: kv.BoolValue(false), + expected: label.BoolValue(false), }, { name: "int64: 012340", str: "012340", - expected: kv.Int64Value(12340), + expected: label.Int64Value(12340), }, { name: "int64: -012340", str: "-012340", - expected: kv.Int64Value(-12340), + expected: label.Int64Value(-12340), }, { name: "int64: 0", str: "0", - expected: kv.Int64Value(0), + expected: label.Int64Value(0), }, { name: "float64: -0.1", str: "-0.1", - expected: kv.Float64Value(-0.1), + expected: label.Float64Value(-0.1), }, { name: "float64: 00.001", str: "00.001", - expected: kv.Float64Value(0.001), + expected: label.Float64Value(0.001), }, { name: "float64: 1E23", str: "1E23", - expected: kv.Float64Value(1e23), + expected: label.Float64Value(1e23), }, { name: "string: foo", str: "foo", - expected: kv.StringValue("foo"), + expected: label.StringValue("foo"), }, } @@ -408,9 +408,9 @@ func TestProcessFromEnv(t *testing.T) { tags: "key=value,key2=123", expectedProcess: Process{ ServiceName: "test-service", - Tags: []kv.KeyValue{ - kv.String("key", "value"), - kv.Int64("key2", 123), + Tags: []label.KeyValue{ + label.String("key", "value"), + label.Int64("key2", 123), }, }, }, @@ -455,16 +455,16 @@ func TestWithProcessFromEnv(t *testing.T) { options: options{ Process: Process{ ServiceName: "old-name", - Tags: []kv.KeyValue{ - kv.String("old-key", "old-value"), + Tags: []label.KeyValue{ + label.String("old-key", "old-value"), }, }, }, expectedOptions: options{ Process: Process{ ServiceName: "service-name", - Tags: []kv.KeyValue{ - kv.String("key", "value"), + Tags: []label.KeyValue{ + label.String("key", "value"), }, }, }, @@ -476,16 +476,16 @@ func TestWithProcessFromEnv(t *testing.T) { options: options{ Process: Process{ ServiceName: "old-name", - Tags: []kv.KeyValue{ - kv.String("old-key", "old-value"), + Tags: []label.KeyValue{ + label.String("old-key", "old-value"), }, }, }, expectedOptions: options{ Process: Process{ ServiceName: "old-name", - Tags: []kv.KeyValue{ - kv.String("old-key", "old-value"), + Tags: []label.KeyValue{ + label.String("old-key", "old-value"), }, }, }, diff --git a/exporters/trace/jaeger/jaeger.go b/exporters/trace/jaeger/jaeger.go index 13ecafe80c6..77fac532f9c 100644 --- a/exporters/trace/jaeger/jaeger.go +++ b/exporters/trace/jaeger/jaeger.go @@ -22,9 +22,9 @@ import ( "google.golang.org/grpc/codes" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) @@ -189,7 +189,7 @@ type Process struct { ServiceName string // Tags are added to Jaeger Process exports - Tags []kv.KeyValue + Tags []label.KeyValue } // Exporter is an implementation of trace.SpanSyncer that uploads spans to Jaeger. @@ -291,45 +291,45 @@ func spanDataToThrift(data *export.SpanData) *gen.Span { } } -func keyValueToTag(keyValue kv.KeyValue) *gen.Tag { +func keyValueToTag(keyValue label.KeyValue) *gen.Tag { var tag *gen.Tag switch keyValue.Value.Type() { - case kv.STRING: + case label.STRING: s := keyValue.Value.AsString() tag = &gen.Tag{ Key: string(keyValue.Key), VStr: &s, VType: gen.TagType_STRING, } - case kv.BOOL: + case label.BOOL: b := keyValue.Value.AsBool() tag = &gen.Tag{ Key: string(keyValue.Key), VBool: &b, VType: gen.TagType_BOOL, } - case kv.INT32: + case label.INT32: i := int64(keyValue.Value.AsInt32()) tag = &gen.Tag{ Key: string(keyValue.Key), VLong: &i, VType: gen.TagType_LONG, } - case kv.INT64: + case label.INT64: i := keyValue.Value.AsInt64() tag = &gen.Tag{ Key: string(keyValue.Key), VLong: &i, VType: gen.TagType_LONG, } - case kv.UINT32: + case label.UINT32: i := int64(keyValue.Value.AsUint32()) tag = &gen.Tag{ Key: string(keyValue.Key), VLong: &i, VType: gen.TagType_LONG, } - case kv.UINT64: + case label.UINT64: // we'll ignore the value if it overflows if i := int64(keyValue.Value.AsUint64()); i >= 0 { tag = &gen.Tag{ @@ -338,14 +338,14 @@ func keyValueToTag(keyValue kv.KeyValue) *gen.Tag { VType: gen.TagType_LONG, } } - case kv.FLOAT32: + case label.FLOAT32: f := float64(keyValue.Value.AsFloat32()) tag = &gen.Tag{ Key: string(keyValue.Key), VDouble: &f, VType: gen.TagType_DOUBLE, } - case kv.FLOAT64: + case label.FLOAT64: f := keyValue.Value.AsFloat64() tag = &gen.Tag{ Key: string(keyValue.Key), diff --git a/exporters/trace/jaeger/jaeger_test.go b/exporters/trace/jaeger/jaeger_test.go index 944bf540fc5..a0fcb6e8350 100644 --- a/exporters/trace/jaeger/jaeger_test.go +++ b/exporters/trace/jaeger/jaeger_test.go @@ -30,11 +30,11 @@ import ( "google.golang.org/grpc/codes" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" apitrace "go.opentelemetry.io/otel/api/trace" gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" ottest "go.opentelemetry.io/otel/internal/testing" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/resource" @@ -205,8 +205,8 @@ func TestNewRawExporter(t *testing.T) { WithProcess( Process{ ServiceName: "jaeger-test", - Tags: []kv.KeyValue{ - kv.String("key", "val"), + Tags: []label.KeyValue{ + label.String("key", "val"), }, }, ), @@ -331,8 +331,8 @@ func TestExporter_ExportSpan(t *testing.T) { withTestCollectorEndpoint(), WithProcess(Process{ ServiceName: serviceName, - Tags: []kv.KeyValue{ - kv.String(tagKey, tagVal), + Tags: []label.KeyValue{ + label.String(tagKey, tagVal), }, }), ) @@ -400,19 +400,19 @@ func Test_spanDataToThrift(t *testing.T) { }, }, }, - Attributes: []kv.KeyValue{ - kv.String("key", keyValue), - kv.Float64("double", doubleValue), - kv.Uint64("uint", uint64(uintValue)), - kv.Uint64("overflows", math.MaxUint64), + Attributes: []label.KeyValue{ + label.String("key", keyValue), + label.Float64("double", doubleValue), + label.Uint64("uint", uint64(uintValue)), + label.Uint64("overflows", math.MaxUint64), }, MessageEvents: []export.Event{ - {Name: eventNameValue, Attributes: []kv.KeyValue{kv.String("k1", keyValue)}, Time: now}, + {Name: eventNameValue, Attributes: []label.KeyValue{label.String("k1", keyValue)}, Time: now}, }, StatusCode: codes.Unknown, StatusMessage: statusMessage, SpanKind: apitrace.SpanKindClient, - Resource: resource.New(kv.String("rk1", rv1), kv.Int64("rk2", rv2)), + Resource: resource.New(label.String("rk1", rv1), label.Int64("rk2", rv2)), InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, diff --git a/exporters/trace/zipkin/model.go b/exporters/trace/zipkin/model.go index a320d33d808..b8e78b3dd03 100644 --- a/exporters/trace/zipkin/model.go +++ b/exporters/trace/zipkin/model.go @@ -21,8 +21,8 @@ import ( zkmodel "github.com/openzipkin/zipkin-go/model" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" ) @@ -122,7 +122,7 @@ func toZipkinAnnotations(events []export.Event) []zkmodel.Annotation { return annotations } -func attributesToJSONMapString(attributes []kv.KeyValue) string { +func attributesToJSONMapString(attributes []label.KeyValue) string { m := make(map[string]interface{}, len(attributes)) for _, attribute := range attributes { m[(string)(attribute.Key)] = attribute.Value.AsInterface() diff --git a/exporters/trace/zipkin/model_test.go b/exporters/trace/zipkin/model_test.go index 87613033620..a2ea9db2d51 100644 --- a/exporters/trace/zipkin/model_test.go +++ b/exporters/trace/zipkin/model_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" ) @@ -40,16 +40,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -73,16 +73,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -105,16 +105,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -137,16 +137,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -169,16 +169,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -201,16 +201,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -233,16 +233,16 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { @@ -265,9 +265,9 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.Uint64("attr1", 42), - kv.String("attr2", "bar"), + Attributes: []label.KeyValue{ + label.Uint64("attr1", 42), + label.String("attr2", "bar"), }, MessageEvents: nil, StatusCode: codes.NotFound, @@ -284,15 +284,15 @@ func TestModelConversion(t *testing.T) { Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), - Attributes: []kv.KeyValue{ - kv.String("error", "false"), + Attributes: []label.KeyValue{ + label.String("error", "false"), }, MessageEvents: []export.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []kv.KeyValue{ - kv.Uint64("eventattr1", 123), + Attributes: []label.KeyValue{ + label.Uint64("eventattr1", 123), }, }, { diff --git a/internal/metric/async.go b/internal/metric/async.go index e57e8fd00a2..039dc8b47f9 100644 --- a/internal/metric/async.go +++ b/internal/metric/async.go @@ -21,8 +21,8 @@ import ( "sync" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" ) var ErrInvalidAsyncRunner = errors.New("unknown async runner type") @@ -32,7 +32,7 @@ var ErrInvalidAsyncRunner = errors.New("unknown async runner type") // the SDK to provide support for running observer callbacks. type AsyncCollector interface { // CollectAsync passes a batch of observations to the MeterImpl. - CollectAsync([]kv.KeyValue, ...metric.Observation) + CollectAsync([]label.KeyValue, ...metric.Observation) } // AsyncInstrumentState manages an ordered set of asynchronous diff --git a/internal/metric/mock.go b/internal/metric/mock.go index c6fb2fd0300..2fc24dd429c 100644 --- a/internal/metric/mock.go +++ b/internal/metric/mock.go @@ -18,23 +18,23 @@ import ( "context" "sync" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" apimetric "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/metric/registry" + "go.opentelemetry.io/otel/label" ) type ( Handle struct { Instrument *Sync - Labels []kv.KeyValue + Labels []label.KeyValue } Batch struct { // Measurement needs to be aligned for 64-bit atomic operations. Measurements []Measurement Ctx context.Context - Labels []kv.KeyValue + Labels []label.KeyValue LibraryName string } @@ -87,14 +87,14 @@ func (s *Sync) Implementation() interface{} { return s } -func (s *Sync) Bind(labels []kv.KeyValue) apimetric.BoundSyncImpl { +func (s *Sync) Bind(labels []label.KeyValue) apimetric.BoundSyncImpl { return &Handle{ Instrument: s, Labels: labels, } } -func (s *Sync) RecordOne(ctx context.Context, number apimetric.Number, labels []kv.KeyValue) { +func (s *Sync) RecordOne(ctx context.Context, number apimetric.Number, labels []label.KeyValue) { s.meter.doRecordSingle(ctx, labels, s, number) } @@ -105,7 +105,7 @@ func (h *Handle) RecordOne(ctx context.Context, number apimetric.Number) { func (h *Handle) Unbind() { } -func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []kv.KeyValue, instrument apimetric.InstrumentImpl, number apimetric.Number) { +func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []label.KeyValue, instrument apimetric.InstrumentImpl, number apimetric.Number) { m.collect(ctx, labels, []Measurement{{ Instrument: instrument, Number: number, @@ -151,7 +151,7 @@ func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metr return a, nil } -func (m *MeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measurements ...apimetric.Measurement) { +func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...apimetric.Measurement) { mm := make([]Measurement, len(measurements)) for i := 0; i < len(measurements); i++ { m := measurements[i] @@ -163,7 +163,7 @@ func (m *MeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measu m.collect(ctx, labels, mm) } -func (m *MeterImpl) CollectAsync(labels []kv.KeyValue, obs ...metric.Observation) { +func (m *MeterImpl) CollectAsync(labels []label.KeyValue, obs ...metric.Observation) { mm := make([]Measurement, len(obs)) for i := 0; i < len(obs); i++ { o := obs[i] @@ -175,7 +175,7 @@ func (m *MeterImpl) CollectAsync(labels []kv.KeyValue, obs ...metric.Observation m.collect(context.Background(), labels, mm) } -func (m *MeterImpl) collect(ctx context.Context, labels []kv.KeyValue, measurements []Measurement) { +func (m *MeterImpl) collect(ctx context.Context, labels []label.KeyValue, measurements []Measurement) { m.lock.Lock() defer m.lock.Unlock() diff --git a/api/internal/rawhelpers.go b/internal/rawhelpers.go similarity index 100% rename from api/internal/rawhelpers.go rename to internal/rawhelpers.go diff --git a/internal/trace/mock_span.go b/internal/trace/mock_span.go index c00f1ec34b2..fe9146e562e 100644 --- a/internal/trace/mock_span.go +++ b/internal/trace/mock_span.go @@ -18,9 +18,9 @@ import ( "context" "time" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) // MockSpan is a mock span used in association with MockTracer for testing purpose only. @@ -34,8 +34,8 @@ type MockSpan struct { var _ apitrace.Span = (*MockSpan)(nil) -// SpanContext returns associated kv.SpanContext. If the receiver is nil it returns -// an empty kv.SpanContext +// SpanContext returns associated label.SpanContext. If the receiver is nil it returns +// an empty label.SpanContext func (ms *MockSpan) SpanContext() apitrace.SpanContext { if ms == nil { return apitrace.EmptySpanContext() @@ -59,7 +59,7 @@ func (ms *MockSpan) SetError(v bool) { } // SetAttributes does nothing. -func (ms *MockSpan) SetAttributes(attributes ...kv.KeyValue) { +func (ms *MockSpan) SetAttributes(attributes ...label.KeyValue) { } // SetAttribute does nothing. @@ -85,9 +85,9 @@ func (ms *MockSpan) Tracer() apitrace.Tracer { } // AddEvent does nothing. -func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) { +func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) { } // AddEvent does nothing. -func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) { +func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) { } diff --git a/internal/trace/parent/parent.go b/internal/trace/parent/parent.go index 5080aed9187..88def335e97 100644 --- a/internal/trace/parent/parent.go +++ b/internal/trace/parent/parent.go @@ -17,8 +17,8 @@ package parent import ( "context" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" ) func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (trace.SpanContext, bool, []trace.Link) { @@ -46,8 +46,8 @@ func addLinkIfValid(links []trace.Link, sc trace.SpanContext, kind string) []tra } return append(links, trace.Link{ SpanContext: sc, - Attributes: []kv.KeyValue{ - kv.String("ignored-on-demand", kind), + Attributes: []label.KeyValue{ + label.String("ignored-on-demand", kind), }, }) } diff --git a/api/kv/benchmark_test.go b/label/benchmark_test.go similarity index 75% rename from api/kv/benchmark_test.go rename to label/benchmark_test.go index a1fea5b290d..85bf58a75f2 100644 --- a/api/kv/benchmark_test.go +++ b/label/benchmark_test.go @@ -12,61 +12,61 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv_test +package label_test import ( "testing" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) type test struct{} var ( arrayVal = []string{"one", "two"} - arrayKeyVal = kv.Array("array", arrayVal) + arrayKeyVal = label.Array("array", arrayVal) boolVal = true - boolKeyVal = kv.Bool("bool", boolVal) + boolKeyVal = label.Bool("bool", boolVal) intVal = int(1) - intKeyVal = kv.Int("int", intVal) + intKeyVal = label.Int("int", intVal) int8Val = int8(1) - int8KeyVal = kv.Int("int8", int(int8Val)) + int8KeyVal = label.Int("int8", int(int8Val)) int16Val = int16(1) - int16KeyVal = kv.Int("int16", int(int16Val)) + int16KeyVal = label.Int("int16", int(int16Val)) int32Val = int32(1) - int32KeyVal = kv.Int32("int32", int32Val) + int32KeyVal = label.Int32("int32", int32Val) int64Val = int64(1) - int64KeyVal = kv.Int64("int64", int64Val) + int64KeyVal = label.Int64("int64", int64Val) uintVal = uint(1) - uintKeyVal = kv.Uint("uint", uintVal) + uintKeyVal = label.Uint("uint", uintVal) uint8Val = uint8(1) - uint8KeyVal = kv.Uint("uint8", uint(uint8Val)) + uint8KeyVal = label.Uint("uint8", uint(uint8Val)) uint16Val = uint16(1) - uint16KeyVal = kv.Uint("uint16", uint(uint16Val)) + uint16KeyVal = label.Uint("uint16", uint(uint16Val)) uint32Val = uint32(1) - uint32KeyVal = kv.Uint32("uint32", uint32Val) + uint32KeyVal = label.Uint32("uint32", uint32Val) uint64Val = uint64(1) - uint64KeyVal = kv.Uint64("uint64", uint64Val) + uint64KeyVal = label.Uint64("uint64", uint64Val) float32Val = float32(1.0) - float32KeyVal = kv.Float32("float32", float32Val) + float32KeyVal = label.Float32("float32", float32Val) float64Val = float64(1.0) - float64KeyVal = kv.Float64("float64", float64Val) + float64KeyVal = label.Float64("float64", float64Val) stringVal = "string" - stringKeyVal = kv.String("string", stringVal) + stringKeyVal = label.String("string", stringVal) bytesVal = []byte("bytes") structVal = test{} @@ -75,196 +75,196 @@ var ( func BenchmarkArrayKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Array("array", arrayVal) + _ = label.Array("array", arrayVal) } } func BenchmarkArrayKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("array", arrayVal) + _ = label.Any("array", arrayVal) } } func BenchmarkBoolKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Bool("bool", boolVal) + _ = label.Bool("bool", boolVal) } } func BenchmarkBoolKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("bool", boolVal) + _ = label.Any("bool", boolVal) } } func BenchmarkIntKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Int("int", intVal) + _ = label.Int("int", intVal) } } func BenchmarkIntKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("int", intVal) + _ = label.Any("int", intVal) } } func BenchmarkInt8KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("int8", int8Val) + _ = label.Any("int8", int8Val) } } func BenchmarkInt16KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("int16", int16Val) + _ = label.Any("int16", int16Val) } } func BenchmarkInt32Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Int32("int32", int32Val) + _ = label.Int32("int32", int32Val) } } func BenchmarkInt32KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("int32", int32Val) + _ = label.Any("int32", int32Val) } } func BenchmarkInt64Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Int64("int64", int64Val) + _ = label.Int64("int64", int64Val) } } func BenchmarkInt64KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("int64", int64Val) + _ = label.Any("int64", int64Val) } } func BenchmarkUintKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Uint("uint", uintVal) + _ = label.Uint("uint", uintVal) } } func BenchmarkUintKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("uint", uintVal) + _ = label.Any("uint", uintVal) } } func BenchmarkUint8KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("uint8", uint8Val) + _ = label.Any("uint8", uint8Val) } } func BenchmarkUint16KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("uint16", uint16Val) + _ = label.Any("uint16", uint16Val) } } func BenchmarkUint32Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Uint32("uint32", uint32Val) + _ = label.Uint32("uint32", uint32Val) } } func BenchmarkUint32KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("uint32", uint32Val) + _ = label.Any("uint32", uint32Val) } } func BenchmarkUint64Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Uint64("uint64", uint64Val) + _ = label.Uint64("uint64", uint64Val) } } func BenchmarkUint64KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("uint64", uint64Val) + _ = label.Any("uint64", uint64Val) } } func BenchmarkFloat32Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Float32("float32", float32Val) + _ = label.Float32("float32", float32Val) } } func BenchmarkFloat32KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("float32", float32Val) + _ = label.Any("float32", float32Val) } } func BenchmarkFloat64Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Float64("float64", float64Val) + _ = label.Float64("float64", float64Val) } } func BenchmarkFloat64KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("float64", float64Val) + _ = label.Any("float64", float64Val) } } func BenchmarkStringKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.String("string", stringVal) + _ = label.String("string", stringVal) } } func BenchmarkStringKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("string", stringVal) + _ = label.Any("string", stringVal) } } func BenchmarkBytesKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("bytes", bytesVal) + _ = label.Any("bytes", bytesVal) } } func BenchmarkStructKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = kv.Any("struct", structVal) + _ = label.Any("struct", structVal) } } diff --git a/api/kv/doc.go b/label/doc.go similarity index 85% rename from api/kv/doc.go rename to label/doc.go index 3e635cdc3bd..d631d23871e 100644 --- a/api/kv/doc.go +++ b/label/doc.go @@ -12,5 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -// package kv provides basic key and value types. -package kv // import "go.opentelemetry.io/otel/api/kv" +// Package label provides key and value labels. +package label // import "go.opentelemetry.io/otel/label" diff --git a/api/label/encoder.go b/label/encoder.go similarity index 98% rename from api/label/encoder.go rename to label/encoder.go index 915b437dd69..17e6d2dfb25 100644 --- a/api/label/encoder.go +++ b/label/encoder.go @@ -18,8 +18,6 @@ import ( "bytes" "sync" "sync/atomic" - - "go.opentelemetry.io/otel/api/kv" ) type ( @@ -119,7 +117,7 @@ func (d *defaultLabelEncoder) Encode(iter Iterator) string { _, _ = buf.WriteRune('=') - if keyValue.Value.Type() == kv.STRING { + if keyValue.Value.Type() == STRING { copyAndEscape(buf, keyValue.Value.AsString()) } else { _, _ = buf.WriteString(keyValue.Value.Emit()) diff --git a/api/label/iterator.go b/label/iterator.go similarity index 87% rename from api/label/iterator.go rename to label/iterator.go index d2ab561854d..9e72239986c 100644 --- a/api/label/iterator.go +++ b/label/iterator.go @@ -14,10 +14,6 @@ package label -import ( - "go.opentelemetry.io/otel/api/kv" -) - // Iterator allows iterating over the set of labels in order, // sorted by key. type Iterator struct { @@ -31,13 +27,13 @@ type Iterator struct { type MergeItererator struct { one oneIterator two oneIterator - current kv.KeyValue + current KeyValue } type oneIterator struct { iter Iterator done bool - label kv.KeyValue + label KeyValue } // Next moves the iterator to the next position. Returns false if there @@ -47,21 +43,21 @@ func (i *Iterator) Next() bool { return i.idx < i.Len() } -// Label returns current kv.KeyValue. Must be called only after Next returns +// Label returns current KeyValue. Must be called only after Next returns // true. -func (i *Iterator) Label() kv.KeyValue { +func (i *Iterator) Label() KeyValue { kv, _ := i.storage.Get(i.idx) return kv } // Attribute is a synonym for Label(). -func (i *Iterator) Attribute() kv.KeyValue { +func (i *Iterator) Attribute() KeyValue { return i.Label() } // IndexedLabel returns current index and label. Must be called only // after Next returns true. -func (i *Iterator) IndexedLabel() (int, kv.KeyValue) { +func (i *Iterator) IndexedLabel() (int, KeyValue) { return i.idx, i.Label() } @@ -73,13 +69,13 @@ func (i *Iterator) Len() int { // ToSlice is a convenience function that creates a slice of labels // from the passed iterator. The iterator is set up to start from the // beginning before creating the slice. -func (i *Iterator) ToSlice() []kv.KeyValue { +func (i *Iterator) ToSlice() []KeyValue { l := i.Len() if l == 0 { return nil } i.idx = -1 - slice := make([]kv.KeyValue, 0, l) + slice := make([]KeyValue, 0, l) for i.Next() { slice = append(slice, i.Label()) } @@ -142,6 +138,6 @@ func (m *MergeItererator) Next() bool { } // Label returns the current value after Next() returns true. -func (m *MergeItererator) Label() kv.KeyValue { +func (m *MergeItererator) Label() KeyValue { return m.current } diff --git a/api/label/iterator_test.go b/label/iterator_test.go similarity index 92% rename from api/label/iterator_test.go rename to label/iterator_test.go index f210b3ccaa3..a028f8d0a98 100644 --- a/api/label/iterator_test.go +++ b/label/iterator_test.go @@ -18,16 +18,14 @@ import ( "fmt" "testing" - "go.opentelemetry.io/otel/api/kv" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/label" + "go.opentelemetry.io/otel/label" ) func TestIterator(t *testing.T) { - one := kv.String("one", "1") - two := kv.Int("two", 2) + one := label.String("one", "1") + two := label.Int("two", 2) lbl := label.NewSet(one, two) iter := lbl.Iter() require.Equal(t, 2, iter.Len()) @@ -66,9 +64,9 @@ func TestMergedIterator(t *testing.T) { expect []string } - makeLabels := func(keys []string, num int) (result []kv.KeyValue) { + makeLabels := func(keys []string, num int) (result []label.KeyValue) { for _, k := range keys { - result = append(result, kv.Int(k, num)) + result = append(result, label.Int(k, num)) } return } diff --git a/api/kv/key.go b/label/key.go similarity index 85% rename from api/kv/key.go rename to label/key.go index a6ca9499864..7d723780990 100644 --- a/api/kv/key.go +++ b/label/key.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv +package label // Key represents the key part in key-value pairs. It's a string. The // allowed character set in the key depends on the use of the key. @@ -21,7 +21,7 @@ type Key string // Bool creates a KeyValue instance with a BOOL Value. // // If creating both key and a bool value at the same time, then -// instead of calling kv.Key(name).Bool(value) consider using a +// instead of calling Key(name).Bool(value) consider using a // convenience function provided by the api/key package - // key.Bool(name, value). func (k Key) Bool(v bool) KeyValue { @@ -34,7 +34,7 @@ func (k Key) Bool(v bool) KeyValue { // Int64 creates a KeyValue instance with an INT64 Value. // // If creating both key and an int64 value at the same time, then -// instead of calling kv.Key(name).Int64(value) consider using a +// instead of calling Key(name).Int64(value) consider using a // convenience function provided by the api/key package - // key.Int64(name, value). func (k Key) Int64(v int64) KeyValue { @@ -47,7 +47,7 @@ func (k Key) Int64(v int64) KeyValue { // Uint64 creates a KeyValue instance with a UINT64 Value. // // If creating both key and a uint64 value at the same time, then -// instead of calling kv.Key(name).Uint64(value) consider using a +// instead of calling Key(name).Uint64(value) consider using a // convenience function provided by the api/key package - // key.Uint64(name, value). func (k Key) Uint64(v uint64) KeyValue { @@ -60,7 +60,7 @@ func (k Key) Uint64(v uint64) KeyValue { // Float64 creates a KeyValue instance with a FLOAT64 Value. // // If creating both key and a float64 value at the same time, then -// instead of calling kv.Key(name).Float64(value) consider using a +// instead of calling Key(name).Float64(value) consider using a // convenience function provided by the api/key package - // key.Float64(name, value). func (k Key) Float64(v float64) KeyValue { @@ -73,7 +73,7 @@ func (k Key) Float64(v float64) KeyValue { // Int32 creates a KeyValue instance with an INT32 Value. // // If creating both key and an int32 value at the same time, then -// instead of calling kv.Key(name).Int32(value) consider using a +// instead of calling Key(name).Int32(value) consider using a // convenience function provided by the api/key package - // key.Int32(name, value). func (k Key) Int32(v int32) KeyValue { @@ -86,7 +86,7 @@ func (k Key) Int32(v int32) KeyValue { // Uint32 creates a KeyValue instance with a UINT32 Value. // // If creating both key and a uint32 value at the same time, then -// instead of calling kv.Key(name).Uint32(value) consider using a +// instead of calling Key(name).Uint32(value) consider using a // convenience function provided by the api/key package - // key.Uint32(name, value). func (k Key) Uint32(v uint32) KeyValue { @@ -99,7 +99,7 @@ func (k Key) Uint32(v uint32) KeyValue { // Float32 creates a KeyValue instance with a FLOAT32 Value. // // If creating both key and a float32 value at the same time, then -// instead of calling kv.Key(name).Float32(value) consider using a +// instead of calling Key(name).Float32(value) consider using a // convenience function provided by the api/key package - // key.Float32(name, value). func (k Key) Float32(v float32) KeyValue { @@ -112,7 +112,7 @@ func (k Key) Float32(v float32) KeyValue { // String creates a KeyValue instance with a STRING Value. // // If creating both key and a string value at the same time, then -// instead of calling kv.Key(name).String(value) consider using a +// instead of calling Key(name).String(value) consider using a // convenience function provided by the api/key package - // key.String(name, value). func (k Key) String(v string) KeyValue { @@ -126,7 +126,7 @@ func (k Key) String(v string) KeyValue { // Value, depending on whether the int type is 32 or 64 bits wide. // // If creating both key and an int value at the same time, then -// instead of calling kv.Key(name).Int(value) consider using a +// instead of calling Key(name).Int(value) consider using a // convenience function provided by the api/key package - // key.Int(name, value). func (k Key) Int(v int) KeyValue { @@ -140,7 +140,7 @@ func (k Key) Int(v int) KeyValue { // Value, depending on whether the uint type is 32 or 64 bits wide. // // If creating both key and a uint value at the same time, then -// instead of calling kv.Key(name).Uint(value) consider using a +// instead of calling Key(name).Uint(value) consider using a // convenience function provided by the api/key package - // key.Uint(name, value). func (k Key) Uint(v uint) KeyValue { @@ -158,7 +158,7 @@ func (k Key) Defined() bool { // Array creates a KeyValue instance with a ARRAY Value. // // If creating both key and a array value at the same time, then -// instead of calling kv.Key(name).String(value) consider using a +// instead of calling Key(name).String(value) consider using a // convenience function provided by the api/key package - // key.Array(name, value). func (k Key) Array(v interface{}) KeyValue { diff --git a/api/kv/key_test.go b/label/key_test.go similarity index 80% rename from api/kv/key_test.go rename to label/key_test.go index d79031ff947..eacdea92768 100644 --- a/api/kv/key_test.go +++ b/label/key_test.go @@ -12,36 +12,36 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv_test +package label_test import ( "encoding/json" "testing" - "go.opentelemetry.io/otel/api/kv" - "github.com/stretchr/testify/require" + + "go.opentelemetry.io/otel/label" ) func TestDefined(t *testing.T) { for _, testcase := range []struct { name string - k kv.Key + k label.Key want bool }{ { name: "Key.Defined() returns true when len(v.Name) != 0", - k: kv.Key("foo"), + k: label.Key("foo"), want: true, }, { name: "Key.Defined() returns false when len(v.Name) == 0", - k: kv.Key(""), + k: label.Key(""), want: false, }, } { t.Run(testcase.name, func(t *testing.T) { - //func (k kv.Key) Defined() bool { + //func (k label.Key) Defined() bool { have := testcase.k.Defined() if have != testcase.want { t.Errorf("Want: %v, but have: %v", testcase.want, have) @@ -51,9 +51,9 @@ func TestDefined(t *testing.T) { } func TestJSONValue(t *testing.T) { - var kvs interface{} = [2]kv.KeyValue{ - kv.String("A", "B"), - kv.Int64("C", 1), + var kvs interface{} = [2]label.KeyValue{ + label.String("A", "B"), + label.Int64("C", 1), } data, err := json.Marshal(kvs) @@ -66,52 +66,52 @@ func TestJSONValue(t *testing.T) { func TestEmit(t *testing.T) { for _, testcase := range []struct { name string - v kv.Value + v label.Value want string }{ { name: `test Key.Emit() can emit a string representing self.BOOL`, - v: kv.BoolValue(true), + v: label.BoolValue(true), want: "true", }, { name: `test Key.Emit() can emit a string representing self.INT32`, - v: kv.Int32Value(42), + v: label.Int32Value(42), want: "42", }, { name: `test Key.Emit() can emit a string representing self.INT64`, - v: kv.Int64Value(42), + v: label.Int64Value(42), want: "42", }, { name: `test Key.Emit() can emit a string representing self.UINT32`, - v: kv.Uint32Value(42), + v: label.Uint32Value(42), want: "42", }, { name: `test Key.Emit() can emit a string representing self.UINT64`, - v: kv.Uint64Value(42), + v: label.Uint64Value(42), want: "42", }, { name: `test Key.Emit() can emit a string representing self.FLOAT32`, - v: kv.Float32Value(42.1), + v: label.Float32Value(42.1), want: "42.1", }, { name: `test Key.Emit() can emit a string representing self.FLOAT64`, - v: kv.Float64Value(42.1), + v: label.Float64Value(42.1), want: "42.1", }, { name: `test Key.Emit() can emit a string representing self.STRING`, - v: kv.StringValue("foo"), + v: label.StringValue("foo"), want: "foo", }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (v kv.Value) Emit() string { + //proto: func (v label.Value) Emit() string { have := testcase.v.Emit() if have != testcase.want { t.Errorf("Want: %s, but have: %s", testcase.want, have) diff --git a/api/kv/kv.go b/label/kv.go similarity index 99% rename from api/kv/kv.go rename to label/kv.go index c09823e85df..3e2764f4735 100644 --- a/api/kv/kv.go +++ b/label/kv.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv +package label import ( "encoding/json" diff --git a/api/kv/kv_test.go b/label/kv_test.go similarity index 69% rename from api/kv/kv_test.go rename to label/kv_test.go index 018dd878f34..068d2932381 100644 --- a/api/kv/kv_test.go +++ b/label/kv_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv_test +package label_test import ( "strings" @@ -20,100 +20,100 @@ import ( "github.com/google/go-cmp/cmp" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) func TestKeyValueConstructors(t *testing.T) { tt := []struct { name string - actual kv.KeyValue - expected kv.KeyValue + actual label.KeyValue + expected label.KeyValue }{ { name: "Bool", - actual: kv.Bool("k1", true), - expected: kv.KeyValue{ + actual: label.Bool("k1", true), + expected: label.KeyValue{ Key: "k1", - Value: kv.BoolValue(true), + Value: label.BoolValue(true), }, }, { name: "Int64", - actual: kv.Int64("k1", 123), - expected: kv.KeyValue{ + actual: label.Int64("k1", 123), + expected: label.KeyValue{ Key: "k1", - Value: kv.Int64Value(123), + Value: label.Int64Value(123), }, }, { name: "Uint64", - actual: kv.Uint64("k1", 1), - expected: kv.KeyValue{ + actual: label.Uint64("k1", 1), + expected: label.KeyValue{ Key: "k1", - Value: kv.Uint64Value(1), + Value: label.Uint64Value(1), }, }, { name: "Float64", - actual: kv.Float64("k1", 123.5), - expected: kv.KeyValue{ + actual: label.Float64("k1", 123.5), + expected: label.KeyValue{ Key: "k1", - Value: kv.Float64Value(123.5), + Value: label.Float64Value(123.5), }, }, { name: "Int32", - actual: kv.Int32("k1", 123), - expected: kv.KeyValue{ + actual: label.Int32("k1", 123), + expected: label.KeyValue{ Key: "k1", - Value: kv.Int32Value(123), + Value: label.Int32Value(123), }, }, { name: "Uint32", - actual: kv.Uint32("k1", 123), - expected: kv.KeyValue{ + actual: label.Uint32("k1", 123), + expected: label.KeyValue{ Key: "k1", - Value: kv.Uint32Value(123), + Value: label.Uint32Value(123), }, }, { name: "Float32", - actual: kv.Float32("k1", 123.5), - expected: kv.KeyValue{ + actual: label.Float32("k1", 123.5), + expected: label.KeyValue{ Key: "k1", - Value: kv.Float32Value(123.5), + Value: label.Float32Value(123.5), }, }, { name: "String", - actual: kv.String("k1", "123.5"), - expected: kv.KeyValue{ + actual: label.String("k1", "123.5"), + expected: label.KeyValue{ Key: "k1", - Value: kv.StringValue("123.5"), + Value: label.StringValue("123.5"), }, }, { name: "Int", - actual: kv.Int("k1", 123), - expected: kv.KeyValue{ + actual: label.Int("k1", 123), + expected: label.KeyValue{ Key: "k1", - Value: kv.IntValue(123), + Value: label.IntValue(123), }, }, { name: "Uint", - actual: kv.Uint("k1", 123), - expected: kv.KeyValue{ + actual: label.Uint("k1", 123), + expected: label.KeyValue{ Key: "k1", - Value: kv.UintValue(123), + Value: label.UintValue(123), }, }, } for _, test := range tt { t.Run(test.name, func(t *testing.T) { - if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(kv.Value{})); diff != "" { + if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(label.Value{})); diff != "" { t.Fatal(diff) } }) @@ -137,84 +137,84 @@ func TestAny(t *testing.T) { for _, testcase := range []struct { key string value interface{} - wantType kv.Type + wantType label.Type wantValue interface{} }{ { key: "bool type inferred", value: true, - wantType: kv.BOOL, + wantType: label.BOOL, wantValue: true, }, { key: "int64 type inferred", value: int64(42), - wantType: kv.INT64, + wantType: label.INT64, wantValue: int64(42), }, { key: "uint64 type inferred", value: uint64(42), - wantType: kv.UINT64, + wantType: label.UINT64, wantValue: uint64(42), }, { key: "float64 type inferred", value: float64(42.1), - wantType: kv.FLOAT64, + wantType: label.FLOAT64, wantValue: 42.1, }, { key: "int32 type inferred", value: int32(42), - wantType: kv.INT32, + wantType: label.INT32, wantValue: int32(42), }, { key: "uint32 type inferred", value: uint32(42), - wantType: kv.UINT32, + wantType: label.UINT32, wantValue: uint32(42), }, { key: "float32 type inferred", value: float32(42.1), - wantType: kv.FLOAT32, + wantType: label.FLOAT32, wantValue: float32(42.1), }, { key: "string type inferred", value: "foo", - wantType: kv.STRING, + wantType: label.STRING, wantValue: "foo", }, { key: "stringer type inferred", value: builder, - wantType: kv.STRING, + wantType: label.STRING, wantValue: "foo", }, { key: "unknown value serialized as %v", value: nil, - wantType: kv.STRING, + wantType: label.STRING, wantValue: "", }, { key: "JSON struct serialized correctly", value: &jsonifyStruct, - wantType: kv.STRING, + wantType: label.STRING, wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`, }, { key: "Invalid JSON struct falls back to string", value: &invalidStruct, - wantType: kv.STRING, + wantType: label.STRING, wantValue: "&{(0+0i)}", }, } { t.Logf("Running test case %s", testcase.key) - keyValue := kv.Any(testcase.key, testcase.value) + keyValue := label.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) } diff --git a/api/label/set.go b/label/set.go similarity index 84% rename from api/label/set.go rename to label/set.go index 789def769a5..3bd5263cbd3 100644 --- a/api/label/set.go +++ b/label/set.go @@ -12,15 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/api/label" +package label import ( "encoding/json" "reflect" "sort" "sync" - - "go.opentelemetry.io/otel/api/kv" ) type ( @@ -43,7 +41,7 @@ type ( encoded [maxConcurrentEncoders]string } - // Distinct wraps a variable-size array of `kv.KeyValue`, + // Distinct wraps a variable-size array of `KeyValue`, // constructed with keys in sorted order. This can be used as // a map key or for equality checking between Sets. Distinct struct { @@ -55,25 +53,25 @@ type ( // the filtered label set. When the filter returns false, the // label is excluded from the filtered label set, and the // label instead appears in the `removed` list of excluded labels. - Filter func(kv.KeyValue) bool + Filter func(KeyValue) bool // Sortable implements `sort.Interface`, used for sorting - // `kv.KeyValue`. This is an exported type to support a + // `KeyValue`. This is an exported type to support a // memory optimization. A pointer to one of these is needed // for the call to `sort.Stable()`, which the caller may // provide in order to avoid an allocation. See // `NewSetWithSortable()`. - Sortable []kv.KeyValue + Sortable []KeyValue ) var ( // keyValueType is used in `computeDistinctReflect`. - keyValueType = reflect.TypeOf(kv.KeyValue{}) + keyValueType = reflect.TypeOf(KeyValue{}) // emptySet is returned for empty label sets. emptySet = &Set{ equivalent: Distinct{ - iface: [0]kv.KeyValue{}, + iface: [0]KeyValue{}, }, } ) @@ -103,44 +101,44 @@ func (l *Set) Len() int { } // Get returns the KeyValue at ordered position `idx` in this set. -func (l *Set) Get(idx int) (kv.KeyValue, bool) { +func (l *Set) Get(idx int) (KeyValue, bool) { if l == nil { - return kv.KeyValue{}, false + return KeyValue{}, false } value := l.equivalent.reflect() if idx >= 0 && idx < value.Len() { // Note: The Go compiler successfully avoids an allocation for // the interface{} conversion here: - return value.Index(idx).Interface().(kv.KeyValue), true + return value.Index(idx).Interface().(KeyValue), true } - return kv.KeyValue{}, false + return KeyValue{}, false } // Value returns the value of a specified key in this set. -func (l *Set) Value(k kv.Key) (kv.Value, bool) { +func (l *Set) Value(k Key) (Value, bool) { if l == nil { - return kv.Value{}, false + return Value{}, false } rValue := l.equivalent.reflect() vlen := rValue.Len() idx := sort.Search(vlen, func(idx int) bool { - return rValue.Index(idx).Interface().(kv.KeyValue).Key >= k + return rValue.Index(idx).Interface().(KeyValue).Key >= k }) if idx >= vlen { - return kv.Value{}, false + return Value{}, false } - keyValue := rValue.Index(idx).Interface().(kv.KeyValue) + keyValue := rValue.Index(idx).Interface().(KeyValue) if k == keyValue.Key { return keyValue.Value, true } - return kv.Value{}, false + return Value{}, false } // HasValue tests whether a key is defined in this set. -func (l *Set) HasValue(k kv.Key) bool { +func (l *Set) HasValue(k Key) bool { if l == nil { return false } @@ -158,7 +156,7 @@ func (l *Set) Iter() Iterator { // ToSlice returns the set of labels belonging to this set, sorted, // where keys appear no more than once. -func (l *Set) ToSlice() []kv.KeyValue { +func (l *Set) ToSlice() []KeyValue { iter := l.Iter() return iter.ToSlice() } @@ -239,7 +237,7 @@ func empty() Set { // // Except for empty sets, this method adds an additional allocation // compared with calls that include a `*Sortable`. -func NewSet(kvs ...kv.KeyValue) Set { +func NewSet(kvs ...KeyValue) Set { // Check for empty set. if len(kvs) == 0 { return empty() @@ -252,7 +250,7 @@ func NewSet(kvs ...kv.KeyValue) Set { // `NewSetWithSortableFiltered` for more details. // // This call includes a `*Sortable` option as a memory optimization. -func NewSetWithSortable(kvs []kv.KeyValue, tmp *Sortable) Set { +func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set { // Check for empty set. if len(kvs) == 0 { return empty() @@ -267,7 +265,7 @@ func NewSetWithSortable(kvs []kv.KeyValue, tmp *Sortable) Set { // This call includes a `Filter` to include/exclude label keys from // the return value. Excluded keys are returned as a slice of label // values. -func NewSetWithFiltered(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) { +func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) { // Check for empty set. if len(kvs) == 0 { return empty(), nil @@ -297,9 +295,9 @@ func NewSetWithFiltered(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) { // The result maintains a cache of encoded labels, by label.EncoderID. // This value should not be copied after its first use. // -// The second `[]kv.KeyValue` return value is a list of labels that were +// The second `[]KeyValue` return value is a list of labels that were // excluded by the Filter (if non-nil). -func NewSetWithSortableFiltered(kvs []kv.KeyValue, tmp *Sortable, filter Filter) (Set, []kv.KeyValue) { +func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (Set, []KeyValue) { // Check for empty set. if len(kvs) == 0 { return empty(), nil @@ -339,8 +337,8 @@ func NewSetWithSortableFiltered(kvs []kv.KeyValue, tmp *Sortable, filter Filter) // filterSet reorders `kvs` so that included keys are contiguous at // the end of the slice, while excluded keys precede the included keys. -func filterSet(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) { - var excluded []kv.KeyValue +func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) { + var excluded []KeyValue // Move labels that do not match the filter so // they're adjacent before calling computeDistinct(). @@ -365,7 +363,7 @@ func filterSet(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) { // Filter returns a filtered copy of this `Set`. See the // documentation for `NewSetWithSortableFiltered` for more details. -func (l *Set) Filter(re Filter) (Set, []kv.KeyValue) { +func (l *Set) Filter(re Filter) (Set, []KeyValue) { if re == nil { return Set{ equivalent: l.equivalent, @@ -380,7 +378,7 @@ func (l *Set) Filter(re Filter) (Set, []kv.KeyValue) { // computeDistinct returns a `Distinct` using either the fixed- or // reflect-oriented code path, depending on the size of the input. // The input slice is assumed to already be sorted and de-duplicated. -func computeDistinct(kvs []kv.KeyValue) Distinct { +func computeDistinct(kvs []KeyValue) Distinct { iface := computeDistinctFixed(kvs) if iface == nil { iface = computeDistinctReflect(kvs) @@ -392,46 +390,46 @@ func computeDistinct(kvs []kv.KeyValue) Distinct { // computeDistinctFixed computes a `Distinct` for small slices. It // returns nil if the input is too large for this code path. -func computeDistinctFixed(kvs []kv.KeyValue) interface{} { +func computeDistinctFixed(kvs []KeyValue) interface{} { switch len(kvs) { case 1: - ptr := new([1]kv.KeyValue) + ptr := new([1]KeyValue) copy((*ptr)[:], kvs) return *ptr case 2: - ptr := new([2]kv.KeyValue) + ptr := new([2]KeyValue) copy((*ptr)[:], kvs) return *ptr case 3: - ptr := new([3]kv.KeyValue) + ptr := new([3]KeyValue) copy((*ptr)[:], kvs) return *ptr case 4: - ptr := new([4]kv.KeyValue) + ptr := new([4]KeyValue) copy((*ptr)[:], kvs) return *ptr case 5: - ptr := new([5]kv.KeyValue) + ptr := new([5]KeyValue) copy((*ptr)[:], kvs) return *ptr case 6: - ptr := new([6]kv.KeyValue) + ptr := new([6]KeyValue) copy((*ptr)[:], kvs) return *ptr case 7: - ptr := new([7]kv.KeyValue) + ptr := new([7]KeyValue) copy((*ptr)[:], kvs) return *ptr case 8: - ptr := new([8]kv.KeyValue) + ptr := new([8]KeyValue) copy((*ptr)[:], kvs) return *ptr case 9: - ptr := new([9]kv.KeyValue) + ptr := new([9]KeyValue) copy((*ptr)[:], kvs) return *ptr case 10: - ptr := new([10]kv.KeyValue) + ptr := new([10]KeyValue) copy((*ptr)[:], kvs) return *ptr default: @@ -441,10 +439,10 @@ func computeDistinctFixed(kvs []kv.KeyValue) interface{} { // computeDistinctReflect computes a `Distinct` using reflection, // works for any size input. -func computeDistinctReflect(kvs []kv.KeyValue) interface{} { +func computeDistinctReflect(kvs []KeyValue) interface{} { at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem() for i, keyValue := range kvs { - *(at.Index(i).Addr().Interface().(*kv.KeyValue)) = keyValue + *(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue } return at.Interface() } diff --git a/api/label/set_test.go b/label/set_test.go similarity index 66% rename from api/label/set_test.go rename to label/set_test.go index 7dbc8c83697..7f6fc0fef67 100644 --- a/api/label/set_test.go +++ b/label/set_test.go @@ -18,14 +18,13 @@ import ( "regexp" "testing" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" + "go.opentelemetry.io/otel/label" "github.com/stretchr/testify/require" ) type testCase struct { - kvs []kv.KeyValue + kvs []label.KeyValue keyRe *regexp.Regexp @@ -33,14 +32,14 @@ type testCase struct { fullEnc string } -func expect(enc string, kvs ...kv.KeyValue) testCase { +func expect(enc string, kvs ...label.KeyValue) testCase { return testCase{ kvs: kvs, encoding: enc, } } -func expectFiltered(enc, filter, fullEnc string, kvs ...kv.KeyValue) testCase { +func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase { return testCase{ kvs: kvs, keyRe: regexp.MustCompile(filter), @@ -51,16 +50,16 @@ func expectFiltered(enc, filter, fullEnc string, kvs ...kv.KeyValue) testCase { func TestSetDedup(t *testing.T) { cases := []testCase{ - expect("A=B", kv.String("A", "2"), kv.String("A", "B")), - expect("A=B", kv.String("A", "2"), kv.Int("A", 1), kv.String("A", "B")), - expect("A=B", kv.String("A", "B"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B")), - - expect("A=B,C=D", kv.String("A", "1"), kv.String("C", "D"), kv.String("A", "B")), - expect("A=B,C=D", kv.String("A", "2"), kv.String("A", "B"), kv.String("C", "D")), - expect("A=B,C=D", kv.Float64("C", 1.2), kv.String("A", "2"), kv.String("A", "B"), kv.String("C", "D")), - expect("A=B,C=D", kv.String("C", "D"), kv.String("A", "B"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B")), - expect("A=B,C=D", kv.String("A", "B"), kv.String("C", "D"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B")), - expect("A=B,C=D", kv.String("A", "B"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B"), kv.String("C", "D")), + expect("A=B", label.String("A", "2"), label.String("A", "B")), + expect("A=B", label.String("A", "2"), label.Int("A", 1), label.String("A", "B")), + expect("A=B", label.String("A", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B")), + + expect("A=B,C=D", label.String("A", "1"), label.String("C", "D"), label.String("A", "B")), + expect("A=B,C=D", label.String("A", "2"), label.String("A", "B"), label.String("C", "D")), + expect("A=B,C=D", label.Float64("C", 1.2), label.String("A", "2"), label.String("A", "B"), label.String("C", "D")), + expect("A=B,C=D", label.String("C", "D"), label.String("A", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B")), + expect("A=B,C=D", label.String("A", "B"), label.String("C", "D"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B")), + expect("A=B,C=D", label.String("A", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B"), label.String("C", "D")), } enc := label.DefaultEncoder() @@ -68,7 +67,7 @@ func TestSetDedup(t *testing.T) { d2s := map[label.Distinct][]string{} for _, tc := range cases { - cpy := make([]kv.KeyValue, len(tc.kvs)) + cpy := make([]label.KeyValue, len(tc.kvs)) copy(cpy, tc.kvs) sl := label.NewSet(cpy...) @@ -130,19 +129,19 @@ func TestSetDedup(t *testing.T) { } func TestUniqueness(t *testing.T) { - short := []kv.KeyValue{ - kv.String("A", "0"), - kv.String("B", "2"), - kv.String("A", "1"), + short := []label.KeyValue{ + label.String("A", "0"), + label.String("B", "2"), + label.String("A", "1"), } - long := []kv.KeyValue{ - kv.String("B", "2"), - kv.String("C", "5"), - kv.String("B", "2"), - kv.String("C", "1"), - kv.String("A", "4"), - kv.String("C", "3"), - kv.String("A", "1"), + long := []label.KeyValue{ + label.String("B", "2"), + label.String("C", "5"), + label.String("B", "2"), + label.String("C", "1"), + label.String("A", "4"), + label.String("C", "3"), + label.String("A", "1"), } cases := []testCase{ expectFiltered("A=1", "^A$", "B=2", short...), @@ -158,9 +157,9 @@ func TestUniqueness(t *testing.T) { enc := label.DefaultEncoder() for _, tc := range cases { - cpy := make([]kv.KeyValue, len(tc.kvs)) + cpy := make([]label.KeyValue, len(tc.kvs)) copy(cpy, tc.kvs) - distinct, uniq := label.NewSetWithFiltered(cpy, func(label kv.KeyValue) bool { + distinct, uniq := label.NewSetWithFiltered(cpy, func(label label.KeyValue) bool { return tc.keyRe.MatchString(string(label.Key)) }) @@ -172,7 +171,7 @@ func TestUniqueness(t *testing.T) { } func TestLookup(t *testing.T) { - set := label.NewSet(kv.Int("C", 3), kv.Int("A", 1), kv.Int("B", 2)) + set := label.NewSet(label.Int("C", 3), label.Int("A", 1), label.Int("B", 2)) value, has := set.Value("C") require.True(t, has) diff --git a/api/kv/type_string.go b/label/type_string.go similarity index 98% rename from api/kv/type_string.go rename to label/type_string.go index 7b1d143ef2e..62afeb60af7 100644 --- a/api/kv/type_string.go +++ b/label/type_string.go @@ -1,6 +1,6 @@ // Code generated by "stringer -type=Type"; DO NOT EDIT. -package kv +package label import "strconv" diff --git a/api/kv/value.go b/label/value.go similarity index 99% rename from api/kv/value.go rename to label/value.go index fa44cfd9d52..633979f1b38 100644 --- a/api/kv/value.go +++ b/label/value.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv +package label import ( "encoding/json" @@ -22,7 +22,7 @@ import ( "strings" "unsafe" - "go.opentelemetry.io/otel/api/internal" + "go.opentelemetry.io/otel/internal" ) //go:generate stringer -type=Type diff --git a/api/kv/value_test.go b/label/value_test.go similarity index 86% rename from api/kv/value_test.go rename to label/value_test.go index 5d7e9bb1c3c..70685945b50 100644 --- a/api/kv/value_test.go +++ b/label/value_test.go @@ -12,78 +12,78 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kv_test +package label_test import ( "testing" "unsafe" - "go.opentelemetry.io/otel/api/kv" - "github.com/google/go-cmp/cmp" + + "go.opentelemetry.io/otel/label" ) func TestValue(t *testing.T) { - k := kv.Key("test") + k := label.Key("test") bli := getBitlessInfo(42) for _, testcase := range []struct { name string - value kv.Value - wantType kv.Type + value label.Value + wantType label.Type wantValue interface{} }{ { name: "Key.Bool() correctly returns keys's internal bool value", value: k.Bool(true).Value, - wantType: kv.BOOL, + wantType: label.BOOL, wantValue: true, }, { name: "Key.Array([]bool) correctly return key's internal bool values", value: k.Array([]bool{true, false}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []bool{true, false}, }, { name: "Key.Int64() correctly returns keys's internal int64 value", value: k.Int64(42).Value, - wantType: kv.INT64, + wantType: label.INT64, wantValue: int64(42), }, { name: "Key.Uint64() correctly returns keys's internal uint64 value", value: k.Uint64(42).Value, - wantType: kv.UINT64, + wantType: label.UINT64, wantValue: uint64(42), }, { name: "Key.Float64() correctly returns keys's internal float64 value", value: k.Float64(42.1).Value, - wantType: kv.FLOAT64, + wantType: label.FLOAT64, wantValue: 42.1, }, { name: "Key.Int32() correctly returns keys's internal int32 value", value: k.Int32(42).Value, - wantType: kv.INT32, + wantType: label.INT32, wantValue: int32(42), }, { name: "Key.Uint32() correctly returns keys's internal uint32 value", value: k.Uint32(42).Value, - wantType: kv.UINT32, + wantType: label.UINT32, wantValue: uint32(42), }, { name: "Key.Float32() correctly returns keys's internal float32 value", value: k.Float32(42.1).Value, - wantType: kv.FLOAT32, + wantType: label.FLOAT32, wantValue: float32(42.1), }, { name: "Key.String() correctly returns keys's internal string value", value: k.String("foo").Value, - wantType: kv.STRING, + wantType: label.STRING, wantValue: "foo", }, { @@ -101,61 +101,61 @@ func TestValue(t *testing.T) { { name: "Key.Array([]int64) correctly returns keys's internal int64 values", value: k.Array([]int64{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []int64{42, 43}, }, { name: "KeyArray([]uint64) correctly returns keys's internal uint64 values", value: k.Array([]uint64{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []uint64{42, 43}, }, { name: "Key.Array([]float64) correctly returns keys's internal float64 values", value: k.Array([]float64{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []float64{42, 43}, }, { name: "Key.Array([]int32) correctly returns keys's internal int32 values", value: k.Array([]int32{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []int32{42, 43}, }, { name: "Key.Array([]uint32) correctly returns keys's internal uint32 values", value: k.Array([]uint32{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []uint32{42, 43}, }, { name: "Key.Array([]float32) correctly returns keys's internal float32 values", value: k.Array([]float32{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []float32{42, 43}, }, { name: "Key.Array([]string) correctly return key's internal string values", value: k.Array([]string{"foo", "bar"}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []string{"foo", "bar"}, }, { name: "Key.Array([]int) correctly returns keys's internal signed integral values", value: k.Array([]int{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []int{42, 43}, }, { name: "Key.Array([]uint) correctly returns keys's internal unsigned integral values", value: k.Array([]uint{42, 43}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: []uint{42, 43}, }, { name: "Key.Array([][]int) correctly return key's multi dimensional array", value: k.Array([][]int{{1, 2}, {3, 4}}).Value, - wantType: kv.ARRAY, + wantType: label.ARRAY, wantValue: [][]int{{1, 2}, {3, 4}}, }, } { @@ -173,8 +173,8 @@ func TestValue(t *testing.T) { type bitlessInfo struct { intValue int uintValue uint - signedType kv.Type - unsignedType kv.Type + signedType label.Type + unsignedType label.Type signedValue interface{} unsignedValue interface{} } @@ -184,8 +184,8 @@ func getBitlessInfo(i int) bitlessInfo { return bitlessInfo{ intValue: i, uintValue: uint(i), - signedType: kv.INT32, - unsignedType: kv.UINT32, + signedType: label.INT32, + unsignedType: label.UINT32, signedValue: int32(i), unsignedValue: uint32(i), } @@ -193,8 +193,8 @@ func getBitlessInfo(i int) bitlessInfo { return bitlessInfo{ intValue: i, uintValue: uint(i), - signedType: kv.INT64, - unsignedType: kv.UINT64, + signedType: label.INT64, + unsignedType: label.UINT64, signedValue: int64(i), unsignedValue: uint64(i), } diff --git a/sdk/export/metric/metric.go b/sdk/export/metric/metric.go index fd6fb616bb4..b0996a7128b 100644 --- a/sdk/export/metric/metric.go +++ b/sdk/export/metric/metric.go @@ -21,8 +21,8 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/resource" ) diff --git a/sdk/export/metric/metric_test.go b/sdk/export/metric/metric_test.go index bfb575e3569..c8435b0f693 100644 --- a/sdk/export/metric/metric_test.go +++ b/sdk/export/metric/metric_test.go @@ -17,18 +17,17 @@ package metric import ( "testing" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" + "go.opentelemetry.io/otel/label" "github.com/stretchr/testify/require" ) -var testSlice = []kv.KeyValue{ - kv.String("bar", "baz"), - kv.Int("foo", 42), +var testSlice = []label.KeyValue{ + label.String("bar", "baz"), + label.Int("foo", 42), } -func newIter(slice []kv.KeyValue) label.Iterator { +func newIter(slice []label.KeyValue) label.Iterator { labels := label.NewSet(slice...) return labels.Iter() } @@ -38,17 +37,17 @@ func TestLabelIterator(t *testing.T) { require.Equal(t, 2, iter.Len()) require.True(t, iter.Next()) - require.Equal(t, kv.String("bar", "baz"), iter.Label()) - idx, label := iter.IndexedLabel() + require.Equal(t, label.String("bar", "baz"), iter.Label()) + idx, kv := iter.IndexedLabel() require.Equal(t, 0, idx) - require.Equal(t, kv.String("bar", "baz"), label) + require.Equal(t, label.String("bar", "baz"), kv) require.Equal(t, 2, iter.Len()) require.True(t, iter.Next()) - require.Equal(t, kv.Int("foo", 42), iter.Label()) - idx, label = iter.IndexedLabel() + require.Equal(t, label.Int("foo", 42), iter.Label()) + idx, kv = iter.IndexedLabel() require.Equal(t, 1, idx) - require.Equal(t, kv.Int("foo", 42), label) + require.Equal(t, label.Int("foo", 42), kv) require.Equal(t, 2, iter.Len()) require.False(t, iter.Next()) diff --git a/sdk/export/metric/metrictest/test.go b/sdk/export/metric/metrictest/test.go index 2ecece356b6..a8eb496b31a 100644 --- a/sdk/export/metric/metrictest/test.go +++ b/sdk/export/metric/metrictest/test.go @@ -21,9 +21,8 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/resource" @@ -92,7 +91,7 @@ func (p *CheckpointSet) Reset() { // // If there is an existing record with the same descriptor and labels, // the stored aggregator will be returned and should be merged. -func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...kv.KeyValue) (agg export.Aggregator, added bool) { +func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...label.KeyValue) (agg export.Aggregator, added bool) { elabels := label.NewSet(labels...) key := mapkey{ diff --git a/sdk/export/trace/trace.go b/sdk/export/trace/trace.go index 144da751862..169c1e77974 100644 --- a/sdk/export/trace/trace.go +++ b/sdk/export/trace/trace.go @@ -20,8 +20,8 @@ import ( "google.golang.org/grpc/codes" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/resource" ) @@ -57,7 +57,7 @@ type SpanData struct { // The wall clock time of EndTime will be adjusted to always be offset // from StartTime by the duration of the span. EndTime time.Time - Attributes []kv.KeyValue + Attributes []label.KeyValue MessageEvents []Event Links []apitrace.Link StatusCode codes.Code @@ -84,8 +84,8 @@ type Event struct { // Name is the name of this event Name string - // Attributes contains a list of kv pairs. - Attributes []kv.KeyValue + // Attributes contains a list of key-value pairs. + Attributes []label.KeyValue // Time is the time at which this event was recorded. Time time.Time diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 6331084b4c0..6fd2e73ecaf 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -21,9 +21,8 @@ import ( "testing" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" sdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/processor/processortest" @@ -60,8 +59,8 @@ func (f *benchFixture) meterMust() metric.MeterMust { return metric.Must(f.meter) } -func makeManyLabels(n int) [][]kv.KeyValue { - r := make([][]kv.KeyValue, n) +func makeManyLabels(n int) [][]label.KeyValue { + r := make([][]label.KeyValue, n) for i := 0; i < n; i++ { r[i] = makeLabels(1) @@ -70,9 +69,9 @@ func makeManyLabels(n int) [][]kv.KeyValue { return r } -func makeLabels(n int) []kv.KeyValue { +func makeLabels(n int) []label.KeyValue { used := map[string]bool{} - l := make([]kv.KeyValue, n) + l := make([]label.KeyValue, n) for i := 0; i < n; i++ { var k string for { @@ -82,7 +81,7 @@ func makeLabels(n int) []kv.KeyValue { break } } - l[i] = kv.Key(k).String(fmt.Sprint("v", rand.Intn(1000000000))) + l[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) } return l } @@ -169,7 +168,7 @@ func BenchmarkAcquireReleaseExistingHandle(b *testing.B) { // Iterators -var benchmarkIteratorVar kv.KeyValue +var benchmarkIteratorVar label.KeyValue func benchmarkIterator(b *testing.B, n int) { labels := label.NewSet(makeLabels(n)...) @@ -218,7 +217,7 @@ func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) { sdk := global.Meter("test") global.SetMeterProvider(fix) - labs := []kv.KeyValue{kv.String("A", "B")} + labs := []label.KeyValue{label.String("A", "B")} cnt := Must(sdk).NewInt64Counter("int64.counter") b.ResetTimer() @@ -539,7 +538,7 @@ func BenchmarkRepeatedDirectCalls(b *testing.B) { fix := newFixture(b) c := fix.meterMust().NewInt64Counter("int64.counter") - k := kv.String("bench", "true") + k := label.String("bench", "true") b.ResetTimer() diff --git a/sdk/metric/controller/pull/pull_test.go b/sdk/metric/controller/pull/pull_test.go index 0dbbd887d4c..f5a053b60ec 100644 --- a/sdk/metric/controller/pull/pull_test.go +++ b/sdk/metric/controller/pull/pull_test.go @@ -22,9 +22,8 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/metric/controller/controllertest" "go.opentelemetry.io/otel/sdk/metric/controller/pull" @@ -47,7 +46,7 @@ func TestPullNoCache(t *testing.T) { meter := puller.Provider().Meter("nocache") counter := metric.Must(meter).NewInt64Counter("counter.sum") - counter.Add(ctx, 10, kv.String("A", "B")) + counter.Add(ctx, 10, label.String("A", "B")) require.NoError(t, puller.Collect(ctx)) records := processortest.NewOutput(label.DefaultEncoder()) @@ -57,7 +56,7 @@ func TestPullNoCache(t *testing.T) { "counter.sum/A=B/": 10, }, records.Map()) - counter.Add(ctx, 10, kv.String("A", "B")) + counter.Add(ctx, 10, label.String("A", "B")) require.NoError(t, puller.Collect(ctx)) records = processortest.NewOutput(label.DefaultEncoder()) @@ -84,7 +83,7 @@ func TestPullWithCache(t *testing.T) { meter := puller.Provider().Meter("nocache") counter := metric.Must(meter).NewInt64Counter("counter.sum") - counter.Add(ctx, 10, kv.String("A", "B")) + counter.Add(ctx, 10, label.String("A", "B")) require.NoError(t, puller.Collect(ctx)) records := processortest.NewOutput(label.DefaultEncoder()) @@ -94,7 +93,7 @@ func TestPullWithCache(t *testing.T) { "counter.sum/A=B/": 10, }, records.Map()) - counter.Add(ctx, 10, kv.String("A", "B")) + counter.Add(ctx, 10, label.String("A", "B")) // Cached value! require.NoError(t, puller.Collect(ctx)) diff --git a/sdk/metric/controller/push/config_test.go b/sdk/metric/controller/push/config_test.go index 6d32a596793..d7079511f0c 100644 --- a/sdk/metric/controller/push/config_test.go +++ b/sdk/metric/controller/push/config_test.go @@ -17,15 +17,14 @@ package push import ( "testing" - "go.opentelemetry.io/otel/api/kv" - "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/resource" ) func TestWithResource(t *testing.T) { - r := resource.New(kv.String("A", "a")) + r := resource.New(label.String("A", "a")) c := &Config{} WithResource(r).Apply(c) diff --git a/sdk/metric/controller/push/push_test.go b/sdk/metric/controller/push/push_test.go index 795fbea0e1a..0e656f69556 100644 --- a/sdk/metric/controller/push/push_test.go +++ b/sdk/metric/controller/push/push_test.go @@ -25,9 +25,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/controller/controllertest" @@ -37,7 +36,7 @@ import ( "go.opentelemetry.io/otel/sdk/resource" ) -var testResource = resource.New(kv.String("R", "V")) +var testResource = resource.New(label.String("R", "V")) type handler struct { sync.Mutex @@ -201,7 +200,7 @@ func TestPushExportError(t *testing.T) { p.Start() runtime.Gosched() - counter1.Add(ctx, 3, kv.String("X", "Y")) + counter1.Add(ctx, 3, label.String("X", "Y")) counter2.Add(ctx, 5) require.Equal(t, 0, exporter.ExportCount()) diff --git a/sdk/metric/correct_test.go b/sdk/metric/correct_test.go index 01d9c2d4dbe..33ac7ee9d3c 100644 --- a/sdk/metric/correct_test.go +++ b/sdk/metric/correct_test.go @@ -24,9 +24,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" metricsdk "go.opentelemetry.io/otel/sdk/metric" @@ -35,7 +34,7 @@ import ( ) var Must = metric.Must -var testResource = resource.New(kv.String("R", "V")) +var testResource = resource.New(label.String("R", "V")) type handler struct { sync.Mutex @@ -209,19 +208,19 @@ func TestSDKLabelsDeduplication(t *testing.T) { keySets = 2 repeats = 3 ) - var keysA []kv.Key - var keysB []kv.Key + var keysA []label.Key + var keysB []label.Key for i := 0; i < maxKeys; i++ { - keysA = append(keysA, kv.Key(fmt.Sprintf("A%03d", i))) - keysB = append(keysB, kv.Key(fmt.Sprintf("B%03d", i))) + keysA = append(keysA, label.Key(fmt.Sprintf("A%03d", i))) + keysB = append(keysB, label.Key(fmt.Sprintf("B%03d", i))) } - var allExpect [][]kv.KeyValue + var allExpect [][]label.KeyValue for numKeys := 0; numKeys < maxKeys; numKeys++ { - var kvsA []kv.KeyValue - var kvsB []kv.KeyValue + var kvsA []label.KeyValue + var kvsB []label.KeyValue for r := 0; r < repeats; r++ { for i := 0; i < numKeys; i++ { kvsA = append(kvsA, keysA[i].Int(r)) @@ -229,8 +228,8 @@ func TestSDKLabelsDeduplication(t *testing.T) { } } - var expectA []kv.KeyValue - var expectB []kv.KeyValue + var expectA []label.KeyValue + var expectB []label.KeyValue for i := 0; i < numKeys; i++ { expectA = append(expectA, keysA[i].Int(repeats-1)) expectB = append(expectB, keysB[i].Int(repeats-1)) @@ -251,7 +250,7 @@ func TestSDKLabelsDeduplication(t *testing.T) { sdk.Collect(ctx) - var actual [][]kv.KeyValue + var actual [][]label.KeyValue for _, rec := range processor.accumulations { sum, _ := rec.Aggregator().(aggregation.Sum).Sum() require.Equal(t, sum, metric.NewInt64Number(2)) @@ -263,7 +262,7 @@ func TestSDKLabelsDeduplication(t *testing.T) { require.ElementsMatch(t, allExpect, actual) } -func newSetIter(kvs ...kv.KeyValue) label.Iterator { +func newSetIter(kvs ...label.KeyValue) label.Iterator { labels := label.NewSet(kvs...) return labels.Iter() } @@ -271,28 +270,28 @@ func newSetIter(kvs ...kv.KeyValue) label.Iterator { func TestDefaultLabelEncoder(t *testing.T) { encoder := label.DefaultEncoder() - encoded := encoder.Encode(newSetIter(kv.String("A", "B"), kv.String("C", "D"))) + encoded := encoder.Encode(newSetIter(label.String("A", "B"), label.String("C", "D"))) require.Equal(t, `A=B,C=D`, encoded) - encoded = encoder.Encode(newSetIter(kv.String("A", "B,c=d"), kv.String(`C\`, "D"))) + encoded = encoder.Encode(newSetIter(label.String("A", "B,c=d"), label.String(`C\`, "D"))) require.Equal(t, `A=B\,c\=d,C\\=D`, encoded) - encoded = encoder.Encode(newSetIter(kv.String(`\`, `=`), kv.String(`,`, `\`))) + encoded = encoder.Encode(newSetIter(label.String(`\`, `=`), label.String(`,`, `\`))) require.Equal(t, `\,=\\,\\=\=`, encoded) // Note: the label encoder does not sort or de-dup values, // that is done in Labels(...). encoded = encoder.Encode(newSetIter( - kv.Int("I", 1), - kv.Uint("U", 1), - kv.Int32("I32", 1), - kv.Uint32("U32", 1), - kv.Int64("I64", 1), - kv.Uint64("U64", 1), - kv.Float64("F64", 1), - kv.Float64("F64", 1), - kv.String("S", "1"), - kv.Bool("B", true), + label.Int("I", 1), + label.Uint("U", 1), + label.Int32("I32", 1), + label.Uint32("U32", 1), + label.Int64("I64", 1), + label.Uint64("U64", 1), + label.Float64("F64", 1), + label.Float64("F64", 1), + label.String("S", "1"), + label.Bool("B", true), )) require.Equal(t, "B=true,F64=1,I=1,I32=1,I64=1,S=1,U=1,U32=1,U64=1", encoded) } @@ -302,42 +301,42 @@ func TestObserverCollection(t *testing.T) { meter, sdk, processor := newSDK(t) _ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(1, kv.String("A", "B")) + result.Observe(1, label.String("A", "B")) // last value wins - result.Observe(-1, kv.String("A", "B")) - result.Observe(-1, kv.String("C", "D")) + result.Observe(-1, label.String("A", "B")) + result.Observe(-1, label.String("C", "D")) }) _ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(-1, kv.String("A", "B")) + result.Observe(-1, label.String("A", "B")) result.Observe(1) // last value wins - result.Observe(1, kv.String("A", "B")) + result.Observe(1, label.String("A", "B")) result.Observe(1) }) _ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(1, kv.String("A", "B")) - result.Observe(2, kv.String("A", "B")) - result.Observe(1, kv.String("C", "D")) + result.Observe(1, label.String("A", "B")) + result.Observe(2, label.String("A", "B")) + result.Observe(1, label.String("C", "D")) }) _ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(2, kv.String("A", "B")) + result.Observe(2, label.String("A", "B")) result.Observe(1) // last value wins - result.Observe(1, kv.String("A", "B")) + result.Observe(1, label.String("A", "B")) result.Observe(1) }) _ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(1, kv.String("A", "B")) - result.Observe(-2, kv.String("A", "B")) - result.Observe(1, kv.String("C", "D")) + result.Observe(1, label.String("A", "B")) + result.Observe(-2, label.String("A", "B")) + result.Observe(1, label.String("C", "D")) }) _ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(2, kv.String("A", "B")) + result.Observe(2, label.String("A", "B")) result.Observe(1) // last value wins - result.Observe(1, kv.String("A", "B")) + result.Observe(1, label.String("A", "B")) result.Observe(-1) }) @@ -376,13 +375,13 @@ func TestSumObserverInputRange(t *testing.T) { // TODO: these tests are testing for negative values, not for _descending values_. Fix. _ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(-2, kv.String("A", "B")) + result.Observe(-2, label.String("A", "B")) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) - result.Observe(-1, kv.String("C", "D")) + result.Observe(-1, label.String("C", "D")) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) }) _ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(-1, kv.String("A", "B")) + result.Observe(-1, label.String("A", "B")) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) result.Observe(-1) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) @@ -411,8 +410,8 @@ func TestObserverBatch(t *testing.T) { var batch = Must(meter).NewBatchObserver( func(_ context.Context, result metric.BatchObserverResult) { result.Observe( - []kv.KeyValue{ - kv.String("A", "B"), + []label.KeyValue{ + label.String("A", "B"), }, floatValueObs.Observation(1), floatValueObs.Observation(-1), @@ -424,8 +423,8 @@ func TestObserverBatch(t *testing.T) { intUpDownSumObs.Observation(-100), ) result.Observe( - []kv.KeyValue{ - kv.String("C", "D"), + []label.KeyValue{ + label.String("C", "D"), }, floatValueObs.Observation(-1), floatSumObs.Observation(-1), @@ -484,9 +483,9 @@ func TestRecordBatch(t *testing.T) { sdk.RecordBatch( ctx, - []kv.KeyValue{ - kv.String("A", "B"), - kv.String("C", "D"), + []label.KeyValue{ + label.String("A", "B"), + label.String("C", "D"), }, counter1.Measurement(1), counter2.Measurement(2), @@ -516,8 +515,8 @@ func TestRecordPersistence(t *testing.T) { meter, sdk, processor := newSDK(t) c := Must(meter).NewFloat64Counter("name.sum") - b := c.Bind(kv.String("bound", "true")) - uk := kv.String("bound", "false") + b := c.Bind(label.String("bound", "true")) + uk := label.String("bound", "false") for i := 0; i < 100; i++ { c.Add(ctx, 1, uk) diff --git a/sdk/metric/processor/basic/basic.go b/sdk/metric/processor/basic/basic.go index cf872c00590..6816e3c2039 100644 --- a/sdk/metric/processor/basic/basic.go +++ b/sdk/metric/processor/basic/basic.go @@ -20,8 +20,8 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/resource" diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index cee2896c487..406cdbaf77d 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -24,9 +24,8 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/metrictest" @@ -103,7 +102,7 @@ func asNumber(nkind metric.NumberKind, value int64) metric.Number { return metric.NewFloat64Number(float64(value)) } -func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...kv.KeyValue) export.Accumulation { +func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...label.KeyValue) export.Accumulation { ls := label.NewSet(labs...) var agg export.Aggregator selector.AggregatorFor(desc, &agg) @@ -122,10 +121,10 @@ func testProcessor( // Note: this selector uses the instrument name to dictate // aggregation kind. selector := processorTest.AggregatorSelector() - res := resource.New(kv.String("R", "V")) + res := resource.New(label.String("R", "V")) - labs1 := []kv.KeyValue{kv.String("L1", "V")} - labs2 := []kv.KeyValue{kv.String("L2", "V")} + labs1 := []label.KeyValue{label.String("L1", "V")} + labs2 := []label.KeyValue{label.String("L2", "V")} testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) { processor := basic.New(selector, ekind, basic.WithMemory(hasMemory)) @@ -362,7 +361,7 @@ func TestBasicTimestamps(t *testing.T) { } func TestStatefulNoMemoryCumulative(t *testing.T) { - res := resource.New(kv.String("R", "V")) + res := resource.New(label.String("R", "V")) ekind := export.CumulativeExporter desc := metric.NewDescriptor("inst.sum", metric.CounterKind, metric.Int64NumberKind) @@ -383,7 +382,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { // Add 10 processor.StartCollection() - _ = processor.Process(updateFor(t, &desc, selector, res, 10, kv.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, 10, label.String("A", "B"))) require.NoError(t, processor.FinishCollection()) // Verify one element @@ -396,7 +395,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { } func TestStatefulNoMemoryDelta(t *testing.T) { - res := resource.New(kv.String("R", "V")) + res := resource.New(label.String("R", "V")) ekind := export.DeltaExporter desc := metric.NewDescriptor("inst.sum", metric.SumObserverKind, metric.Int64NumberKind) @@ -417,7 +416,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) { // Add 10 processor.StartCollection() - _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B"))) require.NoError(t, processor.FinishCollection()) // Verify one element @@ -436,7 +435,7 @@ func TestMultiObserverSum(t *testing.T) { export.DeltaExporter, } { - res := resource.New(kv.String("R", "V")) + res := resource.New(label.String("R", "V")) desc := metric.NewDescriptor("observe.sum", metric.SumObserverKind, metric.Int64NumberKind) selector := processorTest.AggregatorSelector() @@ -446,9 +445,9 @@ func TestMultiObserverSum(t *testing.T) { for i := 1; i < 3; i++ { // Add i*10*3 times processor.StartCollection() - _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B"))) - _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B"))) - _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B"))) require.NoError(t, processor.FinishCollection()) // Multiplier is 1 for deltas, otherwise i. diff --git a/sdk/metric/processor/processortest/test.go b/sdk/metric/processor/processortest/test.go index d927cd6a820..dd855a2a208 100644 --- a/sdk/metric/processor/processortest/test.go +++ b/sdk/metric/processor/processortest/test.go @@ -21,8 +21,8 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/aggregator/array" diff --git a/sdk/metric/processor/processortest/test_test.go b/sdk/metric/processor/processortest/test_test.go index dc27e1043a3..1ff009cb419 100644 --- a/sdk/metric/processor/processortest/test_test.go +++ b/sdk/metric/processor/processortest/test_test.go @@ -20,9 +20,8 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" metricsdk "go.opentelemetry.io/otel/sdk/metric" processorTest "go.opentelemetry.io/otel/sdk/metric/processor/processortest" @@ -34,7 +33,7 @@ func generateTestData(proc export.Processor) { accum := metricsdk.NewAccumulator( proc, metricsdk.WithResource( - resource.New(kv.String("R", "V")), + resource.New(label.String("R", "V")), ), ) meter := metric.WrapMeterImpl(accum, "testing") @@ -43,13 +42,13 @@ func generateTestData(proc export.Processor) { _ = metric.Must(meter).NewInt64SumObserver("observer.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(10, kv.String("K1", "V1")) - result.Observe(11, kv.String("K1", "V2")) + result.Observe(10, label.String("K1", "V1")) + result.Observe(11, label.String("K1", "V2")) }, ) - counter.Add(ctx, 100, kv.String("K1", "V1")) - counter.Add(ctx, 101, kv.String("K1", "V2")) + counter.Add(ctx, 100, label.String("K1", "V1")) + counter.Add(ctx, 101, label.String("K1", "V2")) accum.Collect(ctx) } diff --git a/sdk/metric/processor/reducer/reducer.go b/sdk/metric/processor/reducer/reducer.go index 0fde654d2f4..aa901b4eafe 100644 --- a/sdk/metric/processor/reducer/reducer.go +++ b/sdk/metric/processor/reducer/reducer.go @@ -15,8 +15,8 @@ package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer" import ( - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" ) diff --git a/sdk/metric/processor/reducer/reducer_test.go b/sdk/metric/processor/reducer/reducer_test.go index ba003fbd313..be9185df785 100644 --- a/sdk/metric/processor/reducer/reducer_test.go +++ b/sdk/metric/processor/reducer/reducer_test.go @@ -20,9 +20,8 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" metricsdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/processor/basic" @@ -32,22 +31,22 @@ import ( ) var ( - kvs1 = []kv.KeyValue{ - kv.Int("A", 1), - kv.Int("B", 2), - kv.Int("C", 3), + kvs1 = []label.KeyValue{ + label.Int("A", 1), + label.Int("B", 2), + label.Int("C", 3), } - kvs2 = []kv.KeyValue{ - kv.Int("A", 1), - kv.Int("B", 0), - kv.Int("C", 3), + kvs2 = []label.KeyValue{ + label.Int("A", 1), + label.Int("B", 0), + label.Int("C", 3), } ) type testFilter struct{} func (testFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter { - return func(label kv.KeyValue) bool { + return func(label label.KeyValue) bool { return label.Key == "A" || label.Key == "C" } } @@ -77,7 +76,7 @@ func TestFilterProcessor(t *testing.T) { accum := metricsdk.NewAccumulator( reducer.New(testFilter{}, processorTest.Checkpointer(testProc)), metricsdk.WithResource( - resource.New(kv.String("R", "V")), + resource.New(label.String("R", "V")), ), ) generateData(accum) @@ -96,7 +95,7 @@ func TestFilterBasicProcessor(t *testing.T) { accum := metricsdk.NewAccumulator( reducer.New(testFilter{}, basicProc), metricsdk.WithResource( - resource.New(kv.String("R", "V")), + resource.New(label.String("R", "V")), ), ) exporter := processorTest.NewExporter(basicProc, label.DefaultEncoder()) diff --git a/sdk/metric/sdk.go b/sdk/metric/sdk.go index d00abeccad9..50ee358e384 100644 --- a/sdk/metric/sdk.go +++ b/sdk/metric/sdk.go @@ -22,11 +22,10 @@ import ( "sync/atomic" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" api "go.opentelemetry.io/otel/api/metric" internal "go.opentelemetry.io/otel/internal/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator" "go.opentelemetry.io/otel/sdk/resource" @@ -214,7 +213,7 @@ func (a *asyncInstrument) getRecorder(labels *label.Set) export.Aggregator { // support re-use of the orderedLabels computed by a previous // measurement in the same batch. This performs two allocations // in the common case. -func (s *syncInstrument) acquireHandle(kvs []kv.KeyValue, labelPtr *label.Set) *record { +func (s *syncInstrument) acquireHandle(kvs []label.KeyValue, labelPtr *label.Set) *record { var rec *record var equiv label.Distinct @@ -287,11 +286,11 @@ func (s *syncInstrument) acquireHandle(kvs []kv.KeyValue, labelPtr *label.Set) * } } -func (s *syncInstrument) Bind(kvs []kv.KeyValue) api.BoundSyncImpl { +func (s *syncInstrument) Bind(kvs []label.KeyValue) api.BoundSyncImpl { return s.acquireHandle(kvs, nil) } -func (s *syncInstrument) RecordOne(ctx context.Context, number api.Number, kvs []kv.KeyValue) { +func (s *syncInstrument) RecordOne(ctx context.Context, number api.Number, kvs []label.KeyValue) { h := s.acquireHandle(kvs, nil) defer h.Unbind() h.RecordOne(ctx, number) @@ -406,7 +405,7 @@ func (m *Accumulator) collectSyncInstruments() int { } // CollectAsync implements internal.AsyncCollector. -func (m *Accumulator) CollectAsync(kv []kv.KeyValue, obs ...metric.Observation) { +func (m *Accumulator) CollectAsync(kv []label.KeyValue, obs ...metric.Observation) { labels := label.NewSetWithSortable(kv, &m.asyncSortSlice) for _, ob := range obs { @@ -483,7 +482,7 @@ func (m *Accumulator) checkpointAsync(a *asyncInstrument) int { } // RecordBatch enters a batch of metric events. -func (m *Accumulator) RecordBatch(ctx context.Context, kvs []kv.KeyValue, measurements ...api.Measurement) { +func (m *Accumulator) RecordBatch(ctx context.Context, kvs []label.KeyValue, measurements ...api.Measurement) { // Labels will be computed the first time acquireHandle is // called. Subsequent calls to acquireHandle will re-use the // previously computed value instead of recomputing the diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index c1368869250..e6a1fae7b3b 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -31,9 +31,9 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" api "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/processor/processortest" @@ -75,7 +75,7 @@ type ( testImpl struct { newInstrument func(meter api.Meter, name string) SyncImpler getUpdateValue func() api.Number - operate func(interface{}, context.Context, api.Number, []kv.KeyValue) + operate func(interface{}, context.Context, api.Number, []label.KeyValue) newStore func() interface{} // storeCollect and storeExpect are the same for @@ -105,7 +105,7 @@ func concurrency() int { return concurrencyPerCPU * runtime.NumCPU() } -func canonicalizeLabels(ls []kv.KeyValue) string { +func canonicalizeLabels(ls []label.KeyValue) string { copy := append(ls[0:0:0], ls...) sort.SliceStable(copy, func(i, j int) bool { return copy[i].Key < copy[j].Key @@ -128,9 +128,9 @@ func getPeriod() time.Duration { return time.Duration(dur) } -func (f *testFixture) someLabels() []kv.KeyValue { +func (f *testFixture) someLabels() []label.KeyValue { n := 1 + rand.Intn(3) - l := make([]kv.KeyValue, n) + l := make([]label.KeyValue, n) for { oused := map[string]bool{} @@ -143,7 +143,7 @@ func (f *testFixture) someLabels() []kv.KeyValue { break } } - l[i] = kv.Key(k).String(fmt.Sprint("v", rand.Intn(1000000000))) + l[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) } lc := canonicalizeLabels(l) f.lock.Lock() @@ -350,7 +350,7 @@ func intCounterTestImpl() testImpl { } } }, - operate: func(inst interface{}, ctx context.Context, value api.Number, labels []kv.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value api.Number, labels []label.KeyValue) { counter := inst.(api.Int64Counter) counter.Add(ctx, value.AsInt64(), labels...) }, @@ -388,7 +388,7 @@ func floatCounterTestImpl() testImpl { } } }, - operate: func(inst interface{}, ctx context.Context, value api.Number, labels []kv.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value api.Number, labels []label.KeyValue) { counter := inst.(api.Float64Counter) counter.Add(ctx, value.AsFloat64(), labels...) }, @@ -424,7 +424,7 @@ func intLastValueTestImpl() testImpl { r1 := rand.Int63() return api.NewInt64Number(rand.Int63() - r1) }, - operate: func(inst interface{}, ctx context.Context, value api.Number, labels []kv.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value api.Number, labels []label.KeyValue) { valuerecorder := inst.(api.Int64ValueRecorder) valuerecorder.Record(ctx, value.AsInt64(), labels...) }, @@ -465,7 +465,7 @@ func floatLastValueTestImpl() testImpl { getUpdateValue: func() api.Number { return api.NewFloat64Number((-0.5 + rand.Float64()) * 100000) }, - operate: func(inst interface{}, ctx context.Context, value api.Number, labels []kv.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value api.Number, labels []label.KeyValue) { valuerecorder := inst.(api.Float64ValueRecorder) valuerecorder.Record(ctx, value.AsFloat64(), labels...) }, diff --git a/sdk/resource/benchmark_test.go b/sdk/resource/benchmark_test.go index 730eb1dc196..bc6b4427dc7 100644 --- a/sdk/resource/benchmark_test.go +++ b/sdk/resource/benchmark_test.go @@ -19,7 +19,7 @@ import ( "math/rand" "testing" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/resource" ) @@ -27,8 +27,8 @@ const conflict = 0.5 func makeLabels(n int) (_, _ *resource.Resource) { used := map[string]bool{} - l1 := make([]kv.KeyValue, n) - l2 := make([]kv.KeyValue, n) + l1 := make([]label.KeyValue, n) + l2 := make([]label.KeyValue, n) for i := 0; i < n; i++ { var k string for { @@ -38,12 +38,12 @@ func makeLabels(n int) (_, _ *resource.Resource) { break } } - l1[i] = kv.String(k, fmt.Sprint("v", rand.Intn(1000000000))) + l1[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) if rand.Float64() < conflict { l2[i] = l1[i] } else { - l2[i] = kv.String(k, fmt.Sprint("v", rand.Intn(1000000000))) + l2[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) } } diff --git a/sdk/resource/env.go b/sdk/resource/env.go index 51adba53427..82690872a20 100644 --- a/sdk/resource/env.go +++ b/sdk/resource/env.go @@ -20,7 +20,7 @@ import ( "os" "strings" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) // envVar is the environment variable name OpenTelemetry Resource information can be assigned to. @@ -50,7 +50,7 @@ func (d *FromEnv) Detect(context.Context) (*Resource, error) { func constructOTResources(s string) (*Resource, error) { pairs := strings.Split(s, ",") - labels := []kv.KeyValue{} + labels := []label.KeyValue{} var invalid []string for _, p := range pairs { field := strings.SplitN(p, "=", 2) @@ -59,7 +59,7 @@ func constructOTResources(s string) (*Resource, error) { continue } k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1]) - labels = append(labels, kv.String(k, v)) + labels = append(labels, label.String(k, v)) } var err error if len(invalid) > 0 { diff --git a/sdk/resource/env_test.go b/sdk/resource/env_test.go index 5302976540a..2c412fb8ff2 100644 --- a/sdk/resource/env_test.go +++ b/sdk/resource/env_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" ) func TestDetectOnePair(t *testing.T) { @@ -32,7 +32,7 @@ func TestDetectOnePair(t *testing.T) { detector := &FromEnv{} res, err := detector.Detect(context.Background()) require.NoError(t, err) - assert.Equal(t, New(kv.String("key", "value")), res) + assert.Equal(t, New(label.String("key", "value")), res) } func TestDetectMultiPairs(t *testing.T) { @@ -43,10 +43,10 @@ func TestDetectMultiPairs(t *testing.T) { res, err := detector.Detect(context.Background()) require.NoError(t, err) assert.Equal(t, res, New( - kv.String("key", "value"), - kv.String("k", "v"), - kv.String("a", "x"), - kv.String("a", "z"), + label.String("key", "value"), + label.String("k", "v"), + label.String("a", "x"), + label.String("a", "z"), )) } @@ -68,6 +68,6 @@ func TestMissingKeyError(t *testing.T) { assert.Error(t, err) assert.Equal(t, err, fmt.Errorf("%w: %v", errMissingValue, "[key]")) assert.Equal(t, res, New( - kv.String("key", "value"), + label.String("key", "value"), )) } diff --git a/sdk/resource/resource.go b/sdk/resource/resource.go index 1f53e50db1c..b03d2b4072f 100644 --- a/sdk/resource/resource.go +++ b/sdk/resource/resource.go @@ -15,8 +15,7 @@ package resource import ( - "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/label" + "go.opentelemetry.io/otel/label" ) // Resource describes an entity about which identifying information @@ -35,7 +34,7 @@ var emptyResource Resource // New creates a resource from a set of attributes. If there are // duplicate keys present in the list of attributes, then the last // value found for the key is preserved. -func New(kvs ...kv.KeyValue) *Resource { +func New(kvs ...label.KeyValue) *Resource { return &Resource{ labels: label.NewSet(kvs...), } @@ -55,7 +54,7 @@ func (r *Resource) String() string { // Attributes returns a copy of attributes from the resource in a sorted order. // To avoid allocating a new slice, use an iterator. -func (r *Resource) Attributes() []kv.KeyValue { +func (r *Resource) Attributes() []label.KeyValue { if r == nil { r = Empty() } @@ -100,7 +99,7 @@ func Merge(a, b *Resource) *Resource { // Note: 'a' labels will overwrite 'b' with last-value-wins in label.Key() // Meaning this is equivalent to: append(b.Attributes(), a.Attributes()...) mi := label.NewMergeIterator(a.LabelSet(), b.LabelSet()) - combine := make([]kv.KeyValue, 0, a.Len()+b.Len()) + combine := make([]label.KeyValue, 0, a.Len()+b.Len()) for mi.Next() { combine = append(combine, mi.Label()) } diff --git a/sdk/resource/resource_test.go b/sdk/resource/resource_test.go index 10222023207..e3e36482efe 100644 --- a/sdk/resource/resource_test.go +++ b/sdk/resource/resource_test.go @@ -22,33 +22,33 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/resource" ) var ( - kv11 = kv.String("k1", "v11") - kv12 = kv.String("k1", "v12") - kv21 = kv.String("k2", "v21") - kv31 = kv.String("k3", "v31") - kv41 = kv.String("k4", "v41") + kv11 = label.String("k1", "v11") + kv12 = label.String("k1", "v12") + kv21 = label.String("k2", "v21") + kv31 = label.String("k3", "v31") + kv41 = label.String("k4", "v41") ) func TestNew(t *testing.T) { cases := []struct { name string - in []kv.KeyValue - want []kv.KeyValue + in []label.KeyValue + want []label.KeyValue }{ { name: "Key with common key order1", - in: []kv.KeyValue{kv12, kv11, kv21}, - want: []kv.KeyValue{kv11, kv21}, + in: []label.KeyValue{kv12, kv11, kv21}, + want: []label.KeyValue{kv11, kv21}, }, { name: "Key with common key order2", - in: []kv.KeyValue{kv11, kv12, kv21}, - want: []kv.KeyValue{kv12, kv21}, + in: []label.KeyValue{kv11, kv12, kv21}, + want: []label.KeyValue{kv12, kv21}, }, { name: "Key with nil", @@ -62,7 +62,7 @@ func TestNew(t *testing.T) { if diff := cmp.Diff( res.Attributes(), c.want, - cmp.AllowUnexported(kv.Value{})); diff != "" { + cmp.AllowUnexported(label.Value{})); diff != "" { t.Fatalf("unwanted result: diff %+v,", diff) } }) @@ -73,37 +73,37 @@ func TestMerge(t *testing.T) { cases := []struct { name string a, b *resource.Resource - want []kv.KeyValue + want []label.KeyValue }{ { name: "Merge with no overlap, no nil", a: resource.New(kv11, kv31), b: resource.New(kv21, kv41), - want: []kv.KeyValue{kv11, kv21, kv31, kv41}, + want: []label.KeyValue{kv11, kv21, kv31, kv41}, }, { name: "Merge with no overlap, no nil, not interleaved", a: resource.New(kv11, kv21), b: resource.New(kv31, kv41), - want: []kv.KeyValue{kv11, kv21, kv31, kv41}, + want: []label.KeyValue{kv11, kv21, kv31, kv41}, }, { name: "Merge with common key order1", a: resource.New(kv11), b: resource.New(kv12, kv21), - want: []kv.KeyValue{kv11, kv21}, + want: []label.KeyValue{kv11, kv21}, }, { name: "Merge with common key order2", a: resource.New(kv12, kv21), b: resource.New(kv11), - want: []kv.KeyValue{kv12, kv21}, + want: []label.KeyValue{kv12, kv21}, }, { name: "Merge with common key order4", a: resource.New(kv11, kv21, kv41), b: resource.New(kv31, kv41), - want: []kv.KeyValue{kv11, kv21, kv31, kv41}, + want: []label.KeyValue{kv11, kv21, kv31, kv41}, }, { name: "Merge with no keys", @@ -115,25 +115,25 @@ func TestMerge(t *testing.T) { name: "Merge with first resource no keys", a: resource.New(), b: resource.New(kv21), - want: []kv.KeyValue{kv21}, + want: []label.KeyValue{kv21}, }, { name: "Merge with second resource no keys", a: resource.New(kv11), b: resource.New(), - want: []kv.KeyValue{kv11}, + want: []label.KeyValue{kv11}, }, { name: "Merge with first resource nil", a: nil, b: resource.New(kv21), - want: []kv.KeyValue{kv21}, + want: []label.KeyValue{kv21}, }, { name: "Merge with second resource nil", a: resource.New(kv11), b: nil, - want: []kv.KeyValue{kv11}, + want: []label.KeyValue{kv11}, }, } for _, c := range cases { @@ -142,7 +142,7 @@ func TestMerge(t *testing.T) { if diff := cmp.Diff( res.Attributes(), c.want, - cmp.AllowUnexported(kv.Value{})); diff != "" { + cmp.AllowUnexported(label.Value{})); diff != "" { t.Fatalf("unwanted result: diff %+v,", diff) } }) @@ -151,7 +151,7 @@ func TestMerge(t *testing.T) { func TestString(t *testing.T) { for _, test := range []struct { - kvs []kv.KeyValue + kvs []label.KeyValue want string }{ { @@ -159,51 +159,51 @@ func TestString(t *testing.T) { want: "", }, { - kvs: []kv.KeyValue{}, + kvs: []label.KeyValue{}, want: "", }, { - kvs: []kv.KeyValue{kv11}, + kvs: []label.KeyValue{kv11}, want: "k1=v11", }, { - kvs: []kv.KeyValue{kv11, kv12}, + kvs: []label.KeyValue{kv11, kv12}, want: "k1=v12", }, { - kvs: []kv.KeyValue{kv11, kv21}, + kvs: []label.KeyValue{kv11, kv21}, want: "k1=v11,k2=v21", }, { - kvs: []kv.KeyValue{kv21, kv11}, + kvs: []label.KeyValue{kv21, kv11}, want: "k1=v11,k2=v21", }, { - kvs: []kv.KeyValue{kv11, kv21, kv31}, + kvs: []label.KeyValue{kv11, kv21, kv31}, want: "k1=v11,k2=v21,k3=v31", }, { - kvs: []kv.KeyValue{kv31, kv11, kv21}, + kvs: []label.KeyValue{kv31, kv11, kv21}, want: "k1=v11,k2=v21,k3=v31", }, { - kvs: []kv.KeyValue{kv.String("A", "a"), kv.String("B", "b")}, + kvs: []label.KeyValue{label.String("A", "a"), label.String("B", "b")}, want: "A=a,B=b", }, { - kvs: []kv.KeyValue{kv.String("A", "a,B=b")}, + kvs: []label.KeyValue{label.String("A", "a,B=b")}, want: `A=a\,B\=b`, }, { - kvs: []kv.KeyValue{kv.String("A", `a,B\=b`)}, + kvs: []label.KeyValue{label.String("A", `a,B\=b`)}, want: `A=a\,B\\\=b`, }, { - kvs: []kv.KeyValue{kv.String("A=a,B", `b`)}, + kvs: []label.KeyValue{label.String("A=a,B", `b`)}, want: `A\=a\,B=b`, }, { - kvs: []kv.KeyValue{kv.String(`A=a\,B`, `b`)}, + kvs: []label.KeyValue{label.String(`A=a\,B`, `b`)}, want: `A\=a\\\,B=b`, }, } { @@ -214,7 +214,7 @@ func TestString(t *testing.T) { } func TestMarshalJSON(t *testing.T) { - r := resource.New(kv.Int64("A", 1), kv.String("C", "D")) + r := resource.New(label.Int64("A", 1), label.String("C", "D")) data, err := json.Marshal(r) require.NoError(t, err) require.Equal(t, diff --git a/sdk/trace/attributesMap.go b/sdk/trace/attributesMap.go index aa938d1bcfc..10dd38bed49 100644 --- a/sdk/trace/attributesMap.go +++ b/sdk/trace/attributesMap.go @@ -17,7 +17,7 @@ package trace import ( "container/list" - "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/export/trace" ) @@ -26,9 +26,9 @@ import ( // Updates are allowed and refreshes the usage of the key. // // This is based from https://github.com/hashicorp/golang-lru/blob/master/simplelru/lru.go -// With a subset of the its operations and specific for holding kv.KeyValue +// With a subset of the its operations and specific for holding label.KeyValue type attributesMap struct { - attributes map[kv.Key]*list.Element + attributes map[label.Key]*list.Element evictList *list.List droppedCount int capacity int @@ -36,14 +36,14 @@ type attributesMap struct { func newAttributesMap(capacity int) *attributesMap { lm := &attributesMap{ - attributes: make(map[kv.Key]*list.Element), + attributes: make(map[label.Key]*list.Element), evictList: list.New(), capacity: capacity, } return lm } -func (am *attributesMap) add(kv kv.KeyValue) { +func (am *attributesMap) add(kv label.KeyValue) { // Check for existing item if ent, ok := am.attributes[kv.Key]; ok { am.evictList.MoveToFront(ent) @@ -68,9 +68,9 @@ func (am *attributesMap) toSpanData(sd *trace.SpanData) { return } - attributes := make([]kv.KeyValue, 0, len) + attributes := make([]label.KeyValue, 0, len) for ent := am.evictList.Back(); ent != nil; ent = ent.Prev() { - if value, ok := ent.Value.(*kv.KeyValue); ok { + if value, ok := ent.Value.(*label.KeyValue); ok { attributes = append(attributes, *value) } } @@ -84,7 +84,7 @@ func (am *attributesMap) removeOldest() { ent := am.evictList.Back() if ent != nil { am.evictList.Remove(ent) - kv := ent.Value.(*kv.KeyValue) + kv := ent.Value.(*label.KeyValue) delete(am.attributes, kv.Key) } } diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index 70dd374f982..c1bbd7cf373 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -18,9 +18,8 @@ import ( "context" "testing" - "go.opentelemetry.io/otel/api/kv" - apitrace "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) @@ -43,10 +42,10 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.Key("key1").Bool(false), - kv.Key("key2").String("hello"), - kv.Key("key3").Uint64(123), - kv.Key("key4").Float64(123.456), + label.Bool("key1", false), + label.String("key2", "hello"), + label.Uint64("key3", 123), + label.Float64("key4", 123.456), ) span.End() } @@ -61,14 +60,14 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.Key("key1").Bool(false), - kv.Key("key2").String("hello"), - kv.Key("key3").Uint64(123), - kv.Key("key4").Float64(123.456), - kv.Key("key21").Bool(false), - kv.Key("key22").String("hello"), - kv.Key("key23").Uint64(123), - kv.Key("key24").Float64(123.456), + label.Bool("key1", false), + label.String("key2", "hello"), + label.Uint64("key3", 123), + label.Float64("key4", 123.456), + label.Bool("key21", false), + label.String("key22", "hello"), + label.Uint64("key23", 123), + label.Float64("key24", 123.456), ) span.End() } @@ -83,16 +82,16 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.Key("key1").Bool(false), - kv.Key("key2").String("hello"), - kv.Key("key3").Int64(123), - kv.Key("key4").Uint64(123), - kv.Key("key5").Int32(123), - kv.Key("key6").Uint32(123), - kv.Key("key7").Float64(123.456), - kv.Key("key8").Float32(123.456), - kv.Key("key9").Int(123), - kv.Key("key10").Uint(123), + label.Bool("key1", false), + label.String("key2", "hello"), + label.Int64("key3", 123), + label.Uint64("key4", 123), + label.Int32("key5", 123), + label.Uint32("key6", 123), + label.Float64("key7", 123.456), + label.Float32("key8", 123.456), + label.Int("key9", 123), + label.Uint("key10", 123), ) span.End() } @@ -107,26 +106,26 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.Key("key1").Bool(false), - kv.Key("key2").String("hello"), - kv.Key("key3").Int64(123), - kv.Key("key4").Uint64(123), - kv.Key("key5").Int32(123), - kv.Key("key6").Uint32(123), - kv.Key("key7").Float64(123.456), - kv.Key("key8").Float32(123.456), - kv.Key("key10").Int(123), - kv.Key("key11").Uint(123), - kv.Key("key21").Bool(false), - kv.Key("key22").String("hello"), - kv.Key("key23").Int64(123), - kv.Key("key24").Uint64(123), - kv.Key("key25").Int32(123), - kv.Key("key26").Uint32(123), - kv.Key("key27").Float64(123.456), - kv.Key("key28").Float32(123.456), - kv.Key("key210").Int(123), - kv.Key("key211").Uint(123), + label.Bool("key1", false), + label.String("key2", "hello"), + label.Int64("key3", 123), + label.Uint64("key4", 123), + label.Int32("key5", 123), + label.Uint32("key6", 123), + label.Float64("key7", 123.456), + label.Float32("key8", 123.456), + label.Int("key10", 123), + label.Uint("key11", 123), + label.Bool("key21", false), + label.String("key22", "hello"), + label.Int64("key23", 123), + label.Uint64("key24", 123), + label.Int32("key25", 123), + label.Uint32("key26", 123), + label.Float64("key27", 123.456), + label.Float32("key28", 123.456), + label.Int("key210", 123), + label.Uint("key211", 123), ) span.End() } diff --git a/sdk/trace/sampling.go b/sdk/trace/sampling.go index c40994a841f..bacdf40fd14 100644 --- a/sdk/trace/sampling.go +++ b/sdk/trace/sampling.go @@ -18,8 +18,8 @@ import ( "encoding/binary" "fmt" - "go.opentelemetry.io/otel/api/kv" api "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/label" ) // Sampler decides whether a trace should be sampled and exported. @@ -35,7 +35,7 @@ type SamplingParameters struct { Name string HasRemoteParent bool Kind api.SpanKind - Attributes []kv.KeyValue + Attributes []label.KeyValue Links []api.Link } @@ -52,7 +52,7 @@ const ( // SamplingResult conveys a SamplingDecision and a set of Attributes. type SamplingResult struct { Decision SamplingDecision - Attributes []kv.KeyValue + Attributes []label.KeyValue } type probabilitySampler struct { diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 489085e7b4f..9e93bfe215b 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -23,16 +23,16 @@ import ( "time" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/internal" ) const ( - errorTypeKey = kv.Key("error.type") - errorMessageKey = kv.Key("error.message") + errorTypeKey = label.Key("error.type") + errorMessageKey = label.Key("error.message") errorEventName = "error" ) @@ -94,7 +94,7 @@ func (s *span) SetStatus(code codes.Code, msg string) { s.mu.Unlock() } -func (s *span) SetAttributes(attributes ...kv.KeyValue) { +func (s *span) SetAttributes(attributes ...label.KeyValue) { if !s.IsRecording() { return } @@ -102,8 +102,8 @@ func (s *span) SetAttributes(attributes ...kv.KeyValue) { } func (s *span) SetAttribute(k string, v interface{}) { - attr := kv.Any(k, v) - if attr.Value.Type() != kv.INVALID { + attr := label.Any(k, v) + if attr.Value.Type() != label.INVALID { s.SetAttributes(attr) } } @@ -194,21 +194,21 @@ func (s *span) Tracer() apitrace.Tracer { return s.tracer } -func (s *span) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) { +func (s *span) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) { if !s.IsRecording() { return } s.addEventWithTimestamp(time.Now(), name, attrs...) } -func (s *span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) { +func (s *span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) { if !s.IsRecording() { return } s.addEventWithTimestamp(timestamp, name, attrs...) } -func (s *span) addEventWithTimestamp(timestamp time.Time, name string, attrs ...kv.KeyValue) { +func (s *span) addEventWithTimestamp(timestamp time.Time, name string, attrs ...label.KeyValue) { s.mu.Lock() defer s.mu.Unlock() s.messageEvents.add(export.Event{ @@ -305,11 +305,11 @@ func (s *span) interfaceArrayToMessageEventArray() []export.Event { return messageEventArr } -func (s *span) copyToCappedAttributes(attributes ...kv.KeyValue) { +func (s *span) copyToCappedAttributes(attributes ...label.KeyValue) { s.mu.Lock() defer s.mu.Unlock() for _, a := range attributes { - if a.Value.Type() != kv.INVALID { + if a.Value.Type() != label.INVALID { s.attributes.add(a) } } @@ -396,7 +396,7 @@ type samplingData struct { name string cfg *Config span *span - attributes []kv.KeyValue + attributes []label.KeyValue links []apitrace.Link kind apitrace.SpanKind } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 3e8838b2664..8a35b2930cc 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -25,6 +25,7 @@ import ( "time" "go.opentelemetry.io/otel/api/global" + "go.opentelemetry.io/otel/label" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -32,7 +33,6 @@ import ( grpccodes "google.golang.org/grpc/codes" "go.opentelemetry.io/otel/api/apitest" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/trace" apitrace "go.opentelemetry.io/otel/api/trace" otelcodes "go.opentelemetry.io/otel/codes" @@ -92,7 +92,7 @@ func (ts *testSampler) ShouldSample(p SamplingParameters) SamplingResult { if strings.HasPrefix(p.Name, ts.prefix) { decision = RecordAndSampled } - return SamplingResult{Decision: decision, Attributes: []kv.KeyValue{kv.Int("callCount", ts.callCount)}} + return SamplingResult{Decision: decision, Attributes: []label.KeyValue{label.Int("callCount", ts.callCount)}} } func (ts testSampler) Description() string { @@ -285,8 +285,8 @@ func TestSetSpanAttributesOnStart(t *testing.T) { tp, _ := NewProvider(WithSyncer(te)) span := startSpan(tp, "StartSpanAttribute", - apitrace.WithAttributes(kv.String("key1", "value1")), - apitrace.WithAttributes(kv.String("key2", "value2")), + apitrace.WithAttributes(label.String("key1", "value1")), + apitrace.WithAttributes(label.String("key2", "value2")), ) got, err := endSpan(te, span) if err != nil { @@ -300,9 +300,9 @@ func TestSetSpanAttributesOnStart(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []kv.KeyValue{ - kv.String("key1", "value1"), - kv.String("key2", "value2"), + Attributes: []label.KeyValue{ + label.String("key1", "value1"), + label.String("key2", "value2"), }, SpanKind: apitrace.SpanKindInternal, HasRemoteParent: true, @@ -317,7 +317,7 @@ func TestSetSpanAttributes(t *testing.T) { te := &testExporter{} tp, _ := NewProvider(WithSyncer(te)) span := startSpan(tp, "SpanAttribute") - span.SetAttributes(kv.Key("key1").String("value1")) + span.SetAttributes(label.String("key1", "value1")) got, err := endSpan(te, span) if err != nil { t.Fatal(err) @@ -330,8 +330,8 @@ func TestSetSpanAttributes(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []kv.KeyValue{ - kv.String("key1", "value1"), + Attributes: []label.KeyValue{ + label.String("key1", "value1"), }, SpanKind: apitrace.SpanKindInternal, HasRemoteParent: true, @@ -349,10 +349,10 @@ func TestSetSpanAttributesOverLimit(t *testing.T) { span := startSpan(tp, "SpanAttributesOverLimit") span.SetAttributes( - kv.Bool("key1", true), - kv.String("key2", "value2"), - kv.Bool("key1", false), // Replace key1. - kv.Int64("key4", 4), // Remove key2 and add key4 + label.Bool("key1", true), + label.String("key2", "value2"), + label.Bool("key1", false), // Replace key1. + label.Int64("key4", 4), // Remove key2 and add key4 ) got, err := endSpan(te, span) if err != nil { @@ -366,9 +366,9 @@ func TestSetSpanAttributesOverLimit(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []kv.KeyValue{ - kv.Bool("key1", false), - kv.Int64("key4", 4), + Attributes: []label.KeyValue{ + label.Bool("key1", false), + label.Int64("key4", 4), }, SpanKind: apitrace.SpanKindInternal, HasRemoteParent: true, @@ -385,14 +385,14 @@ func TestEvents(t *testing.T) { tp, _ := NewProvider(WithSyncer(te)) span := startSpan(tp, "Events") - k1v1 := kv.Key("key1").String("value1") - k2v2 := kv.Bool("key2", true) - k3v3 := kv.Int64("key3", 3) + k1v1 := label.String("key1", "value1") + k2v2 := label.Bool("key2", true) + k3v3 := label.Int64("key3", 3) - span.AddEvent(context.Background(), "foo", kv.Key("key1").String("value1")) + span.AddEvent(context.Background(), "foo", label.String("key1", "value1")) span.AddEvent(context.Background(), "bar", - kv.Bool("key2", true), - kv.Int64("key3", 3), + label.Bool("key2", true), + label.Int64("key3", 3), ) got, err := endSpan(te, span) if err != nil { @@ -414,8 +414,8 @@ func TestEvents(t *testing.T) { Name: "span0", HasRemoteParent: true, MessageEvents: []export.Event{ - {Name: "foo", Attributes: []kv.KeyValue{k1v1}}, - {Name: "bar", Attributes: []kv.KeyValue{k2v2, k3v3}}, + {Name: "foo", Attributes: []label.KeyValue{k1v1}}, + {Name: "bar", Attributes: []label.KeyValue{k2v2, k3v3}}, }, SpanKind: apitrace.SpanKindInternal, InstrumentationLibrary: instrumentation.Library{Name: "Events"}, @@ -431,19 +431,19 @@ func TestEventsOverLimit(t *testing.T) { tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) span := startSpan(tp, "EventsOverLimit") - k1v1 := kv.Key("key1").String("value1") - k2v2 := kv.Bool("key2", false) - k3v3 := kv.Key("key3").String("value3") + k1v1 := label.String("key1", "value1") + k2v2 := label.Bool("key2", false) + k3v3 := label.String("key3", "value3") - span.AddEvent(context.Background(), "fooDrop", kv.Key("key1").String("value1")) + span.AddEvent(context.Background(), "fooDrop", label.String("key1", "value1")) span.AddEvent(context.Background(), "barDrop", - kv.Bool("key2", true), - kv.Key("key3").String("value3"), + label.Bool("key2", true), + label.String("key3", "value3"), ) - span.AddEvent(context.Background(), "foo", kv.Key("key1").String("value1")) + span.AddEvent(context.Background(), "foo", label.String("key1", "value1")) span.AddEvent(context.Background(), "bar", - kv.Bool("key2", false), - kv.Key("key3").String("value3"), + label.Bool("key2", false), + label.String("key3", "value3"), ) got, err := endSpan(te, span) if err != nil { @@ -464,8 +464,8 @@ func TestEventsOverLimit(t *testing.T) { ParentSpanID: sid, Name: "span0", MessageEvents: []export.Event{ - {Name: "foo", Attributes: []kv.KeyValue{k1v1}}, - {Name: "bar", Attributes: []kv.KeyValue{k2v2, k3v3}}, + {Name: "foo", Attributes: []label.KeyValue{k1v1}}, + {Name: "bar", Attributes: []label.KeyValue{k2v2, k3v3}}, }, DroppedMessageEventCount: 2, HasRemoteParent: true, @@ -481,18 +481,18 @@ func TestLinks(t *testing.T) { te := &testExporter{} tp, _ := NewProvider(WithSyncer(te)) - k1v1 := kv.Key("key1").String("value1") - k2v2 := kv.Key("key2").String("value2") - k3v3 := kv.Key("key3").String("value3") + k1v1 := label.String("key1", "value1") + k2v2 := label.String("key2", "value2") + k3v3 := label.String("key3", "value3") sc1 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} span := startSpan(tp, "Links", - apitrace.LinkedTo(sc1, kv.Key("key1").String("value1")), + apitrace.LinkedTo(sc1, label.String("key1", "value1")), apitrace.LinkedTo(sc2, - kv.Key("key2").String("value2"), - kv.Key("key3").String("value3"), + label.String("key2", "value2"), + label.String("key3", "value3"), ), ) @@ -510,8 +510,8 @@ func TestLinks(t *testing.T) { Name: "span0", HasRemoteParent: true, Links: []apitrace.Link{ - {SpanContext: sc1, Attributes: []kv.KeyValue{k1v1}}, - {SpanContext: sc2, Attributes: []kv.KeyValue{k2v2, k3v3}}, + {SpanContext: sc1, Attributes: []label.KeyValue{k1v1}}, + {SpanContext: sc2, Attributes: []label.KeyValue{k2v2, k3v3}}, }, SpanKind: apitrace.SpanKindInternal, InstrumentationLibrary: instrumentation.Library{Name: "Links"}, @@ -532,13 +532,13 @@ func TestLinksOverLimit(t *testing.T) { tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) span := startSpan(tp, "LinksOverLimit", - apitrace.LinkedTo(sc1, kv.Key("key1").String("value1")), - apitrace.LinkedTo(sc2, kv.Key("key2").String("value2")), - apitrace.LinkedTo(sc3, kv.Key("key3").String("value3")), + apitrace.LinkedTo(sc1, label.String("key1", "value1")), + apitrace.LinkedTo(sc2, label.String("key2", "value2")), + apitrace.LinkedTo(sc3, label.String("key3", "value3")), ) - k2v2 := kv.Key("key2").String("value2") - k3v3 := kv.Key("key3").String("value3") + k2v2 := label.String("key2", "value2") + k3v3 := label.String("key3", "value3") got, err := endSpan(te, span) if err != nil { @@ -553,8 +553,8 @@ func TestLinksOverLimit(t *testing.T) { ParentSpanID: sid, Name: "span0", Links: []apitrace.Link{ - {SpanContext: sc2, Attributes: []kv.KeyValue{k2v2}}, - {SpanContext: sc3, Attributes: []kv.KeyValue{k3v3}}, + {SpanContext: sc2, Attributes: []label.KeyValue{k2v2}}, + {SpanContext: sc3, Attributes: []label.KeyValue{k3v3}}, }, DroppedLinkCount: 1, HasRemoteParent: true, @@ -619,7 +619,7 @@ func TestSetSpanStatus(t *testing.T) { func cmpDiff(x, y interface{}) string { return cmp.Diff(x, y, - cmp.AllowUnexported(kv.Value{}), + cmp.AllowUnexported(label.Value{}), cmp.AllowUnexported(export.Event{})) } @@ -956,7 +956,7 @@ func TestRecordError(t *testing.T) { { Name: errorEventName, Time: errTime, - Attributes: []kv.KeyValue{ + Attributes: []label.KeyValue{ errorTypeKey.String(s.typ), errorMessageKey.String(s.msg), }, @@ -1003,7 +1003,7 @@ func TestRecordErrorWithStatus(t *testing.T) { { Name: errorEventName, Time: errTime, - Attributes: []kv.KeyValue{ + Attributes: []label.KeyValue{ errorTypeKey.String("go.opentelemetry.io/otel/internal/testing.TestError"), errorMessageKey.String("test error"), }, @@ -1088,9 +1088,9 @@ func TestWithResource(t *testing.T) { var te testExporter tp, _ := NewProvider(WithSyncer(&te), WithConfig(Config{DefaultSampler: AlwaysSample()}), - WithResource(resource.New(kv.String("rk1", "rv1"), kv.Int64("rk2", 5)))) + WithResource(resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5)))) span := startSpan(tp, "WithResource") - span.SetAttributes(kv.String("key1", "value1")) + span.SetAttributes(label.String("key1", "value1")) got, err := endSpan(&te, span) if err != nil { t.Error(err.Error()) @@ -1103,12 +1103,12 @@ func TestWithResource(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []kv.KeyValue{ - kv.String("key1", "value1"), + Attributes: []label.KeyValue{ + label.String("key1", "value1"), }, SpanKind: apitrace.SpanKindInternal, HasRemoteParent: true, - Resource: resource.New(kv.String("rk1", "rv1"), kv.Int64("rk2", 5)), + Resource: resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5)), InstrumentationLibrary: instrumentation.Library{Name: "WithResource"}, } if diff := cmpDiff(got, want); diff != "" { @@ -1167,7 +1167,7 @@ func TestSpanCapturesPanic(t *testing.T) { require.Len(t, te.spans, 1) require.Len(t, te.spans[0].MessageEvents, 1) assert.Equal(t, te.spans[0].MessageEvents[0].Name, errorEventName) - assert.Equal(t, te.spans[0].MessageEvents[0].Attributes, []kv.KeyValue{ + assert.Equal(t, te.spans[0].MessageEvents[0].Attributes, []label.KeyValue{ errorTypeKey.String("*errors.errorString"), errorMessageKey.String("error message"), }) diff --git a/semconv/http.go b/semconv/http.go index 748dde0c080..1ffe550111f 100644 --- a/semconv/http.go +++ b/semconv/http.go @@ -21,16 +21,16 @@ import ( "strconv" "strings" - "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) // NetAttributesFromHTTPRequest generates attributes of the net // namespace as specified by the OpenTelemetry specification for a // span. The network parameter is a string that net.Dial function // from standard library can understand. -func NetAttributesFromHTTPRequest(network string, request *http.Request) []kv.KeyValue { - attrs := []kv.KeyValue{} +func NetAttributesFromHTTPRequest(network string, request *http.Request) []label.KeyValue { + attrs := []label.KeyValue{} switch network { case "tcp", "tcp4", "tcp6": @@ -121,9 +121,9 @@ func NetAttributesFromHTTPRequest(network string, request *http.Request) []kv.Ke // EndUserAttributesFromHTTPRequest generates attributes of the // enduser namespace as specified by the OpenTelemetry specification // for a span. -func EndUserAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { +func EndUserAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { if username, _, ok := request.BasicAuth(); ok { - return []kv.KeyValue{EnduserIDKey.String(username)} + return []label.KeyValue{EnduserIDKey.String(username)} } return nil } @@ -131,8 +131,8 @@ func EndUserAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { // HTTPClientAttributesFromHTTPRequest generates attributes of the // http namespace as specified by the OpenTelemetry specification for // a span on the client side. -func HTTPClientAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { - attrs := []kv.KeyValue{} +func HTTPClientAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { + attrs := []label.KeyValue{} if request.Method != "" { attrs = append(attrs, HTTPMethodKey.String(request.Method)) @@ -145,8 +145,8 @@ func HTTPClientAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { return append(attrs, httpCommonAttributesFromHTTPRequest(request)...) } -func httpCommonAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { - attrs := []kv.KeyValue{} +func httpCommonAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { + attrs := []label.KeyValue{} if ua := request.UserAgent(); ua != "" { attrs = append(attrs, HTTPUserAgentKey.String(ua)) } @@ -157,9 +157,9 @@ func httpCommonAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { return append(attrs, httpBasicAttributesFromHTTPRequest(request)...) } -func httpBasicAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { +func httpBasicAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { // as these attributes are used by HTTPServerMetricAttributesFromHTTPRequest, they should be low-cardinality - attrs := []kv.KeyValue{} + attrs := []label.KeyValue{} if request.TLS != nil { attrs = append(attrs, HTTPSchemeHTTPS) @@ -186,8 +186,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []kv.KeyValue { // HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes // to be used with server-side HTTP metrics. -func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []kv.KeyValue { - attrs := []kv.KeyValue{} +func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []label.KeyValue { + attrs := []label.KeyValue{} if serverName != "" { attrs = append(attrs, HTTPServerNameKey.String(serverName)) } @@ -198,8 +198,8 @@ func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http. // http namespace as specified by the OpenTelemetry specification for // a span on the server side. Currently, only basic authentication is // supported. -func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []kv.KeyValue { - attrs := []kv.KeyValue{ +func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []label.KeyValue { + attrs := []label.KeyValue{ HTTPMethodKey.String(request.Method), HTTPTargetKey.String(request.RequestURI), } @@ -220,8 +220,8 @@ func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http // HTTPAttributesFromHTTPStatusCode generates attributes of the http // namespace as specified by the OpenTelemetry specification for a // span. -func HTTPAttributesFromHTTPStatusCode(code int) []kv.KeyValue { - attrs := []kv.KeyValue{ +func HTTPAttributesFromHTTPStatusCode(code int) []label.KeyValue { + attrs := []label.KeyValue{ HTTPStatusCodeKey.Int(code), } text := http.StatusText(code) diff --git a/semconv/http_test.go b/semconv/http_test.go index cfc26014ecd..a5943272b79 100644 --- a/semconv/http_test.go +++ b/semconv/http_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/assert" - otelkv "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/label" ) type tlsOption int @@ -47,7 +47,7 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { url *url.URL header http.Header - expected []otelkv.KeyValue + expected []label.KeyValue } testcases := []testcase{ { @@ -62,8 +62,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), }, }, { @@ -78,8 +78,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.UDP"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.UDP"), }, }, { @@ -94,8 +94,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP"), + expected: []label.KeyValue{ + label.String("net.transport", "IP"), }, }, { @@ -110,8 +110,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "Unix"), + expected: []label.KeyValue{ + label.String("net.transport", "Unix"), }, }, { @@ -126,8 +126,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "other"), + expected: []label.KeyValue{ + label.String("net.transport", "other"), }, }, { @@ -142,10 +142,10 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), }, }, { @@ -160,10 +160,10 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.name", "example.com"), - otelkv.Int("net.peer.port", 56), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.name", "example.com"), + label.Int("net.peer.port", 56), }, }, { @@ -178,9 +178,9 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), }, }, { @@ -195,9 +195,9 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.name", "example.com"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.name", "example.com"), }, }, { @@ -212,8 +212,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), }, }, { @@ -228,11 +228,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.name", "example.com"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.name", "example.com"), }, }, { @@ -247,11 +247,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.ip", "4.3.2.1"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.ip", "4.3.2.1"), }, }, { @@ -266,12 +266,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.name", "example.com"), - otelkv.Int("net.host.port", 78), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.name", "example.com"), + label.Int("net.host.port", 78), }, }, { @@ -286,12 +286,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.ip", "4.3.2.1"), - otelkv.Int("net.host.port", 78), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.ip", "4.3.2.1"), + label.Int("net.host.port", 78), }, }, { @@ -306,11 +306,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.name", "example.com"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.name", "example.com"), }, }, { @@ -325,11 +325,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.ip", "4.3.2.1"), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.ip", "4.3.2.1"), }, }, { @@ -344,10 +344,10 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), }, }, { @@ -364,12 +364,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { header: http.Header{ "Host": []string{"4.3.2.1:78"}, }, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.ip", "4.3.2.1"), - otelkv.Int("net.host.port", 78), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.ip", "4.3.2.1"), + label.Int("net.host.port", 78), }, }, { @@ -385,12 +385,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []otelkv.KeyValue{ - otelkv.String("net.transport", "IP.TCP"), - otelkv.String("net.peer.ip", "1.2.3.4"), - otelkv.Int("net.peer.port", 56), - otelkv.String("net.host.ip", "4.3.2.1"), - otelkv.Int("net.host.port", 78), + expected: []label.KeyValue{ + label.String("net.transport", "IP.TCP"), + label.String("net.peer.ip", "1.2.3.4"), + label.Int("net.peer.port", 56), + label.String("net.host.ip", "4.3.2.1"), + label.Int("net.host.port", 78), }, }, } @@ -403,11 +403,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { func TestEndUserAttributesFromHTTPRequest(t *testing.T) { r := testRequest("GET", "/user/123", "HTTP/1.1", "", "", nil, http.Header{}, withTLS) - var expected []otelkv.KeyValue + var expected []label.KeyValue got := EndUserAttributesFromHTTPRequest(r) assert.ElementsMatch(t, expected, got) r.SetBasicAuth("admin", "password") - expected = []otelkv.KeyValue{otelkv.String("enduser.id", "admin")} + expected = []label.KeyValue{label.String("enduser.id", "admin")} got = EndUserAttributesFromHTTPRequest(r) assert.ElementsMatch(t, expected, got) } @@ -429,7 +429,7 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { tls tlsOption contentLength int64 - expected []otelkv.KeyValue + expected []label.KeyValue } testcases := []testcase{ { @@ -446,11 +446,11 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: noTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "http"), - otelkv.String("http.flavor", "1.0"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "http"), + label.String("http.flavor", "1.0"), }, }, { @@ -467,12 +467,12 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: noTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "http"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.server_name", "my-server-name"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "http"), + label.String("http.flavor", "1.0"), + label.String("http.server_name", "my-server-name"), }, }, { @@ -489,12 +489,12 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.server_name", "my-server-name"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.server_name", "my-server-name"), }, }, { @@ -511,13 +511,13 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.server_name", "my-server-name"), - otelkv.String("http.route", "/user/:id"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.server_name", "my-server-name"), + label.String("http.route", "/user/:id"), }, }, { @@ -534,14 +534,14 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.server_name", "my-server-name"), - otelkv.String("http.route", "/user/:id"), - otelkv.String("http.host", "example.com"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.server_name", "my-server-name"), + label.String("http.route", "/user/:id"), + label.String("http.host", "example.com"), }, }, { @@ -560,15 +560,15 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.server_name", "my-server-name"), - otelkv.String("http.route", "/user/:id"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.server_name", "my-server-name"), + label.String("http.route", "/user/:id"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), }, }, { @@ -588,16 +588,16 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { "X-Forwarded-For": []string{"1.2.3.4"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.server_name", "my-server-name"), - otelkv.String("http.route", "/user/:id"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), - otelkv.String("http.client_ip", "1.2.3.4"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.server_name", "my-server-name"), + label.String("http.route", "/user/:id"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), + label.String("http.client_ip", "1.2.3.4"), }, }, { @@ -617,16 +617,16 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { "X-Forwarded-For": []string{"1.2.3.4"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.1"), - otelkv.String("http.server_name", "my-server-name"), - otelkv.String("http.route", "/user/:id"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), - otelkv.String("http.client_ip", "1.2.3.4"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.1"), + label.String("http.server_name", "my-server-name"), + label.String("http.route", "/user/:id"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), + label.String("http.client_ip", "1.2.3.4"), }, }, { @@ -646,16 +646,16 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { "X-Forwarded-For": []string{"1.2.3.4"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "2"), - otelkv.String("http.server_name", "my-server-name"), - otelkv.String("http.route", "/user/:id"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), - otelkv.String("http.client_ip", "1.2.3.4"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "2"), + label.String("http.server_name", "my-server-name"), + label.String("http.route", "/user/:id"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), + label.String("http.client_ip", "1.2.3.4"), }, }, { @@ -663,11 +663,11 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { method: "GET", requestURI: "/user/123", contentLength: 100, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.target", "/user/123"), - otelkv.String("http.scheme", "http"), - otelkv.Int64("http.request_content_length", 100), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.target", "/user/123"), + label.String("http.scheme", "http"), + label.Int64("http.request_content_length", 100), }, }, } @@ -680,15 +680,15 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { } func TestHTTPAttributesFromHTTPStatusCode(t *testing.T) { - expected := []otelkv.KeyValue{ - otelkv.Int("http.status_code", 404), - otelkv.String("http.status_text", "Not Found"), + expected := []label.KeyValue{ + label.Int("http.status_code", 404), + label.String("http.status_text", "Not Found"), } got := HTTPAttributesFromHTTPStatusCode(http.StatusNotFound) assertElementsMatch(t, expected, got, "with valid HTTP status code") assert.ElementsMatch(t, expected, got) - expected = []otelkv.KeyValue{ - otelkv.Int("http.status_code", 499), + expected = []label.KeyValue{ + label.Int("http.status_code", 499), } got = HTTPAttributesFromHTTPStatusCode(499) assertElementsMatch(t, expected, got, "with invalid HTTP status code") @@ -732,7 +732,7 @@ func getExpectedGRPCCodeForHTTPCode(code int) codes.Code { return codes.Internal } -func assertElementsMatch(t *testing.T, expected, got []otelkv.KeyValue, format string, args ...interface{}) { +func assertElementsMatch(t *testing.T, expected, got []label.KeyValue, format string, args ...interface{}) { if !assert.ElementsMatchf(t, expected, got, format, args...) { t.Log("expected:", kvStr(expected)) t.Log("got:", kvStr(got)) @@ -774,16 +774,16 @@ func protoToInts(proto string) (int, int) { return 13, 42 } -func kvStr(kvs []otelkv.KeyValue) string { +func kvStr(kvs []label.KeyValue) string { sb := strings.Builder{} sb.WriteRune('[') - for idx, kv := range kvs { + for idx, label := range kvs { if idx > 0 { sb.WriteString(", ") } - sb.WriteString((string)(kv.Key)) + sb.WriteString((string)(label.Key)) sb.WriteString(": ") - sb.WriteString(kv.Value.Emit()) + sb.WriteString(label.Value.Emit()) } sb.WriteRune(']') return sb.String() @@ -803,7 +803,7 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { tls tlsOption contentLength int64 - expected []otelkv.KeyValue + expected []label.KeyValue }{ { name: "stripped", @@ -817,11 +817,11 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: noTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "http"), - otelkv.String("http.flavor", "1.0"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "http"), + label.String("http.flavor", "1.0"), }, }, { @@ -836,11 +836,11 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), }, }, { @@ -855,12 +855,12 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.host", "example.com"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.host", "example.com"), }, }, { @@ -877,13 +877,13 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.0"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.0"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), }, }, { @@ -900,13 +900,13 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "1.1"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "1.1"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), }, }, { @@ -923,13 +923,13 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "https"), - otelkv.String("http.flavor", "2"), - otelkv.String("http.host", "example.com"), - otelkv.String("http.user_agent", "foodownloader"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "https"), + label.String("http.flavor", "2"), + label.String("http.host", "example.com"), + label.String("http.user_agent", "foodownloader"), }, }, { @@ -939,11 +939,11 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, contentLength: 100, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "http"), - otelkv.Int64("http.request_content_length", 100), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "http"), + label.Int64("http.request_content_length", 100), }, }, { @@ -952,10 +952,10 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { url: &url.URL{ Path: "/user/123", }, - expected: []otelkv.KeyValue{ - otelkv.String("http.method", "GET"), - otelkv.String("http.url", "/user/123"), - otelkv.String("http.scheme", "http"), + expected: []label.KeyValue{ + label.String("http.method", "GET"), + label.String("http.url", "/user/123"), + label.String("http.scheme", "http"), }, }, } diff --git a/semconv/resource.go b/semconv/resource.go index fc1e11edfbe..fb94ddc384d 100644 --- a/semconv/resource.go +++ b/semconv/resource.go @@ -14,25 +14,25 @@ package semconv -import "go.opentelemetry.io/otel/api/kv" +import "go.opentelemetry.io/otel/label" // Semantic conventions for service resource attribute keys. const ( // Name of the service. - ServiceNameKey = kv.Key("service.name") + ServiceNameKey = label.Key("service.name") // A namespace for `service.name`. This needs to have meaning that helps // to distinguish a group of services. For example, the team name that // owns a group of services. `service.name` is expected to be unique // within the same namespace. - ServiceNamespaceKey = kv.Key("service.namespace") + ServiceNamespaceKey = label.Key("service.namespace") // A unique identifier of the service instance. In conjunction with the // `service.name` and `service.namespace` this must be unique. - ServiceInstanceIDKey = kv.Key("service.instance.id") + ServiceInstanceIDKey = label.Key("service.instance.id") // The version of the service API. - ServiceVersionKey = kv.Key("service.version") + ServiceVersionKey = label.Key("service.version") ) // Semantic conventions for telemetry SDK resource attribute keys. @@ -47,13 +47,13 @@ const ( // // The value `opentelemetry` is reserved and MUST NOT be used by // non-OpenTelemetry SDKs. - TelemetrySDKNameKey = kv.Key("telemetry.sdk.name") + TelemetrySDKNameKey = label.Key("telemetry.sdk.name") // The language of the telemetry SDK. - TelemetrySDKLanguageKey = kv.Key("telemetry.sdk.language") + TelemetrySDKLanguageKey = label.Key("telemetry.sdk.language") // The version string of the telemetry SDK. - TelemetrySDKVersionKey = kv.Key("telemetry.sdk.version") + TelemetrySDKVersionKey = label.Key("telemetry.sdk.version") ) // Semantic conventions for telemetry SDK resource attributes. @@ -64,60 +64,60 @@ var ( // Semantic conventions for container resource attribute keys. const ( // A uniquely identifying name for the Container. - ContainerNameKey = kv.Key("container.name") + ContainerNameKey = label.Key("container.name") // Container ID, usually a UUID, as for example used to // identify Docker containers. The UUID might be abbreviated. - ContainerIDKey = kv.Key("container.id") + ContainerIDKey = label.Key("container.id") // Name of the image the container was built on. - ContainerImageNameKey = kv.Key("container.image.name") + ContainerImageNameKey = label.Key("container.image.name") // Container image tag. - ContainerImageTagKey = kv.Key("container.image.tag") + ContainerImageTagKey = label.Key("container.image.tag") ) // Semantic conventions for Function-as-a-Service resource attribute keys. const ( // A uniquely identifying name for the FaaS. - FaaSNameKey = kv.Key("faas.name") + FaaSNameKey = label.Key("faas.name") // The unique name of the function being executed. - FaaSIDKey = kv.Key("faas.id") + FaaSIDKey = label.Key("faas.id") // The version of the function being executed. - FaaSVersionKey = kv.Key("faas.version") + FaaSVersionKey = label.Key("faas.version") // The execution environment identifier. - FaaSInstanceKey = kv.Key("faas.instance") + FaaSInstanceKey = label.Key("faas.instance") ) // Semantic conventions for operating system process resource attribute keys. const ( // Process identifier (PID). - ProcessPIDKey = kv.Key("process.pid") + ProcessPIDKey = label.Key("process.pid") // The name of the process executable. On Linux based systems, can be // set to the `Name` in `proc/[pid]/status`. On Windows, can be set to // the base name of `GetProcessImageFileNameW`. - ProcessExecutableNameKey = kv.Key("process.executable.name") + ProcessExecutableNameKey = label.Key("process.executable.name") // The full path to the process executable. On Linux based systems, can // be set to the target of `proc/[pid]/exe`. On Windows, can be set to // the result of `GetProcessImageFileNameW`. - ProcessExecutablePathKey = kv.Key("process.executable.path") + ProcessExecutablePathKey = label.Key("process.executable.path") // The command used to launch the process (i.e. the command name). On // Linux based systems, can be set to the zeroth string in // `proc/[pid]/cmdline`. On Windows, can be set to the first parameter // extracted from `GetCommandLineW`. - ProcessCommandKey = kv.Key("process.command") + ProcessCommandKey = label.Key("process.command") // The full command used to launch the process. The value can be either // a list of strings representing the ordered list of arguments, or a // single string representing the full command. On Linux based systems, // can be set to the list of null-delimited strings extracted from // `proc/[pid]/cmdline`. On Windows, can be set to the result of // `GetCommandLineW`. - ProcessCommandLineKey = kv.Key("process.command_line") + ProcessCommandLineKey = label.Key("process.command_line") // The username of the user that owns the process. - ProcessOwnerKey = kv.Key("process.owner") + ProcessOwnerKey = label.Key("process.owner") ) // Semantic conventions for Kubernetes resource attribute keys. @@ -126,55 +126,55 @@ const ( // does not have cluster names as an internal concept so this may be // set to any meaningful value within the environment. For example, // GKE clusters have a name which can be used for this label. - K8SClusterNameKey = kv.Key("k8s.cluster.name") + K8SClusterNameKey = label.Key("k8s.cluster.name") // The name of the namespace that the pod is running in. - K8SNamespaceNameKey = kv.Key("k8s.namespace.name") + K8SNamespaceNameKey = label.Key("k8s.namespace.name") // The name of the pod. - K8SPodNameKey = kv.Key("k8s.pod.name") + K8SPodNameKey = label.Key("k8s.pod.name") // The name of the deployment. - K8SDeploymentNameKey = kv.Key("k8s.deployment.name") + K8SDeploymentNameKey = label.Key("k8s.deployment.name") ) // Semantic conventions for host resource attribute keys. const ( // A uniquely identifying name for the host. - HostNameKey = kv.Key("host.name") + HostNameKey = label.Key("host.name") // A hostname as returned by the 'hostname' command on host machine. - HostHostNameKey = kv.Key("host.hostname") + HostHostNameKey = label.Key("host.hostname") // Unique host ID. For cloud environments this will be the instance ID. - HostIDKey = kv.Key("host.id") + HostIDKey = label.Key("host.id") // Type of host. For cloud environments this will be the machine type. - HostTypeKey = kv.Key("host.type") + HostTypeKey = label.Key("host.type") // Name of the OS or VM image the host is running. - HostImageNameKey = kv.Key("host.image.name") + HostImageNameKey = label.Key("host.image.name") // Identifier of the image the host is running. - HostImageIDKey = kv.Key("host.image.id") + HostImageIDKey = label.Key("host.image.id") // Version of the image the host is running. - HostImageVersionKey = kv.Key("host.image.version") + HostImageVersionKey = label.Key("host.image.version") ) // Semantic conventions for cloud environment resource attribute keys. const ( // Name of the cloud provider. - CloudProviderKey = kv.Key("cloud.provider") + CloudProviderKey = label.Key("cloud.provider") // The account ID from the cloud provider used for authorization. - CloudAccountIDKey = kv.Key("cloud.account.id") + CloudAccountIDKey = label.Key("cloud.account.id") // Geographical region where this resource is. - CloudRegionKey = kv.Key("cloud.region") + CloudRegionKey = label.Key("cloud.region") // Zone of the region where this resource is. - CloudZoneKey = kv.Key("cloud.zone") + CloudZoneKey = label.Key("cloud.zone") ) var ( diff --git a/semconv/trace.go b/semconv/trace.go index 991ab9a4397..46330e32b18 100644 --- a/semconv/trace.go +++ b/semconv/trace.go @@ -14,31 +14,31 @@ package semconv -import "go.opentelemetry.io/otel/api/kv" +import "go.opentelemetry.io/otel/label" // Semantic conventions for attribute keys used for network related // operations. const ( // Transport protocol used. - NetTransportKey = kv.Key("net.transport") + NetTransportKey = label.Key("net.transport") // Remote address of the peer. - NetPeerIPKey = kv.Key("net.peer.ip") + NetPeerIPKey = label.Key("net.peer.ip") // Remote port number. - NetPeerPortKey = kv.Key("net.peer.port") + NetPeerPortKey = label.Key("net.peer.port") // Remote hostname or similar. - NetPeerNameKey = kv.Key("net.peer.name") + NetPeerNameKey = label.Key("net.peer.name") // Local host IP. Useful in case of a multi-IP host. - NetHostIPKey = kv.Key("net.host.ip") + NetHostIPKey = label.Key("net.host.ip") // Local host port. - NetHostPortKey = kv.Key("net.host.port") + NetHostPortKey = label.Key("net.host.port") // Local hostname or similar. - NetHostNameKey = kv.Key("net.host.name") + NetHostNameKey = label.Key("net.host.name") ) var ( @@ -55,7 +55,7 @@ var ( const ( // Service name of the remote service. Should equal the actual // `service.name` resource attribute of the remote service, if any. - PeerServiceKey = kv.Key("peer.service") + PeerServiceKey = label.Key("peer.service") ) // Semantic conventions for attribute keys used to identify an authorized @@ -63,70 +63,70 @@ const ( const ( // Username or the client identifier extracted from the access token or // authorization header in the inbound request from outside the system. - EnduserIDKey = kv.Key("enduser.id") + EnduserIDKey = label.Key("enduser.id") // Actual or assumed role the client is making the request with. - EnduserRoleKey = kv.Key("enduser.role") + EnduserRoleKey = label.Key("enduser.role") // Scopes or granted authorities the client currently possesses. - EnduserScopeKey = kv.Key("enduser.scope") + EnduserScopeKey = label.Key("enduser.scope") ) // Semantic conventions for attribute keys for HTTP. const ( // HTTP request method. - HTTPMethodKey = kv.Key("http.method") + HTTPMethodKey = label.Key("http.method") // Full HTTP request URL in the form: // scheme://host[:port]/path?query[#fragment]. - HTTPUrlKey = kv.Key("http.url") + HTTPUrlKey = label.Key("http.url") // The full request target as passed in a HTTP request line or // equivalent, e.g. "/path/12314/?q=ddds#123". - HTTPTargetKey = kv.Key("http.target") + HTTPTargetKey = label.Key("http.target") // The value of the HTTP host header. - HTTPHostKey = kv.Key("http.host") + HTTPHostKey = label.Key("http.host") // The URI scheme identifying the used protocol. - HTTPSchemeKey = kv.Key("http.scheme") + HTTPSchemeKey = label.Key("http.scheme") // HTTP response status code. - HTTPStatusCodeKey = kv.Key("http.status_code") + HTTPStatusCodeKey = label.Key("http.status_code") // HTTP reason phrase. - HTTPStatusTextKey = kv.Key("http.status_text") + HTTPStatusTextKey = label.Key("http.status_text") // Kind of HTTP protocol used. - HTTPFlavorKey = kv.Key("http.flavor") + HTTPFlavorKey = label.Key("http.flavor") // Value of the HTTP User-Agent header sent by the client. - HTTPUserAgentKey = kv.Key("http.user_agent") + HTTPUserAgentKey = label.Key("http.user_agent") // The primary server name of the matched virtual host. - HTTPServerNameKey = kv.Key("http.server_name") + HTTPServerNameKey = label.Key("http.server_name") // The matched route served (path template). For example, // "/users/:userID?". - HTTPRouteKey = kv.Key("http.route") + HTTPRouteKey = label.Key("http.route") // The IP address of the original client behind all proxies, if known // (e.g. from X-Forwarded-For). - HTTPClientIPKey = kv.Key("http.client_ip") + HTTPClientIPKey = label.Key("http.client_ip") // The size of the request payload body in bytes. - HTTPRequestContentLengthKey = kv.Key("http.request_content_length") + HTTPRequestContentLengthKey = label.Key("http.request_content_length") // The size of the uncompressed request payload body after transport decoding. // Not set if transport encoding not used. - HTTPRequestContentLengthUncompressedKey = kv.Key("http.request_content_length_uncompressed") + HTTPRequestContentLengthUncompressedKey = label.Key("http.request_content_length_uncompressed") // The size of the response payload body in bytes. - HTTPResponseContentLengthKey = kv.Key("http.response_content_length") + HTTPResponseContentLengthKey = label.Key("http.response_content_length") // The size of the uncompressed response payload body after transport decoding. // Not set if transport encoding not used. - HTTPResponseContentLengthUncompressedKey = kv.Key("http.response_content_length_uncompressed") + HTTPResponseContentLengthUncompressedKey = label.Key("http.response_content_length_uncompressed") ) var ( @@ -143,13 +143,13 @@ var ( // Semantic conventions for attribute keys for database connections. const ( // Identifier for the database system (DBMS) being used. - DBSystemKey = kv.Key("db.system") + DBSystemKey = label.Key("db.system") // Database Connection String with embedded credentials removed. - DBConnectionStringKey = kv.Key("db.connection_string") + DBConnectionStringKey = label.Key("db.connection_string") // Username for accessing database. - DBUserKey = kv.Key("db.user") + DBUserKey = label.Key("db.user") ) var ( @@ -178,56 +178,56 @@ var ( // Semantic conventions for attribute keys for database calls. const ( // Database instance name. - DBNameKey = kv.Key("db.name") + DBNameKey = label.Key("db.name") // A database statement for the given database type. - DBStatementKey = kv.Key("db.statement") + DBStatementKey = label.Key("db.statement") // A database operation for the given database type. - DBOperationKey = kv.Key("db.operation") + DBOperationKey = label.Key("db.operation") ) // Database technology-specific attributes const ( // Name of the Cassandra keyspace accessed. Use instead of `db.name`. - DBCassandraKeyspaceKey = kv.Key("db.cassandra.keyspace") + DBCassandraKeyspaceKey = label.Key("db.cassandra.keyspace") // HBase namespace accessed. Use instead of `db.name`. - DBHBaseNamespaceKey = kv.Key("db.hbase.namespace") + DBHBaseNamespaceKey = label.Key("db.hbase.namespace") // Index of Redis database accessed. Use instead of `db.name`. - DBRedisDBIndexKey = kv.Key("db.redis.database_index") + DBRedisDBIndexKey = label.Key("db.redis.database_index") // Collection being accessed within the database in `db.name`. - DBMongoDBCollectionKey = kv.Key("db.mongodb.collection") + DBMongoDBCollectionKey = label.Key("db.mongodb.collection") ) // Semantic conventions for attribute keys for RPC. const ( // A string identifying the remoting system. - RPCSystemKey = kv.Key("rpc.system") + RPCSystemKey = label.Key("rpc.system") // The full name of the service being called. - RPCServiceKey = kv.Key("rpc.service") + RPCServiceKey = label.Key("rpc.service") // The name of the method being called. - RPCMethodKey = kv.Key("rpc.method") + RPCMethodKey = label.Key("rpc.method") // Name of message transmitted or received. - RPCNameKey = kv.Key("name") + RPCNameKey = label.Key("name") // Type of message transmitted or received. - RPCMessageTypeKey = kv.Key("message.type") + RPCMessageTypeKey = label.Key("message.type") // Identifier of message transmitted or received. - RPCMessageIDKey = kv.Key("message.id") + RPCMessageIDKey = label.Key("message.id") // The compressed size of the message transmitted or received in bytes. - RPCMessageCompressedSizeKey = kv.Key("message.compressed_size") + RPCMessageCompressedSizeKey = label.Key("message.compressed_size") // The uncompressed size of the message transmitted or received in // bytes. - RPCMessageUncompressedSizeKey = kv.Key("message.uncompressed_size") + RPCMessageUncompressedSizeKey = label.Key("message.uncompressed_size") ) var ( @@ -243,44 +243,44 @@ var ( const ( // A unique identifier describing the messaging system. For example, // kafka, rabbitmq or activemq. - MessagingSystemKey = kv.Key("messaging.system") + MessagingSystemKey = label.Key("messaging.system") // The message destination name, e.g. MyQueue or MyTopic. - MessagingDestinationKey = kv.Key("messaging.destination") + MessagingDestinationKey = label.Key("messaging.destination") // The kind of message destination. - MessagingDestinationKindKey = kv.Key("messaging.destination_kind") + MessagingDestinationKindKey = label.Key("messaging.destination_kind") // Describes if the destination is temporary or not. - MessagingTempDestinationKey = kv.Key("messaging.temp_destination") + MessagingTempDestinationKey = label.Key("messaging.temp_destination") // The name of the transport protocol. - MessagingProtocolKey = kv.Key("messaging.protocol") + MessagingProtocolKey = label.Key("messaging.protocol") // The version of the transport protocol. - MessagingProtocolVersionKey = kv.Key("messaging.protocol_version") + MessagingProtocolVersionKey = label.Key("messaging.protocol_version") // Messaging service URL. - MessagingURLKey = kv.Key("messaging.url") + MessagingURLKey = label.Key("messaging.url") // Identifier used by the messaging system for a message. - MessagingMessageIDKey = kv.Key("messaging.message_id") + MessagingMessageIDKey = label.Key("messaging.message_id") // Identifier used by the messaging system for a conversation. - MessagingConversationIDKey = kv.Key("messaging.conversation_id") + MessagingConversationIDKey = label.Key("messaging.conversation_id") // The (uncompressed) size of the message payload in bytes. - MessagingMessagePayloadSizeBytesKey = kv.Key("messaging.message_payload_size_bytes") + MessagingMessagePayloadSizeBytesKey = label.Key("messaging.message_payload_size_bytes") // The compressed size of the message payload in bytes. - MessagingMessagePayloadCompressedSizeBytesKey = kv.Key("messaging.message_payload_compressed_size_bytes") + MessagingMessagePayloadCompressedSizeBytesKey = label.Key("messaging.message_payload_compressed_size_bytes") // Identifies which part and kind of message consumption is being // preformed. - MessagingOperationKey = kv.Key("messaging.operation") + MessagingOperationKey = label.Key("messaging.operation") // RabbitMQ specific attribute describing the destination routing key. - MessagingRabbitMQRoutingKeyKey = kv.Key("messaging.rabbitmq.routing_key") + MessagingRabbitMQRoutingKeyKey = label.Key("messaging.rabbitmq.routing_key") ) var ( @@ -297,34 +297,34 @@ var ( const ( // Type of the trigger on which the function is executed. - FaaSTriggerKey = kv.Key("faas.trigger") + FaaSTriggerKey = label.Key("faas.trigger") // String containing the execution identifier of the function. - FaaSExecutionKey = kv.Key("faas.execution") + FaaSExecutionKey = label.Key("faas.execution") // A boolean indicating that the serverless function is executed // for the first time (aka cold start). - FaaSColdstartKey = kv.Key("faas.coldstart") + FaaSColdstartKey = label.Key("faas.coldstart") // The name of the source on which the operation was performed. // For example, in Cloud Storage or S3 corresponds to the bucket name, // and in Cosmos DB to the database name. - FaaSDocumentCollectionKey = kv.Key("faas.document.collection") + FaaSDocumentCollectionKey = label.Key("faas.document.collection") // The type of the operation that was performed on the data. - FaaSDocumentOperationKey = kv.Key("faas.document.operation") + FaaSDocumentOperationKey = label.Key("faas.document.operation") // A string containing the time when the data was accessed. - FaaSDocumentTimeKey = kv.Key("faas.document.time") + FaaSDocumentTimeKey = label.Key("faas.document.time") // The document name/table subjected to the operation. - FaaSDocumentNameKey = kv.Key("faas.document.name") + FaaSDocumentNameKey = label.Key("faas.document.name") // The function invocation time. - FaaSTimeKey = kv.Key("faas.time") + FaaSTimeKey = label.Key("faas.time") // The schedule period as Cron Expression. - FaaSCronKey = kv.Key("faas.cron") + FaaSCronKey = label.Key("faas.cron") ) var (