diff --git a/CHANGELOG.md b/CHANGELOG.md index 147406ef4e2..a11b609d0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Replaced interface `oteltest.SpanRecorder` with its existing implementation `StandardSpanRecorder` (#1542). +- Renamed the `otel/label` package to `otel/attribute`. (#1541) ### Added diff --git a/label/benchmark_test.go b/attribute/benchmark_test.go similarity index 75% rename from label/benchmark_test.go rename to attribute/benchmark_test.go index 05b9deec2c3..1448d5d833f 100644 --- a/label/benchmark_test.go +++ b/attribute/benchmark_test.go @@ -12,40 +12,40 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label_test +package attribute_test import ( "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) type test struct{} var ( arrayVal = []string{"one", "two"} - arrayKeyVal = label.Array("array", arrayVal) + arrayKeyVal = attribute.Array("array", arrayVal) boolVal = true - boolKeyVal = label.Bool("bool", boolVal) + boolKeyVal = attribute.Bool("bool", boolVal) intVal = int(1) - intKeyVal = label.Int("int", intVal) + intKeyVal = attribute.Int("int", intVal) int8Val = int8(1) - int8KeyVal = label.Int("int8", int(int8Val)) + int8KeyVal = attribute.Int("int8", int(int8Val)) int16Val = int16(1) - int16KeyVal = label.Int("int16", int(int16Val)) + int16KeyVal = attribute.Int("int16", int(int16Val)) int64Val = int64(1) - int64KeyVal = label.Int64("int64", int64Val) + int64KeyVal = attribute.Int64("int64", int64Val) float64Val = float64(1.0) - float64KeyVal = label.Float64("float64", float64Val) + float64KeyVal = attribute.Float64("float64", float64Val) stringVal = "string" - stringKeyVal = label.String("string", stringVal) + stringKeyVal = attribute.String("string", stringVal) bytesVal = []byte("bytes") structVal = test{} @@ -54,112 +54,112 @@ var ( func BenchmarkArrayKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Array("array", arrayVal) + _ = attribute.Array("array", arrayVal) } } func BenchmarkArrayKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("array", arrayVal) + _ = attribute.Any("array", arrayVal) } } func BenchmarkBoolKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Bool("bool", boolVal) + _ = attribute.Bool("bool", boolVal) } } func BenchmarkBoolKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("bool", boolVal) + _ = attribute.Any("bool", boolVal) } } func BenchmarkIntKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Int("int", intVal) + _ = attribute.Int("int", intVal) } } func BenchmarkIntKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("int", intVal) + _ = attribute.Any("int", intVal) } } func BenchmarkInt8KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("int8", int8Val) + _ = attribute.Any("int8", int8Val) } } func BenchmarkInt16KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("int16", int16Val) + _ = attribute.Any("int16", int16Val) } } func BenchmarkInt64Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Int64("int64", int64Val) + _ = attribute.Int64("int64", int64Val) } } func BenchmarkInt64KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("int64", int64Val) + _ = attribute.Any("int64", int64Val) } } func BenchmarkFloat64Key(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Float64("float64", float64Val) + _ = attribute.Float64("float64", float64Val) } } func BenchmarkFloat64KeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("float64", float64Val) + _ = attribute.Any("float64", float64Val) } } func BenchmarkStringKey(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.String("string", stringVal) + _ = attribute.String("string", stringVal) } } func BenchmarkStringKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("string", stringVal) + _ = attribute.Any("string", stringVal) } } func BenchmarkBytesKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("bytes", bytesVal) + _ = attribute.Any("bytes", bytesVal) } } func BenchmarkStructKeyAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - _ = label.Any("struct", structVal) + _ = attribute.Any("struct", structVal) } } diff --git a/label/doc.go b/attribute/doc.go similarity index 87% rename from label/doc.go rename to attribute/doc.go index abdffdb46f5..44bc32c9e07 100644 --- a/label/doc.go +++ b/attribute/doc.go @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package label provides key and value labels. +// package attribute provides key and value attributes. // // This package is currently in a pre-GA phase. Backwards incompatible changes // may be introduced in subsequent minor version releases as we work to track // the evolving OpenTelemetry specification and user feedback. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" diff --git a/label/encoder.go b/attribute/encoder.go similarity index 98% rename from label/encoder.go rename to attribute/encoder.go index 4620873df73..8b940f78dc4 100644 --- a/label/encoder.go +++ b/attribute/encoder.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" import ( "bytes" @@ -28,7 +28,7 @@ type ( Encoder interface { // Encode returns the serialized encoding of the label // set using its Iterator. This result may be cached - // by a label.Set. + // by a attribute.Set. Encode(iterator Iterator) string // ID returns a value that is unique for each class of diff --git a/label/iterator.go b/attribute/iterator.go similarity index 96% rename from label/iterator.go rename to attribute/iterator.go index a968e766827..e03aabb62bd 100644 --- a/label/iterator.go +++ b/attribute/iterator.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" // Iterator allows iterating over the set of labels in order, // sorted by key. @@ -55,7 +55,7 @@ func (i *Iterator) Attribute() KeyValue { return i.Label() } -// IndexedLabel returns current index and label. Must be called only +// IndexedLabel returns current index and attribute. Must be called only // after Next returns true. func (i *Iterator) IndexedLabel() (int, KeyValue) { return i.idx, i.Label() diff --git a/label/iterator_test.go b/attribute/iterator_test.go similarity index 86% rename from label/iterator_test.go rename to attribute/iterator_test.go index a028f8d0a98..9c5d4d7dbda 100644 --- a/label/iterator_test.go +++ b/attribute/iterator_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label_test +package attribute_test import ( "fmt" @@ -20,13 +20,13 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) func TestIterator(t *testing.T) { - one := label.String("one", "1") - two := label.Int("two", 2) - lbl := label.NewSet(one, two) + one := attribute.String("one", "1") + two := attribute.Int("two", 2) + lbl := attribute.NewSet(one, two) iter := lbl.Iter() require.Equal(t, 2, iter.Len()) @@ -49,7 +49,7 @@ func TestIterator(t *testing.T) { } func TestEmptyIterator(t *testing.T) { - lbl := label.NewSet() + lbl := attribute.NewSet() iter := lbl.Iter() require.Equal(t, 0, iter.Len()) require.False(t, iter.Next()) @@ -64,9 +64,9 @@ func TestMergedIterator(t *testing.T) { expect []string } - makeLabels := func(keys []string, num int) (result []label.KeyValue) { + makeLabels := func(keys []string, num int) (result []attribute.KeyValue) { for _, k := range keys { - result = append(result, label.Int(k, num)) + result = append(result, attribute.Int(k, num)) } return } @@ -131,10 +131,10 @@ func TestMergedIterator(t *testing.T) { labels1 := makeLabels(input.keys1, 1) labels2 := makeLabels(input.keys2, 2) - set1 := label.NewSet(labels1...) - set2 := label.NewSet(labels2...) + set1 := attribute.NewSet(labels1...) + set2 := attribute.NewSet(labels2...) - merge := label.NewMergeIterator(&set1, &set2) + merge := attribute.NewMergeIterator(&set1, &set2) var result []string diff --git a/label/key.go b/attribute/key.go similarity index 97% rename from label/key.go rename to attribute/key.go index 3f038cf6df6..492c438a9f5 100644 --- a/label/key.go +++ b/attribute/key.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" // 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. diff --git a/label/key_test.go b/attribute/key_test.go similarity index 79% rename from label/key_test.go rename to attribute/key_test.go index 66aeb060fd6..6d9f0fedd65 100644 --- a/label/key_test.go +++ b/attribute/key_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label_test +package attribute_test import ( "encoding/json" @@ -20,28 +20,28 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) func TestDefined(t *testing.T) { for _, testcase := range []struct { name string - k label.Key + k attribute.Key want bool }{ { name: "Key.Defined() returns true when len(v.Name) != 0", - k: label.Key("foo"), + k: attribute.Key("foo"), want: true, }, { name: "Key.Defined() returns false when len(v.Name) == 0", - k: label.Key(""), + k: attribute.Key(""), want: false, }, } { t.Run(testcase.name, func(t *testing.T) { - //func (k label.Key) Defined() bool { + //func (k attribute.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]label.KeyValue{ - label.String("A", "B"), - label.Int64("C", 1), + var kvs interface{} = [2]attribute.KeyValue{ + attribute.String("A", "B"), + attribute.Int64("C", 1), } data, err := json.Marshal(kvs) @@ -66,32 +66,32 @@ func TestJSONValue(t *testing.T) { func TestEmit(t *testing.T) { for _, testcase := range []struct { name string - v label.Value + v attribute.Value want string }{ { name: `test Key.Emit() can emit a string representing self.BOOL`, - v: label.BoolValue(true), + v: attribute.BoolValue(true), want: "true", }, { name: `test Key.Emit() can emit a string representing self.INT64`, - v: label.Int64Value(42), + v: attribute.Int64Value(42), want: "42", }, { name: `test Key.Emit() can emit a string representing self.FLOAT64`, - v: label.Float64Value(42.1), + v: attribute.Float64Value(42.1), want: "42.1", }, { name: `test Key.Emit() can emit a string representing self.STRING`, - v: label.StringValue("foo"), + v: attribute.StringValue("foo"), want: "foo", }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (v label.Value) Emit() string { + //proto: func (v attribute.Value) Emit() string { have := testcase.v.Emit() if have != testcase.want { t.Errorf("Want: %s, but have: %s", testcase.want, have) diff --git a/label/kv.go b/attribute/kv.go similarity index 97% rename from label/kv.go rename to attribute/kv.go index 4b027c6072b..0e5b06d8273 100644 --- a/label/kv.go +++ b/attribute/kv.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" import ( "encoding/json" diff --git a/label/kv_test.go b/attribute/kv_test.go similarity index 72% rename from label/kv_test.go rename to attribute/kv_test.go index 85376dbd2f2..3f77fdf2913 100644 --- a/label/kv_test.go +++ b/attribute/kv_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label_test +package attribute_test import ( "strings" @@ -20,60 +20,60 @@ import ( "github.com/google/go-cmp/cmp" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) func TestKeyValueConstructors(t *testing.T) { tt := []struct { name string - actual label.KeyValue - expected label.KeyValue + actual attribute.KeyValue + expected attribute.KeyValue }{ { name: "Bool", - actual: label.Bool("k1", true), - expected: label.KeyValue{ + actual: attribute.Bool("k1", true), + expected: attribute.KeyValue{ Key: "k1", - Value: label.BoolValue(true), + Value: attribute.BoolValue(true), }, }, { name: "Int64", - actual: label.Int64("k1", 123), - expected: label.KeyValue{ + actual: attribute.Int64("k1", 123), + expected: attribute.KeyValue{ Key: "k1", - Value: label.Int64Value(123), + Value: attribute.Int64Value(123), }, }, { name: "Float64", - actual: label.Float64("k1", 123.5), - expected: label.KeyValue{ + actual: attribute.Float64("k1", 123.5), + expected: attribute.KeyValue{ Key: "k1", - Value: label.Float64Value(123.5), + Value: attribute.Float64Value(123.5), }, }, { name: "String", - actual: label.String("k1", "123.5"), - expected: label.KeyValue{ + actual: attribute.String("k1", "123.5"), + expected: attribute.KeyValue{ Key: "k1", - Value: label.StringValue("123.5"), + Value: attribute.StringValue("123.5"), }, }, { name: "Int", - actual: label.Int("k1", 123), - expected: label.KeyValue{ + actual: attribute.Int("k1", 123), + expected: attribute.KeyValue{ Key: "k1", - Value: label.IntValue(123), + Value: attribute.IntValue(123), }, }, } for _, test := range tt { t.Run(test.name, func(t *testing.T) { - if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(label.Value{})); diff != "" { + if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(attribute.Value{})); diff != "" { t.Fatal(diff) } }) @@ -97,60 +97,60 @@ func TestAny(t *testing.T) { for _, testcase := range []struct { key string value interface{} - wantType label.Type + wantType attribute.Type wantValue interface{} }{ { key: "bool type inferred", value: true, - wantType: label.BOOL, + wantType: attribute.BOOL, wantValue: true, }, { key: "int64 type inferred", value: int64(42), - wantType: label.INT64, + wantType: attribute.INT64, wantValue: int64(42), }, { key: "float64 type inferred", value: float64(42.1), - wantType: label.FLOAT64, + wantType: attribute.FLOAT64, wantValue: 42.1, }, { key: "string type inferred", value: "foo", - wantType: label.STRING, + wantType: attribute.STRING, wantValue: "foo", }, { key: "stringer type inferred", value: builder, - wantType: label.STRING, + wantType: attribute.STRING, wantValue: "foo", }, { key: "unknown value serialized as %v", value: nil, - wantType: label.STRING, + wantType: attribute.STRING, wantValue: "", }, { key: "JSON struct serialized correctly", value: &jsonifyStruct, - wantType: label.STRING, + wantType: attribute.STRING, wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`, }, { key: "Invalid JSON struct falls back to string", value: &invalidStruct, - wantType: label.STRING, + wantType: attribute.STRING, wantValue: "&{(0+0i)}", }, } { t.Logf("Running test case %s", testcase.key) - keyValue := label.Any(testcase.key, testcase.value) + keyValue := attribute.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/label/set.go b/attribute/set.go similarity index 98% rename from label/set.go rename to attribute/set.go index 2d2f0045041..882dc112f72 100644 --- a/label/set.go +++ b/attribute/set.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" import ( "encoding/json" @@ -295,7 +295,7 @@ func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) { // - allocating a `Set` for storing the return value of this // constructor. // -// The result maintains a cache of encoded labels, by label.EncoderID. +// The result maintains a cache of encoded labels, by attribute.EncoderID. // This value should not be copied after its first use. // // The second `[]KeyValue` return value is a list of labels that were diff --git a/label/set_test.go b/attribute/set_test.go similarity index 59% rename from label/set_test.go rename to attribute/set_test.go index 7f6fc0fef67..1293c3aad8f 100644 --- a/label/set_test.go +++ b/attribute/set_test.go @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label_test +package attribute_test import ( "regexp" "testing" - "go.opentelemetry.io/otel/label" - "github.com/stretchr/testify/require" + + "go.opentelemetry.io/otel/attribute" ) type testCase struct { - kvs []label.KeyValue + kvs []attribute.KeyValue keyRe *regexp.Regexp @@ -32,14 +32,14 @@ type testCase struct { fullEnc string } -func expect(enc string, kvs ...label.KeyValue) testCase { +func expect(enc string, kvs ...attribute.KeyValue) testCase { return testCase{ kvs: kvs, encoding: enc, } } -func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase { +func expectFiltered(enc, filter, fullEnc string, kvs ...attribute.KeyValue) testCase { return testCase{ kvs: kvs, keyRe: regexp.MustCompile(filter), @@ -50,26 +50,26 @@ func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase func TestSetDedup(t *testing.T) { cases := []testCase{ - 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")), + expect("A=B", attribute.String("A", "2"), attribute.String("A", "B")), + expect("A=B", attribute.String("A", "2"), attribute.Int("A", 1), attribute.String("A", "B")), + expect("A=B", attribute.String("A", "B"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B")), + + expect("A=B,C=D", attribute.String("A", "1"), attribute.String("C", "D"), attribute.String("A", "B")), + expect("A=B,C=D", attribute.String("A", "2"), attribute.String("A", "B"), attribute.String("C", "D")), + expect("A=B,C=D", attribute.Float64("C", 1.2), attribute.String("A", "2"), attribute.String("A", "B"), attribute.String("C", "D")), + expect("A=B,C=D", attribute.String("C", "D"), attribute.String("A", "B"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B")), + expect("A=B,C=D", attribute.String("A", "B"), attribute.String("C", "D"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B")), + expect("A=B,C=D", attribute.String("A", "B"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B"), attribute.String("C", "D")), } - enc := label.DefaultEncoder() + enc := attribute.DefaultEncoder() - s2d := map[string][]label.Distinct{} - d2s := map[label.Distinct][]string{} + s2d := map[string][]attribute.Distinct{} + d2s := map[attribute.Distinct][]string{} for _, tc := range cases { - cpy := make([]label.KeyValue, len(tc.kvs)) + cpy := make([]attribute.KeyValue, len(tc.kvs)) copy(cpy, tc.kvs) - sl := label.NewSet(cpy...) + sl := attribute.NewSet(cpy...) // Ensure that the input was reordered but no elements went missing. require.ElementsMatch(t, tc.kvs, cpy) @@ -129,19 +129,19 @@ func TestSetDedup(t *testing.T) { } func TestUniqueness(t *testing.T) { - short := []label.KeyValue{ - label.String("A", "0"), - label.String("B", "2"), - label.String("A", "1"), + short := []attribute.KeyValue{ + attribute.String("A", "0"), + attribute.String("B", "2"), + attribute.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"), + long := []attribute.KeyValue{ + attribute.String("B", "2"), + attribute.String("C", "5"), + attribute.String("B", "2"), + attribute.String("C", "1"), + attribute.String("A", "4"), + attribute.String("C", "3"), + attribute.String("A", "1"), } cases := []testCase{ expectFiltered("A=1", "^A$", "B=2", short...), @@ -154,16 +154,16 @@ func TestUniqueness(t *testing.T) { expectFiltered("C=3", "C", "A=1,B=2", long...), expectFiltered("", "D", "A=1,B=2,C=3", long...), } - enc := label.DefaultEncoder() + enc := attribute.DefaultEncoder() for _, tc := range cases { - cpy := make([]label.KeyValue, len(tc.kvs)) + cpy := make([]attribute.KeyValue, len(tc.kvs)) copy(cpy, tc.kvs) - distinct, uniq := label.NewSetWithFiltered(cpy, func(label label.KeyValue) bool { + distinct, uniq := attribute.NewSetWithFiltered(cpy, func(label attribute.KeyValue) bool { return tc.keyRe.MatchString(string(label.Key)) }) - full := label.NewSet(uniq...) + full := attribute.NewSet(uniq...) require.Equal(t, tc.encoding, distinct.Encoded(enc)) require.Equal(t, tc.fullEnc, full.Encoded(enc)) @@ -171,7 +171,7 @@ func TestUniqueness(t *testing.T) { } func TestLookup(t *testing.T) { - set := label.NewSet(label.Int("C", 3), label.Int("A", 1), label.Int("B", 2)) + set := attribute.NewSet(attribute.Int("C", 3), attribute.Int("A", 1), attribute.Int("B", 2)) value, has := set.Value("C") require.True(t, has) diff --git a/label/type_string.go b/attribute/type_string.go similarity index 97% rename from label/type_string.go rename to attribute/type_string.go index 56a54a32d19..1f2c7dccfa5 100644 --- a/label/type_string.go +++ b/attribute/type_string.go @@ -1,6 +1,6 @@ // Code generated by "stringer -type=Type"; DO NOT EDIT. -package label +package attribute import "strconv" diff --git a/label/value.go b/attribute/value.go similarity index 98% rename from label/value.go rename to attribute/value.go index 9fd0268b562..44ef795cb78 100644 --- a/label/value.go +++ b/attribute/value.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label // import "go.opentelemetry.io/otel/label" +package attribute // import "go.opentelemetry.io/otel/attribute" import ( "encoding/json" diff --git a/label/value_test.go b/attribute/value_test.go similarity index 84% rename from label/value_test.go rename to attribute/value_test.go index ca11c494cbd..3fed8b7d3b8 100644 --- a/label/value_test.go +++ b/attribute/value_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package label_test +package attribute_test import ( "reflect" @@ -20,46 +20,46 @@ import ( "github.com/google/go-cmp/cmp" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) func TestValue(t *testing.T) { - k := label.Key("test") + k := attribute.Key("test") bli := getBitlessInfo(42) for _, testcase := range []struct { name string - value label.Value - wantType label.Type + value attribute.Value + wantType attribute.Type wantValue interface{} }{ { name: "Key.Bool() correctly returns keys's internal bool value", value: k.Bool(true).Value, - wantType: label.BOOL, + wantType: attribute.BOOL, wantValue: true, }, { name: "Key.Array([]bool) correctly return key's internal bool values", value: k.Array([]bool{true, false}).Value, - wantType: label.ARRAY, + wantType: attribute.ARRAY, wantValue: [2]bool{true, false}, }, { name: "Key.Int64() correctly returns keys's internal int64 value", value: k.Int64(42).Value, - wantType: label.INT64, + wantType: attribute.INT64, wantValue: int64(42), }, { name: "Key.Float64() correctly returns keys's internal float64 value", value: k.Float64(42.1).Value, - wantType: label.FLOAT64, + wantType: attribute.FLOAT64, wantValue: 42.1, }, { name: "Key.String() correctly returns keys's internal string value", value: k.String("foo").Value, - wantType: label.STRING, + wantType: attribute.STRING, wantValue: "foo", }, { @@ -71,31 +71,31 @@ func TestValue(t *testing.T) { { name: "Key.Array([]int64) correctly returns keys's internal int64 values", value: k.Array([]int64{42, 43}).Value, - wantType: label.ARRAY, + wantType: attribute.ARRAY, wantValue: [2]int64{42, 43}, }, { name: "Key.Array([]float64) correctly returns keys's internal float64 values", value: k.Array([]float64{42, 43}).Value, - wantType: label.ARRAY, + wantType: attribute.ARRAY, wantValue: [2]float64{42, 43}, }, { name: "Key.Array([]string) correctly return key's internal string values", value: k.Array([]string{"foo", "bar"}).Value, - wantType: label.ARRAY, + wantType: attribute.ARRAY, wantValue: [2]string{"foo", "bar"}, }, { name: "Key.Array([]int) correctly returns keys's internal signed integral values", value: k.Array([]int{42, 43}).Value, - wantType: label.ARRAY, + wantType: attribute.ARRAY, wantValue: [2]int{42, 43}, }, { name: "Key.Array([][]int) refuses to create multi-dimensional array", value: k.Array([][]int{{1, 2}, {3, 4}}).Value, - wantType: label.INVALID, + wantType: attribute.INVALID, wantValue: nil, }, } { @@ -103,7 +103,7 @@ func TestValue(t *testing.T) { if testcase.value.Type() != testcase.wantType { t.Errorf("wrong value type, got %#v, expected %#v", testcase.value.Type(), testcase.wantType) } - if testcase.wantType == label.INVALID { + if testcase.wantType == attribute.INVALID { continue } got := testcase.value.AsInterface() @@ -116,7 +116,7 @@ func TestValue(t *testing.T) { type bitlessInfo struct { intValue int uintValue uint - signedType label.Type + signedType attribute.Type signedValue interface{} } @@ -124,13 +124,13 @@ func getBitlessInfo(i int) bitlessInfo { return bitlessInfo{ intValue: i, uintValue: uint(i), - signedType: label.INT64, + signedType: attribute.INT64, signedValue: int64(i), } } func TestAsArrayValue(t *testing.T) { - v := label.ArrayValue([]int{1, 2, 3}).AsArray() + v := attribute.ArrayValue([]int{1, 2, 3}).AsArray() // Ensure the returned dynamic type is stable. if got, want := reflect.TypeOf(v).Kind(), reflect.Array; got != want { t.Errorf("AsArray() returned %T, want %T", got, want) diff --git a/baggage/baggage.go b/baggage/baggage.go index 66b8416f1f3..365388c654e 100644 --- a/baggage/baggage.go +++ b/baggage/baggage.go @@ -17,35 +17,35 @@ package baggage // import "go.opentelemetry.io/otel/baggage" import ( "context" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/baggage" - "go.opentelemetry.io/otel/label" ) // Set returns a copy of the set of baggage key-values in ctx. -func Set(ctx context.Context) label.Set { +func Set(ctx context.Context) attribute.Set { // TODO (MrAlias, #1222): The underlying storage, the Map, shares many of - // the functional elements of the label.Set. These should be unified so + // the functional elements of the attribute.Set. These should be unified so // this conversion is unnecessary and there is no performance hit calling // this. m := baggage.MapFromContext(ctx) - values := make([]label.KeyValue, 0, m.Len()) - m.Foreach(func(kv label.KeyValue) bool { + values := make([]attribute.KeyValue, 0, m.Len()) + m.Foreach(func(kv attribute.KeyValue) bool { values = append(values, kv) return true }) - return label.NewSet(values...) + return attribute.NewSet(values...) } // Value returns the value related to key in the baggage of ctx. If no -// value is set, the returned label.Value will be an uninitialized zero-value +// value is set, the returned attribute.Value will be an uninitialized zero-value // with type INVALID. -func Value(ctx context.Context, key label.Key) label.Value { +func Value(ctx context.Context, key attribute.Key) attribute.Value { v, _ := baggage.MapFromContext(ctx).Value(key) return v } // ContextWithValues returns a copy of parent with pairs updated in the baggage. -func ContextWithValues(parent context.Context, pairs ...label.KeyValue) context.Context { +func ContextWithValues(parent context.Context, pairs ...attribute.KeyValue) context.Context { m := baggage.MapFromContext(parent).Apply(baggage.MapUpdate{ MultiKV: pairs, }) @@ -54,7 +54,7 @@ func ContextWithValues(parent context.Context, pairs ...label.KeyValue) context. // ContextWithoutValues returns a copy of parent in which the values related // to keys have been removed from the baggage. -func ContextWithoutValues(parent context.Context, keys ...label.Key) context.Context { +func ContextWithoutValues(parent context.Context, keys ...attribute.Key) context.Context { m := baggage.MapFromContext(parent).Apply(baggage.MapUpdate{ DropMultiK: keys, }) diff --git a/baggage/baggage_test.go b/baggage/baggage_test.go index f87c3b2b64d..53f57b1bcd4 100644 --- a/baggage/baggage_test.go +++ b/baggage/baggage_test.go @@ -18,8 +18,8 @@ import ( "context" "testing" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/baggage" - "go.opentelemetry.io/otel/label" ) func TestBaggage(t *testing.T) { @@ -31,7 +31,7 @@ func TestBaggage(t *testing.T) { t.Fatalf("empty baggage returned a set with %d elements", b.Len()) } - first, second, third := label.Key("first"), label.Key("second"), label.Key("third") + first, second, third := attribute.Key("first"), attribute.Key("second"), attribute.Key("third") ctx = ContextWithValues(ctx, first.Bool(true), second.String("2")) m := baggage.MapFromContext(ctx) v, ok := m.Value(first) @@ -59,11 +59,11 @@ func TestBaggage(t *testing.T) { } v = Value(ctx, first) - if v.Type() != label.BOOL || !v.AsBool() { + if v.Type() != attribute.BOOL || !v.AsBool() { t.Fatal("Value failed to get correct first value") } v = Value(ctx, second) - if v.Type() != label.STRING || v.AsString() != "2" { + if v.Type() != attribute.STRING || v.AsString() != "2" { t.Fatal("Value failed to get correct second value") } diff --git a/bridge/opencensus/bridge.go b/bridge/opencensus/bridge.go index aabcbf1774e..b5620394294 100644 --- a/bridge/opencensus/bridge.go +++ b/bridge/opencensus/bridge.go @@ -21,9 +21,9 @@ import ( octrace "go.opencensus.io/trace" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/bridge/opencensus/utils" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" ) @@ -114,29 +114,29 @@ func (s *span) AddAttributes(attributes ...octrace.Attribute) { s.otSpan.SetAttributes(convertAttributes(attributes)...) } -func convertAttributes(attributes []octrace.Attribute) []label.KeyValue { - otAttributes := make([]label.KeyValue, len(attributes)) +func convertAttributes(attributes []octrace.Attribute) []attribute.KeyValue { + otAttributes := make([]attribute.KeyValue, len(attributes)) for i, a := range attributes { - otAttributes[i] = label.KeyValue{ - Key: label.Key(a.Key()), + otAttributes[i] = attribute.KeyValue{ + Key: attribute.Key(a.Key()), Value: convertValue(a.Value()), } } return otAttributes } -func convertValue(ocval interface{}) label.Value { +func convertValue(ocval interface{}) attribute.Value { switch v := ocval.(type) { case bool: - return label.BoolValue(v) + return attribute.BoolValue(v) case int64: - return label.Int64Value(v) + return attribute.Int64Value(v) case float64: - return label.Float64Value(v) + return attribute.Float64Value(v) case string: - return label.StringValue(v) + return attribute.StringValue(v) default: - return label.StringValue("unknown") + return attribute.StringValue("unknown") } } @@ -149,20 +149,20 @@ func (s *span) Annotatef(attributes []octrace.Attribute, format string, a ...int } var ( - uncompressedKey = label.Key("uncompressed byte size") - compressedKey = label.Key("compressed byte size") + uncompressedKey = attribute.Key("uncompressed byte size") + compressedKey = attribute.Key("compressed byte size") ) func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) { s.otSpan.AddEvent("message send", trace.WithAttributes( - label.KeyValue{ + attribute.KeyValue{ Key: uncompressedKey, - Value: label.Int64Value(uncompressedByteSize), + Value: attribute.Int64Value(uncompressedByteSize), }, - label.KeyValue{ + attribute.KeyValue{ Key: compressedKey, - Value: label.Int64Value(compressedByteSize), + Value: attribute.Int64Value(compressedByteSize), }), ) } @@ -170,13 +170,13 @@ func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedBy func (s *span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) { s.otSpan.AddEvent("message receive", trace.WithAttributes( - label.KeyValue{ + attribute.KeyValue{ Key: uncompressedKey, - Value: label.Int64Value(uncompressedByteSize), + Value: attribute.Int64Value(uncompressedByteSize), }, - label.KeyValue{ + attribute.KeyValue{ Key: compressedKey, - Value: label.Int64Value(compressedByteSize), + Value: attribute.Int64Value(compressedByteSize), }), ) } diff --git a/bridge/opencensus/bridge_test.go b/bridge/opencensus/bridge_test.go index 917e483098f..b06bb9e7d15 100644 --- a/bridge/opencensus/bridge_test.go +++ b/bridge/opencensus/bridge_test.go @@ -20,9 +20,9 @@ import ( octrace "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/bridge/opencensus/utils" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/trace" ) @@ -218,16 +218,16 @@ func TestSetThings(t *testing.T) { t.Errorf("Got code %v, expected foo", s.StatusMessage()) } - if v := s.Attributes()[label.Key("bool")]; !v.AsBool() { + if v := s.Attributes()[attribute.Key("bool")]; !v.AsBool() { t.Errorf("Got attributes[bool] %v, expected true", v.AsBool()) } - if v := s.Attributes()[label.Key("int64")]; v.AsInt64() != 12345 { + if v := s.Attributes()[attribute.Key("int64")]; v.AsInt64() != 12345 { t.Errorf("Got attributes[int64] %v, expected 12345", v.AsInt64()) } - if v := s.Attributes()[label.Key("float64")]; v.AsFloat64() != 12.345 { + if v := s.Attributes()[attribute.Key("float64")]; v.AsFloat64() != 12.345 { t.Errorf("Got attributes[float64] %v, expected 12.345", v.AsFloat64()) } - if v := s.Attributes()[label.Key("string")]; v.AsString() != "stringval" { + if v := s.Attributes()[attribute.Key("string")]; v.AsString() != "stringval" { t.Errorf("Got attributes[string] %v, expected stringval", v.AsString()) } @@ -238,22 +238,22 @@ func TestSetThings(t *testing.T) { annotatefEvent := s.Events()[1] sendEvent := s.Events()[2] receiveEvent := s.Events()[3] - if v := annotateEvent.Attributes[label.Key("string")]; v.AsString() != "annotateval" { + if v := annotateEvent.Attributes[attribute.Key("string")]; v.AsString() != "annotateval" { t.Errorf("Got annotateEvent.Attributes[string] = %v, expected annotateval", v.AsString()) } if annotateEvent.Name != "annotate" { t.Errorf("Got annotateEvent.Name = %v, expected annotate", annotateEvent.Name) } - if v := annotatefEvent.Attributes[label.Key("int64")]; v.AsInt64() != 12345 { + if v := annotatefEvent.Attributes[attribute.Key("int64")]; v.AsInt64() != 12345 { t.Errorf("Got annotatefEvent.Attributes[int64] = %v, expected 12345", v.AsInt64()) } - if v := annotatefEvent.Attributes[label.Key("float64")]; v.AsFloat64() != 12.345 { + if v := annotatefEvent.Attributes[attribute.Key("float64")]; v.AsFloat64() != 12.345 { t.Errorf("Got annotatefEvent.Attributes[float64] = %v, expected 12.345", v.AsFloat64()) } if annotatefEvent.Name != "annotate67890" { t.Errorf("Got annotatefEvent.Name = %v, expected annotate67890", annotatefEvent.Name) } - if v := annotateEvent.Attributes[label.Key("string")]; v.AsString() != "annotateval" { + if v := annotateEvent.Attributes[attribute.Key("string")]; v.AsString() != "annotateval" { t.Errorf("Got annotateEvent.Attributes[string] = %v, expected annotateval", v.AsString()) } if sendEvent.Name != "message send" { diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 7dd2d688c2c..4036b863522 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -26,12 +26,12 @@ import ( otlog "github.com/opentracing/opentracing-go/log" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/bridge/opentracing/migration" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/trace/noop" otelparent "go.opentelemetry.io/otel/internal/trace/parent" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" ) @@ -58,19 +58,19 @@ func newBridgeSpanContext(otelSpanContext trace.SpanContext, parentOtSpanContext } func (c *bridgeSpanContext) ForeachBaggageItem(handler func(k, v string) bool) { - c.baggageItems.Foreach(func(kv label.KeyValue) bool { + c.baggageItems.Foreach(func(kv attribute.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(baggage.MapUpdate{SingleKV: label.String(crk, value)}) + c.baggageItems = c.baggageItems.Apply(baggage.MapUpdate{SingleKV: attribute.String(crk, value)}) } func (c *bridgeSpanContext) baggageItem(restrictedKey string) string { crk := http.CanonicalHeaderKey(restrictedKey) - val, _ := c.baggageItems.Value(label.Key(crk)) + val, _ := c.baggageItems.Value(attribute.Key(crk)) return val.Emit() } @@ -161,7 +161,7 @@ func (s *bridgeSpan) LogFields(fields ...otlog.Field) { } type bridgeFieldEncoder struct { - pairs []label.KeyValue + pairs []attribute.KeyValue } var _ otlog.Encoder = &bridgeFieldEncoder{} @@ -214,7 +214,7 @@ func (e *bridgeFieldEncoder) emitCommon(key string, value interface{}) { e.pairs = append(e.pairs, otTagToOTelLabel(key, value)) } -func otLogFieldsToOTelLabels(fields []otlog.Field) []label.KeyValue { +func otLogFieldsToOTelLabels(fields []otlog.Field) []attribute.KeyValue { encoder := &bridgeFieldEncoder{} for _, field := range fields { field.Marshal(encoder) @@ -363,7 +363,7 @@ func (t *BridgeTracer) baggageSetHook(ctx context.Context) context.Context { // context, so we don't care about the old hooks. clearCtx, _, _ := baggage.ContextWithNoHooks(ctx) m := baggage.MapFromContext(clearCtx) - m.Foreach(func(kv label.KeyValue) bool { + m.Foreach(func(kv attribute.KeyValue) bool { bSpan.setBaggageItemOnly(string(kv.Key), kv.Value.Emit()) return true }) @@ -385,9 +385,9 @@ func (t *BridgeTracer) baggageGetHook(ctx context.Context, m baggage.Map) baggag if len(items) == 0 { return m } - kv := make([]label.KeyValue, 0, len(items)) + kv := make([]attribute.KeyValue, 0, len(items)) for k, v := range items { - kv = append(kv, label.String(k, v)) + kv = append(kv, attribute.String(k, v)) } return m.Apply(baggage.MapUpdate{MultiKV: kv}) } @@ -474,10 +474,10 @@ func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) co return ctx } -func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.KeyValue, trace.SpanKind, bool) { +func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]attribute.KeyValue, trace.SpanKind, bool) { kind := trace.SpanKindInternal err := false - var pairs []label.KeyValue + var pairs []attribute.KeyValue for k, v := range tags { switch k { case string(otext.SpanKind): @@ -504,7 +504,7 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.Ke return pairs, kind, err } -// otTagToOTelLabel converts given key-value into label.KeyValue. +// otTagToOTelLabel converts given key-value into attribute.KeyValue. // Note that some conversions are not obvious: // - int -> int64 // - uint -> string @@ -512,7 +512,7 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.Ke // - uint32 -> int64 // - uint64 -> string // - float32 -> float64 -func otTagToOTelLabel(k string, v interface{}) label.KeyValue { +func otTagToOTelLabel(k string, v interface{}) attribute.KeyValue { key := otTagToOTelLabelKey(k) switch val := v.(type) { case bool: @@ -540,8 +540,8 @@ func otTagToOTelLabel(k string, v interface{}) label.KeyValue { } } -func otTagToOTelLabelKey(k string) label.Key { - return label.Key(k) +func otTagToOTelLabelKey(k string) attribute.Key { + return attribute.Key(k) } func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpanContext, []trace.Link) { @@ -580,9 +580,9 @@ func otSpanReferenceToOTelLink(bridgeSC *bridgeSpanContext, refType ot.SpanRefer } } -func otSpanReferenceTypeToOTelLinkAttributes(refType ot.SpanReferenceType) []label.KeyValue { - return []label.KeyValue{ - label.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)), +func otSpanReferenceTypeToOTelLinkAttributes(refType ot.SpanReferenceType) []attribute.KeyValue { + return []attribute.KeyValue{ + attribute.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)), } } diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index 256d887e58b..cc477cf8d49 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -21,22 +21,22 @@ import ( "sync" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/internal/baggage" otelparent "go.opentelemetry.io/otel/internal/trace/parent" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/bridge/opentracing/migration" ) var ( - 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") + ComponentKey = attribute.Key("component") + ServiceKey = attribute.Key("service") + StatusCodeKey = attribute.Key("status.code") + StatusMessageKey = attribute.Key("status.message") + ErrorKey = attribute.Key("error") + NameKey = attribute.Key("name") ) type MockContextKeyValue struct { @@ -221,7 +221,7 @@ func (s *MockSpan) SetError(v bool) { s.SetAttributes(ErrorKey.Bool(v)) } -func (s *MockSpan) SetAttributes(attributes ...label.KeyValue) { +func (s *MockSpan) SetAttributes(attributes ...attribute.KeyValue) { s.applyUpdate(baggage.MapUpdate{ MultiKV: attributes, }) @@ -255,8 +255,8 @@ func (s *MockSpan) RecordError(err error, opts ...trace.EventOption) { s.SetStatus(codes.Error, "") opts = append(opts, trace.WithAttributes( - label.String("error.type", reflect.TypeOf(err).String()), - label.String("error.message", err.Error()), + attribute.String("error.type", reflect.TypeOf(err).String()), + attribute.String("error.message", err.Error()), )) s.AddEvent("error", opts...) } diff --git a/bridge/opentracing/mix_test.go b/bridge/opentracing/mix_test.go index c897c4e2248..368332a5d00 100644 --- a/bridge/opentracing/mix_test.go +++ b/bridge/opentracing/mix_test.go @@ -22,8 +22,8 @@ import ( ot "github.com/opentracing/opentracing-go" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" otelbaggage "go.opentelemetry.io/otel/internal/baggage" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" "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 = otelbaggage.NewContext(ctx, label.String(otelKey, value)) + ctx = otelbaggage.NewContext(ctx, attribute.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) - otelbaggage.MapFromContext(ctx).Foreach(func(kv label.KeyValue) bool { + otelbaggage.MapFromContext(ctx).Foreach(func(kv attribute.KeyValue) bool { otelRecording[string(kv.Key)] = kv.Value.Emit() return true }) @@ -721,62 +721,62 @@ func TestOtTagToOTelLabel_CheckTypeConversions(t *testing.T) { tableTest := []struct { key string value interface{} - expectedValueType label.Type + expectedValueType attribute.Type }{ { key: "bool to bool", value: true, - expectedValueType: label.BOOL, + expectedValueType: attribute.BOOL, }, { key: "int to int64", value: 123, - expectedValueType: label.INT64, + expectedValueType: attribute.INT64, }, { key: "uint to string", value: uint(1234), - expectedValueType: label.STRING, + expectedValueType: attribute.STRING, }, { key: "int32 to int64", value: int32(12345), - expectedValueType: label.INT64, + expectedValueType: attribute.INT64, }, { key: "uint32 to int64", value: uint32(123456), - expectedValueType: label.INT64, + expectedValueType: attribute.INT64, }, { key: "int64 to int64", value: int64(1234567), - expectedValueType: label.INT64, + expectedValueType: attribute.INT64, }, { key: "uint64 to string", value: uint64(12345678), - expectedValueType: label.STRING, + expectedValueType: attribute.STRING, }, { key: "float32 to float64", value: float32(3.14), - expectedValueType: label.FLOAT64, + expectedValueType: attribute.FLOAT64, }, { key: "float64 to float64", value: float64(3.14), - expectedValueType: label.FLOAT64, + expectedValueType: attribute.FLOAT64, }, { key: "string to string", value: "string_value", - expectedValueType: label.STRING, + expectedValueType: attribute.STRING, }, { key: "unexpected type to string", value: struct{}{}, - expectedValueType: label.STRING, + expectedValueType: attribute.STRING, }, } diff --git a/example/jaeger/main.go b/example/jaeger/main.go index 7af58754dc7..fa879c9986c 100644 --- a/example/jaeger/main.go +++ b/example/jaeger/main.go @@ -21,8 +21,8 @@ import ( "log" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "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: []label.KeyValue{ - label.String("exporter", "jaeger"), - label.Float64("float", 312.23), + Tags: []attribute.KeyValue{ + attribute.String("exporter", "jaeger"), + attribute.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 ed2e668dcac..1193f8ad018 100644 --- a/example/namedtracer/foo/foo.go +++ b/example/namedtracer/foo/foo.go @@ -18,12 +18,12 @@ import ( "context" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) var ( - lemonsKey = label.Key("ex.com/lemons") + lemonsKey = attribute.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 471b44ed2e6..9356309504f 100644 --- a/example/namedtracer/main.go +++ b/example/namedtracer/main.go @@ -19,18 +19,18 @@ import ( "log" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/baggage" "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" "go.opentelemetry.io/otel/trace" ) var ( - fooKey = label.Key("ex.com/foo") - barKey = label.Key("ex.com/bar") - anotherKey = label.Key("ex.com/another") + fooKey = attribute.Key("ex.com/foo") + barKey = attribute.Key("ex.com/bar") + anotherKey = attribute.Key("ex.com/another") ) var tp *sdktrace.TracerProvider @@ -68,7 +68,7 @@ func main() { var span trace.Span ctx, span = tracer.Start(ctx, "operation") defer span.End() - span.AddEvent("Nice operation!", trace.WithAttributes(label.Int("bogons", 100))) + span.AddEvent("Nice operation!", trace.WithAttributes(attribute.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 abaaf77dc53..073d7e974fd 100644 --- a/example/otel-collector/main.go +++ b/example/otel-collector/main.go @@ -26,9 +26,9 @@ import ( "google.golang.org/grpc" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/propagation" @@ -109,10 +109,10 @@ func main() { // labels represent additional key-value descriptors that can be bound to a // metric observer or recorder. - commonLabels := []label.KeyValue{ - label.String("labelA", "chocolate"), - label.String("labelB", "raspberry"), - label.String("labelC", "vanilla"), + commonLabels := []attribute.KeyValue{ + attribute.String("labelA", "chocolate"), + attribute.String("labelB", "raspberry"), + attribute.String("labelC", "vanilla"), } // Recorder metric example diff --git a/example/prom-collector/main.go b/example/prom-collector/main.go index 7dcd936b42c..349b2d8c0e4 100644 --- a/example/prom-collector/main.go +++ b/example/prom-collector/main.go @@ -23,10 +23,10 @@ import ( "google.golang.org/grpc" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/metric/prometheus" "go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" @@ -41,7 +41,7 @@ func initMeter() { res, err := resource.New( ctx, - resource.WithAttributes(label.String("R", "V")), + resource.WithAttributes(attribute.String("R", "V")), ) if err != nil { log.Fatal("could not initialize resource:", err) @@ -94,8 +94,8 @@ func initMeter() { func main() { initMeter() - labels := []label.KeyValue{ - label.String("label1", "value1"), + labels := []attribute.KeyValue{ + attribute.String("label1", "value1"), } meter := global.Meter("ex.com/prom-collector") diff --git a/example/prometheus/main.go b/example/prometheus/main.go index bf294f97c45..874dc09a666 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -22,14 +22,14 @@ import ( "sync" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/metric/prometheus" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" ) var ( - lemonsKey = label.Key("ex.com/lemons") + lemonsKey = attribute.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([]label.KeyValue) + observerLabelsToReport := new([]attribute.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 := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")} - notSoCommonLabels := []label.KeyValue{lemonsKey.Int(13)} + commonLabels := []attribute.KeyValue{lemonsKey.Int(10), attribute.String("A", "1"), attribute.String("B", "2"), attribute.String("C", "3")} + notSoCommonLabels := []attribute.KeyValue{lemonsKey.Int(13)} ctx := context.Background() diff --git a/exporters/metric/prometheus/example_test.go b/exporters/metric/prometheus/example_test.go index 3eb264393c3..d5259b98ca5 100644 --- a/exporters/metric/prometheus/example_test.go +++ b/exporters/metric/prometheus/example_test.go @@ -22,8 +22,8 @@ import ( "net/http" "net/http/httptest" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/metric/prometheus" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" "go.opentelemetry.io/otel/sdk/resource" @@ -41,7 +41,7 @@ func ExampleNewExportPipeline() { res, err := resource.New( context.Background(), resource.WithoutBuiltin(), // Test-only! - resource.WithAttributes(label.String("R", "V")), + resource.WithAttributes(attribute.String("R", "V")), ) if err != nil { panic(err) @@ -68,8 +68,8 @@ func ExampleNewExportPipeline() { metric.WithDescription("Records values"), ) - counter.Add(ctx, 100, label.String("key", "value")) - recorder.Record(ctx, 100, label.String("key", "value")) + counter.Add(ctx, 100, attribute.String("key", "value")) + recorder.Record(ctx, 100, attribute.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 fbdad8754ef..e876cdedc63 100644 --- a/exporters/metric/prometheus/prometheus.go +++ b/exporters/metric/prometheus/prometheus.go @@ -27,7 +27,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/number" @@ -349,7 +349,7 @@ func mergeLabels(record export.Record, keys, values *[]string) { // Duplicate keys are resolved by taking the record label value over // the resource value. - mi := label.NewMergeIterator(record.Labels(), record.Resource().LabelSet()) + mi := attribute.NewMergeIterator(record.Labels(), record.Resource().LabelSet()) for mi.Next() { label := mi.Label() if keys != nil { diff --git a/exporters/metric/prometheus/prometheus_test.go b/exporters/metric/prometheus/prometheus_test.go index 2bddf70b229..58edce70996 100644 --- a/exporters/metric/prometheus/prometheus_test.go +++ b/exporters/metric/prometheus/prometheus_test.go @@ -26,8 +26,8 @@ import ( "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/metric/prometheus" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" "go.opentelemetry.io/otel/sdk/resource" @@ -43,7 +43,7 @@ func TestPrometheusExporter(t *testing.T) { DefaultHistogramBoundaries: []float64{-0.5, 1}, }, controller.WithCollectPeriod(0), - controller.WithResource(resource.NewWithAttributes(label.String("R", "V"))), + controller.WithResource(resource.NewWithAttributes(attribute.String("R", "V"))), ) require.NoError(t, err) @@ -52,9 +52,9 @@ func TestPrometheusExporter(t *testing.T) { counter := metric.Must(meter).NewFloat64Counter("counter") valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder") - labels := []label.KeyValue{ - label.Key("A").String("B"), - label.Key("C").String("D"), + labels := []attribute.KeyValue{ + attribute.Key("A").String("B"), + attribute.Key("C").String("D"), } ctx := context.Background() @@ -144,14 +144,14 @@ func TestPrometheusStatefulness(t *testing.T) { metric.WithDescription("Counts things"), ) - counter.Add(ctx, 100, label.String("key", "value")) + counter.Add(ctx, 100, attribute.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, label.String("key", "value")) + counter.Add(ctx, 100, attribute.String("key", "value")) require.Equal(t, `# HELP a_counter Counts things # TYPE a_counter counter diff --git a/exporters/otlp/internal/otlptest/data.go b/exporters/otlp/internal/otlptest/data.go index 79e001c6499..da054134733 100644 --- a/exporters/otlp/internal/otlptest/data.go +++ b/exporters/otlp/internal/otlptest/data.go @@ -19,8 +19,8 @@ import ( "fmt" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" exportmetric "go.opentelemetry.io/otel/sdk/export/metric" @@ -66,14 +66,14 @@ func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelect metric.CounterInstrumentKind, number.Int64Kind, ) - res := resource.NewWithAttributes(label.String("a", "b")) + res := resource.NewWithAttributes(attribute.String("a", "b")) agg := sum.New(1) if err := agg[0].Update(context.Background(), number.NewInt64Number(42), &desc); err != nil { return err } start := time.Date(2020, time.December, 8, 19, 15, 0, 0, time.UTC) end := time.Date(2020, time.December, 8, 19, 16, 0, 0, time.UTC) - labels := label.NewSet(label.String("abc", "def"), label.Int64("one", 1)) + labels := attribute.NewSet(attribute.String("abc", "def"), attribute.Int64("one", 1)) rec := exportmetric.NewRecord(&desc, &labels, res, agg[0].Aggregation(), start, end) return recordFunc(rec) } @@ -92,7 +92,7 @@ func SingleSpanSnapshot() []*exporttrace.SpanSnapshot { Name: "foo", StartTime: time.Date(2020, time.December, 8, 20, 23, 0, 0, time.UTC), EndTime: time.Date(2020, time.December, 0, 20, 24, 0, 0, time.UTC), - Attributes: []label.KeyValue{}, + Attributes: []attribute.KeyValue{}, MessageEvents: []trace.Event{}, Links: []trace.Link{}, StatusCode: codes.Ok, @@ -102,7 +102,7 @@ func SingleSpanSnapshot() []*exporttrace.SpanSnapshot { DroppedMessageEventCount: 0, DroppedLinkCount: 0, ChildSpanCount: 0, - Resource: resource.NewWithAttributes(label.String("a", "b")), + Resource: resource.NewWithAttributes(attribute.String("a", "b")), InstrumentationLibrary: instrumentation.Library{ Name: "bar", Version: "0.0.0", diff --git a/exporters/otlp/internal/otlptest/otlptest.go b/exporters/otlp/internal/otlptest/otlptest.go index 47c7cb3b865..fa95a08d3a0 100644 --- a/exporters/otlp/internal/otlptest/otlptest.go +++ b/exporters/otlp/internal/otlptest/otlptest.go @@ -23,9 +23,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" exportmetric "go.opentelemetry.io/otel/sdk/export/metric" @@ -50,14 +50,14 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr } tp1 := sdktrace.NewTracerProvider(append(pOpts, sdktrace.WithResource(resource.NewWithAttributes( - label.String("rk1", "rv11)"), - label.Int64("rk2", 5), + attribute.String("rk1", "rv11)"), + attribute.Int64("rk2", 5), )))...) tp2 := sdktrace.NewTracerProvider(append(pOpts, sdktrace.WithResource(resource.NewWithAttributes( - label.String("rk1", "rv12)"), - label.Float64("rk3", 6.5), + attribute.String("rk1", "rv12)"), + attribute.Float64("rk3", 6.5), )))...) tr1 := tp1.Tracer("test-tracer1") @@ -66,11 +66,11 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr m := 4 for i := 0; i < m; i++ { _, span := tr1.Start(ctx, "AlwaysSample") - span.SetAttributes(label.Int64("i", int64(i))) + span.SetAttributes(attribute.Int64("i", int64(i))) span.End() _, span = tr2.Start(ctx, "AlwaysSample") - span.SetAttributes(label.Int64("i", int64(i))) + span.SetAttributes(attribute.Int64("i", int64(i))) span.End() } @@ -80,7 +80,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr require.NoError(t, cont.Start(ctx)) meter := cont.MeterProvider().Meter("test-meter") - labels := []label.KeyValue{label.Bool("test", true)} + labels := []attribute.KeyValue{attribute.Bool("test", true)} type data struct { iKind metric.InstrumentKind diff --git a/exporters/otlp/internal/transform/attribute.go b/exporters/otlp/internal/transform/attribute.go index b97007fcc61..8ad27f7f6c0 100644 --- a/exporters/otlp/internal/transform/attribute.go +++ b/exporters/otlp/internal/transform/attribute.go @@ -17,14 +17,14 @@ package transform import ( "reflect" + "go.opentelemetry.io/otel/attribute" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/resource" ) // Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values. -func Attributes(attrs []label.KeyValue) []*commonpb.KeyValue { +func Attributes(attrs []attribute.KeyValue) []*commonpb.KeyValue { if len(attrs) == 0 { return nil } @@ -50,29 +50,29 @@ func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue { return out } -func toAttribute(v label.KeyValue) *commonpb.KeyValue { +func toAttribute(v attribute.KeyValue) *commonpb.KeyValue { result := &commonpb.KeyValue{ Key: string(v.Key), Value: new(commonpb.AnyValue), } switch v.Value.Type() { - case label.BOOL: + case attribute.BOOL: result.Value.Value = &commonpb.AnyValue_BoolValue{ BoolValue: v.Value.AsBool(), } - case label.INT64: + case attribute.INT64: result.Value.Value = &commonpb.AnyValue_IntValue{ IntValue: v.Value.AsInt64(), } - case label.FLOAT64: + case attribute.FLOAT64: result.Value.Value = &commonpb.AnyValue_DoubleValue{ DoubleValue: v.Value.AsFloat64(), } - case label.STRING: + case attribute.STRING: result.Value.Value = &commonpb.AnyValue_StringValue{ StringValue: v.Value.AsString(), } - case label.ARRAY: + case attribute.ARRAY: result.Value.Value = &commonpb.AnyValue_ArrayValue{ ArrayValue: &commonpb.ArrayValue{ Values: arrayValues(v), @@ -86,7 +86,7 @@ func toAttribute(v label.KeyValue) *commonpb.KeyValue { return result } -func arrayValues(kv label.KeyValue) []*commonpb.AnyValue { +func arrayValues(kv attribute.KeyValue) []*commonpb.AnyValue { a := kv.Value.AsArray() aType := reflect.TypeOf(a) var valueFunc func(reflect.Value) *commonpb.AnyValue diff --git a/exporters/otlp/internal/transform/attribute_test.go b/exporters/otlp/internal/transform/attribute_test.go index 1ffabdff6e7..beafb86cb1f 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/attribute" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" - "go.opentelemetry.io/otel/label" ) type attributeTest struct { - attrs []label.KeyValue + attrs []attribute.KeyValue expected []*commonpb.KeyValue } @@ -32,12 +32,12 @@ func TestAttributes(t *testing.T) { for _, test := range []attributeTest{ {nil, nil}, { - []label.KeyValue{ - label.Int("int to int", 123), - label.Int64("int64 to int64", 1234567), - label.Float64("float64 to double", 1.61), - label.String("string to string", "string"), - label.Bool("bool to bool", true), + []attribute.KeyValue{ + attribute.Int("int to int", 123), + attribute.Int64("int64 to int64", 1234567), + attribute.Float64("float64 to double", 1.61), + attribute.String("string to string", "string"), + attribute.Bool("bool to bool", true), }, []*commonpb.KeyValue{ { @@ -111,8 +111,8 @@ func TestArrayAttributes(t *testing.T) { for _, test := range []attributeTest{ {nil, nil}, { - []label.KeyValue{ - label.Array("invalid", [][]string{{"1", "2"}, {"a"}}), + []attribute.KeyValue{ + attribute.Array("invalid", [][]string{{"1", "2"}, {"a"}}), }, []*commonpb.KeyValue{ { @@ -126,12 +126,12 @@ func TestArrayAttributes(t *testing.T) { }, }, { - []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("int64 array to int64 array", []int64{1, 2, 3}), - 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"}), + []attribute.KeyValue{ + attribute.Array("bool array to bool array", []bool{true, false}), + attribute.Array("int array to int64 array", []int{1, 2, 3}), + attribute.Array("int64 array to int64 array", []int64{1, 2, 3}), + attribute.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}), + attribute.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 ca913457950..123ef2e8fda 100644 --- a/exporters/otlp/internal/transform/metric.go +++ b/exporters/otlp/internal/transform/metric.go @@ -24,11 +24,11 @@ import ( "sync" "time" + "go.opentelemetry.io/otel/attribute" 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" resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -170,7 +170,7 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, e } // group by unique Resource string. - grouped := make(map[label.Distinct]resourceBatch) + grouped := make(map[attribute.Distinct]resourceBatch) for res := range in { if res.Err != nil { errStrings = append(errStrings, res.Err.Error()) @@ -611,7 +611,7 @@ func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Hi } // stringKeyValues transforms a label iterator into an OTLP StringKeyValues. -func stringKeyValues(iter label.Iterator) []*commonpb.StringKeyValue { +func stringKeyValues(iter attribute.Iterator) []*commonpb.StringKeyValue { l := iter.Len() if l == 0 { return nil diff --git a/exporters/otlp/internal/transform/metric_test.go b/exporters/otlp/internal/transform/metric_test.go index 8a54c189f95..b36eaccec8d 100644 --- a/exporters/otlp/internal/transform/metric_test.go +++ b/exporters/otlp/internal/transform/metric_test.go @@ -24,9 +24,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" 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/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -55,7 +55,7 @@ const ( func TestStringKeyValues(t *testing.T) { tests := []struct { - kvs []label.KeyValue + kvs []attribute.KeyValue expected []*commonpb.StringKeyValue }{ { @@ -63,21 +63,21 @@ func TestStringKeyValues(t *testing.T) { nil, }, { - []label.KeyValue{}, + []attribute.KeyValue{}, nil, }, { - []label.KeyValue{ - label.Bool("true", true), - label.Int64("one", 1), - label.Int64("two", 2), - label.Float64("three", 3), - label.Int("four", 4), - label.Int("five", 5), - label.Float64("six", 6), - label.Int("seven", 7), - label.Int("eight", 8), - label.String("the", "final word"), + []attribute.KeyValue{ + attribute.Bool("true", true), + attribute.Int64("one", 1), + attribute.Int64("two", 2), + attribute.Float64("three", 3), + attribute.Int("four", 4), + attribute.Int("five", 5), + attribute.Float64("six", 6), + attribute.Int("seven", 7), + attribute.Int("eight", 8), + attribute.String("the", "final word"), }, []*commonpb.StringKeyValue{ {Key: "eight", Value: "8"}, @@ -95,7 +95,7 @@ func TestStringKeyValues(t *testing.T) { } for _, test := range tests { - labels := label.NewSet(test.kvs...) + labels := attribute.NewSet(test.kvs...) assert.Equal(t, test.expected, stringKeyValues(labels.Iter())) } } @@ -123,7 +123,7 @@ func TestMinMaxSumCountValue(t *testing.T) { func TestMinMaxSumCountDatapoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := label.NewSet() + labels := attribute.NewSet() mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc)) assert.NoError(t, mmsc.Update(context.Background(), 1, &desc)) @@ -162,7 +162,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) { func TestSumIntDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := label.NewSet() + labels := attribute.NewSet() s, ckpt := metrictest.Unslice2(sumAgg.New(2)) assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc)) @@ -190,7 +190,7 @@ func TestSumIntDataPoints(t *testing.T) { func TestSumFloatDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) - labels := label.NewSet() + labels := attribute.NewSet() s, ckpt := metrictest.Unslice2(sumAgg.New(2)) assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc)) @@ -219,7 +219,7 @@ func TestSumFloatDataPoints(t *testing.T) { func TestLastValueIntDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := label.NewSet() + labels := attribute.NewSet() s, ckpt := metrictest.Unslice2(lvAgg.New(2)) assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc)) @@ -245,7 +245,7 @@ func TestLastValueIntDataPoints(t *testing.T) { func TestExactIntDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := label.NewSet() + labels := attribute.NewSet() e, ckpt := metrictest.Unslice2(arrAgg.New(2)) assert.NoError(t, e.Update(context.Background(), number.Number(100), &desc)) require.NoError(t, e.SynchronizedMove(ckpt, &desc)) @@ -271,7 +271,7 @@ func TestExactIntDataPoints(t *testing.T) { func TestExactFloatDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) - labels := label.NewSet() + labels := attribute.NewSet() e, ckpt := metrictest.Unslice2(arrAgg.New(2)) assert.NoError(t, e.Update(context.Background(), number.NewFloat64Number(100), &desc)) require.NoError(t, e.SynchronizedMove(ckpt, &desc)) @@ -297,7 +297,7 @@ func TestExactFloatDataPoints(t *testing.T) { func TestSumErrUnknownValueType(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1)) - labels := label.NewSet() + labels := attribute.NewSet() s := &sumAgg.New(1)[0] record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd) value, err := s.Sum() @@ -382,7 +382,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{} func TestRecordAggregatorIncompatibleErrors(t *testing.T) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) - labels := label.NewSet() + labels := attribute.NewSet() res := resource.Empty() test := &testAgg{ kind: kind, @@ -419,7 +419,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) { func TestRecordAggregatorUnexpectedErrors(t *testing.T) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) - labels := label.NewSet() + labels := attribute.NewSet() res := resource.Empty() return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd)) } diff --git a/exporters/otlp/internal/transform/resource_test.go b/exporters/otlp/internal/transform/resource_test.go index f1e35c9cc9b..f56b56b6a9f 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/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/resource" ) @@ -38,7 +38,7 @@ func TestEmptyResource(t *testing.T) { */ func TestResourceAttributes(t *testing.T) { - attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)} + attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} got := Resource(resource.NewWithAttributes(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 33ecbc89a72..2e57f1ddd1f 100644 --- a/exporters/otlp/internal/transform/span.go +++ b/exporters/otlp/internal/transform/span.go @@ -15,10 +15,10 @@ package transform import ( + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" - "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/trace" @@ -35,10 +35,10 @@ func SpanData(sdl []*export.SpanSnapshot) []*tracepb.ResourceSpans { return nil } - rsm := make(map[label.Distinct]*tracepb.ResourceSpans) + rsm := make(map[attribute.Distinct]*tracepb.ResourceSpans) type ilsKey struct { - r label.Distinct + r attribute.Distinct il instrumentation.Library } ilsm := make(map[ilsKey]*tracepb.InstrumentationLibrarySpans) diff --git a/exporters/otlp/internal/transform/span_test.go b/exporters/otlp/internal/transform/span_test.go index 8023a2904f7..163357a876b 100644 --- a/exporters/otlp/internal/transform/span_test.go +++ b/exporters/otlp/internal/transform/span_test.go @@ -24,8 +24,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/codes" @@ -77,12 +77,12 @@ func TestEmptySpanEvent(t *testing.T) { } func TestSpanEvent(t *testing.T) { - attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)} + attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC) got := spanEvents([]trace.Event{ { Name: "test 1", - Attributes: []label.KeyValue{}, + Attributes: []attribute.KeyValue{}, Time: eventTime, }, { @@ -121,7 +121,7 @@ func TestEmptyLinks(t *testing.T) { } func TestLinks(t *testing.T) { - attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)} + attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} l := []trace.Link{ {}, { @@ -199,7 +199,7 @@ func TestSpanData(t *testing.T) { // March 31, 2020 5:01:26 1234nanos (UTC) startTime := time.Unix(1585674086, 1234) endTime := startTime.Add(10 * time.Second) - traceState, _ := trace.TraceStateFromKeyValues(label.String("key1", "val1"), label.String("key2", "val2")) + traceState, _ := trace.TraceStateFromKeyValues(attribute.String("key1", "val1"), attribute.String("key2", "val2")) spanData := &export.SpanSnapshot{ SpanContext: trace.SpanContext{ TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, @@ -213,13 +213,13 @@ func TestSpanData(t *testing.T) { EndTime: endTime, MessageEvents: []trace.Event{ {Time: startTime, - Attributes: []label.KeyValue{ - label.Int64("CompressedByteSize", 512), + Attributes: []attribute.KeyValue{ + attribute.Int64("CompressedByteSize", 512), }, }, {Time: endTime, - Attributes: []label.KeyValue{ - label.String("MessageEventType", "Recv"), + Attributes: []attribute.KeyValue{ + attribute.String("MessageEventType", "Recv"), }, }, }, @@ -230,8 +230,8 @@ func TestSpanData(t *testing.T) { SpanID: trace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, TraceFlags: 0, }, - Attributes: []label.KeyValue{ - label.String("LinkType", "Parent"), + Attributes: []attribute.KeyValue{ + attribute.String("LinkType", "Parent"), }, }, { @@ -240,21 +240,21 @@ func TestSpanData(t *testing.T) { SpanID: trace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, TraceFlags: 0, }, - Attributes: []label.KeyValue{ - label.String("LinkType", "Child"), + Attributes: []attribute.KeyValue{ + attribute.String("LinkType", "Child"), }, }, }, StatusCode: codes.Error, StatusMessage: "utterly unrecognized", HasRemoteParent: true, - Attributes: []label.KeyValue{ - label.Int64("timeout_ns", 12e9), + Attributes: []attribute.KeyValue{ + attribute.Int64("timeout_ns", 12e9), }, DroppedAttributeCount: 1, DroppedMessageEventCount: 2, DroppedLinkCount: 3, - Resource: resource.NewWithAttributes(label.String("rk1", "rv1"), label.Int64("rk2", 5)), + Resource: resource.NewWithAttributes(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5)), InstrumentationLibrary: instrumentation.Library{ Name: "go.opentelemetry.io/test/otel", Version: "v0.0.1", diff --git a/exporters/otlp/otlp_metric_test.go b/exporters/otlp/otlp_metric_test.go index 3da92f098ab..e1544831e2a 100644 --- a/exporters/otlp/otlp_metric_test.go +++ b/exporters/otlp/otlp_metric_test.go @@ -23,11 +23,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp" 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" resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" metricsdk "go.opentelemetry.io/otel/sdk/export/metric" @@ -73,15 +73,15 @@ type record struct { nKind number.Kind resource *resource.Resource opts []metric.InstrumentOption - labels []label.KeyValue + labels []attribute.KeyValue } var ( - baseKeyValues = []label.KeyValue{label.String("host", "test.com")} - cpuKey = label.Key("CPU") + baseKeyValues = []attribute.KeyValue{attribute.String("host", "test.com")} + cpuKey = attribute.Key("CPU") - testInstA = resource.NewWithAttributes(label.String("instance", "tester-a")) - testInstB = resource.NewWithAttributes(label.String("instance", "tester-b")) + testInstA = resource.NewWithAttributes(attribute.String("instance", "tester-a")) + testInstB = resource.NewWithAttributes(attribute.String("instance", "tester-b")) testHistogramBoundaries = []float64{2.0, 4.0, 8.0} @@ -744,13 +744,13 @@ func TestStatelessExportKind(t *testing.T) { func runMetricExportTests(t *testing.T, opts []otlp.ExporterOption, rs []record, expected []metricpb.ResourceMetrics) { exp, driver := newExporter(t, opts...) - recs := map[label.Distinct][]metricsdk.Record{} - resources := map[label.Distinct]*resource.Resource{} + recs := map[attribute.Distinct][]metricsdk.Record{} + resources := map[attribute.Distinct]*resource.Resource{} for _, r := range rs { - lcopy := make([]label.KeyValue, len(r.labels)) + lcopy := make([]attribute.KeyValue, len(r.labels)) copy(lcopy, r.labels) desc := metric.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...) - labs := label.NewSet(lcopy...) + labs := attribute.NewSet(lcopy...) var agg, ckpt metricsdk.Aggregator if r.iKind.Adding() { diff --git a/exporters/otlp/otlp_span_test.go b/exporters/otlp/otlp_span_test.go index b446fc0e39b..77a06e8c655 100644 --- a/exporters/otlp/otlp_span_test.go +++ b/exporters/otlp/otlp_span_test.go @@ -21,11 +21,11 @@ import ( "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" 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/trace" tracesdk "go.opentelemetry.io/otel/sdk/export/trace" @@ -64,13 +64,13 @@ func TestExportSpans(t *testing.T) { Name: "parent process", StartTime: startTime, EndTime: endTime, - Attributes: []label.KeyValue{ - label.String("user", "alice"), - label.Bool("authenticated", true), + Attributes: []attribute.KeyValue{ + attribute.String("user", "alice"), + attribute.Bool("authenticated", true), }, StatusCode: codes.Ok, StatusMessage: "Ok", - Resource: resource.NewWithAttributes(label.String("instance", "tester-a")), + Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-a", Version: "v0.1.0", @@ -86,13 +86,13 @@ func TestExportSpans(t *testing.T) { Name: "secondary parent process", StartTime: startTime, EndTime: endTime, - Attributes: []label.KeyValue{ - label.String("user", "alice"), - label.Bool("authenticated", true), + Attributes: []attribute.KeyValue{ + attribute.String("user", "alice"), + attribute.Bool("authenticated", true), }, StatusCode: codes.Ok, StatusMessage: "Ok", - Resource: resource.NewWithAttributes(label.String("instance", "tester-a")), + Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-b", Version: "v0.1.0", @@ -109,13 +109,13 @@ func TestExportSpans(t *testing.T) { Name: "internal process", StartTime: startTime, EndTime: endTime, - Attributes: []label.KeyValue{ - label.String("user", "alice"), - label.Bool("authenticated", true), + Attributes: []attribute.KeyValue{ + attribute.String("user", "alice"), + attribute.Bool("authenticated", true), }, StatusCode: codes.Ok, StatusMessage: "Ok", - Resource: resource.NewWithAttributes(label.String("instance", "tester-a")), + Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-a", Version: "v0.1.0", @@ -131,13 +131,13 @@ func TestExportSpans(t *testing.T) { Name: "parent process", StartTime: startTime, EndTime: endTime, - Attributes: []label.KeyValue{ - label.String("user", "bob"), - label.Bool("authenticated", false), + Attributes: []attribute.KeyValue{ + attribute.String("user", "bob"), + attribute.Bool("authenticated", false), }, StatusCode: codes.Error, StatusMessage: "Unauthenticated", - Resource: resource.NewWithAttributes(label.String("instance", "tester-b")), + Resource: resource.NewWithAttributes(attribute.String("instance", "tester-b")), InstrumentationLibrary: instrumentation.Library{ Name: "lib-a", Version: "v1.1.0", diff --git a/exporters/otlp/otlpgrpc/otlp_integration_test.go b/exporters/otlp/otlpgrpc/otlp_integration_test.go index 3566fbe4184..499be757372 100644 --- a/exporters/otlp/otlpgrpc/otlp_integration_test.go +++ b/exporters/otlp/otlpgrpc/otlp_integration_test.go @@ -28,11 +28,11 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/encoding/gzip" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" "go.opentelemetry.io/otel/exporters/otlp/internal/otlptest" "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" - "go.opentelemetry.io/otel/label" exporttrace "go.opentelemetry.io/otel/sdk/export/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) @@ -344,12 +344,12 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) { defer func() { _ = tp.Shutdown(ctx) }() tr := tp.Tracer("test-tracer") - testKvs := []label.KeyValue{ - label.Int("Int", 1), - label.Int64("Int64", int64(3)), - label.Float64("Float64", 2.22), - label.Bool("Bool", true), - label.String("String", "test"), + testKvs := []attribute.KeyValue{ + attribute.Int("Int", 1), + attribute.Int64("Int64", int64(3)), + attribute.Float64("Float64", 2.22), + attribute.Bool("Bool", true), + attribute.String("String", "test"), } _, span := tr.Start(ctx, "AlwaysSample") span.SetAttributes(testKvs...) diff --git a/exporters/stdout/config.go b/exporters/stdout/config.go index 4bf90b36e94..7700c20245f 100644 --- a/exporters/stdout/config.go +++ b/exporters/stdout/config.go @@ -18,14 +18,14 @@ import ( "io" "os" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) var ( defaultWriter = os.Stdout defaultPrettyPrint = false defaultTimestamps = true - defaultLabelEncoder = label.DefaultEncoder() + defaultLabelEncoder = attribute.DefaultEncoder() defaultDisableTraceExport = false defaultDisableMetricExport = false ) @@ -44,7 +44,7 @@ type Config struct { Timestamps bool // LabelEncoder encodes the labels. - LabelEncoder label.Encoder + LabelEncoder attribute.Encoder // DisableTraceExport prevents any export of trace telemetry. DisableTraceExport bool @@ -112,12 +112,12 @@ func (o timestampsOption) Apply(config *Config) { } // WithLabelEncoder sets the label encoder used in export. -func WithLabelEncoder(enc label.Encoder) Option { +func WithLabelEncoder(enc attribute.Encoder) Option { return labelEncoderOption{enc} } type labelEncoderOption struct { - LabelEncoder label.Encoder + LabelEncoder attribute.Encoder } func (o labelEncoderOption) Apply(config *Config) { diff --git a/exporters/stdout/example_test.go b/exporters/stdout/example_test.go index a1938777b8a..fc41dafa264 100644 --- a/exporters/stdout/example_test.go +++ b/exporters/stdout/example_test.go @@ -19,8 +19,8 @@ import ( "log" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/stdout" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/trace" @@ -45,7 +45,7 @@ var ( loopCounter = metric.Must(meter).NewInt64Counter("function.loops") paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param") - nameKey = label.Key("function.name") + nameKey = attribute.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 9b183a0022d..9ea020da59b 100644 --- a/exporters/stdout/metric.go +++ b/exporters/stdout/metric.go @@ -21,7 +21,7 @@ import ( "strings" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" exportmetric "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -61,14 +61,14 @@ func (e *metricExporter) Export(_ context.Context, checkpointSet exportmetric.Ch kind := desc.NumberKind() encodedResource := record.Resource().Encoded(e.config.LabelEncoder) - var instLabels []label.KeyValue + var instLabels []attribute.KeyValue if name := desc.InstrumentationName(); name != "" { - instLabels = append(instLabels, label.String("instrumentation.name", name)) + instLabels = append(instLabels, attribute.String("instrumentation.name", name)) if version := desc.InstrumentationVersion(); version != "" { - instLabels = append(instLabels, label.String("instrumentation.version", version)) + instLabels = append(instLabels, attribute.String("instrumentation.version", version)) } } - instSet := label.NewSet(instLabels...) + instSet := attribute.NewSet(instLabels...) encodedInstLabels := instSet.Encoded(e.config.LabelEncoder) var expose line diff --git a/exporters/stdout/metric_test.go b/exporters/stdout/metric_test.go index d5ebcfca864..43e8aee9597 100644 --- a/exporters/stdout/metric_test.go +++ b/exporters/stdout/metric_test.go @@ -26,8 +26,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/stdout" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -46,7 +46,7 @@ type testFixture struct { output *bytes.Buffer } -var testResource = resource.NewWithAttributes(label.String("R", "V")) +var testResource = resource.NewWithAttributes(attribute.String("R", "V")) func newFixture(t *testing.T, opts ...stdout.Option) testFixture { buf := &bytes.Buffer{} @@ -135,7 +135,7 @@ func TestStdoutCounterFormat(t *testing.T) { aggregatortest.CheckedUpdate(fix.t, cagg, number.NewInt64Number(123), &desc) require.NoError(t, cagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) + checkpointSet.Add(&desc, ckpt, attribute.String("A", "B"), attribute.String("C", "D")) fix.Export(checkpointSet) @@ -153,7 +153,7 @@ func TestStdoutLastValueFormat(t *testing.T) { aggregatortest.CheckedUpdate(fix.t, lvagg, number.NewFloat64Number(123.456), &desc) require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) + checkpointSet.Add(&desc, ckpt, attribute.String("A", "B"), attribute.String("C", "D")) fix.Export(checkpointSet) @@ -173,7 +173,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) { aggregatortest.CheckedUpdate(fix.t, magg, number.NewFloat64Number(876.543), &desc) require.NoError(t, magg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) + checkpointSet.Add(&desc, ckpt, attribute.String("A", "B"), attribute.String("C", "D")) fix.Export(checkpointSet) @@ -194,7 +194,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) { require.NoError(t, aagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D")) + checkpointSet.Add(&desc, ckpt, attribute.String("A", "B"), attribute.String("C", "D")) fix.Export(checkpointSet) @@ -244,7 +244,7 @@ func TestStdoutLastValueNotSet(t *testing.T) { lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc)) - checkpointSet.Add(&desc, lvagg, label.String("A", "B"), label.String("C", "D")) + checkpointSet.Add(&desc, lvagg, attribute.String("A", "B"), attribute.String("C", "D")) fix.Export(checkpointSet) @@ -255,9 +255,9 @@ func TestStdoutResource(t *testing.T) { type testCase struct { expect string res *resource.Resource - attrs []label.KeyValue + attrs []attribute.KeyValue } - newCase := func(expect string, res *resource.Resource, attrs ...label.KeyValue) testCase { + newCase := func(expect string, res *resource.Resource, attrs ...attribute.KeyValue) testCase { return testCase{ expect: expect, res: res, @@ -266,23 +266,23 @@ func TestStdoutResource(t *testing.T) { } testCases := []testCase{ newCase("R1=V1,R2=V2,A=B,C=D", - resource.NewWithAttributes(label.String("R1", "V1"), label.String("R2", "V2")), - label.String("A", "B"), - label.String("C", "D")), + resource.NewWithAttributes(attribute.String("R1", "V1"), attribute.String("R2", "V2")), + attribute.String("A", "B"), + attribute.String("C", "D")), newCase("R1=V1,R2=V2", - resource.NewWithAttributes(label.String("R1", "V1"), label.String("R2", "V2")), + resource.NewWithAttributes(attribute.String("R1", "V1"), attribute.String("R2", "V2")), ), newCase("A=B,C=D", nil, - label.String("A", "B"), - label.String("C", "D"), + attribute.String("A", "B"), + attribute.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.NewWithAttributes(label.String("R1", "V1"), label.String("R2", "V2")), - label.String("R1", "V3"), - label.String("R2", "V4")), + resource.NewWithAttributes(attribute.String("R1", "V1"), attribute.String("R2", "V2")), + attribute.String("R1", "V3"), + attribute.String("R2", "V4")), } for _, tc := range testCases { diff --git a/exporters/stdout/trace_test.go b/exporters/stdout/trace_test.go index 59d9cd70a8b..af61302df2f 100644 --- a/exporters/stdout/trace_test.go +++ b/exporters/stdout/trace_test.go @@ -22,9 +22,9 @@ import ( "testing" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "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" "go.opentelemetry.io/otel/trace" @@ -42,10 +42,10 @@ func TestExporter_ExportSpan(t *testing.T) { now := time.Now() traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") spanID, _ := trace.SpanIDFromHex("0102030405060708") - traceState, _ := trace.TraceStateFromKeyValues(label.String("key", "val")) + traceState, _ := trace.TraceStateFromKeyValues(attribute.String("key", "val")) keyValue := "value" doubleValue := 123.456 - resource := resource.NewWithAttributes(label.String("rk1", "rv11")) + resource := resource.NewWithAttributes(attribute.String("rk1", "rv11")) testSpan := &export.SpanSnapshot{ SpanContext: trace.SpanContext{ @@ -56,13 +56,13 @@ func TestExporter_ExportSpan(t *testing.T) { Name: "/foo", StartTime: now, EndTime: now, - Attributes: []label.KeyValue{ - label.String("key", keyValue), - label.Float64("double", doubleValue), + Attributes: []attribute.KeyValue{ + attribute.String("key", keyValue), + attribute.Float64("double", doubleValue), }, MessageEvents: []trace.Event{ - {Name: "foo", Attributes: []label.KeyValue{label.String("key", keyValue)}, Time: now}, - {Name: "bar", Attributes: []label.KeyValue{label.Float64("double", doubleValue)}, Time: now}, + {Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now}, + {Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now}, }, SpanKind: trace.SpanKindInternal, StatusCode: codes.Error, diff --git a/exporters/trace/jaeger/env.go b/exporters/trace/jaeger/env.go index d2f7fe284c5..b9f53c367ee 100644 --- a/exporters/trace/jaeger/env.go +++ b/exporters/trace/jaeger/env.go @@ -21,7 +21,7 @@ import ( "strings" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // 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) ([]label.KeyValue, error) { +func parseTags(sTags string) ([]attribute.KeyValue, error) { pairs := strings.Split(sTags, ",") - tags := make([]label.KeyValue, len(pairs)) + tags := make([]attribute.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) ([]label.KeyValue, error) { return tags, nil } -func parseKeyValue(k, v string) label.KeyValue { - return label.KeyValue{ - Key: label.Key(k), +func parseKeyValue(k, v string) attribute.KeyValue { + return attribute.KeyValue{ + Key: attribute.Key(k), Value: parseValue(v), } } -func parseValue(str string) label.Value { +func parseValue(str string) attribute.Value { if v, err := strconv.ParseInt(str, 10, 64); err == nil { - return label.Int64Value(v) + return attribute.Int64Value(v) } if v, err := strconv.ParseFloat(str, 64); err == nil { - return label.Float64Value(v) + return attribute.Float64Value(v) } if v, err := strconv.ParseBool(str); err == nil { - return label.BoolValue(v) + return attribute.BoolValue(v) } // Fallback - return label.StringValue(str) + return attribute.StringValue(str) } diff --git a/exporters/trace/jaeger/env_test.go b/exporters/trace/jaeger/env_test.go index c3ffed60757..dd267c23e07 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/attribute" ottest "go.opentelemetry.io/otel/internal/internaltest" - "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 []label.KeyValue + expectedTags []attribute.KeyValue expectedError error }{ { name: "string", tagStr: "key=value", - expectedTags: []label.KeyValue{ + expectedTags: []attribute.KeyValue{ { Key: "key", - Value: label.StringValue("value"), + Value: attribute.StringValue("value"), }, }, }, { name: "int64", tagStr: "k=9223372036854775807,k2=-9223372036854775808", - expectedTags: []label.KeyValue{ + expectedTags: []attribute.KeyValue{ { Key: "k", - Value: label.Int64Value(math.MaxInt64), + Value: attribute.Int64Value(math.MaxInt64), }, { Key: "k2", - Value: label.Int64Value(math.MinInt64), + Value: attribute.Int64Value(math.MinInt64), }, }, }, { name: "float64", tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2", - expectedTags: []label.KeyValue{ + expectedTags: []attribute.KeyValue{ { Key: "k", - Value: label.Float64Value(math.MaxFloat64), + Value: attribute.Float64Value(math.MaxFloat64), }, { Key: "k2", - Value: label.Float64Value(math.SmallestNonzeroFloat64), + Value: attribute.Float64Value(math.SmallestNonzeroFloat64), }, { Key: "k3", - Value: label.Float64Value(-1.2), + Value: attribute.Float64Value(-1.2), }, }, }, { name: "multiple type values", tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}", - expectedTags: []label.KeyValue{ + expectedTags: []attribute.KeyValue{ { Key: "k", - Value: label.StringValue("v"), + Value: attribute.StringValue("v"), }, { Key: "k2", - Value: label.Int64Value(123), + Value: attribute.Int64Value(123), }, { Key: "k3", - Value: label.StringValue("v3"), + Value: attribute.StringValue("v3"), }, { Key: "k4", - Value: label.Float64Value(-1.2), + Value: attribute.Float64Value(-1.2), }, { Key: "k5", - Value: label.StringValue("not-default"), + Value: attribute.StringValue("not-default"), }, { Key: "k6", - Value: label.StringValue("default"), + Value: attribute.StringValue("default"), }, }, }, @@ -144,52 +144,52 @@ func Test_parseValue(t *testing.T) { testCases := []struct { name string str string - expected label.Value + expected attribute.Value }{ { name: "bool: true", str: "true", - expected: label.BoolValue(true), + expected: attribute.BoolValue(true), }, { name: "bool: false", str: "false", - expected: label.BoolValue(false), + expected: attribute.BoolValue(false), }, { name: "int64: 012340", str: "012340", - expected: label.Int64Value(12340), + expected: attribute.Int64Value(12340), }, { name: "int64: -012340", str: "-012340", - expected: label.Int64Value(-12340), + expected: attribute.Int64Value(-12340), }, { name: "int64: 0", str: "0", - expected: label.Int64Value(0), + expected: attribute.Int64Value(0), }, { name: "float64: -0.1", str: "-0.1", - expected: label.Float64Value(-0.1), + expected: attribute.Float64Value(-0.1), }, { name: "float64: 00.001", str: "00.001", - expected: label.Float64Value(0.001), + expected: attribute.Float64Value(0.001), }, { name: "float64: 1E23", str: "1E23", - expected: label.Float64Value(1e23), + expected: attribute.Float64Value(1e23), }, { name: "string: foo", str: "foo", - expected: label.StringValue("foo"), + expected: attribute.StringValue("foo"), }, } @@ -408,9 +408,9 @@ func TestProcessFromEnv(t *testing.T) { tags: "key=value,key2=123", expectedProcess: Process{ ServiceName: "test-service", - Tags: []label.KeyValue{ - label.String("key", "value"), - label.Int64("key2", 123), + Tags: []attribute.KeyValue{ + attribute.String("key", "value"), + attribute.Int64("key2", 123), }, }, }, @@ -455,16 +455,16 @@ func TestWithProcessFromEnv(t *testing.T) { options: options{ Process: Process{ ServiceName: "old-name", - Tags: []label.KeyValue{ - label.String("old-key", "old-value"), + Tags: []attribute.KeyValue{ + attribute.String("old-key", "old-value"), }, }, }, expectedOptions: options{ Process: Process{ ServiceName: "service-name", - Tags: []label.KeyValue{ - label.String("key", "value"), + Tags: []attribute.KeyValue{ + attribute.String("key", "value"), }, }, }, @@ -476,16 +476,16 @@ func TestWithProcessFromEnv(t *testing.T) { options: options{ Process: Process{ ServiceName: "old-name", - Tags: []label.KeyValue{ - label.String("old-key", "old-value"), + Tags: []attribute.KeyValue{ + attribute.String("old-key", "old-value"), }, }, }, expectedOptions: options{ Process: Process{ ServiceName: "old-name", - Tags: []label.KeyValue{ - label.String("old-key", "old-value"), + Tags: []attribute.KeyValue{ + attribute.String("old-key", "old-value"), }, }, }, diff --git a/exporters/trace/jaeger/jaeger.go b/exporters/trace/jaeger/jaeger.go index 1330cddcfaa..dcd43c83fee 100644 --- a/exporters/trace/jaeger/jaeger.go +++ b/exporters/trace/jaeger/jaeger.go @@ -23,9 +23,9 @@ import ( "google.golang.org/api/support/bundler" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" 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" "go.opentelemetry.io/otel/trace" @@ -193,7 +193,7 @@ type Process struct { ServiceName string // Tags are added to Jaeger Process exports - Tags []label.KeyValue + Tags []attribute.KeyValue } // Exporter is an implementation of an OTel SpanSyncer that uploads spans to @@ -342,31 +342,31 @@ func spanSnapshotToThrift(ss *export.SpanSnapshot) *gen.Span { } } -func keyValueToTag(keyValue label.KeyValue) *gen.Tag { +func keyValueToTag(keyValue attribute.KeyValue) *gen.Tag { var tag *gen.Tag switch keyValue.Value.Type() { - case label.STRING: + case attribute.STRING: s := keyValue.Value.AsString() tag = &gen.Tag{ Key: string(keyValue.Key), VStr: &s, VType: gen.TagType_STRING, } - case label.BOOL: + case attribute.BOOL: b := keyValue.Value.AsBool() tag = &gen.Tag{ Key: string(keyValue.Key), VBool: &b, VType: gen.TagType_BOOL, } - case label.INT64: + case attribute.INT64: i := keyValue.Value.AsInt64() tag = &gen.Tag{ Key: string(keyValue.Key), VLong: &i, VType: gen.TagType_LONG, } - case label.FLOAT64: + case attribute.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 82cb42932bf..503b9d9668e 100644 --- a/exporters/trace/jaeger/jaeger_test.go +++ b/exporters/trace/jaeger/jaeger_test.go @@ -28,10 +28,10 @@ import ( "google.golang.org/api/support/bundler" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" ottest "go.opentelemetry.io/otel/internal/internaltest" - "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" @@ -203,8 +203,8 @@ func TestNewRawExporter(t *testing.T) { WithProcess( Process{ ServiceName: "jaeger-test", - Tags: []label.KeyValue{ - label.String("key", "val"), + Tags: []attribute.KeyValue{ + attribute.String("key", "val"), }, }, ), @@ -329,8 +329,8 @@ func TestExporter_ExportSpan(t *testing.T) { withTestCollectorEndpoint(), WithProcess(Process{ ServiceName: serviceName, - Tags: []label.KeyValue{ - label.String(tagKey, tagVal), + Tags: []attribute.KeyValue{ + attribute.String(tagKey, tagVal), }, }), ) @@ -396,18 +396,18 @@ func Test_spanSnapshotToThrift(t *testing.T) { }, }, }, - Attributes: []label.KeyValue{ - label.String("key", keyValue), - label.Float64("double", doubleValue), - label.Int64("int", intValue), + Attributes: []attribute.KeyValue{ + attribute.String("key", keyValue), + attribute.Float64("double", doubleValue), + attribute.Int64("int", intValue), }, MessageEvents: []trace.Event{ - {Name: eventNameValue, Attributes: []label.KeyValue{label.String("k1", keyValue)}, Time: now}, + {Name: eventNameValue, Attributes: []attribute.KeyValue{attribute.String("k1", keyValue)}, Time: now}, }, StatusCode: codes.Error, StatusMessage: statusMessage, SpanKind: trace.SpanKindClient, - Resource: resource.NewWithAttributes(label.String("rk1", rv1), label.Int64("rk2", rv2)), + Resource: resource.NewWithAttributes(attribute.String("rk1", rv1), attribute.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 e4ee0098ddc..a670926aea1 100644 --- a/exporters/trace/zipkin/model.go +++ b/exporters/trace/zipkin/model.go @@ -21,7 +21,7 @@ import ( zkmodel "github.com/openzipkin/zipkin-go/model" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/trace" ) @@ -127,7 +127,7 @@ func toZipkinAnnotations(events []trace.Event) []zkmodel.Annotation { return annotations } -func attributesToJSONMapString(attributes []label.KeyValue) string { +func attributesToJSONMapString(attributes []attribute.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 9d50f6c9b57..82b2c333b65 100644 --- a/exporters/trace/zipkin/model_test.go +++ b/exporters/trace/zipkin/model_test.go @@ -24,8 +24,8 @@ import ( zkmodel "github.com/openzipkin/zipkin-go/model" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" export "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/trace" @@ -44,16 +44,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -77,16 +77,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -109,16 +109,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -141,16 +141,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -173,16 +173,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -205,16 +205,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -237,16 +237,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -269,9 +269,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: []label.KeyValue{ - label.Int64("attr1", 42), - label.String("attr2", "bar"), + Attributes: []attribute.KeyValue{ + attribute.Int64("attr1", 42), + attribute.String("attr2", "bar"), }, MessageEvents: nil, StatusCode: codes.Error, @@ -288,15 +288,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: []label.KeyValue{ - label.String("error", "false"), + Attributes: []attribute.KeyValue{ + attribute.String("error", "false"), }, MessageEvents: []trace.Event{ { Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Name: "ev1", - Attributes: []label.KeyValue{ - label.Int64("eventattr1", 123), + Attributes: []attribute.KeyValue{ + attribute.Int64("eventattr1", 123), }, }, { @@ -677,11 +677,11 @@ func Test_toZipkinTags(t *testing.T) { { name: "attributes", data: &export.SpanSnapshot{ - Attributes: []label.KeyValue{ - label.String("key", keyValue), - label.Float64("double", doubleValue), - label.Int64("uint", uintValue), - label.Bool("ok", true), + Attributes: []attribute.KeyValue{ + attribute.String("key", keyValue), + attribute.Float64("double", doubleValue), + attribute.Int64("uint", uintValue), + attribute.Bool("ok", true), }, }, want: map[string]string{ @@ -704,8 +704,8 @@ func Test_toZipkinTags(t *testing.T) { { name: "omit-noerror", data: &export.SpanSnapshot{ - Attributes: []label.KeyValue{ - label.Bool("error", false), + Attributes: []attribute.KeyValue{ + attribute.Bool("error", false), }, }, want: map[string]string{ @@ -716,9 +716,9 @@ func Test_toZipkinTags(t *testing.T) { { name: "statusCode", data: &export.SpanSnapshot{ - Attributes: []label.KeyValue{ - label.String("key", keyValue), - label.Bool("error", true), + Attributes: []attribute.KeyValue{ + attribute.String("key", keyValue), + attribute.Bool("error", true), }, StatusCode: codes.Error, StatusMessage: statusMessage, @@ -743,7 +743,7 @@ func Test_toZipkinTags(t *testing.T) { { name: "instrLib-noversion", data: &export.SpanSnapshot{ - Attributes: []label.KeyValue{}, + Attributes: []attribute.KeyValue{}, InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, }, @@ -757,7 +757,7 @@ func Test_toZipkinTags(t *testing.T) { { name: "instrLib-with-version", data: &export.SpanSnapshot{ - Attributes: []label.KeyValue{}, + Attributes: []attribute.KeyValue{}, InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, diff --git a/internal/baggage/baggage.go b/internal/baggage/baggage.go index 6b5c0c2d933..b1f7daf8d86 100644 --- a/internal/baggage/baggage.go +++ b/internal/baggage/baggage.go @@ -18,11 +18,11 @@ package baggage import ( "context" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) -type rawMap map[label.Key]label.Value -type keySet map[label.Key]struct{} +type rawMap map[attribute.Key]attribute.Value +type keySet map[attribute.Key]struct{} // Map is an immutable storage for correlations. type Map struct { @@ -35,18 +35,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 label.Key + DropSingleK attribute.Key // DropMultiK contains all the keys to be dropped from // correlations. - DropMultiK []label.Key + DropMultiK []attribute.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 label.KeyValue + SingleKV attribute.KeyValue // MultiKV contains all the key-value pairs to be added to // correlations. - MultiKV []label.KeyValue + MultiKV []attribute.KeyValue } func newMap(raw rawMap) Map { @@ -104,7 +104,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) { deletionsCount++ } if deletionsCount > 0 { - delSet = make(map[label.Key]struct{}, deletionsCount) + delSet = make(map[attribute.Key]struct{}, deletionsCount) for _, k := range update.DropMultiK { delSet[k] = struct{}{} } @@ -118,7 +118,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) { additionsCount++ } if additionsCount > 0 { - addSet = make(map[label.Key]struct{}, additionsCount) + addSet = make(map[attribute.Key]struct{}, additionsCount) for _, k := range update.MultiKV { addSet[k.Key] = struct{}{} } @@ -149,14 +149,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 label.Key) (label.Value, bool) { +func (m Map) Value(k attribute.Key) (attribute.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 label.Key) bool { +func (m Map) HasValue(k attribute.Key) bool { _, has := m.Value(k) return has } @@ -169,9 +169,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(label.KeyValue) bool) { +func (m Map) Foreach(f func(attribute.KeyValue) bool) { for k, v := range m.m { - if !f(label.KeyValue{ + if !f(attribute.KeyValue{ Key: k, Value: v, }) { @@ -316,7 +316,7 @@ func ContextWithNoCorrelationData(ctx context.Context) 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 ...label.KeyValue) context.Context { +func NewContext(ctx context.Context, keyvalues ...attribute.KeyValue) context.Context { return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{ MultiKV: keyvalues, })) diff --git a/internal/baggage/baggage_test.go b/internal/baggage/baggage_test.go index 6338fe92580..8c164a5c5cf 100644 --- a/internal/baggage/baggage_test.go +++ b/internal/baggage/baggage_test.go @@ -18,14 +18,14 @@ import ( "fmt" "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) type testCase struct { name string value MapUpdate init []int - wantKVs []label.KeyValue + wantKVs []attribute.KeyValue } func TestMap(t *testing.T) { @@ -46,7 +46,7 @@ func TestMap(t *testing.T) { } } // test Foreach() - got.Foreach(func(kv label.KeyValue) bool { + got.Foreach(func(kv attribute.KeyValue) bool { for _, want := range testcase.wantKVs { if kv == want { return false @@ -85,192 +85,192 @@ func getTestCases() []testCase { return []testCase{ { name: "map with MultiKV", - value: MapUpdate{MultiKV: []label.KeyValue{ - label.Int64("key1", 1), - label.String("key2", "val2")}, + value: MapUpdate{MultiKV: []attribute.KeyValue{ + attribute.Int64("key1", 1), + attribute.String("key2", "val2")}, }, init: []int{}, - wantKVs: []label.KeyValue{ - label.Int64("key1", 1), - label.String("key2", "val2"), + wantKVs: []attribute.KeyValue{ + attribute.Int64("key1", 1), + attribute.String("key2", "val2"), }, }, { name: "map with SingleKV", - value: MapUpdate{SingleKV: label.String("key1", "val1")}, + value: MapUpdate{SingleKV: attribute.String("key1", "val1")}, init: []int{}, - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), }, }, { name: "map with both add fields", - value: MapUpdate{SingleKV: label.Int64("key1", 3), - MultiKV: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2")}, + value: MapUpdate{SingleKV: attribute.Int64("key1", 3), + MultiKV: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2")}, }, init: []int{}, - wantKVs: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), }, }, { name: "map with empty MapUpdate", value: MapUpdate{}, init: []int{}, - wantKVs: []label.KeyValue{}, + wantKVs: []attribute.KeyValue{}, }, { name: "map with DropSingleK", - value: MapUpdate{DropSingleK: label.Key("key1")}, + value: MapUpdate{DropSingleK: attribute.Key("key1")}, init: []int{}, - wantKVs: []label.KeyValue{}, + wantKVs: []attribute.KeyValue{}, }, { name: "map with DropMultiK", - value: MapUpdate{DropMultiK: []label.Key{ - label.Key("key1"), label.Key("key2"), + value: MapUpdate{DropMultiK: []attribute.Key{ + attribute.Key("key1"), attribute.Key("key2"), }}, init: []int{}, - wantKVs: []label.KeyValue{}, + wantKVs: []attribute.KeyValue{}, }, { name: "map with both drop fields", value: MapUpdate{ - DropSingleK: label.Key("key1"), - DropMultiK: []label.Key{ - label.Key("key1"), - label.Key("key2"), + DropSingleK: attribute.Key("key1"), + DropMultiK: []attribute.Key{ + attribute.Key("key1"), + attribute.Key("key2"), }, }, init: []int{}, - wantKVs: []label.KeyValue{}, + wantKVs: []attribute.KeyValue{}, }, { name: "map with all fields", value: MapUpdate{ - DropSingleK: label.Key("key1"), - DropMultiK: []label.Key{ - label.Key("key1"), - label.Key("key2"), + DropSingleK: attribute.Key("key1"), + DropMultiK: []attribute.Key{ + attribute.Key("key1"), + attribute.Key("key2"), }, - SingleKV: label.String("key4", "val4"), - MultiKV: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), - label.String("key3", "val3"), + SingleKV: attribute.String("key4", "val4"), + MultiKV: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, init: []int{}, - wantKVs: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), - label.String("key3", "val3"), - label.String("key4", "val4"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), + attribute.String("key4", "val4"), }, }, { name: "Existing map with MultiKV", - value: MapUpdate{MultiKV: []label.KeyValue{ - label.Int64("key1", 1), - label.String("key2", "val2")}, + value: MapUpdate{MultiKV: []attribute.KeyValue{ + attribute.Int64("key1", 1), + attribute.String("key2", "val2")}, }, init: []int{5}, - wantKVs: []label.KeyValue{ - label.Int64("key1", 1), - label.String("key2", "val2"), - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.Int64("key1", 1), + attribute.String("key2", "val2"), + attribute.Int("key5", 5), }, }, { name: "Existing map with SingleKV", - value: MapUpdate{SingleKV: label.String("key1", "val1")}, + value: MapUpdate{SingleKV: attribute.String("key1", "val1")}, init: []int{5}, - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.Int("key5", 5), }, }, { name: "Existing map with both add fields", - value: MapUpdate{SingleKV: label.Int64("key1", 3), - MultiKV: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2")}, + value: MapUpdate{SingleKV: attribute.Int64("key1", 3), + MultiKV: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2")}, }, init: []int{5}, - wantKVs: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), + attribute.Int("key5", 5), }, }, { name: "Existing map with empty MapUpdate", value: MapUpdate{}, init: []int{5}, - wantKVs: []label.KeyValue{ - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.Int("key5", 5), }, }, { name: "Existing map with DropSingleK", - value: MapUpdate{DropSingleK: label.Key("key1")}, + value: MapUpdate{DropSingleK: attribute.Key("key1")}, init: []int{1, 5}, - wantKVs: []label.KeyValue{ - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.Int("key5", 5), }, }, { name: "Existing map with DropMultiK", - value: MapUpdate{DropMultiK: []label.Key{ - label.Key("key1"), label.Key("key2"), + value: MapUpdate{DropMultiK: []attribute.Key{ + attribute.Key("key1"), attribute.Key("key2"), }}, init: []int{1, 5}, - wantKVs: []label.KeyValue{ - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.Int("key5", 5), }, }, { name: "Existing map with both drop fields", value: MapUpdate{ - DropSingleK: label.Key("key1"), - DropMultiK: []label.Key{ - label.Key("key1"), - label.Key("key2"), + DropSingleK: attribute.Key("key1"), + DropMultiK: []attribute.Key{ + attribute.Key("key1"), + attribute.Key("key2"), }, }, init: []int{1, 2, 5}, - wantKVs: []label.KeyValue{ - label.Int("key5", 5), + wantKVs: []attribute.KeyValue{ + attribute.Int("key5", 5), }, }, { name: "Existing map with all the fields", value: MapUpdate{ - DropSingleK: label.Key("key1"), - DropMultiK: []label.Key{ - label.Key("key1"), - label.Key("key2"), - label.Key("key5"), - label.Key("key6"), + DropSingleK: attribute.Key("key1"), + DropMultiK: []attribute.Key{ + attribute.Key("key1"), + attribute.Key("key2"), + attribute.Key("key5"), + attribute.Key("key6"), }, - SingleKV: label.String("key4", "val4"), - MultiKV: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), - label.String("key3", "val3"), + SingleKV: attribute.String("key4", "val4"), + MultiKV: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, init: []int{5, 6, 7}, - wantKVs: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), - label.String("key3", "val3"), - label.String("key4", "val4"), - label.Int("key7", 7), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), + attribute.String("key4", "val4"), + attribute.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[label.Key(fmt.Sprintf("key%d", v))] = label.IntValue(v) + r[attribute.Key(fmt.Sprintf("key%d", v))] = attribute.IntValue(v) } return newMap(r) } diff --git a/internal/global/benchmark_test.go b/internal/global/benchmark_test.go index a4cbebbfeeb..ea06b7dd87e 100644 --- a/internal/global/benchmark_test.go +++ b/internal/global/benchmark_test.go @@ -19,8 +19,8 @@ import ( "testing" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/global" - "go.opentelemetry.io/otel/label" metricglobal "go.opentelemetry.io/otel/metric/global" ) @@ -31,7 +31,7 @@ func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { global.ResetForTest() ctx := context.Background() sdk := metricglobal.Meter("test") - labs := []label.KeyValue{label.String("A", "B")} + labs := []attribute.KeyValue{attribute.String("A", "B")} cnt := Must(sdk).NewInt64Counter("int64.counter") b.ResetTimer() diff --git a/internal/global/meter.go b/internal/global/meter.go index 8b288df780f..36f9edeb8c6 100644 --- a/internal/global/meter.go +++ b/internal/global/meter.go @@ -20,7 +20,7 @@ import ( "sync/atomic" "unsafe" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/registry" @@ -109,7 +109,7 @@ type syncHandle struct { delegate unsafe.Pointer // (*metric.BoundInstrumentImpl) inst *syncImpl - labels []label.KeyValue + labels []attribute.KeyValue initialize sync.Once } @@ -228,7 +228,7 @@ func (inst *syncImpl) Implementation() interface{} { return inst } -func (inst *syncImpl) Bind(labels []label.KeyValue) metric.BoundSyncImpl { +func (inst *syncImpl) Bind(labels []attribute.KeyValue) metric.BoundSyncImpl { if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil { return (*implPtr).Bind(labels) } @@ -300,13 +300,13 @@ func (obs *asyncImpl) setDelegate(d metric.MeterImpl) { // Metric updates -func (m *meterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) { +func (m *meterImpl) RecordBatch(ctx context.Context, labels []attribute.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 number.Number, labels []label.KeyValue) { +func (inst *syncImpl) RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue) { if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil { (*instPtr).RecordOne(ctx, number, labels) } diff --git a/internal/global/meter_test.go b/internal/global/meter_test.go index 6426d3c8fbf..830ef074c8a 100644 --- a/internal/global/meter_test.go +++ b/internal/global/meter_test.go @@ -21,8 +21,8 @@ import ( "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/global" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" metricglobal "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/number" @@ -40,9 +40,9 @@ func TestDirect(t *testing.T) { ctx := context.Background() meter1 := metricglobal.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0")) meter2 := metricglobal.Meter("test2") - labels1 := []label.KeyValue{label.String("A", "B")} - labels2 := []label.KeyValue{label.String("C", "D")} - labels3 := []label.KeyValue{label.String("E", "F")} + labels1 := []attribute.KeyValue{attribute.String("A", "B")} + labels2 := []attribute.KeyValue{attribute.String("C", "D")} + labels3 := []attribute.KeyValue{attribute.String("E", "F")} counter := Must(meter1).NewInt64Counter("test.counter") counter.Add(ctx, 1, labels1...) @@ -139,7 +139,7 @@ func TestBound(t *testing.T) { // vs. the above, to cover all the instruments. ctx := context.Background() glob := metricglobal.Meter("test") - labels1 := []label.KeyValue{label.String("A", "B")} + labels1 := []attribute.KeyValue{attribute.String("A", "B")} counter := Must(glob).NewFloat64Counter("test.counter") boundC := counter.Bind(labels1...) @@ -183,7 +183,7 @@ func TestUnbind(t *testing.T) { global.ResetForTest() glob := metricglobal.Meter("test") - labels1 := []label.KeyValue{label.String("A", "B")} + labels1 := []attribute.KeyValue{attribute.String("A", "B")} counter := Must(glob).NewFloat64Counter("test.counter") boundC := counter.Bind(labels1...) diff --git a/internal/metric/async.go b/internal/metric/async.go index 11d0c032d6d..f05faca8a90 100644 --- a/internal/metric/async.go +++ b/internal/metric/async.go @@ -21,7 +21,7 @@ import ( "sync" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" ) @@ -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(labels []label.KeyValue, observation ...metric.Observation) + CollectAsync(labels []attribute.KeyValue, observation ...metric.Observation) } // AsyncInstrumentState manages an ordered set of asynchronous diff --git a/internal/trace/parent/parent.go b/internal/trace/parent/parent.go index 0529265108d..232961fb161 100644 --- a/internal/trace/parent/parent.go +++ b/internal/trace/parent/parent.go @@ -17,7 +17,7 @@ package parent import ( "context" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -46,8 +46,8 @@ func addLinkIfValid(links []trace.Link, sc trace.SpanContext, kind string) []tra } return append(links, trace.Link{ SpanContext: sc, - Attributes: []label.KeyValue{ - label.String("ignored-on-demand", kind), + Attributes: []attribute.KeyValue{ + attribute.String("ignored-on-demand", kind), }, }) } diff --git a/metric/metric.go b/metric/metric.go index 0b988abba88..b591985df68 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -17,7 +17,7 @@ package metric // import "go.opentelemetry.io/otel/metric" import ( "context" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/unit" ) @@ -42,7 +42,7 @@ type Meter struct { } // RecordBatch atomically records a batch of measurements. -func (m Meter) RecordBatch(ctx context.Context, ls []label.KeyValue, ms ...Measurement) { +func (m Meter) RecordBatch(ctx context.Context, ls []attribute.KeyValue, ms ...Measurement) { if m.impl == nil { return } diff --git a/metric/metric_instrument.go b/metric/metric_instrument.go index 6e2f9ce9552..6f3fc997cb9 100644 --- a/metric/metric_instrument.go +++ b/metric/metric_instrument.go @@ -20,7 +20,7 @@ import ( "context" "errors" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" ) @@ -116,25 +116,25 @@ type BatchObserverFunc func(context.Context, BatchObserverResult) // observations for one asynchronous integer metric instrument. type Int64ObserverResult struct { instrument AsyncImpl - function func([]label.KeyValue, ...Observation) + function func([]attribute.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([]label.KeyValue, ...Observation) + function func([]attribute.KeyValue, ...Observation) } // BatchObserverResult is passed to a batch observer callback to // capture observations for multiple asynchronous instruments. type BatchObserverResult struct { - function func([]label.KeyValue, ...Observation) + function func([]attribute.KeyValue, ...Observation) } // Observe captures a single integer value from the associated // instrument callback, with the given labels. -func (ir Int64ObserverResult) Observe(value int64, labels ...label.KeyValue) { +func (ir Int64ObserverResult) Observe(value int64, labels ...attribute.KeyValue) { ir.function(labels, Observation{ instrument: ir.instrument, number: number.NewInt64Number(value), @@ -143,7 +143,7 @@ func (ir Int64ObserverResult) Observe(value int64, labels ...label.KeyValue) { // Observe captures a single floating point value from the associated // instrument callback, with the given labels. -func (fr Float64ObserverResult) Observe(value float64, labels ...label.KeyValue) { +func (fr Float64ObserverResult) Observe(value float64, labels ...attribute.KeyValue) { fr.function(labels, Observation{ instrument: fr.instrument, number: number.NewFloat64Number(value), @@ -152,7 +152,7 @@ func (fr Float64ObserverResult) Observe(value float64, labels ...label.KeyValue) // Observe captures a multiple observations from the associated batch // instrument callback, with the given labels. -func (br BatchObserverResult) Observe(labels []label.KeyValue, obs ...Observation) { +func (br BatchObserverResult) Observe(labels []attribute.KeyValue, obs ...Observation) { br.function(labels, obs...) } @@ -173,7 +173,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([]label.KeyValue, ...Observation)) + Run(ctx context.Context, single AsyncImpl, capture func([]attribute.KeyValue, ...Observation)) AsyncRunner } @@ -183,7 +183,7 @@ type AsyncSingleRunner interface { type AsyncBatchRunner interface { // Run accepts a function for capturing observations of // multiple instruments. - Run(ctx context.Context, capture func([]label.KeyValue, ...Observation)) + Run(ctx context.Context, capture func([]attribute.KeyValue, ...Observation)) AsyncRunner } @@ -217,7 +217,7 @@ func (*Float64ObserverFunc) AnyRunner() {} func (*BatchObserverFunc) AnyRunner() {} // Run implements AsyncSingleRunner. -func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) { +func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]attribute.KeyValue, ...Observation)) { (*i)(ctx, Int64ObserverResult{ instrument: impl, function: function, @@ -225,7 +225,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([]label.KeyValue, ...Observation)) { +func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]attribute.KeyValue, ...Observation)) { (*f)(ctx, Float64ObserverResult{ instrument: impl, function: function, @@ -233,7 +233,7 @@ func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function } // Run implements AsyncBatchRunner. -func (b *BatchObserverFunc) Run(ctx context.Context, function func([]label.KeyValue, ...Observation)) { +func (b *BatchObserverFunc) Run(ctx context.Context, function func([]attribute.KeyValue, ...Observation)) { (*b)(ctx, BatchObserverResult{ function: function, }) @@ -442,7 +442,7 @@ func (s syncInstrument) SyncImpl() SyncImpl { return s.instrument } -func (s syncInstrument) bind(labels []label.KeyValue) syncBoundInstrument { +func (s syncInstrument) bind(labels []attribute.KeyValue) syncBoundInstrument { return newSyncBoundInstrument(s.instrument.Bind(labels)) } @@ -454,7 +454,7 @@ func (s syncInstrument) int64Measurement(value int64) Measurement { return newMeasurement(s.instrument, number.NewInt64Number(value)) } -func (s syncInstrument) directRecord(ctx context.Context, number number.Number, labels []label.KeyValue) { +func (s syncInstrument) directRecord(ctx context.Context, number number.Number, labels []attribute.KeyValue) { s.instrument.RecordOne(ctx, number, labels) } @@ -577,14 +577,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 ...label.KeyValue) (h BoundFloat64Counter) { +func (c Float64Counter) Bind(labels ...attribute.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 ...label.KeyValue) (h BoundInt64Counter) { +func (c Int64Counter) Bind(labels ...attribute.KeyValue) (h BoundInt64Counter) { h.syncBoundInstrument = c.bind(labels) return } @@ -603,13 +603,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 ...label.KeyValue) { +func (c Float64Counter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) { c.directRecord(ctx, number.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 ...label.KeyValue) { +func (c Int64Counter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) { c.directRecord(ctx, number.NewInt64Number(value), labels) } @@ -652,14 +652,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 ...label.KeyValue) (h BoundFloat64UpDownCounter) { +func (c Float64UpDownCounter) Bind(labels ...attribute.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 ...label.KeyValue) (h BoundInt64UpDownCounter) { +func (c Int64UpDownCounter) Bind(labels ...attribute.KeyValue) (h BoundInt64UpDownCounter) { h.syncBoundInstrument = c.bind(labels) return } @@ -678,13 +678,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 ...label.KeyValue) { +func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) { c.directRecord(ctx, number.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 ...label.KeyValue) { +func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) { c.directRecord(ctx, number.NewInt64Number(value), labels) } @@ -726,14 +726,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 ...label.KeyValue) (h BoundFloat64ValueRecorder) { +func (c Float64ValueRecorder) Bind(labels ...attribute.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 ...label.KeyValue) (h BoundInt64ValueRecorder) { +func (c Int64ValueRecorder) Bind(labels ...attribute.KeyValue) (h BoundInt64ValueRecorder) { h.syncBoundInstrument = c.bind(labels) return } @@ -753,14 +753,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 ...label.KeyValue) { +func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...attribute.KeyValue) { c.directRecord(ctx, number.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 ...label.KeyValue) { +func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...attribute.KeyValue) { c.directRecord(ctx, number.NewInt64Number(value), labels) } diff --git a/metric/metric_noop.go b/metric/metric_noop.go index 5cf26fc249f..30e57b6945b 100644 --- a/metric/metric_noop.go +++ b/metric/metric_noop.go @@ -17,7 +17,7 @@ package metric // import "go.opentelemetry.io/otel/metric" import ( "context" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" ) @@ -51,9 +51,9 @@ func (noopBoundInstrument) RecordOne(context.Context, number.Number) { func (noopBoundInstrument) Unbind() { } -func (NoopSync) Bind([]label.KeyValue) BoundSyncImpl { +func (NoopSync) Bind([]attribute.KeyValue) BoundSyncImpl { return noopBoundInstrument{} } -func (NoopSync) RecordOne(context.Context, number.Number, []label.KeyValue) { +func (NoopSync) RecordOne(context.Context, number.Number, []attribute.KeyValue) { } diff --git a/metric/metric_sdkapi.go b/metric/metric_sdkapi.go index 77d6adb173b..94164f7b485 100644 --- a/metric/metric_sdkapi.go +++ b/metric/metric_sdkapi.go @@ -17,7 +17,7 @@ package metric // import "go.opentelemetry.io/otel/metric" import ( "context" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" ) @@ -25,7 +25,7 @@ import ( // implementation. type MeterImpl interface { // RecordBatch atomically records a batch of measurements. - RecordBatch(ctx context.Context, labels []label.KeyValue, measurement ...Measurement) + RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurement ...Measurement) // NewSyncInstrument returns a newly constructed // synchronous instrument implementation or an error, should @@ -60,10 +60,10 @@ type SyncImpl interface { // Bind creates an implementation-level bound instrument, // binding a label set with this instrument implementation. - Bind(labels []label.KeyValue) BoundSyncImpl + Bind(labels []attribute.KeyValue) BoundSyncImpl // RecordOne captures a single synchronous metric event. - RecordOne(ctx context.Context, number number.Number, labels []label.KeyValue) + RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue) } // BoundSyncImpl is the implementation-level interface to a diff --git a/metric/metric_test.go b/metric/metric_test.go index 3250f0e1588..a50bf68cd74 100644 --- a/metric/metric_test.go +++ b/metric/metric_test.go @@ -19,7 +19,7 @@ import ( "errors" "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/oteltest" @@ -119,7 +119,7 @@ func TestPrecomputedSum(t *testing.T) { } } -func checkSyncBatches(ctx context.Context, t *testing.T, labels []label.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { +func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { t.Helper() batchesCount := len(mock.MeasurementBatches) @@ -213,7 +213,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := oteltest.NewMeter() c := Must(meter).NewFloat64Counter("test.counter.float") ctx := context.Background() - labels := []label.KeyValue{label.String("A", "B")} + labels := []attribute.KeyValue{attribute.String("A", "B")} c.Add(ctx, 1994.1, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -742) @@ -226,7 +226,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := oteltest.NewMeter() c := Must(meter).NewInt64Counter("test.counter.int") ctx := context.Background() - labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")} + labels := []attribute.KeyValue{attribute.String("A", "B"), attribute.String("C", "D")} c.Add(ctx, 42, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, 4200) @@ -240,7 +240,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := oteltest.NewMeter() c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int") ctx := context.Background() - labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")} + labels := []attribute.KeyValue{attribute.String("A", "B"), attribute.String("C", "D")} c.Add(ctx, 100, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -100) @@ -253,7 +253,7 @@ func TestCounter(t *testing.T) { mockSDK, meter := oteltest.NewMeter() c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float") ctx := context.Background() - labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")} + labels := []attribute.KeyValue{attribute.String("A", "B"), attribute.String("C", "D")} c.Add(ctx, 100.1, labels...) boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -76) @@ -269,7 +269,7 @@ func TestValueRecorder(t *testing.T) { mockSDK, meter := oteltest.NewMeter() m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float") ctx := context.Background() - labels := []label.KeyValue{} + labels := []attribute.KeyValue{} m.Record(ctx, 42, labels...) boundInstrument := m.Bind(labels...) boundInstrument.Record(ctx, 0) @@ -282,7 +282,7 @@ func TestValueRecorder(t *testing.T) { mockSDK, meter := oteltest.NewMeter() m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int") ctx := context.Background() - labels := []label.KeyValue{label.Int("I", 1)} + labels := []attribute.KeyValue{attribute.Int("I", 1)} m.Record(ctx, 173, labels...) boundInstrument := m.Bind(labels...) boundInstrument.Record(ctx, 80) @@ -295,7 +295,7 @@ func TestValueRecorder(t *testing.T) { func TestObserverInstruments(t *testing.T) { t.Run("float valueobserver", func(t *testing.T) { - labels := []label.KeyValue{label.String("O", "P")} + labels := []attribute.KeyValue{attribute.String("O", "P")} mockSDK, meter := oteltest.NewMeter() o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) @@ -306,7 +306,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("int valueobserver", func(t *testing.T) { - labels := []label.KeyValue{} + labels := []attribute.KeyValue{} mockSDK, meter := oteltest.NewMeter() o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) @@ -317,7 +317,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("float sumobserver", func(t *testing.T) { - labels := []label.KeyValue{label.String("O", "P")} + labels := []attribute.KeyValue{attribute.String("O", "P")} mockSDK, meter := oteltest.NewMeter() o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) @@ -328,7 +328,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("int sumobserver", func(t *testing.T) { - labels := []label.KeyValue{} + labels := []attribute.KeyValue{} mockSDK, meter := oteltest.NewMeter() o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) @@ -339,7 +339,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("float updownsumobserver", func(t *testing.T) { - labels := []label.KeyValue{label.String("O", "P")} + labels := []attribute.KeyValue{attribute.String("O", "P")} mockSDK, meter := oteltest.NewMeter() o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) @@ -350,7 +350,7 @@ func TestObserverInstruments(t *testing.T) { ) }) t.Run("int updownsumobserver", func(t *testing.T) { - labels := []label.KeyValue{} + labels := []attribute.KeyValue{} mockSDK, meter := oteltest.NewMeter() o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) @@ -368,9 +368,9 @@ func TestBatchObserverInstruments(t *testing.T) { var obs1 metric.Int64ValueObserver var obs2 metric.Float64ValueObserver - labels := []label.KeyValue{ - label.String("A", "B"), - label.String("C", "D"), + labels := []attribute.KeyValue{ + attribute.String("A", "B"), + attribute.String("C", "D"), } cb := Must(meter).NewBatchObserver( @@ -407,7 +407,7 @@ func TestBatchObserverInstruments(t *testing.T) { require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, oteltest.ResolveNumberByKind(t, number.Float64Kind, 42))) } -func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { +func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { t.Helper() assert.Len(t, mock.MeasurementBatches, 1) if len(mock.MeasurementBatches) < 1 { @@ -435,7 +435,7 @@ type testWrappedMeter struct { var _ metric.MeterImpl = testWrappedMeter{} -func (testWrappedMeter) RecordBatch(context.Context, []label.KeyValue, ...metric.Measurement) { +func (testWrappedMeter) RecordBatch(context.Context, []attribute.KeyValue, ...metric.Measurement) { } func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { diff --git a/metric/registry/registry.go b/metric/registry/registry.go index 955ba050eb9..0a42a0fdf8d 100644 --- a/metric/registry/registry.go +++ b/metric/registry/registry.go @@ -19,7 +19,7 @@ import ( "fmt" "sync" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" ) @@ -75,7 +75,7 @@ func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl { } // RecordBatch implements metric.MeterImpl. -func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, ms ...metric.Measurement) { +func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, ms ...metric.Measurement) { u.impl.RecordBatch(ctx, labels, ms...) } diff --git a/oteltest/event.go b/oteltest/event.go index 1dca00e7d9c..7e5b1f9f280 100644 --- a/oteltest/event.go +++ b/oteltest/event.go @@ -17,12 +17,12 @@ package oteltest // import "go.opentelemetry.io/otel/oteltest" import ( "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // Event encapsulates the properties of calls to AddEvent. type Event struct { Timestamp time.Time Name string - Attributes map[label.Key]label.Value + Attributes map[attribute.Key]attribute.Value } diff --git a/oteltest/harness.go b/oteltest/harness.go index 309e6832a5c..428094dcdab 100644 --- a/oteltest/harness.go +++ b/oteltest/harness.go @@ -20,9 +20,9 @@ import ( "testing" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/internal/matchers" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" ) @@ -200,7 +200,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { span.SetName("new name") }, "#SetAttributes": func(span trace.Span) { - span.SetAttributes(label.String("key1", "value"), label.Int("key2", 123)) + span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) }, } var mechanisms = map[string]func() trace.Span{ diff --git a/oteltest/meter.go b/oteltest/meter.go index d7899ce71a8..bef72d23791 100644 --- a/oteltest/meter.go +++ b/oteltest/meter.go @@ -19,8 +19,8 @@ import ( "sync" "testing" + "go.opentelemetry.io/otel/attribute" internalmetric "go.opentelemetry.io/otel/internal/metric" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/registry" @@ -29,14 +29,14 @@ import ( type ( Handle struct { Instrument *Sync - Labels []label.KeyValue + Labels []attribute.KeyValue } Batch struct { // Measurement needs to be aligned for 64-bit atomic operations. Measurements []Measurement Ctx context.Context - Labels []label.KeyValue + Labels []attribute.KeyValue LibraryName string } @@ -90,14 +90,14 @@ func (s *Sync) Implementation() interface{} { return s } -func (s *Sync) Bind(labels []label.KeyValue) metric.BoundSyncImpl { +func (s *Sync) Bind(labels []attribute.KeyValue) metric.BoundSyncImpl { return &Handle{ Instrument: s, Labels: labels, } } -func (s *Sync) RecordOne(ctx context.Context, number number.Number, labels []label.KeyValue) { +func (s *Sync) RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue) { s.meter.doRecordSingle(ctx, labels, s, number) } @@ -108,7 +108,7 @@ func (h *Handle) RecordOne(ctx context.Context, number number.Number) { func (h *Handle) Unbind() { } -func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []label.KeyValue, instrument metric.InstrumentImpl, number number.Number) { +func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []attribute.KeyValue, instrument metric.InstrumentImpl, number number.Number) { m.collect(ctx, labels, []Measurement{{ Instrument: instrument, Number: number, @@ -154,7 +154,7 @@ func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metr return a, nil } -func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) { +func (m *MeterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurements ...metric.Measurement) { mm := make([]Measurement, len(measurements)) for i := 0; i < len(measurements); i++ { m := measurements[i] @@ -166,7 +166,7 @@ func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, me m.collect(ctx, labels, mm) } -func (m *MeterImpl) CollectAsync(labels []label.KeyValue, obs ...metric.Observation) { +func (m *MeterImpl) CollectAsync(labels []attribute.KeyValue, obs ...metric.Observation) { mm := make([]Measurement, len(obs)) for i := 0; i < len(obs); i++ { o := obs[i] @@ -178,7 +178,7 @@ func (m *MeterImpl) CollectAsync(labels []label.KeyValue, obs ...metric.Observat m.collect(context.Background(), labels, mm) } -func (m *MeterImpl) collect(ctx context.Context, labels []label.KeyValue, measurements []Measurement) { +func (m *MeterImpl) collect(ctx context.Context, labels []attribute.KeyValue, measurements []Measurement) { m.lock.Lock() defer m.lock.Unlock() @@ -199,13 +199,13 @@ type Measured struct { Name string InstrumentationName string InstrumentationVersion string - Labels map[label.Key]label.Value + Labels map[attribute.Key]attribute.Value Number number.Number } // LabelsToMap converts label set to keyValue map, to be easily used in tests -func LabelsToMap(kvs ...label.KeyValue) map[label.Key]label.Value { - m := map[label.Key]label.Value{} +func LabelsToMap(kvs ...attribute.KeyValue) map[attribute.Key]attribute.Value { + m := map[attribute.Key]attribute.Value{} for _, label := range kvs { m[label.Key] = label.Value } diff --git a/oteltest/span.go b/oteltest/span.go index 9504a5af471..2e109f2d88a 100644 --- a/oteltest/span.go +++ b/oteltest/span.go @@ -20,14 +20,14 @@ import ( "sync" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" ) const ( - errorTypeKey = label.Key("error.type") - errorMessageKey = label.Key("error.message") + errorTypeKey = attribute.Key("error.type") + errorMessageKey = attribute.Key("error.message") errorEventName = "error" ) @@ -45,7 +45,7 @@ type Span struct { endTime time.Time statusCode codes.Code statusMessage string - attributes map[label.Key]label.Value + attributes map[attribute.Key]attribute.Value events []Event links []trace.Link spanKind trace.SpanKind @@ -111,9 +111,9 @@ func (s *Span) AddEvent(name string, o ...trace.EventOption) { c := trace.NewEventConfig(o...) - var attributes map[label.Key]label.Value + var attributes map[attribute.Key]attribute.Value if l := len(c.Attributes); l > 0 { - attributes = make(map[label.Key]label.Value, l) + attributes = make(map[attribute.Key]attribute.Value, l) for _, attr := range c.Attributes { attributes[attr.Key] = attr.Value } @@ -162,7 +162,7 @@ func (s *Span) SetName(name string) { } // SetAttributes sets attrs as attributes of s. -func (s *Span) SetAttributes(attrs ...label.KeyValue) { +func (s *Span) SetAttributes(attrs ...attribute.KeyValue) { s.lock.Lock() defer s.lock.Unlock() @@ -187,11 +187,11 @@ func (s *Span) ParentSpanID() trace.SpanID { return s.parentSpanID } // Attributes returns the attributes set on s, 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 s. -func (s *Span) Attributes() map[label.Key]label.Value { +func (s *Span) Attributes() map[attribute.Key]attribute.Value { s.lock.RLock() defer s.lock.RUnlock() - attributes := make(map[label.Key]label.Value) + attributes := make(map[attribute.Key]attribute.Value) for k, v := range s.attributes { attributes[k] = v diff --git a/oteltest/span_test.go b/oteltest/span_test.go index 6aebee593fb..3f8304d065d 100644 --- a/oteltest/span_test.go +++ b/oteltest/span_test.go @@ -22,10 +22,10 @@ import ( "testing" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" ottest "go.opentelemetry.io/otel/internal/internaltest" "go.opentelemetry.io/otel/internal/matchers" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/trace" ) @@ -161,9 +161,9 @@ func TestSpan(t *testing.T) { expectedEvents := []oteltest.Event{{ Timestamp: testTime, Name: "error", - Attributes: map[label.Key]label.Value{ - label.Key("error.type"): label.StringValue(s.typ), - label.Key("error.message"): label.StringValue(s.msg), + Attributes: map[attribute.Key]attribute.Value{ + attribute.Key("error.type"): attribute.StringValue(s.typ), + attribute.Key("error.message"): attribute.StringValue(s.msg), }, }} e.Expect(subject.Events()).ToEqual(expectedEvents) @@ -191,9 +191,9 @@ func TestSpan(t *testing.T) { expectedEvents := []oteltest.Event{{ Timestamp: testTime, Name: "error", - Attributes: map[label.Key]label.Value{ - label.Key("error.type"): label.StringValue("go.opentelemetry.io/otel/internal/internaltest.TestError"), - label.Key("error.message"): label.StringValue(errMsg), + Attributes: map[attribute.Key]attribute.Value{ + attribute.Key("error.type"): attribute.StringValue("go.opentelemetry.io/otel/internal/internaltest.TestError"), + attribute.Key("error.message"): attribute.StringValue(errMsg), }, }} e.Expect(subject.Events()).ToEqual(expectedEvents) @@ -330,7 +330,7 @@ func TestSpan(t *testing.T) { subject, ok := span.(*oteltest.Span) e.Expect(ok).ToBeTrue() - e.Expect(subject.Attributes()).ToEqual(map[label.Key]label.Value{}) + e.Expect(subject.Attributes()).ToEqual(map[attribute.Key]attribute.Value{}) }) t.Run("returns the most recently set attributes", func(t *testing.T) { @@ -344,9 +344,9 @@ func TestSpan(t *testing.T) { subject, ok := span.(*oteltest.Span) e.Expect(ok).ToBeTrue() - attr1 := label.String("key1", "value1") - attr2 := label.String("key2", "value2") - attr3 := label.String("key3", "value3") + attr1 := attribute.String("key1", "value1") + attr2 := attribute.String("key2", "value2") + attr3 := attribute.String("key3", "value3") unexpectedAttr := attr2.Key.String("unexpected") subject.SetAttributes(attr1, unexpectedAttr, attr3) @@ -370,7 +370,7 @@ func TestSpan(t *testing.T) { subject, ok := span.(*oteltest.Span) e.Expect(ok).ToBeTrue() - expectedAttr := label.String("key", "value") + expectedAttr := attribute.String("key", "value") subject.SetAttributes(expectedAttr) subject.End() @@ -400,7 +400,7 @@ func TestSpan(t *testing.T) { go func() { defer wg.Done() - subject.SetAttributes(label.String("key", "value")) + subject.SetAttributes(attribute.String("key", "value")) }() go func() { @@ -458,9 +458,9 @@ func TestSpan(t *testing.T) { e.Expect(ok).ToBeTrue() event1Name := "event1" - event1Attributes := []label.KeyValue{ - label.String("event1Attr1", "foo"), - label.String("event1Attr2", "bar"), + event1Attributes := []attribute.KeyValue{ + attribute.String("event1Attr1", "foo"), + attribute.String("event1Attr2", "bar"), } event1Start := time.Now() @@ -469,8 +469,8 @@ func TestSpan(t *testing.T) { event2Timestamp := time.Now().AddDate(5, 0, 0) event2Name := "event1" - event2Attributes := []label.KeyValue{ - label.String("event2Attr", "abc"), + event2Attributes := []attribute.KeyValue{ + attribute.String("event2Attr", "abc"), } subject.AddEvent(event2Name, trace.WithTimestamp(event2Timestamp), trace.WithAttributes(event2Attributes...)) diff --git a/oteltest/tracer.go b/oteltest/tracer.go index cf0cc2a66af..555e71a8fe1 100644 --- a/oteltest/tracer.go +++ b/oteltest/tracer.go @@ -18,7 +18,7 @@ import ( "context" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -46,7 +46,7 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanOptio span := &Span{ tracer: t, startTime: startTime, - attributes: make(map[label.Key]label.Value), + attributes: make(map[attribute.Key]attribute.Value), links: []trace.Link{}, spanKind: c.SpanKind, } @@ -54,17 +54,17 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanOptio if c.NewRoot { span.spanContext = trace.SpanContext{} - iodKey := label.Key("ignored-on-demand") + iodKey := attribute.Key("ignored-on-demand") if lsc := trace.SpanContextFromContext(ctx); lsc.IsValid() { span.links = append(span.links, trace.Link{ SpanContext: lsc, - Attributes: []label.KeyValue{iodKey.String("current")}, + Attributes: []attribute.KeyValue{iodKey.String("current")}, }) } if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() { span.links = append(span.links, trace.Link{ SpanContext: rsc, - Attributes: []label.KeyValue{iodKey.String("remote")}, + Attributes: []attribute.KeyValue{iodKey.String("remote")}, }) } } else { diff --git a/oteltest/tracer_test.go b/oteltest/tracer_test.go index b4b9e776bc4..5cca521e9bc 100644 --- a/oteltest/tracer_test.go +++ b/oteltest/tracer_test.go @@ -22,8 +22,8 @@ import ( "testing" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/matchers" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/trace" ) @@ -67,8 +67,8 @@ func TestTracer(t *testing.T) { e := matchers.NewExpecter(t) - attr1 := label.String("a", "1") - attr2 := label.String("b", "2") + attr1 := attribute.String("a", "1") + attr2 := attribute.String("b", "2") subject := tp.Tracer(t.Name()) _, span := subject.Start(context.Background(), "test", trace.WithAttributes(attr1, attr2)) @@ -200,14 +200,14 @@ func TestTracer(t *testing.T) { expectedLinks := []trace.Link{ { SpanContext: parentSpanContext, - Attributes: []label.KeyValue{ - label.String("ignored-on-demand", "current"), + Attributes: []attribute.KeyValue{ + attribute.String("ignored-on-demand", "current"), }, }, { SpanContext: remoteParentSpanContext, - Attributes: []label.KeyValue{ - label.String("ignored-on-demand", "remote"), + Attributes: []attribute.KeyValue{ + attribute.String("ignored-on-demand", "remote"), }, }, } @@ -225,16 +225,16 @@ func TestTracer(t *testing.T) { _, span := subject.Start(context.Background(), "link1") link1 := trace.Link{ SpanContext: span.SpanContext(), - Attributes: []label.KeyValue{ - label.String("a", "1"), + Attributes: []attribute.KeyValue{ + attribute.String("a", "1"), }, } _, span = subject.Start(context.Background(), "link2") link2 := trace.Link{ SpanContext: span.SpanContext(), - Attributes: []label.KeyValue{ - label.String("b", "2"), + Attributes: []attribute.KeyValue{ + attribute.String("b", "2"), }, } diff --git a/propagation/baggage.go b/propagation/baggage.go index 2c416d7fbd7..bc76191892e 100644 --- a/propagation/baggage.go +++ b/propagation/baggage.go @@ -19,8 +19,8 @@ import ( "net/url" "strings" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/baggage" - "go.opentelemetry.io/otel/label" ) const baggageHeader = "baggage" @@ -38,7 +38,7 @@ func (b Baggage) Inject(ctx context.Context, carrier TextMapCarrier) { baggageMap := baggage.MapFromContext(ctx) firstIter := true var headerValueBuilder strings.Builder - baggageMap.Foreach(func(kv label.KeyValue) bool { + baggageMap.Foreach(func(kv attribute.KeyValue) bool { if !firstIter { headerValueBuilder.WriteRune(',') } @@ -62,7 +62,7 @@ func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context } baggageValues := strings.Split(bVal, ",") - keyValues := make([]label.KeyValue, 0, len(baggageValues)) + keyValues := make([]attribute.KeyValue, 0, len(baggageValues)) for _, baggageValue := range baggageValues { valueAndProps := strings.Split(baggageValue, ";") if len(valueAndProps) < 1 { @@ -92,7 +92,7 @@ func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context trimmedValueWithProps.WriteString(prop) } - keyValues = append(keyValues, label.String(trimmedName, trimmedValueWithProps.String())) + keyValues = append(keyValues, attribute.String(trimmedName, trimmedValueWithProps.String())) } if len(keyValues) > 0 { diff --git a/propagation/baggage_test.go b/propagation/baggage_test.go index 94685068112..f9749d620df 100644 --- a/propagation/baggage_test.go +++ b/propagation/baggage_test.go @@ -22,8 +22,8 @@ import ( "github.com/google/go-cmp/cmp" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/internal/baggage" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/propagation" ) @@ -32,54 +32,54 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) { tests := []struct { name string header string - wantKVs []label.KeyValue + wantKVs []attribute.KeyValue }{ { name: "valid w3cHeader", header: "key1=val1,key2=val2", - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), }, }, { name: "valid w3cHeader with spaces", header: "key1 = val1, key2 =val2 ", - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), }, }, { name: "valid w3cHeader with properties", header: "key1=val1,key2=val2;prop=1", - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2;prop=1"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2;prop=1"), }, }, { name: "valid header with url-escaped comma", header: "key1=val1,key2=val2%2Cval3", - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2,val3"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2,val3"), }, }, { name: "valid header with an invalid header", header: "key1=val1,key2=val2,a,val3", - wantKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), }, }, { name: "valid header with no value", header: "key1=,key2=val2", - wantKVs: []label.KeyValue{ - label.String("key1", ""), - label.String("key2", "val2"), + wantKVs: []attribute.KeyValue{ + attribute.String("key1", ""), + attribute.String("key2", "val2"), }, }, } @@ -101,9 +101,9 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) { ) } totalDiff := "" - wantBaggage.Foreach(func(keyValue label.KeyValue) bool { + wantBaggage.Foreach(func(keyValue attribute.KeyValue) bool { val, _ := gotBaggage.Value(keyValue.Key) - diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{})) + diff := cmp.Diff(keyValue, attribute.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(attribute.Value{})) if diff != "" { totalDiff += diff + "\n" } @@ -121,7 +121,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { tests := []struct { name string header string - hasKVs []label.KeyValue + hasKVs []attribute.KeyValue }{ { name: "no key values", @@ -130,17 +130,17 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { { name: "invalid header with existing context", header: "header2", - hasKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), + hasKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), }, }, { name: "empty header value", header: "", - hasKVs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), + hasKVs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), }, }, } @@ -162,9 +162,9 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { ) } totalDiff := "" - wantBaggage.Foreach(func(keyValue label.KeyValue) bool { + wantBaggage.Foreach(func(keyValue attribute.KeyValue) bool { val, _ := gotBaggage.Value(keyValue.Key) - diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{})) + diff := cmp.Diff(keyValue, attribute.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(attribute.Value{})) if diff != "" { totalDiff += diff + "\n" } @@ -178,33 +178,33 @@ func TestInjectBaggageToHTTPReq(t *testing.T) { propagator := propagation.Baggage{} tests := []struct { name string - kvs []label.KeyValue + kvs []attribute.KeyValue wantInHeader []string wantedLen int }{ { name: "two simple values", - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), }, wantInHeader: []string{"key1=val1", "key2=val2"}, }, { name: "two values with escaped chars", - kvs: []label.KeyValue{ - label.String("key1", "val1,val2"), - label.String("key2", "val3=4"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1,val2"), + attribute.String("key2", "val3=4"), }, wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"}, }, { name: "values of non-string types", - kvs: []label.KeyValue{ - label.Bool("key1", true), - label.Int("key2", 123), - label.Int64("key3", 123), - label.Float64("key4", 123.567), + kvs: []attribute.KeyValue{ + attribute.Bool("key1", true), + attribute.Int("key2", 123), + attribute.Int64("key3", 123), + attribute.Float64("key4", 123.567), }, wantInHeader: []string{ "key1=true", diff --git a/propagation/trace_context.go b/propagation/trace_context.go index fa18b8540a0..fc52975cfcb 100644 --- a/propagation/trace_context.go +++ b/propagation/trace_context.go @@ -21,7 +21,7 @@ import ( "regexp" "strings" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -151,14 +151,14 @@ func parseTraceState(in string) trace.TraceState { return trace.TraceState{} } - kvs := []label.KeyValue{} + kvs := []attribute.KeyValue{} for _, entry := range strings.Split(in, ",") { parts := strings.SplitN(entry, "=", 2) if len(parts) != 2 { // Parse failure, abort! return trace.TraceState{} } - kvs = append(kvs, label.String(parts[0], parts[1])) + kvs = append(kvs, attribute.String(parts[0], parts[1])) } // Ignoring error here as "failure to parse tracestate MUST NOT diff --git a/propagation/trace_context_test.go b/propagation/trace_context_test.go index 092bf3d2ba7..7601cf440fa 100644 --- a/propagation/trace_context_test.go +++ b/propagation/trace_context_test.go @@ -21,7 +21,7 @@ import ( "github.com/google/go-cmp/cmp" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" @@ -280,7 +280,7 @@ func TestTraceStatePropagation(t *testing.T) { prop := propagation.TraceContext{} stateHeader := "tracestate" parentHeader := "traceparent" - state, err := trace.TraceStateFromKeyValues(label.String("key1", "value1"), label.String("key2", "value2")) + state, err := trace.TraceStateFromKeyValues(attribute.String("key1", "value1"), attribute.String("key2", "value2")) if err != nil { t.Fatalf("Unable to construct expected TraceState: %s", err.Error()) } @@ -341,7 +341,7 @@ func TestTraceStatePropagation(t *testing.T) { if diff := cmp.Diff( trace.RemoteSpanContextFromContext(ctx), tt.wantSc, - cmp.AllowUnexported(label.Value{}), + cmp.AllowUnexported(attribute.Value{}), cmp.AllowUnexported(trace.TraceState{}), ); diff != "" { t.Errorf("Extracted tracestate: -got +want %s", diff) diff --git a/sdk/export/metric/metric.go b/sdk/export/metric/metric.go index 525fe8f3a63..55965a2392a 100644 --- a/sdk/export/metric/metric.go +++ b/sdk/export/metric/metric.go @@ -21,7 +21,7 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -267,7 +267,7 @@ type CheckpointSet interface { // steps. type Metadata struct { descriptor *metric.Descriptor - labels *label.Set + labels *attribute.Set resource *resource.Resource } @@ -295,7 +295,7 @@ func (m Metadata) Descriptor() *metric.Descriptor { // Labels describes the labels associated with the instrument and the // aggregated data. -func (m Metadata) Labels() *label.Set { +func (m Metadata) Labels() *attribute.Set { return m.labels } @@ -308,7 +308,7 @@ func (m Metadata) Resource() *resource.Resource { // Accumulations to send to Processors. The Descriptor, Labels, Resource, // and Aggregator represent aggregate metric events received over a single // collection period. -func NewAccumulation(descriptor *metric.Descriptor, labels *label.Set, resource *resource.Resource, aggregator Aggregator) Accumulation { +func NewAccumulation(descriptor *metric.Descriptor, labels *attribute.Set, resource *resource.Resource, aggregator Aggregator) Accumulation { return Accumulation{ Metadata: Metadata{ descriptor: descriptor, @@ -328,7 +328,7 @@ func (r Accumulation) Aggregator() Aggregator { // NewRecord allows Processor implementations to construct export // records. The Descriptor, Labels, and Aggregator represent // aggregate metric events received over a single collection period. -func NewRecord(descriptor *metric.Descriptor, labels *label.Set, resource *resource.Resource, aggregation aggregation.Aggregation, start, end time.Time) Record { +func NewRecord(descriptor *metric.Descriptor, labels *attribute.Set, resource *resource.Resource, aggregation aggregation.Aggregation, start, end time.Time) Record { return Record{ Metadata: Metadata{ descriptor: descriptor, diff --git a/sdk/export/metric/metric_test.go b/sdk/export/metric/metric_test.go index c8435b0f693..706e3b83a51 100644 --- a/sdk/export/metric/metric_test.go +++ b/sdk/export/metric/metric_test.go @@ -17,18 +17,18 @@ package metric import ( "testing" - "go.opentelemetry.io/otel/label" - "github.com/stretchr/testify/require" + + "go.opentelemetry.io/otel/attribute" ) -var testSlice = []label.KeyValue{ - label.String("bar", "baz"), - label.Int("foo", 42), +var testSlice = []attribute.KeyValue{ + attribute.String("bar", "baz"), + attribute.Int("foo", 42), } -func newIter(slice []label.KeyValue) label.Iterator { - labels := label.NewSet(slice...) +func newIter(slice []attribute.KeyValue) attribute.Iterator { + labels := attribute.NewSet(slice...) return labels.Iter() } @@ -37,17 +37,17 @@ func TestLabelIterator(t *testing.T) { require.Equal(t, 2, iter.Len()) require.True(t, iter.Next()) - require.Equal(t, label.String("bar", "baz"), iter.Label()) + require.Equal(t, attribute.String("bar", "baz"), iter.Label()) idx, kv := iter.IndexedLabel() require.Equal(t, 0, idx) - require.Equal(t, label.String("bar", "baz"), kv) + require.Equal(t, attribute.String("bar", "baz"), kv) require.Equal(t, 2, iter.Len()) require.True(t, iter.Next()) - require.Equal(t, label.Int("foo", 42), iter.Label()) + require.Equal(t, attribute.Int("foo", 42), iter.Label()) idx, kv = iter.IndexedLabel() require.Equal(t, 1, idx) - require.Equal(t, label.Int("foo", 42), kv) + require.Equal(t, attribute.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 9905300d893..7e8314e7a6c 100644 --- a/sdk/export/metric/metrictest/test.go +++ b/sdk/export/metric/metrictest/test.go @@ -21,7 +21,7 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -31,7 +31,7 @@ import ( type mapkey struct { desc *metric.Descriptor - distinct label.Distinct + distinct attribute.Distinct } // CheckpointSet is useful for testing Exporters. @@ -92,8 +92,8 @@ 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 ...label.KeyValue) (agg export.Aggregator, added bool) { - elabels := label.NewSet(labels...) +func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...attribute.KeyValue) (agg export.Aggregator, added bool) { + elabels := attribute.NewSet(labels...) key := mapkey{ desc: desc, diff --git a/sdk/export/trace/trace.go b/sdk/export/trace/trace.go index 2851a0e06cb..63073f23b75 100644 --- a/sdk/export/trace/trace.go +++ b/sdk/export/trace/trace.go @@ -18,8 +18,8 @@ import ( "context" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -62,7 +62,7 @@ type SpanSnapshot 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 []label.KeyValue + Attributes []attribute.KeyValue MessageEvents []trace.Event Links []trace.Link StatusCode codes.Code diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index ac861a90b4e..63c421f0106 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -20,7 +20,7 @@ import ( "math/rand" "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -59,8 +59,8 @@ func (f *benchFixture) meterMust() metric.MeterMust { return metric.Must(f.meter) } -func makeManyLabels(n int) [][]label.KeyValue { - r := make([][]label.KeyValue, n) +func makeManyLabels(n int) [][]attribute.KeyValue { + r := make([][]attribute.KeyValue, n) for i := 0; i < n; i++ { r[i] = makeLabels(1) @@ -69,9 +69,9 @@ func makeManyLabels(n int) [][]label.KeyValue { return r } -func makeLabels(n int) []label.KeyValue { +func makeLabels(n int) []attribute.KeyValue { used := map[string]bool{} - l := make([]label.KeyValue, n) + l := make([]attribute.KeyValue, n) for i := 0; i < n; i++ { var k string for { @@ -81,7 +81,7 @@ func makeLabels(n int) []label.KeyValue { break } } - l[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) + l[i] = attribute.String(k, fmt.Sprint("v", rand.Intn(1000000000))) } return l } @@ -120,7 +120,7 @@ func BenchmarkInt64CounterAddWithLabels_16(b *testing.B) { } // Note: performance does not depend on label set size for the -// benchmarks below--all are benchmarked for a single label. +// benchmarks below--all are benchmarked for a single attribute. func BenchmarkAcquireNewHandle(b *testing.B) { fix := newFixture(b) @@ -168,10 +168,10 @@ func BenchmarkAcquireReleaseExistingHandle(b *testing.B) { // Iterators -var benchmarkIteratorVar label.KeyValue +var benchmarkIteratorVar attribute.KeyValue func benchmarkIterator(b *testing.B, n int) { - labels := label.NewSet(makeLabels(n)...) + labels := attribute.NewSet(makeLabels(n)...) b.ResetTimer() for i := 0; i < b.N; i++ { iter := labels.Iter() @@ -217,7 +217,7 @@ func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) { sdk := global.Meter("test") global.SetMeterProvider(fix) - labs := []label.KeyValue{label.String("A", "B")} + labs := []attribute.KeyValue{attribute.String("A", "B")} cnt := Must(sdk).NewInt64Counter("int64.sum") b.ResetTimer() @@ -520,7 +520,7 @@ func BenchmarkRepeatedDirectCalls(b *testing.B) { fix := newFixture(b) c := fix.meterMust().NewInt64Counter("int64.sum") - k := label.String("bench", "true") + k := attribute.String("bench", "true") b.ResetTimer() diff --git a/sdk/metric/controller/basic/config_test.go b/sdk/metric/controller/basic/config_test.go index b9210d6c334..51a42494b5e 100644 --- a/sdk/metric/controller/basic/config_test.go +++ b/sdk/metric/controller/basic/config_test.go @@ -19,12 +19,12 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/resource" ) func TestWithResource(t *testing.T) { - r := resource.NewWithAttributes(label.String("A", "a")) + r := resource.NewWithAttributes(attribute.String("A", "a")) c := &Config{} WithResource(r).Apply(c) diff --git a/sdk/metric/controller/basic/controller_test.go b/sdk/metric/controller/basic/controller_test.go index 521d27b91fe..bc334fee6ea 100644 --- a/sdk/metric/controller/basic/controller_test.go +++ b/sdk/metric/controller/basic/controller_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -35,7 +35,7 @@ import ( ) func getMap(t *testing.T, cont *controller.Controller) map[string]float64 { - out := processortest.NewOutput(label.DefaultEncoder()) + out := processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, cont.ForEach( export.CumulativeExportKindSelector(), @@ -70,16 +70,16 @@ func TestControllerUsesResource(t *testing.T) { { name: "uses default if no resource option", options: nil, - wanted: resource.Default().Encoded(label.DefaultEncoder())}, + wanted: resource.Default().Encoded(attribute.DefaultEncoder())}, { name: "explicit resource", - options: []controller.Option{controller.WithResource(resource.NewWithAttributes(label.String("R", "S")))}, + options: []controller.Option{controller.WithResource(resource.NewWithAttributes(attribute.String("R", "S")))}, wanted: "R=S"}, { name: "last resource wins", options: []controller.Option{ controller.WithResource(resource.Default()), - controller.WithResource(resource.NewWithAttributes(label.String("R", "S"))), + controller.WithResource(resource.NewWithAttributes(attribute.String("R", "S"))), }, wanted: "R=S", }, @@ -128,7 +128,7 @@ func TestStartNoExporter(t *testing.T) { func(ctx context.Context, result metric.Int64ObserverResult) { calls++ checkTestContext(t, ctx) - result.Observe(calls, label.String("A", "B")) + result.Observe(calls, attribute.String("A", "B")) }, ) @@ -251,7 +251,7 @@ func newBlockingExporter() *blockingExporter { return &blockingExporter{ exporter: processortest.NewExporter( export.CumulativeExportKindSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ), } } @@ -332,7 +332,7 @@ func TestExportTimeout(t *testing.T) { func TestCollectAfterStopThenStartAgain(t *testing.T) { exp := processortest.NewExporter( export.CumulativeExportKindSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ) cont := controller.New( processor.New( diff --git a/sdk/metric/controller/basic/pull_test.go b/sdk/metric/controller/basic/pull_test.go index 30c5ecef63e..b77a4fd57b4 100644 --- a/sdk/metric/controller/basic/pull_test.go +++ b/sdk/metric/controller/basic/pull_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" @@ -47,20 +47,20 @@ func TestPullNoCollect(t *testing.T) { meter := puller.MeterProvider().Meter("nocache") counter := metric.Must(meter).NewInt64Counter("counter.sum") - counter.Add(ctx, 10, label.String("A", "B")) + counter.Add(ctx, 10, attribute.String("A", "B")) require.NoError(t, puller.Collect(ctx)) - records := processortest.NewOutput(label.DefaultEncoder()) + records := processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 10, }, records.Map()) - counter.Add(ctx, 10, label.String("A", "B")) + counter.Add(ctx, 10, attribute.String("A", "B")) require.NoError(t, puller.Collect(ctx)) - records = processortest.NewOutput(label.DefaultEncoder()) + records = processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord)) require.EqualValues(t, map[string]float64{ @@ -85,21 +85,21 @@ func TestPullWithCollect(t *testing.T) { meter := puller.MeterProvider().Meter("nocache") counter := metric.Must(meter).NewInt64Counter("counter.sum") - counter.Add(ctx, 10, label.String("A", "B")) + counter.Add(ctx, 10, attribute.String("A", "B")) require.NoError(t, puller.Collect(ctx)) - records := processortest.NewOutput(label.DefaultEncoder()) + records := processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 10, }, records.Map()) - counter.Add(ctx, 10, label.String("A", "B")) + counter.Add(ctx, 10, attribute.String("A", "B")) // Cached value! require.NoError(t, puller.Collect(ctx)) - records = processortest.NewOutput(label.DefaultEncoder()) + records = processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord)) require.EqualValues(t, map[string]float64{ @@ -111,7 +111,7 @@ func TestPullWithCollect(t *testing.T) { // Re-computed value! require.NoError(t, puller.Collect(ctx)) - records = processortest.NewOutput(label.DefaultEncoder()) + records = processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord)) require.EqualValues(t, map[string]float64{ diff --git a/sdk/metric/controller/basic/push_test.go b/sdk/metric/controller/basic/push_test.go index 4add5f3f523..d1bf3be8482 100644 --- a/sdk/metric/controller/basic/push_test.go +++ b/sdk/metric/controller/basic/push_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -37,7 +37,7 @@ import ( "go.opentelemetry.io/otel/sdk/resource" ) -var testResource = resource.NewWithAttributes(label.String("R", "V")) +var testResource = resource.NewWithAttributes(attribute.String("R", "V")) type handler struct { sync.Mutex @@ -68,7 +68,7 @@ func init() { func newExporter() *processortest.Exporter { return processortest.NewExporter( export.StatelessExportKindSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ) } @@ -76,7 +76,7 @@ func newCheckpointer() export.Checkpointer { return processortest.Checkpointer( processortest.NewProcessor( processortest.AggregatorSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ), ) } @@ -205,7 +205,7 @@ func TestPushExportError(t *testing.T) { require.NoError(t, p.Start(ctx)) runtime.Gosched() - counter1.Add(ctx, 3, label.String("X", "Y")) + counter1.Add(ctx, 3, attribute.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 c19e8ef4541..1b34e8bcdcf 100644 --- a/sdk/metric/correct_test.go +++ b/sdk/metric/correct_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -35,7 +35,7 @@ import ( ) var Must = metric.Must -var testResource = resource.NewWithAttributes(label.String("R", "V")) +var testResource = resource.NewWithAttributes(attribute.String("R", "V")) type handler struct { sync.Mutex @@ -209,19 +209,19 @@ func TestSDKLabelsDeduplication(t *testing.T) { keySets = 2 repeats = 3 ) - var keysA []label.Key - var keysB []label.Key + var keysA []attribute.Key + var keysB []attribute.Key for i := 0; i < maxKeys; i++ { - keysA = append(keysA, label.Key(fmt.Sprintf("A%03d", i))) - keysB = append(keysB, label.Key(fmt.Sprintf("B%03d", i))) + keysA = append(keysA, attribute.Key(fmt.Sprintf("A%03d", i))) + keysB = append(keysB, attribute.Key(fmt.Sprintf("B%03d", i))) } - var allExpect [][]label.KeyValue + var allExpect [][]attribute.KeyValue for numKeys := 0; numKeys < maxKeys; numKeys++ { - var kvsA []label.KeyValue - var kvsB []label.KeyValue + var kvsA []attribute.KeyValue + var kvsB []attribute.KeyValue for r := 0; r < repeats; r++ { for i := 0; i < numKeys; i++ { kvsA = append(kvsA, keysA[i].Int(r)) @@ -229,8 +229,8 @@ func TestSDKLabelsDeduplication(t *testing.T) { } } - var expectA []label.KeyValue - var expectB []label.KeyValue + var expectA []attribute.KeyValue + var expectB []attribute.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 +251,7 @@ func TestSDKLabelsDeduplication(t *testing.T) { sdk.Collect(ctx) - var actual [][]label.KeyValue + var actual [][]attribute.KeyValue for _, rec := range processor.accumulations { sum, _ := rec.Aggregator().(aggregation.Sum).Sum() require.Equal(t, sum, number.NewInt64Number(2)) @@ -263,32 +263,32 @@ func TestSDKLabelsDeduplication(t *testing.T) { require.ElementsMatch(t, allExpect, actual) } -func newSetIter(kvs ...label.KeyValue) label.Iterator { - labels := label.NewSet(kvs...) +func newSetIter(kvs ...attribute.KeyValue) attribute.Iterator { + labels := attribute.NewSet(kvs...) return labels.Iter() } func TestDefaultLabelEncoder(t *testing.T) { - encoder := label.DefaultEncoder() + encoder := attribute.DefaultEncoder() - encoded := encoder.Encode(newSetIter(label.String("A", "B"), label.String("C", "D"))) + encoded := encoder.Encode(newSetIter(attribute.String("A", "B"), attribute.String("C", "D"))) require.Equal(t, `A=B,C=D`, encoded) - encoded = encoder.Encode(newSetIter(label.String("A", "B,c=d"), label.String(`C\`, "D"))) + encoded = encoder.Encode(newSetIter(attribute.String("A", "B,c=d"), attribute.String(`C\`, "D"))) require.Equal(t, `A=B\,c\=d,C\\=D`, encoded) - encoded = encoder.Encode(newSetIter(label.String(`\`, `=`), label.String(`,`, `\`))) + encoded = encoder.Encode(newSetIter(attribute.String(`\`, `=`), attribute.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( - label.Int("I", 1), - label.Int64("I64", 1), - label.Float64("F64", 1), - label.Float64("F64", 1), - label.String("S", "1"), - label.Bool("B", true), + attribute.Int("I", 1), + attribute.Int64("I64", 1), + attribute.Float64("F64", 1), + attribute.Float64("F64", 1), + attribute.String("S", "1"), + attribute.Bool("B", true), )) require.Equal(t, "B=true,F64=1,I=1,I64=1,S=1", encoded) } @@ -299,42 +299,42 @@ func TestObserverCollection(t *testing.T) { mult := 1 _ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(float64(mult), label.String("A", "B")) + result.Observe(float64(mult), attribute.String("A", "B")) // last value wins - result.Observe(float64(-mult), label.String("A", "B")) - result.Observe(float64(-mult), label.String("C", "D")) + result.Observe(float64(-mult), attribute.String("A", "B")) + result.Observe(float64(-mult), attribute.String("C", "D")) }) _ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(int64(-mult), label.String("A", "B")) + result.Observe(int64(-mult), attribute.String("A", "B")) result.Observe(int64(mult)) // last value wins - result.Observe(int64(mult), label.String("A", "B")) + result.Observe(int64(mult), attribute.String("A", "B")) result.Observe(int64(mult)) }) _ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(float64(mult), label.String("A", "B")) - result.Observe(float64(2*mult), label.String("A", "B")) - result.Observe(float64(mult), label.String("C", "D")) + result.Observe(float64(mult), attribute.String("A", "B")) + result.Observe(float64(2*mult), attribute.String("A", "B")) + result.Observe(float64(mult), attribute.String("C", "D")) }) _ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(int64(2*mult), label.String("A", "B")) + result.Observe(int64(2*mult), attribute.String("A", "B")) result.Observe(int64(mult)) // last value wins - result.Observe(int64(mult), label.String("A", "B")) + result.Observe(int64(mult), attribute.String("A", "B")) result.Observe(int64(mult)) }) _ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { - result.Observe(float64(mult), label.String("A", "B")) - result.Observe(float64(-2*mult), label.String("A", "B")) - result.Observe(float64(mult), label.String("C", "D")) + result.Observe(float64(mult), attribute.String("A", "B")) + result.Observe(float64(-2*mult), attribute.String("A", "B")) + result.Observe(float64(mult), attribute.String("C", "D")) }) _ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(int64(2*mult), label.String("A", "B")) + result.Observe(int64(2*mult), attribute.String("A", "B")) result.Observe(int64(mult)) // last value wins - result.Observe(int64(mult), label.String("A", "B")) + result.Observe(int64(mult), attribute.String("A", "B")) result.Observe(int64(-mult)) }) @@ -347,7 +347,7 @@ func TestObserverCollection(t *testing.T) { collected := sdk.Collect(ctx) require.Equal(t, collected, len(processor.accumulations)) - out := processortest.NewOutput(label.DefaultEncoder()) + out := processortest.NewOutput(attribute.DefaultEncoder()) for _, rec := range processor.accumulations { require.NoError(t, out.AddAccumulation(rec)) } @@ -377,13 +377,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, label.String("A", "B")) + result.Observe(-2, attribute.String("A", "B")) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) - result.Observe(-1, label.String("C", "D")) + result.Observe(-1, attribute.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, label.String("A", "B")) + result.Observe(-1, attribute.String("A", "B")) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) result.Observe(-1) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) @@ -412,8 +412,8 @@ func TestObserverBatch(t *testing.T) { var batch = Must(meter).NewBatchObserver( func(_ context.Context, result metric.BatchObserverResult) { result.Observe( - []label.KeyValue{ - label.String("A", "B"), + []attribute.KeyValue{ + attribute.String("A", "B"), }, floatValueObs.Observation(1), floatValueObs.Observation(-1), @@ -425,8 +425,8 @@ func TestObserverBatch(t *testing.T) { intUpDownSumObs.Observation(-100), ) result.Observe( - []label.KeyValue{ - label.String("C", "D"), + []attribute.KeyValue{ + attribute.String("C", "D"), }, floatValueObs.Observation(-1), floatSumObs.Observation(-1), @@ -452,7 +452,7 @@ func TestObserverBatch(t *testing.T) { require.Equal(t, collected, len(processor.accumulations)) - out := processortest.NewOutput(label.DefaultEncoder()) + out := processortest.NewOutput(attribute.DefaultEncoder()) for _, rec := range processor.accumulations { require.NoError(t, out.AddAccumulation(rec)) } @@ -485,9 +485,9 @@ func TestRecordBatch(t *testing.T) { sdk.RecordBatch( ctx, - []label.KeyValue{ - label.String("A", "B"), - label.String("C", "D"), + []attribute.KeyValue{ + attribute.String("A", "B"), + attribute.String("C", "D"), }, counter1.Measurement(1), counter2.Measurement(2), @@ -497,7 +497,7 @@ func TestRecordBatch(t *testing.T) { sdk.Collect(ctx) - out := processortest.NewOutput(label.DefaultEncoder()) + out := processortest.NewOutput(attribute.DefaultEncoder()) for _, rec := range processor.accumulations { require.NoError(t, out.AddAccumulation(rec)) } @@ -517,8 +517,8 @@ func TestRecordPersistence(t *testing.T) { meter, sdk, processor := newSDK(t) c := Must(meter).NewFloat64Counter("name.sum") - b := c.Bind(label.String("bound", "true")) - uk := label.String("bound", "false") + b := c.Bind(attribute.String("bound", "true")) + uk := attribute.String("bound", "false") for i := 0; i < 100; i++ { c.Add(ctx, 1, uk) @@ -579,7 +579,7 @@ func TestSyncInAsync(t *testing.T) { sdk.Collect(ctx) - out := processortest.NewOutput(label.DefaultEncoder()) + out := processortest.NewOutput(attribute.DefaultEncoder()) for _, rec := range processor.accumulations { require.NoError(t, out.AddAccumulation(rec)) } diff --git a/sdk/metric/processor/basic/basic.go b/sdk/metric/processor/basic/basic.go index 2e2a7c5df41..39d1972dc9b 100644 --- a/sdk/metric/processor/basic/basic.go +++ b/sdk/metric/processor/basic/basic.go @@ -20,7 +20,7 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -48,13 +48,13 @@ type ( // instead of the descriptor pointer. See // https://github.com/open-telemetry/opentelemetry-go/issues/862. descriptor *metric.Descriptor - distinct label.Distinct - resource label.Distinct + distinct attribute.Distinct + resource attribute.Distinct } stateValue struct { // labels corresponds to the stateKey.distinct field. - labels *label.Set + labels *attribute.Set // resource corresponds to the stateKey.resource field. resource *resource.Resource diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index 11b59717ea5..0362975e041 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -103,8 +103,8 @@ func asNumber(nkind number.Kind, value int64) number.Number { return number.NewFloat64Number(float64(value)) } -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...) +func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...attribute.KeyValue) export.Accumulation { + ls := attribute.NewSet(labs...) var agg export.Aggregator selector.AggregatorFor(desc, &agg) require.NoError(t, agg.Update(context.Background(), asNumber(desc.NumberKind(), value), desc)) @@ -122,10 +122,10 @@ func testProcessor( // Note: this selector uses the instrument name to dictate // aggregation kind. selector := processorTest.AggregatorSelector() - res := resource.NewWithAttributes(label.String("R", "V")) + res := resource.NewWithAttributes(attribute.String("R", "V")) - labs1 := []label.KeyValue{label.String("L1", "V")} - labs2 := []label.KeyValue{label.String("L2", "V")} + labs1 := []attribute.KeyValue{attribute.String("L1", "V")} + labs2 := []attribute.KeyValue{attribute.String("L2", "V")} testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) { processor := basic.New(selector, export.ConstantExportKindSelector(ekind), basic.WithMemory(hasMemory)) @@ -183,7 +183,7 @@ func testProcessor( } // Test the final checkpoint state. - records1 := processorTest.NewOutput(label.DefaultEncoder()) + records1 := processorTest.NewOutput(attribute.DefaultEncoder()) err = checkpointSet.ForEach(export.ConstantExportKindSelector(ekind), records1.AddRecord) // Test for an allowed error: @@ -297,7 +297,7 @@ func TestBasicInconsistent(t *testing.T) { b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) - accum := export.NewAccumulation(&desc, label.EmptySet(), resource.Empty(), metrictest.NoopAggregator{}) + accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), metrictest.NoopAggregator{}) require.Equal(t, basic.ErrInconsistentState, b.Process(accum)) // Test invalid kind: @@ -320,7 +320,7 @@ func TestBasicTimestamps(t *testing.T) { afterNew := time.Now() desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) - accum := export.NewAccumulation(&desc, label.EmptySet(), resource.Empty(), metrictest.NoopAggregator{}) + accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), metrictest.NoopAggregator{}) b.StartCollection() _ = b.Process(accum) @@ -362,7 +362,7 @@ func TestBasicTimestamps(t *testing.T) { } func TestStatefulNoMemoryCumulative(t *testing.T) { - res := resource.NewWithAttributes(label.String("R", "V")) + res := resource.NewWithAttributes(attribute.String("R", "V")) ekindSel := export.CumulativeExportKindSelector() desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, number.Int64Kind) @@ -377,17 +377,17 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { require.NoError(t, processor.FinishCollection()) // Verify zero elements - records := processorTest.NewOutput(label.DefaultEncoder()) + records := processorTest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.EqualValues(t, map[string]float64{}, records.Map()) // Add 10 processor.StartCollection() - _ = processor.Process(updateFor(t, &desc, selector, res, 10, label.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, 10, attribute.String("A", "B"))) require.NoError(t, processor.FinishCollection()) // Verify one element - records = processorTest.NewOutput(label.DefaultEncoder()) + records = processorTest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.EqualValues(t, map[string]float64{ "inst.sum/A=B/R=V": float64(i * 10), @@ -396,7 +396,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { } func TestStatefulNoMemoryDelta(t *testing.T) { - res := resource.NewWithAttributes(label.String("R", "V")) + res := resource.NewWithAttributes(attribute.String("R", "V")) ekindSel := export.DeltaExportKindSelector() desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, number.Int64Kind) @@ -411,17 +411,17 @@ func TestStatefulNoMemoryDelta(t *testing.T) { require.NoError(t, processor.FinishCollection()) // Verify zero elements - records := processorTest.NewOutput(label.DefaultEncoder()) + records := processorTest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.EqualValues(t, map[string]float64{}, records.Map()) // Add 10 processor.StartCollection() - _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), attribute.String("A", "B"))) require.NoError(t, processor.FinishCollection()) // Verify one element - records = processorTest.NewOutput(label.DefaultEncoder()) + records = processorTest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.EqualValues(t, map[string]float64{ "inst.sum/A=B/R=V": 10, @@ -435,7 +435,7 @@ func TestMultiObserverSum(t *testing.T) { export.DeltaExportKindSelector(), } { - res := resource.NewWithAttributes(label.String("R", "V")) + res := resource.NewWithAttributes(attribute.String("R", "V")) desc := metric.NewDescriptor("observe.sum", metric.SumObserverInstrumentKind, number.Int64Kind) selector := processorTest.AggregatorSelector() @@ -445,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), 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"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), attribute.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), attribute.String("A", "B"))) + _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), attribute.String("A", "B"))) require.NoError(t, processor.FinishCollection()) // Multiplier is 1 for deltas, otherwise i. @@ -457,7 +457,7 @@ func TestMultiObserverSum(t *testing.T) { } // Verify one element - records := processorTest.NewOutput(label.DefaultEncoder()) + records := processorTest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.EqualValues(t, map[string]float64{ "observe.sum/A=B/R=V": float64(3 * 10 * multiplier), @@ -494,7 +494,7 @@ func TestSumObserverEndToEnd(t *testing.T) { accum.Collect(ctx) require.NoError(t, proc.FinishCollection()) - exporter := processortest.NewExporter(eselector, label.DefaultEncoder()) + exporter := processortest.NewExporter(eselector, attribute.DefaultEncoder()) require.NoError(t, exporter.Export(ctx, data)) require.EqualValues(t, map[string]float64{ diff --git a/sdk/metric/processor/processortest/test.go b/sdk/metric/processor/processortest/test.go index 9b767291b58..933639f38c0 100644 --- a/sdk/metric/processor/processortest/test.go +++ b/sdk/metric/processor/processortest/test.go @@ -21,7 +21,7 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -40,14 +40,14 @@ type ( // attributes. mapKey struct { desc *metric.Descriptor - labels label.Distinct - resource label.Distinct + labels attribute.Distinct + resource attribute.Distinct } // mapValue is value stored in a processor used to produce a // CheckpointSet. mapValue struct { - labels *label.Set + labels *attribute.Set resource *resource.Resource aggregator export.Aggregator } @@ -55,7 +55,7 @@ type ( // Output implements export.CheckpointSet. Output struct { m map[mapKey]mapValue - labelEncoder label.Encoder + labelEncoder attribute.Encoder sync.RWMutex } @@ -101,7 +101,7 @@ type ( // // Where in the example A=1,B=2 is the encoded labels and R=V is the // encoded resource value. -func NewProcessor(selector export.AggregatorSelector, encoder label.Encoder) *Processor { +func NewProcessor(selector export.AggregatorSelector, encoder attribute.Encoder) *Processor { return &Processor{ AggregatorSelector: selector, output: NewOutput(encoder), @@ -202,7 +202,7 @@ func (testAggregatorSelector) AggregatorFor(desc *metric.Descriptor, aggPtrs ... // (from an Accumulator) or an expected set of Records (from a // Processor). If testing with an Accumulator, it may be simpler to // use the test Processor in this package. -func NewOutput(labelEncoder label.Encoder) *Output { +func NewOutput(labelEncoder attribute.Encoder) *Output { return &Output{ m: make(map[mapKey]mapValue), labelEncoder: labelEncoder, @@ -318,7 +318,7 @@ func (o *Output) AddAccumulation(acc export.Accumulation) error { // // Where in the example A=1,B=2 is the encoded labels and R=V is the // encoded resource value. -func NewExporter(selector export.ExportKindSelector, encoder label.Encoder) *Exporter { +func NewExporter(selector export.ExportKindSelector, encoder attribute.Encoder) *Exporter { return &Exporter{ ExportKindSelector: selector, output: NewOutput(encoder), diff --git a/sdk/metric/processor/processortest/test_test.go b/sdk/metric/processor/processortest/test_test.go index c4541d2656a..771a3c65d8e 100644 --- a/sdk/metric/processor/processortest/test_test.go +++ b/sdk/metric/processor/processortest/test_test.go @@ -20,7 +20,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" metricsdk "go.opentelemetry.io/otel/sdk/metric" @@ -32,7 +32,7 @@ func generateTestData(proc export.Processor) { ctx := context.Background() accum := metricsdk.NewAccumulator( proc, - resource.NewWithAttributes(label.String("R", "V")), + resource.NewWithAttributes(attribute.String("R", "V")), ) meter := metric.WrapMeterImpl(accum, "testing") @@ -40,13 +40,13 @@ func generateTestData(proc export.Processor) { _ = metric.Must(meter).NewInt64SumObserver("observer.sum", func(_ context.Context, result metric.Int64ObserverResult) { - result.Observe(10, label.String("K1", "V1")) - result.Observe(11, label.String("K1", "V2")) + result.Observe(10, attribute.String("K1", "V1")) + result.Observe(11, attribute.String("K1", "V2")) }, ) - counter.Add(ctx, 100, label.String("K1", "V1")) - counter.Add(ctx, 101, label.String("K1", "V2")) + counter.Add(ctx, 100, attribute.String("K1", "V1")) + counter.Add(ctx, 101, attribute.String("K1", "V2")) accum.Collect(ctx) } @@ -56,7 +56,7 @@ func TestProcessorTesting(t *testing.T) { // generate Accumulations. testProc := processorTest.NewProcessor( processorTest.AggregatorSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ) checkpointer := processorTest.Checkpointer(testProc) @@ -75,7 +75,7 @@ func TestProcessorTesting(t *testing.T) { // Export the data and validate it again. exporter := processorTest.NewExporter( export.StatelessExportKindSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ) err := exporter.Export(context.Background(), checkpointer.CheckpointSet()) diff --git a/sdk/metric/processor/reducer/doc.go b/sdk/metric/processor/reducer/doc.go index d8028f97d07..18b00b8197f 100644 --- a/sdk/metric/processor/reducer/doc.go +++ b/sdk/metric/processor/reducer/doc.go @@ -20,7 +20,7 @@ may be introduced in subsequent minor version releases as we work to track the evolving OpenTelemetry specification and user feedback. The metrics Processor component this package implements applies a -`label.Filter` to each processed `export.Accumulation` to remove labels before +`attribute.Filter` to each processed `export.Accumulation` to remove labels before passing the result to another Processor. This Processor can be used to reduce inherent dimensionality in the data, as a way to control the cost of collecting high cardinality metric data. @@ -33,7 +33,7 @@ type someFilter struct{ // ... } -func (someFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter { +func (someFilter) LabelFilterFor(_ *metric.Descriptor) attribute.Filter { return func(label kv.KeyValue) bool { // return true to keep this label, false to drop this label // ... diff --git a/sdk/metric/processor/reducer/reducer.go b/sdk/metric/processor/reducer/reducer.go index 91c4dae2d52..9a994706783 100644 --- a/sdk/metric/processor/reducer/reducer.go +++ b/sdk/metric/processor/reducer/reducer.go @@ -15,7 +15,7 @@ package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer" import ( - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" ) @@ -31,7 +31,7 @@ type ( // LabelFilterSelector is the interface used to configure a // specific Filter to an instrument. LabelFilterSelector interface { - LabelFilterFor(descriptor *metric.Descriptor) label.Filter + LabelFilterFor(descriptor *metric.Descriptor) attribute.Filter } ) diff --git a/sdk/metric/processor/reducer/reducer_test.go b/sdk/metric/processor/reducer/reducer_test.go index 138f3825dde..d43fa630395 100644 --- a/sdk/metric/processor/reducer/reducer_test.go +++ b/sdk/metric/processor/reducer/reducer_test.go @@ -20,7 +20,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" export "go.opentelemetry.io/otel/sdk/export/metric" metricsdk "go.opentelemetry.io/otel/sdk/metric" @@ -31,22 +31,22 @@ import ( ) var ( - kvs1 = []label.KeyValue{ - label.Int("A", 1), - label.Int("B", 2), - label.Int("C", 3), + kvs1 = []attribute.KeyValue{ + attribute.Int("A", 1), + attribute.Int("B", 2), + attribute.Int("C", 3), } - kvs2 = []label.KeyValue{ - label.Int("A", 1), - label.Int("B", 0), - label.Int("C", 3), + kvs2 = []attribute.KeyValue{ + attribute.Int("A", 1), + attribute.Int("B", 0), + attribute.Int("C", 3), } ) type testFilter struct{} -func (testFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter { - return func(label label.KeyValue) bool { +func (testFilter) LabelFilterFor(_ *metric.Descriptor) attribute.Filter { + return func(label attribute.KeyValue) bool { return label.Key == "A" || label.Key == "C" } } @@ -71,11 +71,11 @@ func generateData(impl metric.MeterImpl) { func TestFilterProcessor(t *testing.T) { testProc := processorTest.NewProcessor( processorTest.AggregatorSelector(), - label.DefaultEncoder(), + attribute.DefaultEncoder(), ) accum := metricsdk.NewAccumulator( reducer.New(testFilter{}, processorTest.Checkpointer(testProc)), - resource.NewWithAttributes(label.String("R", "V")), + resource.NewWithAttributes(attribute.String("R", "V")), ) generateData(accum) @@ -92,9 +92,9 @@ func TestFilterBasicProcessor(t *testing.T) { basicProc := basic.New(processorTest.AggregatorSelector(), export.CumulativeExportKindSelector()) accum := metricsdk.NewAccumulator( reducer.New(testFilter{}, basicProc), - resource.NewWithAttributes(label.String("R", "V")), + resource.NewWithAttributes(attribute.String("R", "V")), ) - exporter := processorTest.NewExporter(basicProc, label.DefaultEncoder()) + exporter := processorTest.NewExporter(basicProc, attribute.DefaultEncoder()) generateData(accum) diff --git a/sdk/metric/sdk.go b/sdk/metric/sdk.go index 14b381c3384..56218a78a56 100644 --- a/sdk/metric/sdk.go +++ b/sdk/metric/sdk.go @@ -22,8 +22,8 @@ import ( "sync/atomic" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" internal "go.opentelemetry.io/otel/internal/metric" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -63,7 +63,7 @@ type ( // asyncSortSlice has a single purpose - as a temporary // place for sorting during labels creation to avoid // allocation. It is cleared after use. - asyncSortSlice label.Sortable + asyncSortSlice attribute.Sortable // resource is applied to all records in this Accumulator. resource *resource.Resource @@ -77,7 +77,7 @@ type ( // its InstrumentID and the encoded form of its labels. mapkey struct { descriptor *metric.Descriptor - ordered label.Distinct + ordered attribute.Distinct } // record maintains the state of one metric instrument. Due @@ -99,18 +99,18 @@ type ( // storage is the stored label set for this record, // except in cases where a label set is shared due to // batch recording. - storage label.Set + storage attribute.Set // labels is the processed label set for this record. // this may refer to the `storage` field in another // record if this label set is shared resulting from // `RecordBatch`. - labels *label.Set + labels *attribute.Set // sortSlice has a single purpose - as a temporary // place for sorting during labels creation to avoid // allocation. - sortSlice label.Sortable + sortSlice attribute.Sortable // inst is a pointer to the corresponding instrument. inst *syncInstrument @@ -131,12 +131,12 @@ type ( instrument // recorders maps ordered labels to the pair of // labelset and recorder - recorders map[label.Distinct]*labeledRecorder + recorders map[attribute.Distinct]*labeledRecorder } labeledRecorder struct { observedEpoch int64 - labels *label.Set + labels *attribute.Set observed export.Aggregator } ) @@ -162,7 +162,7 @@ func (s *syncInstrument) Implementation() interface{} { return s } -func (a *asyncInstrument) observe(num number.Number, labels *label.Set) { +func (a *asyncInstrument) observe(num number.Number, labels *attribute.Set) { if err := aggregator.RangeTest(num, &a.descriptor); err != nil { otel.Handle(err) return @@ -179,7 +179,7 @@ func (a *asyncInstrument) observe(num number.Number, labels *label.Set) { } } -func (a *asyncInstrument) getRecorder(labels *label.Set) export.Aggregator { +func (a *asyncInstrument) getRecorder(labels *attribute.Set) export.Aggregator { lrec, ok := a.recorders[labels.Equivalent()] if ok { // Note: SynchronizedMove(nil) can't return an error @@ -191,7 +191,7 @@ func (a *asyncInstrument) getRecorder(labels *label.Set) export.Aggregator { var rec export.Aggregator a.meter.processor.AggregatorFor(&a.descriptor, &rec) if a.recorders == nil { - a.recorders = make(map[label.Distinct]*labeledRecorder) + a.recorders = make(map[attribute.Distinct]*labeledRecorder) } // This may store nil recorder in the map, thus disabling the // asyncInstrument for the labelset for good. This is intentional, @@ -209,16 +209,16 @@ 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 []label.KeyValue, labelPtr *label.Set) *record { +func (s *syncInstrument) acquireHandle(kvs []attribute.KeyValue, labelPtr *attribute.Set) *record { var rec *record - var equiv label.Distinct + var equiv attribute.Distinct if labelPtr == nil { // This memory allocation may not be used, but it's // needed for the `sortSlice` field, to avoid an // allocation while sorting. rec = &record{} - rec.storage = label.NewSetWithSortable(kvs, &rec.sortSlice) + rec.storage = attribute.NewSetWithSortable(kvs, &rec.sortSlice) rec.labels = &rec.storage equiv = rec.storage.Equivalent() } else { @@ -282,11 +282,11 @@ func (s *syncInstrument) acquireHandle(kvs []label.KeyValue, labelPtr *label.Set } } -func (s *syncInstrument) Bind(kvs []label.KeyValue) metric.BoundSyncImpl { +func (s *syncInstrument) Bind(kvs []attribute.KeyValue) metric.BoundSyncImpl { return s.acquireHandle(kvs, nil) } -func (s *syncInstrument) RecordOne(ctx context.Context, num number.Number, kvs []label.KeyValue) { +func (s *syncInstrument) RecordOne(ctx context.Context, num number.Number, kvs []attribute.KeyValue) { h := s.acquireHandle(kvs, nil) defer h.Unbind() h.RecordOne(ctx, num) @@ -396,8 +396,8 @@ func (m *Accumulator) collectSyncInstruments() int { } // CollectAsync implements internal.AsyncCollector. -func (m *Accumulator) CollectAsync(kv []label.KeyValue, obs ...metric.Observation) { - labels := label.NewSetWithSortable(kv, &m.asyncSortSlice) +func (m *Accumulator) CollectAsync(kv []attribute.KeyValue, obs ...metric.Observation) { + labels := attribute.NewSetWithSortable(kv, &m.asyncSortSlice) for _, ob := range obs { if a := m.fromAsync(ob.AsyncImpl()); a != nil { @@ -472,12 +472,12 @@ func (m *Accumulator) checkpointAsync(a *asyncInstrument) int { } // RecordBatch enters a batch of metric events. -func (m *Accumulator) RecordBatch(ctx context.Context, kvs []label.KeyValue, measurements ...metric.Measurement) { +func (m *Accumulator) RecordBatch(ctx context.Context, kvs []attribute.KeyValue, measurements ...metric.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 // ordered labels. - var labelsPtr *label.Set + var labelsPtr *attribute.Set for i, meas := range measurements { s := m.fromSync(meas.SyncImpl()) if s == nil { diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index 4878435bde3..27ad978b620 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -31,7 +31,7 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -75,7 +75,7 @@ type ( testImpl struct { newInstrument func(meter metric.Meter, name string) SyncImpler getUpdateValue func() number.Number - operate func(interface{}, context.Context, number.Number, []label.KeyValue) + operate func(interface{}, context.Context, number.Number, []attribute.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 []label.KeyValue) string { +func canonicalizeLabels(ls []attribute.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() []label.KeyValue { +func (f *testFixture) someLabels() []attribute.KeyValue { n := 1 + rand.Intn(3) - l := make([]label.KeyValue, n) + l := make([]attribute.KeyValue, n) for { oused := map[string]bool{} @@ -143,7 +143,7 @@ func (f *testFixture) someLabels() []label.KeyValue { break } } - l[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) + l[i] = attribute.String(k, fmt.Sprint("v", rand.Intn(1000000000))) } lc := canonicalizeLabels(l) f.lock.Lock() @@ -351,7 +351,7 @@ func intCounterTestImpl() testImpl { } } }, - operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value number.Number, labels []attribute.KeyValue) { counter := inst.(metric.Int64Counter) counter.Add(ctx, value.AsInt64(), labels...) }, @@ -389,7 +389,7 @@ func floatCounterTestImpl() testImpl { } } }, - operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value number.Number, labels []attribute.KeyValue) { counter := inst.(metric.Float64Counter) counter.Add(ctx, value.AsFloat64(), labels...) }, @@ -425,7 +425,7 @@ func intLastValueTestImpl() testImpl { r1 := rand.Int63() return number.NewInt64Number(rand.Int63() - r1) }, - operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value number.Number, labels []attribute.KeyValue) { valuerecorder := inst.(metric.Int64ValueRecorder) valuerecorder.Record(ctx, value.AsInt64(), labels...) }, @@ -466,7 +466,7 @@ func floatLastValueTestImpl() testImpl { getUpdateValue: func() number.Number { return number.NewFloat64Number((-0.5 + rand.Float64()) * 100000) }, - operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) { + operate: func(inst interface{}, ctx context.Context, value number.Number, labels []attribute.KeyValue) { valuerecorder := inst.(metric.Float64ValueRecorder) valuerecorder.Record(ctx, value.AsFloat64(), labels...) }, diff --git a/sdk/resource/benchmark_test.go b/sdk/resource/benchmark_test.go index ddb64bbe731..e4e762fbe2c 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/label" + "go.opentelemetry.io/otel/attribute" "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([]label.KeyValue, n) - l2 := make([]label.KeyValue, n) + l1 := make([]attribute.KeyValue, n) + l2 := make([]attribute.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] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) + l1[i] = attribute.String(k, fmt.Sprint("v", rand.Intn(1000000000))) if rand.Float64() < conflict { l2[i] = l1[i] } else { - l2[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000))) + l2[i] = attribute.String(k, fmt.Sprint("v", rand.Intn(1000000000))) } } diff --git a/sdk/resource/builtin.go b/sdk/resource/builtin.go index f96148ed134..4bf09e19647 100644 --- a/sdk/resource/builtin.go +++ b/sdk/resource/builtin.go @@ -21,7 +21,7 @@ import ( "path/filepath" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/semconv" ) @@ -41,7 +41,7 @@ type ( Host struct{} stringDetector struct { - K label.Key + K attribute.Key F func() (string, error) } @@ -71,7 +71,7 @@ func (Host) Detect(ctx context.Context) (*Resource, error) { // StringDetector returns a Detector that will produce a *Resource // containing the string as a value corresponding to k. -func StringDetector(k label.Key, f func() (string, error)) Detector { +func StringDetector(k attribute.Key, f func() (string, error)) Detector { return stringDetector{K: k, F: f} } diff --git a/sdk/resource/builtin_test.go b/sdk/resource/builtin_test.go index dad4b656b85..aac9e5d4943 100644 --- a/sdk/resource/builtin_test.go +++ b/sdk/resource/builtin_test.go @@ -22,13 +22,13 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/resource" ) func TestBuiltinStringDetector(t *testing.T) { E := fmt.Errorf("no K") - res, err := resource.StringDetector(label.Key("K"), func() (string, error) { + res, err := resource.StringDetector(attribute.Key("K"), func() (string, error) { return "", E }).Detect(context.Background()) require.True(t, errors.Is(err, E)) @@ -40,8 +40,8 @@ func TestBuiltinStringConfig(t *testing.T) { res, err := resource.New( context.Background(), resource.WithoutBuiltin(), - resource.WithAttributes(label.String("A", "B")), - resource.WithDetectors(resource.StringDetector(label.Key("K"), func() (string, error) { + resource.WithAttributes(attribute.String("A", "B")), + resource.WithDetectors(resource.StringDetector(attribute.Key("K"), func() (string, error) { return "", fmt.Errorf("K-IS-MISSING") })), ) diff --git a/sdk/resource/config.go b/sdk/resource/config.go index 5082816e819..6ea27f5a96f 100644 --- a/sdk/resource/config.go +++ b/sdk/resource/config.go @@ -17,7 +17,7 @@ package resource // import "go.opentelemetry.io/otel/sdk/resource" import ( "context" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // config contains configuration for Resource creation. @@ -45,12 +45,12 @@ type Option interface { } // WithAttributes adds attributes to the configured Resource. -func WithAttributes(attributes ...label.KeyValue) Option { +func WithAttributes(attributes ...attribute.KeyValue) Option { return WithDetectors(detectAttributes{attributes}) } type detectAttributes struct { - attributes []label.KeyValue + attributes []attribute.KeyValue } func (d detectAttributes) Detect(context.Context) (*Resource, error) { diff --git a/sdk/resource/config_test.go b/sdk/resource/config_test.go index 7220f6c8b45..046a39bd3fa 100644 --- a/sdk/resource/config_test.go +++ b/sdk/resource/config_test.go @@ -23,8 +23,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ottest "go.opentelemetry.io/otel/internal/internaltest" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/sdk/resource" ) @@ -114,7 +114,7 @@ func TestWithoutBuiltin(t *testing.T) { res, err := resource.New( ctx, resource.WithoutBuiltin(), - resource.WithAttributes(label.String("hello", "collector")), + resource.WithAttributes(attribute.String("hello", "collector")), ) require.NoError(t, err) require.EqualValues(t, map[string]string{ diff --git a/sdk/resource/env.go b/sdk/resource/env.go index a8b9189591e..c87c82119c4 100644 --- a/sdk/resource/env.go +++ b/sdk/resource/env.go @@ -20,7 +20,7 @@ import ( "os" "strings" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // envVar is the environment variable name OpenTelemetry Resource information can be assigned to. @@ -53,7 +53,7 @@ func (FromEnv) Detect(context.Context) (*Resource, error) { func constructOTResources(s string) (*Resource, error) { pairs := strings.Split(s, ",") - labels := []label.KeyValue{} + labels := []attribute.KeyValue{} var invalid []string for _, p := range pairs { field := strings.SplitN(p, "=", 2) @@ -62,7 +62,7 @@ func constructOTResources(s string) (*Resource, error) { continue } k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1]) - labels = append(labels, label.String(k, v)) + labels = append(labels, attribute.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 2499288ca5d..50b788c2ff3 100644 --- a/sdk/resource/env_test.go +++ b/sdk/resource/env_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" ottest "go.opentelemetry.io/otel/internal/internaltest" - "go.opentelemetry.io/otel/label" ) func TestDetectOnePair(t *testing.T) { @@ -36,7 +36,7 @@ func TestDetectOnePair(t *testing.T) { detector := &FromEnv{} res, err := detector.Detect(context.Background()) require.NoError(t, err) - assert.Equal(t, NewWithAttributes(label.String("key", "value")), res) + assert.Equal(t, NewWithAttributes(attribute.String("key", "value")), res) } func TestDetectMultiPairs(t *testing.T) { @@ -51,10 +51,10 @@ func TestDetectMultiPairs(t *testing.T) { res, err := detector.Detect(context.Background()) require.NoError(t, err) assert.Equal(t, res, NewWithAttributes( - label.String("key", "value"), - label.String("k", "v"), - label.String("a", "x"), - label.String("a", "z"), + attribute.String("key", "value"), + attribute.String("k", "v"), + attribute.String("a", "x"), + attribute.String("a", "z"), )) } @@ -83,6 +83,6 @@ func TestMissingKeyError(t *testing.T) { assert.Error(t, err) assert.Equal(t, err, fmt.Errorf("%w: %v", errMissingValue, "[key]")) assert.Equal(t, res, NewWithAttributes( - label.String("key", "value"), + attribute.String("key", "value"), )) } diff --git a/sdk/resource/resource.go b/sdk/resource/resource.go index 10b826e61a7..e69dace36a2 100644 --- a/sdk/resource/resource.go +++ b/sdk/resource/resource.go @@ -18,8 +18,7 @@ import ( "context" "go.opentelemetry.io/otel" - - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // Resource describes an entity about which identifying information @@ -30,7 +29,7 @@ import ( // (`*resource.Resource`). The `nil` value is equivalent to an empty // Resource. type Resource struct { - labels label.Set + labels attribute.Set } var ( @@ -47,9 +46,9 @@ var ( // NewWithAttributes 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 NewWithAttributes(kvs ...label.KeyValue) *Resource { +func NewWithAttributes(kvs ...attribute.KeyValue) *Resource { return &Resource{ - labels: label.NewSet(kvs...), + labels: attribute.NewSet(kvs...), } } @@ -62,12 +61,12 @@ func (r *Resource) String() string { if r == nil { return "" } - return r.labels.Encoded(label.DefaultEncoder()) + return r.labels.Encoded(attribute.DefaultEncoder()) } // 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() []label.KeyValue { +func (r *Resource) Attributes() []attribute.KeyValue { if r == nil { r = Empty() } @@ -76,7 +75,7 @@ func (r *Resource) Attributes() []label.KeyValue { // Iter returns an interator of the Resource attributes. // This is ideal to use if you do not want a copy of the attributes. -func (r *Resource) Iter() label.Iterator { +func (r *Resource) Iter() attribute.Iterator { if r == nil { r = Empty() } @@ -110,10 +109,10 @@ func Merge(a, b *Resource) *Resource { return a } - // Note: 'b' labels will overwrite 'a' with last-value-wins in label.Key() + // Note: 'b' labels will overwrite 'a' with last-value-wins in attribute.Key() // Meaning this is equivalent to: append(a.Attributes(), b.Attributes()...) - mi := label.NewMergeIterator(b.LabelSet(), a.LabelSet()) - combine := make([]label.KeyValue, 0, a.Len()+b.Len()) + mi := attribute.NewMergeIterator(b.LabelSet(), a.LabelSet()) + combine := make([]attribute.KeyValue, 0, a.Len()+b.Len()) for mi.Next() { combine = append(combine, mi.Label()) } @@ -135,12 +134,12 @@ func Default() *Resource { // Equivalent returns an object that can be compared for equality // between two resources. This value is suitable for use as a key in // a map. -func (r *Resource) Equivalent() label.Distinct { +func (r *Resource) Equivalent() attribute.Distinct { return r.LabelSet().Equivalent() } -// LabelSet returns the equivalent *label.Set. -func (r *Resource) LabelSet() *label.Set { +// LabelSet returns the equivalent *attribute.Set. +func (r *Resource) LabelSet() *attribute.Set { if r == nil { r = Empty() } @@ -167,7 +166,7 @@ func (r *Resource) Len() int { // Encoded returns an encoded representation of the resource by // applying a label encoder. The result is cached by the underlying // label set. -func (r *Resource) Encoded(enc label.Encoder) string { +func (r *Resource) Encoded(enc attribute.Encoder) string { if r == nil { return "" } diff --git a/sdk/resource/resource_test.go b/sdk/resource/resource_test.go index 0ecf1150bba..63dd381cfe2 100644 --- a/sdk/resource/resource_test.go +++ b/sdk/resource/resource_test.go @@ -24,35 +24,35 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/semconv" ) var ( - 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") - kv42 = label.String("k4", "") + kv11 = attribute.String("k1", "v11") + kv12 = attribute.String("k1", "v12") + kv21 = attribute.String("k2", "v21") + kv31 = attribute.String("k3", "v31") + kv41 = attribute.String("k4", "v41") + kv42 = attribute.String("k4", "") ) func TestNew(t *testing.T) { cases := []struct { name string - in []label.KeyValue - want []label.KeyValue + in []attribute.KeyValue + want []attribute.KeyValue }{ { name: "Key with common key order1", - in: []label.KeyValue{kv12, kv11, kv21}, - want: []label.KeyValue{kv11, kv21}, + in: []attribute.KeyValue{kv12, kv11, kv21}, + want: []attribute.KeyValue{kv11, kv21}, }, { name: "Key with common key order2", - in: []label.KeyValue{kv11, kv12, kv21}, - want: []label.KeyValue{kv12, kv21}, + in: []attribute.KeyValue{kv11, kv12, kv21}, + want: []attribute.KeyValue{kv12, kv21}, }, { name: "Key with nil", @@ -66,7 +66,7 @@ func TestNew(t *testing.T) { if diff := cmp.Diff( res.Attributes(), c.want, - cmp.AllowUnexported(label.Value{})); diff != "" { + cmp.AllowUnexported(attribute.Value{})); diff != "" { t.Fatalf("unwanted result: diff %+v,", diff) } }) @@ -77,37 +77,37 @@ func TestMerge(t *testing.T) { cases := []struct { name string a, b *resource.Resource - want []label.KeyValue + want []attribute.KeyValue }{ { name: "Merge with no overlap, no nil", a: resource.NewWithAttributes(kv11, kv31), b: resource.NewWithAttributes(kv21, kv41), - want: []label.KeyValue{kv11, kv21, kv31, kv41}, + want: []attribute.KeyValue{kv11, kv21, kv31, kv41}, }, { name: "Merge with no overlap, no nil, not interleaved", a: resource.NewWithAttributes(kv11, kv21), b: resource.NewWithAttributes(kv31, kv41), - want: []label.KeyValue{kv11, kv21, kv31, kv41}, + want: []attribute.KeyValue{kv11, kv21, kv31, kv41}, }, { name: "Merge with common key order1", a: resource.NewWithAttributes(kv11), b: resource.NewWithAttributes(kv12, kv21), - want: []label.KeyValue{kv12, kv21}, + want: []attribute.KeyValue{kv12, kv21}, }, { name: "Merge with common key order2", a: resource.NewWithAttributes(kv12, kv21), b: resource.NewWithAttributes(kv11), - want: []label.KeyValue{kv11, kv21}, + want: []attribute.KeyValue{kv11, kv21}, }, { name: "Merge with common key order4", a: resource.NewWithAttributes(kv11, kv21, kv41), b: resource.NewWithAttributes(kv31, kv41), - want: []label.KeyValue{kv11, kv21, kv31, kv41}, + want: []attribute.KeyValue{kv11, kv21, kv31, kv41}, }, { name: "Merge with no keys", @@ -119,37 +119,37 @@ func TestMerge(t *testing.T) { name: "Merge with first resource no keys", a: resource.NewWithAttributes(), b: resource.NewWithAttributes(kv21), - want: []label.KeyValue{kv21}, + want: []attribute.KeyValue{kv21}, }, { name: "Merge with second resource no keys", a: resource.NewWithAttributes(kv11), b: resource.NewWithAttributes(), - want: []label.KeyValue{kv11}, + want: []attribute.KeyValue{kv11}, }, { name: "Merge with first resource nil", a: nil, b: resource.NewWithAttributes(kv21), - want: []label.KeyValue{kv21}, + want: []attribute.KeyValue{kv21}, }, { name: "Merge with second resource nil", a: resource.NewWithAttributes(kv11), b: nil, - want: []label.KeyValue{kv11}, + want: []attribute.KeyValue{kv11}, }, { name: "Merge with first resource value empty string", a: resource.NewWithAttributes(kv42), b: resource.NewWithAttributes(kv41), - want: []label.KeyValue{kv41}, + want: []attribute.KeyValue{kv41}, }, { name: "Merge with second resource value empty string", a: resource.NewWithAttributes(kv41), b: resource.NewWithAttributes(kv42), - want: []label.KeyValue{kv42}, + want: []attribute.KeyValue{kv42}, }, } for _, c := range cases { @@ -158,7 +158,7 @@ func TestMerge(t *testing.T) { if diff := cmp.Diff( res.Attributes(), c.want, - cmp.AllowUnexported(label.Value{})); diff != "" { + cmp.AllowUnexported(attribute.Value{})); diff != "" { t.Fatalf("unwanted result: diff %+v,", diff) } }) @@ -182,7 +182,7 @@ func TestDefault(t *testing.T) { func TestString(t *testing.T) { for _, test := range []struct { - kvs []label.KeyValue + kvs []attribute.KeyValue want string }{ { @@ -190,51 +190,51 @@ func TestString(t *testing.T) { want: "", }, { - kvs: []label.KeyValue{}, + kvs: []attribute.KeyValue{}, want: "", }, { - kvs: []label.KeyValue{kv11}, + kvs: []attribute.KeyValue{kv11}, want: "k1=v11", }, { - kvs: []label.KeyValue{kv11, kv12}, + kvs: []attribute.KeyValue{kv11, kv12}, want: "k1=v12", }, { - kvs: []label.KeyValue{kv11, kv21}, + kvs: []attribute.KeyValue{kv11, kv21}, want: "k1=v11,k2=v21", }, { - kvs: []label.KeyValue{kv21, kv11}, + kvs: []attribute.KeyValue{kv21, kv11}, want: "k1=v11,k2=v21", }, { - kvs: []label.KeyValue{kv11, kv21, kv31}, + kvs: []attribute.KeyValue{kv11, kv21, kv31}, want: "k1=v11,k2=v21,k3=v31", }, { - kvs: []label.KeyValue{kv31, kv11, kv21}, + kvs: []attribute.KeyValue{kv31, kv11, kv21}, want: "k1=v11,k2=v21,k3=v31", }, { - kvs: []label.KeyValue{label.String("A", "a"), label.String("B", "b")}, + kvs: []attribute.KeyValue{attribute.String("A", "a"), attribute.String("B", "b")}, want: "A=a,B=b", }, { - kvs: []label.KeyValue{label.String("A", "a,B=b")}, + kvs: []attribute.KeyValue{attribute.String("A", "a,B=b")}, want: `A=a\,B\=b`, }, { - kvs: []label.KeyValue{label.String("A", `a,B\=b`)}, + kvs: []attribute.KeyValue{attribute.String("A", `a,B\=b`)}, want: `A=a\,B\\\=b`, }, { - kvs: []label.KeyValue{label.String("A=a,B", `b`)}, + kvs: []attribute.KeyValue{attribute.String("A=a,B", `b`)}, want: `A\=a\,B=b`, }, { - kvs: []label.KeyValue{label.String(`A=a\,B`, `b`)}, + kvs: []attribute.KeyValue{attribute.String(`A=a\,B`, `b`)}, want: `A\=a\\\,B=b`, }, } { @@ -245,7 +245,7 @@ func TestString(t *testing.T) { } func TestMarshalJSON(t *testing.T) { - r := resource.NewWithAttributes(label.Int64("A", 1), label.String("C", "D")) + r := resource.NewWithAttributes(attribute.Int64("A", 1), attribute.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 6b2f1346306..b891c8178b7 100644 --- a/sdk/trace/attributesmap.go +++ b/sdk/trace/attributesmap.go @@ -17,7 +17,7 @@ package trace // import "go.opentelemetry.io/otel/sdk/trace" import ( "container/list" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // attributesMap is a capped map of attributes, holding the most recent attributes. @@ -25,9 +25,9 @@ import ( // Updates are allowed and they refresh 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 label.KeyValue +// With a subset of the its operations and specific for holding attribute.KeyValue type attributesMap struct { - attributes map[label.Key]*list.Element + attributes map[attribute.Key]*list.Element evictList *list.List droppedCount int capacity int @@ -35,14 +35,14 @@ type attributesMap struct { func newAttributesMap(capacity int) *attributesMap { lm := &attributesMap{ - attributes: make(map[label.Key]*list.Element), + attributes: make(map[attribute.Key]*list.Element), evictList: list.New(), capacity: capacity, } return lm } -func (am *attributesMap) add(kv label.KeyValue) { +func (am *attributesMap) add(kv attribute.KeyValue) { // Check for existing item if ent, ok := am.attributes[kv.Key]; ok { am.evictList.MoveToFront(ent) @@ -61,18 +61,18 @@ func (am *attributesMap) add(kv label.KeyValue) { } } -// toKeyValue copies the attributesMap into a slice of label.KeyValue and +// toKeyValue copies the attributesMap into a slice of attribute.KeyValue and // returns it. If the map is empty, a nil is returned. // TODO: Is it more efficient to return a pointer to the slice? -func (am *attributesMap) toKeyValue() []label.KeyValue { +func (am *attributesMap) toKeyValue() []attribute.KeyValue { len := am.evictList.Len() if len == 0 { return nil } - attributes := make([]label.KeyValue, 0, len) + attributes := make([]attribute.KeyValue, 0, len) for ent := am.evictList.Back(); ent != nil; ent = ent.Prev() { - if value, ok := ent.Value.(*label.KeyValue); ok { + if value, ok := ent.Value.(*attribute.KeyValue); ok { attributes = append(attributes, *value) } } @@ -85,7 +85,7 @@ func (am *attributesMap) removeOldest() { ent := am.evictList.Back() if ent != nil { am.evictList.Remove(ent) - kv := ent.Value.(*label.KeyValue) + kv := ent.Value.(*attribute.KeyValue) delete(am.attributes, kv.Key) } } diff --git a/sdk/trace/attributesmap_test.go b/sdk/trace/attributesmap_test.go index defa378b36b..90a201e2195 100644 --- a/sdk/trace/attributesmap_test.go +++ b/sdk/trace/attributesmap_test.go @@ -18,7 +18,7 @@ import ( "fmt" "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) const testKeyFmt = "test-key-%d" @@ -28,7 +28,7 @@ func TestAttributesMap(t *testing.T) { attrMap := newAttributesMap(wantCapacity) for i := 0; i < 256; i++ { - attrMap.add(label.Int(fmt.Sprintf(testKeyFmt, i), i)) + attrMap.add(attribute.Int(fmt.Sprintf(testKeyFmt, i), i)) } if attrMap.capacity != wantCapacity { t.Errorf("attrMap.capacity: got '%d'; want '%d'", attrMap.capacity, wantCapacity) @@ -39,14 +39,14 @@ func TestAttributesMap(t *testing.T) { } for i := 0; i < wantCapacity; i++ { - key := label.Key(fmt.Sprintf(testKeyFmt, i)) + key := attribute.Key(fmt.Sprintf(testKeyFmt, i)) _, ok := attrMap.attributes[key] if ok { t.Errorf("key %q should be dropped", testKeyFmt) } } for i := wantCapacity; i < 256; i++ { - key := label.Key(fmt.Sprintf(testKeyFmt, i)) + key := attribute.Key(fmt.Sprintf(testKeyFmt, i)) _, ok := attrMap.attributes[key] if !ok { t.Errorf("key %q should not be dropped", key) @@ -58,7 +58,7 @@ func TestAttributesMapGetOldestRemoveOldest(t *testing.T) { attrMap := newAttributesMap(128) for i := 0; i < 128; i++ { - attrMap.add(label.Int(fmt.Sprintf(testKeyFmt, i), i)) + attrMap.add(attribute.Int(fmt.Sprintf(testKeyFmt, i), i)) } attrMap.removeOldest() @@ -66,7 +66,7 @@ func TestAttributesMapGetOldestRemoveOldest(t *testing.T) { attrMap.removeOldest() for i := 0; i < 3; i++ { - key := label.Key(fmt.Sprintf(testKeyFmt, i)) + key := attribute.Key(fmt.Sprintf(testKeyFmt, i)) _, ok := attrMap.attributes[key] if ok { t.Errorf("key %q should be removed", key) @@ -78,7 +78,7 @@ func TestAttributesMapToKeyValue(t *testing.T) { attrMap := newAttributesMap(128) for i := 0; i < 128; i++ { - attrMap.add(label.Int(fmt.Sprintf(testKeyFmt, i), i)) + attrMap.add(attribute.Int(fmt.Sprintf(testKeyFmt, i), i)) } kv := attrMap.toKeyValue() @@ -94,7 +94,7 @@ func BenchmarkAttributesMapToKeyValue(b *testing.B) { attrMap := newAttributesMap(128) for i := 0; i < 128; i++ { - attrMap.add(label.Int(fmt.Sprintf(testKeyFmt, i), i)) + attrMap.add(attribute.Int(fmt.Sprintf(testKeyFmt, i), i)) } for n := 0; n < b.N; n++ { diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index 77b1319f9dc..183fbd3f29d 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -18,7 +18,7 @@ import ( "context" "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -43,9 +43,9 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - label.Bool("key1", false), - label.String("key2", "hello"), - label.Float64("key4", 123.456), + attribute.Bool("key1", false), + attribute.String("key2", "hello"), + attribute.Float64("key4", 123.456), ) span.End() } @@ -60,12 +60,12 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - label.Bool("key1", false), - label.String("key2", "hello"), - label.Float64("key4", 123.456), - label.Bool("key21", false), - label.String("key22", "hello"), - label.Float64("key24", 123.456), + attribute.Bool("key1", false), + attribute.String("key2", "hello"), + attribute.Float64("key4", 123.456), + attribute.Bool("key21", false), + attribute.String("key22", "hello"), + attribute.Float64("key24", 123.456), ) span.End() } @@ -80,11 +80,11 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - label.Bool("key1", false), - label.String("key2", "hello"), - label.Int64("key3", 123), - label.Float64("key7", 123.456), - label.Int("key9", 123), + attribute.Bool("key1", false), + attribute.String("key2", "hello"), + attribute.Int64("key3", 123), + attribute.Float64("key7", 123.456), + attribute.Int("key9", 123), ) span.End() } @@ -99,16 +99,16 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - label.Bool("key1", false), - label.String("key2", "hello"), - label.Int64("key3", 123), - label.Float64("key7", 123.456), - label.Int("key10", 123), - label.Bool("key21", false), - label.String("key22", "hello"), - label.Int64("key23", 123), - label.Float64("key27", 123.456), - label.Int("key210", 123), + attribute.Bool("key1", false), + attribute.String("key2", "hello"), + attribute.Int64("key3", 123), + attribute.Float64("key7", 123.456), + attribute.Int("key10", 123), + attribute.Bool("key21", false), + attribute.String("key22", "hello"), + attribute.Int64("key23", 123), + attribute.Float64("key27", 123.456), + attribute.Int("key210", 123), ) span.End() } diff --git a/sdk/trace/sampling.go b/sdk/trace/sampling.go index c42465c41e8..d6fda1c2a93 100644 --- a/sdk/trace/sampling.go +++ b/sdk/trace/sampling.go @@ -18,7 +18,7 @@ import ( "encoding/binary" "fmt" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -35,7 +35,7 @@ type SamplingParameters struct { Name string HasRemoteParent bool Kind trace.SpanKind - Attributes []label.KeyValue + Attributes []attribute.KeyValue Links []trace.Link } @@ -59,7 +59,7 @@ const ( // SamplingResult conveys a SamplingDecision, set of Attributes and a Tracestate. type SamplingResult struct { Decision SamplingDecision - Attributes []label.KeyValue + Attributes []attribute.KeyValue Tracestate trace.TraceState } diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index c8cde14c72d..0d6f4f24e79 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -220,7 +220,7 @@ func TestTracestateIsPassed(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - traceState, err := trace.TraceStateFromKeyValues(label.String("k", "v")) + traceState, err := trace.TraceStateFromKeyValues(attribute.String("k", "v")) if err != nil { t.Error(err) } diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 388238e25fa..08d3a9e8cb5 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -21,8 +21,8 @@ import ( "sync" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/trace" export "go.opentelemetry.io/otel/sdk/export/trace" @@ -32,8 +32,8 @@ import ( ) const ( - errorTypeKey = label.Key("error.type") - errorMessageKey = label.Key("error.message") + errorTypeKey = attribute.Key("error.type") + errorMessageKey = attribute.Key("error.message") errorEventName = "error" ) @@ -49,7 +49,7 @@ type ReadOnlySpan interface { SpanKind() trace.SpanKind StartTime() time.Time EndTime() time.Time - Attributes() []label.KeyValue + Attributes() []attribute.KeyValue Links() []trace.Link Events() []trace.Event StatusCode() codes.Code @@ -175,7 +175,7 @@ func (s *span) SetStatus(code codes.Code, msg string) { // will be overwritten with the value contained in attributes. // // If this span is not being recorded than this method does nothing. -func (s *span) SetAttributes(attributes ...label.KeyValue) { +func (s *span) SetAttributes(attributes ...attribute.KeyValue) { if !s.IsRecording() { return } @@ -342,11 +342,11 @@ func (s *span) EndTime() time.Time { } // Attributes returns the attributes of this span. -func (s *span) Attributes() []label.KeyValue { +func (s *span) Attributes() []attribute.KeyValue { s.mu.Lock() defer s.mu.Unlock() if s.attributes.evictList.Len() == 0 { - return []label.KeyValue{} + return []attribute.KeyValue{} } return s.attributes.toKeyValue() } @@ -461,11 +461,11 @@ func (s *span) interfaceArrayToMessageEventArray() []trace.Event { return messageEventArr } -func (s *span) copyToCappedAttributes(attributes ...label.KeyValue) { +func (s *span) copyToCappedAttributes(attributes ...attribute.KeyValue) { s.mu.Lock() defer s.mu.Unlock() for _, a := range attributes { - if a.Value.Type() != label.INVALID { + if a.Value.Type() != attribute.INVALID { s.attributes.add(a) } } @@ -548,7 +548,7 @@ type samplingData struct { name string cfg *Config span *span - attributes []label.KeyValue + attributes []attribute.KeyValue links []trace.Link kind trace.SpanKind } diff --git a/sdk/trace/span_processor_test.go b/sdk/trace/span_processor_test.go index f2376d37df4..4dd918c3345 100644 --- a/sdk/trace/span_processor_test.go +++ b/sdk/trace/span_processor_test.go @@ -18,7 +18,7 @@ import ( "context" "testing" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" ) @@ -32,10 +32,10 @@ type testSpanProcessor struct { func (t *testSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWriteSpan) { psc := trace.RemoteSpanContextFromContext(parent) - kv := []label.KeyValue{ + kv := []attribute.KeyValue{ { Key: "SpanProcessorName", - Value: label.StringValue(t.name), + Value: attribute.StringValue(t.name), }, // Store parent trace ID and span ID as attributes to be read later in // tests so that we "do something" with the parent argument. Real @@ -43,11 +43,11 @@ func (t *testSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWrite // a more meaningful way. { Key: "ParentTraceID", - Value: label.StringValue(psc.TraceID.String()), + Value: attribute.StringValue(psc.TraceID.String()), }, { Key: "ParentSpanID", - Value: label.StringValue(psc.SpanID.String()), + Value: attribute.StringValue(psc.SpanID.String()), }, } s.AddEvent("OnStart", trace.WithAttributes(kv...)) diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index d3934574a91..689ad60650c 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -26,8 +26,8 @@ import ( "time" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/trace" @@ -150,7 +150,7 @@ func (ts *testSampler) ShouldSample(p SamplingParameters) SamplingResult { if strings.HasPrefix(p.Name, ts.prefix) { decision = RecordAndSample } - return SamplingResult{Decision: decision, Attributes: []label.KeyValue{label.Int("callCount", ts.callCount)}} + return SamplingResult{Decision: decision, Attributes: []attribute.KeyValue{attribute.Int("callCount", ts.callCount)}} } func (ts testSampler) Description() string { @@ -314,7 +314,7 @@ func TestStartSpanWithParent(t *testing.T) { t.Error(err) } - ts, err := trace.TraceStateFromKeyValues(label.String("k", "v")) + ts, err := trace.TraceStateFromKeyValues(attribute.String("k", "v")) if err != nil { t.Error(err) } @@ -346,8 +346,8 @@ func TestSetSpanAttributesOnStart(t *testing.T) { tp := NewTracerProvider(WithSyncer(te), WithResource(resource.Empty())) span := startSpan(tp, "StartSpanAttribute", - trace.WithAttributes(label.String("key1", "value1")), - trace.WithAttributes(label.String("key2", "value2")), + trace.WithAttributes(attribute.String("key1", "value1")), + trace.WithAttributes(attribute.String("key2", "value2")), ) got, err := endSpan(te, span) if err != nil { @@ -361,9 +361,9 @@ func TestSetSpanAttributesOnStart(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []label.KeyValue{ - label.String("key1", "value1"), - label.String("key2", "value2"), + Attributes: []attribute.KeyValue{ + attribute.String("key1", "value1"), + attribute.String("key2", "value2"), }, SpanKind: trace.SpanKindInternal, HasRemoteParent: true, @@ -378,7 +378,7 @@ func TestSetSpanAttributes(t *testing.T) { te := NewTestExporter() tp := NewTracerProvider(WithSyncer(te), WithResource(resource.Empty())) span := startSpan(tp, "SpanAttribute") - span.SetAttributes(label.String("key1", "value1")) + span.SetAttributes(attribute.String("key1", "value1")) got, err := endSpan(te, span) if err != nil { t.Fatal(err) @@ -391,8 +391,8 @@ func TestSetSpanAttributes(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []label.KeyValue{ - label.String("key1", "value1"), + Attributes: []attribute.KeyValue{ + attribute.String("key1", "value1"), }, SpanKind: trace.SpanKindInternal, HasRemoteParent: true, @@ -444,7 +444,7 @@ func TestSamplerAttributesLocalChildSpan(t *testing.T) { }, ParentSpanID: sid, Name: "span1", - Attributes: []label.KeyValue{label.Int("callCount", 2)}, + Attributes: []attribute.KeyValue{attribute.Int("callCount", 2)}, SpanKind: trace.SpanKindInternal, HasRemoteParent: false, InstrumentationLibrary: instrumentation.Library{Name: "SpanTwo"}, @@ -456,7 +456,7 @@ func TestSamplerAttributesLocalChildSpan(t *testing.T) { }, ParentSpanID: pid, Name: "span0", - Attributes: []label.KeyValue{label.Int("callCount", 1)}, + Attributes: []attribute.KeyValue{attribute.Int("callCount", 1)}, SpanKind: trace.SpanKindInternal, HasRemoteParent: false, ChildSpanCount: 1, @@ -476,10 +476,10 @@ func TestSetSpanAttributesOverLimit(t *testing.T) { span := startSpan(tp, "SpanAttributesOverLimit") span.SetAttributes( - label.Bool("key1", true), - label.String("key2", "value2"), - label.Bool("key1", false), // Replace key1. - label.Int64("key4", 4), // Remove key2 and add key4 + attribute.Bool("key1", true), + attribute.String("key2", "value2"), + attribute.Bool("key1", false), // Replace key1. + attribute.Int64("key4", 4), // Remove key2 and add key4 ) got, err := endSpan(te, span) if err != nil { @@ -493,9 +493,9 @@ func TestSetSpanAttributesOverLimit(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []label.KeyValue{ - label.Bool("key1", false), - label.Int64("key4", 4), + Attributes: []attribute.KeyValue{ + attribute.Bool("key1", false), + attribute.Int64("key4", 4), }, SpanKind: trace.SpanKindInternal, HasRemoteParent: true, @@ -512,14 +512,14 @@ func TestEvents(t *testing.T) { tp := NewTracerProvider(WithSyncer(te), WithResource(resource.Empty())) span := startSpan(tp, "Events") - k1v1 := label.String("key1", "value1") - k2v2 := label.Bool("key2", true) - k3v3 := label.Int64("key3", 3) + k1v1 := attribute.String("key1", "value1") + k2v2 := attribute.Bool("key2", true) + k3v3 := attribute.Int64("key3", 3) - span.AddEvent("foo", trace.WithAttributes(label.String("key1", "value1"))) + span.AddEvent("foo", trace.WithAttributes(attribute.String("key1", "value1"))) span.AddEvent("bar", trace.WithAttributes( - label.Bool("key2", true), - label.Int64("key3", 3), + attribute.Bool("key2", true), + attribute.Int64("key3", 3), )) got, err := endSpan(te, span) if err != nil { @@ -541,8 +541,8 @@ func TestEvents(t *testing.T) { Name: "span0", HasRemoteParent: true, MessageEvents: []trace.Event{ - {Name: "foo", Attributes: []label.KeyValue{k1v1}}, - {Name: "bar", Attributes: []label.KeyValue{k2v2, k3v3}}, + {Name: "foo", Attributes: []attribute.KeyValue{k1v1}}, + {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, }, SpanKind: trace.SpanKindInternal, InstrumentationLibrary: instrumentation.Library{Name: "Events"}, @@ -558,19 +558,19 @@ func TestEventsOverLimit(t *testing.T) { tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te), WithResource(resource.Empty())) span := startSpan(tp, "EventsOverLimit") - k1v1 := label.String("key1", "value1") - k2v2 := label.Bool("key2", false) - k3v3 := label.String("key3", "value3") + k1v1 := attribute.String("key1", "value1") + k2v2 := attribute.Bool("key2", false) + k3v3 := attribute.String("key3", "value3") - span.AddEvent("fooDrop", trace.WithAttributes(label.String("key1", "value1"))) + span.AddEvent("fooDrop", trace.WithAttributes(attribute.String("key1", "value1"))) span.AddEvent("barDrop", trace.WithAttributes( - label.Bool("key2", true), - label.String("key3", "value3"), + attribute.Bool("key2", true), + attribute.String("key3", "value3"), )) - span.AddEvent("foo", trace.WithAttributes(label.String("key1", "value1"))) + span.AddEvent("foo", trace.WithAttributes(attribute.String("key1", "value1"))) span.AddEvent("bar", trace.WithAttributes( - label.Bool("key2", false), - label.String("key3", "value3"), + attribute.Bool("key2", false), + attribute.String("key3", "value3"), )) got, err := endSpan(te, span) if err != nil { @@ -591,8 +591,8 @@ func TestEventsOverLimit(t *testing.T) { ParentSpanID: sid, Name: "span0", MessageEvents: []trace.Event{ - {Name: "foo", Attributes: []label.KeyValue{k1v1}}, - {Name: "bar", Attributes: []label.KeyValue{k2v2, k3v3}}, + {Name: "foo", Attributes: []attribute.KeyValue{k1v1}}, + {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, }, DroppedMessageEventCount: 2, HasRemoteParent: true, @@ -608,16 +608,16 @@ func TestLinks(t *testing.T) { te := NewTestExporter() tp := NewTracerProvider(WithSyncer(te), WithResource(resource.Empty())) - k1v1 := label.String("key1", "value1") - k2v2 := label.String("key2", "value2") - k3v3 := label.String("key3", "value3") + k1v1 := attribute.String("key1", "value1") + k2v2 := attribute.String("key2", "value2") + k3v3 := attribute.String("key3", "value3") sc1 := trace.SpanContext{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}} sc2 := trace.SpanContext{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}} links := []trace.Link{ - {SpanContext: sc1, Attributes: []label.KeyValue{k1v1}}, - {SpanContext: sc2, Attributes: []label.KeyValue{k2v2, k3v3}}, + {SpanContext: sc1, Attributes: []attribute.KeyValue{k1v1}}, + {SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2, k3v3}}, } span := startSpan(tp, "Links", trace.WithLinks(links...)) @@ -655,14 +655,14 @@ func TestLinksOverLimit(t *testing.T) { span := startSpan(tp, "LinksOverLimit", trace.WithLinks( - trace.Link{SpanContext: sc1, Attributes: []label.KeyValue{label.String("key1", "value1")}}, - trace.Link{SpanContext: sc2, Attributes: []label.KeyValue{label.String("key2", "value2")}}, - trace.Link{SpanContext: sc3, Attributes: []label.KeyValue{label.String("key3", "value3")}}, + trace.Link{SpanContext: sc1, Attributes: []attribute.KeyValue{attribute.String("key1", "value1")}}, + trace.Link{SpanContext: sc2, Attributes: []attribute.KeyValue{attribute.String("key2", "value2")}}, + trace.Link{SpanContext: sc3, Attributes: []attribute.KeyValue{attribute.String("key3", "value3")}}, ), ) - k2v2 := label.String("key2", "value2") - k3v3 := label.String("key3", "value3") + k2v2 := attribute.String("key2", "value2") + k3v3 := attribute.String("key3", "value3") got, err := endSpan(te, span) if err != nil { @@ -677,8 +677,8 @@ func TestLinksOverLimit(t *testing.T) { ParentSpanID: sid, Name: "span0", Links: []trace.Link{ - {SpanContext: sc2, Attributes: []label.KeyValue{k2v2}}, - {SpanContext: sc3, Attributes: []label.KeyValue{k3v3}}, + {SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2}}, + {SpanContext: sc3, Attributes: []attribute.KeyValue{k3v3}}, }, DroppedLinkCount: 1, HasRemoteParent: true, @@ -743,7 +743,7 @@ func TestSetSpanStatus(t *testing.T) { func cmpDiff(x, y interface{}) string { return cmp.Diff(x, y, - cmp.AllowUnexported(label.Value{}), + cmp.AllowUnexported(attribute.Value{}), cmp.AllowUnexported(trace.Event{}), cmp.AllowUnexported(trace.TraceState{})) } @@ -1097,7 +1097,7 @@ func TestRecordError(t *testing.T) { { Name: errorEventName, Time: errTime, - Attributes: []label.KeyValue{ + Attributes: []attribute.KeyValue{ errorTypeKey.String(s.typ), errorMessageKey.String(s.msg), }, @@ -1198,15 +1198,15 @@ func TestWithResource(t *testing.T) { }, { name: "explicit resource", - options: []TracerProviderOption{WithResource(resource.NewWithAttributes(label.String("rk1", "rv1"), label.Int64("rk2", 5)))}, - want: resource.NewWithAttributes(label.String("rk1", "rv1"), label.Int64("rk2", 5)), + options: []TracerProviderOption{WithResource(resource.NewWithAttributes(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5)))}, + want: resource.NewWithAttributes(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5)), }, { name: "last resource wins", options: []TracerProviderOption{ - WithResource(resource.NewWithAttributes(label.String("rk1", "vk1"), label.Int64("rk2", 5))), - WithResource(resource.NewWithAttributes(label.String("rk3", "rv3"), label.Int64("rk4", 10)))}, - want: resource.NewWithAttributes(label.String("rk3", "rv3"), label.Int64("rk4", 10)), + WithResource(resource.NewWithAttributes(attribute.String("rk1", "vk1"), attribute.Int64("rk2", 5))), + WithResource(resource.NewWithAttributes(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10)))}, + want: resource.NewWithAttributes(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10)), }, } for _, tc := range cases { @@ -1216,7 +1216,7 @@ func TestWithResource(t *testing.T) { defaultOptions := []TracerProviderOption{WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()})} tp := NewTracerProvider(append(defaultOptions, tc.options...)...) span := startSpan(tp, "WithResource") - span.SetAttributes(label.String("key1", "value1")) + span.SetAttributes(attribute.String("key1", "value1")) got, err := endSpan(te, span) if err != nil { t.Error(err.Error()) @@ -1228,8 +1228,8 @@ func TestWithResource(t *testing.T) { }, ParentSpanID: sid, Name: "span0", - Attributes: []label.KeyValue{ - label.String("key1", "value1"), + Attributes: []attribute.KeyValue{ + attribute.String("key1", "value1"), }, SpanKind: trace.SpanKindInternal, HasRemoteParent: true, @@ -1295,14 +1295,14 @@ func TestSpanCapturesPanic(t *testing.T) { require.Len(t, spans, 1) require.Len(t, spans[0].MessageEvents, 1) assert.Equal(t, spans[0].MessageEvents[0].Name, errorEventName) - assert.Equal(t, spans[0].MessageEvents[0].Attributes, []label.KeyValue{ + assert.Equal(t, spans[0].MessageEvents[0].Attributes, []attribute.KeyValue{ errorTypeKey.String("*errors.errorString"), errorMessageKey.String("error message"), }) } func TestReadOnlySpan(t *testing.T) { - kv := label.String("foo", "bar") + kv := attribute.String("foo", "bar") tp := NewTracerProvider(WithResource(resource.NewWithAttributes(kv))) cfg := tp.config.Load().(*Config) diff --git a/semconv/http.go b/semconv/http.go index 50b0f696e5e..f1e377c64fe 100644 --- a/semconv/http.go +++ b/semconv/http.go @@ -21,16 +21,16 @@ import ( "strconv" "strings" + "go.opentelemetry.io/otel/attribute" "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) []label.KeyValue { - attrs := []label.KeyValue{} +func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue { + attrs := []attribute.KeyValue{} switch network { case "tcp", "tcp4", "tcp6": @@ -121,9 +121,9 @@ func NetAttributesFromHTTPRequest(network string, request *http.Request) []label // EndUserAttributesFromHTTPRequest generates attributes of the // enduser namespace as specified by the OpenTelemetry specification // for a span. -func EndUserAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { +func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { if username, _, ok := request.BasicAuth(); ok { - return []label.KeyValue{EnduserIDKey.String(username)} + return []attribute.KeyValue{EnduserIDKey.String(username)} } return nil } @@ -131,8 +131,8 @@ func EndUserAttributesFromHTTPRequest(request *http.Request) []label.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) []label.KeyValue { - attrs := []label.KeyValue{} +func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { + attrs := []attribute.KeyValue{} if request.Method != "" { attrs = append(attrs, HTTPMethodKey.String(request.Method)) @@ -145,8 +145,8 @@ func HTTPClientAttributesFromHTTPRequest(request *http.Request) []label.KeyValue return append(attrs, httpCommonAttributesFromHTTPRequest(request)...) } -func httpCommonAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { - attrs := []label.KeyValue{} +func httpCommonAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { + attrs := []attribute.KeyValue{} if ua := request.UserAgent(); ua != "" { attrs = append(attrs, HTTPUserAgentKey.String(ua)) } @@ -157,9 +157,9 @@ func httpCommonAttributesFromHTTPRequest(request *http.Request) []label.KeyValue return append(attrs, httpBasicAttributesFromHTTPRequest(request)...) } -func httpBasicAttributesFromHTTPRequest(request *http.Request) []label.KeyValue { +func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { // as these attributes are used by HTTPServerMetricAttributesFromHTTPRequest, they should be low-cardinality - attrs := []label.KeyValue{} + attrs := []attribute.KeyValue{} if request.TLS != nil { attrs = append(attrs, HTTPSchemeHTTPS) @@ -186,8 +186,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []label.KeyValue // HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes // to be used with server-side HTTP metrics. -func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []label.KeyValue { - attrs := []label.KeyValue{} +func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue { + attrs := []attribute.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) []label.KeyValue { - attrs := []label.KeyValue{ +func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue { + attrs := []attribute.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) []label.KeyValue { - attrs := []label.KeyValue{ +func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue { + attrs := []attribute.KeyValue{ HTTPStatusCodeKey.Int(code), } return attrs diff --git a/semconv/http_test.go b/semconv/http_test.go index 9db08af66e7..6dcf867ddbe 100644 --- a/semconv/http_test.go +++ b/semconv/http_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/attribute" "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 []label.KeyValue + expected []attribute.KeyValue } testcases := []testcase{ { @@ -62,8 +62,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), }, }, { @@ -78,8 +78,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.UDP"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.UDP"), }, }, { @@ -94,8 +94,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP"), }, }, { @@ -110,8 +110,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "Unix"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "Unix"), }, }, { @@ -126,8 +126,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "other"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "other"), }, }, { @@ -142,10 +142,10 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), - label.String("net.peer.ip", "1.2.3.4"), - label.Int("net.peer.port", 56), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), }, }, { @@ -160,10 +160,10 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), - label.String("net.peer.name", "example.com"), - label.Int("net.peer.port", 56), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.name", "example.com"), + attribute.Int("net.peer.port", 56), }, }, { @@ -178,9 +178,9 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), - label.String("net.peer.ip", "1.2.3.4"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), }, }, { @@ -195,9 +195,9 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), - label.String("net.peer.name", "example.com"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.name", "example.com"), }, }, { @@ -212,8 +212,8 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), }, }, { @@ -228,11 +228,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.name", "example.com"), }, }, { @@ -247,11 +247,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.ip", "4.3.2.1"), }, }, { @@ -266,12 +266,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.name", "example.com"), + attribute.Int("net.host.port", 78), }, }, { @@ -286,12 +286,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.ip", "4.3.2.1"), + attribute.Int("net.host.port", 78), }, }, { @@ -306,11 +306,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.name", "example.com"), }, }, { @@ -325,11 +325,11 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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"), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.ip", "4.3.2.1"), }, }, { @@ -344,10 +344,10 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - expected: []label.KeyValue{ - label.String("net.transport", "IP.TCP"), - label.String("net.peer.ip", "1.2.3.4"), - label.Int("net.peer.port", 56), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.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: []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), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.ip", "4.3.2.1"), + attribute.Int("net.host.port", 78), }, }, { @@ -385,12 +385,12 @@ func TestNetAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, header: nil, - 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), + expected: []attribute.KeyValue{ + attribute.String("net.transport", "IP.TCP"), + attribute.String("net.peer.ip", "1.2.3.4"), + attribute.Int("net.peer.port", 56), + attribute.String("net.host.ip", "4.3.2.1"), + attribute.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 []label.KeyValue + var expected []attribute.KeyValue got := EndUserAttributesFromHTTPRequest(r) assert.ElementsMatch(t, expected, got) r.SetBasicAuth("admin", "password") - expected = []label.KeyValue{label.String("enduser.id", "admin")} + expected = []attribute.KeyValue{attribute.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 []label.KeyValue + expected []attribute.KeyValue } testcases := []testcase{ { @@ -446,11 +446,11 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: noTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "http"), + attribute.String("http.flavor", "1.0"), }, }, { @@ -467,12 +467,12 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: noTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "http"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.server_name", "my-server-name"), }, }, { @@ -489,12 +489,12 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.server_name", "my-server-name"), }, }, { @@ -511,13 +511,13 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.server_name", "my-server-name"), + attribute.String("http.route", "/user/:id"), }, }, { @@ -534,14 +534,14 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.server_name", "my-server-name"), + attribute.String("http.route", "/user/:id"), + attribute.String("http.host", "example.com"), }, }, { @@ -560,15 +560,15 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.server_name", "my-server-name"), + attribute.String("http.route", "/user/:id"), + attribute.String("http.host", "example.com"), + attribute.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: []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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.server_name", "my-server-name"), + attribute.String("http.route", "/user/:id"), + attribute.String("http.host", "example.com"), + attribute.String("http.user_agent", "foodownloader"), + attribute.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: []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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.1"), + attribute.String("http.server_name", "my-server-name"), + attribute.String("http.route", "/user/:id"), + attribute.String("http.host", "example.com"), + attribute.String("http.user_agent", "foodownloader"), + attribute.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: []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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "2"), + attribute.String("http.server_name", "my-server-name"), + attribute.String("http.route", "/user/:id"), + attribute.String("http.host", "example.com"), + attribute.String("http.user_agent", "foodownloader"), + attribute.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: []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), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.target", "/user/123"), + attribute.String("http.scheme", "http"), + attribute.Int64("http.request_content_length", 100), }, }, } @@ -680,14 +680,14 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) { } func TestHTTPAttributesFromHTTPStatusCode(t *testing.T) { - expected := []label.KeyValue{ - label.Int("http.status_code", 404), + expected := []attribute.KeyValue{ + attribute.Int("http.status_code", 404), } got := HTTPAttributesFromHTTPStatusCode(http.StatusNotFound) assertElementsMatch(t, expected, got, "with valid HTTP status code") assert.ElementsMatch(t, expected, got) - expected = []label.KeyValue{ - label.Int("http.status_code", 499), + expected = []attribute.KeyValue{ + attribute.Int("http.status_code", 499), } got = HTTPAttributesFromHTTPStatusCode(499) assertElementsMatch(t, expected, got, "with invalid HTTP status code") @@ -723,7 +723,7 @@ func getExpectedCodeForHTTPCode(code int) codes.Code { return codes.Error } -func assertElementsMatch(t *testing.T, expected, got []label.KeyValue, format string, args ...interface{}) { +func assertElementsMatch(t *testing.T, expected, got []attribute.KeyValue, format string, args ...interface{}) { if !assert.ElementsMatchf(t, expected, got, format, args...) { t.Log("expected:", kvStr(expected)) t.Log("got:", kvStr(got)) @@ -765,7 +765,7 @@ func protoToInts(proto string) (int, int) { return 13, 42 } -func kvStr(kvs []label.KeyValue) string { +func kvStr(kvs []attribute.KeyValue) string { sb := strings.Builder{} sb.WriteRune('[') for idx, label := range kvs { @@ -794,7 +794,7 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { tls tlsOption contentLength int64 - expected []label.KeyValue + expected []attribute.KeyValue }{ { name: "stripped", @@ -808,11 +808,11 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: noTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "http"), + attribute.String("http.flavor", "1.0"), }, }, { @@ -827,11 +827,11 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), }, }, { @@ -846,12 +846,12 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { }, header: nil, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.host", "example.com"), }, }, { @@ -868,13 +868,13 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.0"), + attribute.String("http.host", "example.com"), + attribute.String("http.user_agent", "foodownloader"), }, }, { @@ -891,13 +891,13 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "1.1"), + attribute.String("http.host", "example.com"), + attribute.String("http.user_agent", "foodownloader"), }, }, { @@ -914,13 +914,13 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { "User-Agent": []string{"foodownloader"}, }, tls: withTLS, - 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"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "https"), + attribute.String("http.flavor", "2"), + attribute.String("http.host", "example.com"), + attribute.String("http.user_agent", "foodownloader"), }, }, { @@ -930,11 +930,11 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { Path: "/user/123", }, contentLength: 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), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "http"), + attribute.Int64("http.request_content_length", 100), }, }, { @@ -943,10 +943,10 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) { url: &url.URL{ Path: "/user/123", }, - expected: []label.KeyValue{ - label.String("http.method", "GET"), - label.String("http.url", "/user/123"), - label.String("http.scheme", "http"), + expected: []attribute.KeyValue{ + attribute.String("http.method", "GET"), + attribute.String("http.url", "/user/123"), + attribute.String("http.scheme", "http"), }, }, } diff --git a/semconv/resource.go b/semconv/resource.go index 59a326d27aa..733b8d46914 100644 --- a/semconv/resource.go +++ b/semconv/resource.go @@ -14,25 +14,25 @@ package semconv // import "go.opentelemetry.io/otel/semconv" -import "go.opentelemetry.io/otel/label" +import "go.opentelemetry.io/otel/attribute" // Semantic conventions for service resource attribute keys. const ( // Name of the service. - ServiceNameKey = label.Key("service.name") + ServiceNameKey = attribute.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 = label.Key("service.namespace") + ServiceNamespaceKey = attribute.Key("service.namespace") // A unique identifier of the service instance. In conjunction with the // `service.name` and `service.namespace` this must be unique. - ServiceInstanceIDKey = label.Key("service.instance.id") + ServiceInstanceIDKey = attribute.Key("service.instance.id") // The version of the service API. - ServiceVersionKey = label.Key("service.version") + ServiceVersionKey = attribute.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 = label.Key("telemetry.sdk.name") + TelemetrySDKNameKey = attribute.Key("telemetry.sdk.name") // The language of the telemetry SDK. - TelemetrySDKLanguageKey = label.Key("telemetry.sdk.language") + TelemetrySDKLanguageKey = attribute.Key("telemetry.sdk.language") // The version string of the telemetry SDK. - TelemetrySDKVersionKey = label.Key("telemetry.sdk.version") + TelemetrySDKVersionKey = attribute.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 = label.Key("container.name") + ContainerNameKey = attribute.Key("container.name") // Container ID, usually a UUID, as for example used to // identify Docker containers. The UUID might be abbreviated. - ContainerIDKey = label.Key("container.id") + ContainerIDKey = attribute.Key("container.id") // Name of the image the container was built on. - ContainerImageNameKey = label.Key("container.image.name") + ContainerImageNameKey = attribute.Key("container.image.name") // Container image tag. - ContainerImageTagKey = label.Key("container.image.tag") + ContainerImageTagKey = attribute.Key("container.image.tag") ) // Semantic conventions for Function-as-a-Service resource attribute keys. const ( // A uniquely identifying name for the FaaS. - FaaSNameKey = label.Key("faas.name") + FaaSNameKey = attribute.Key("faas.name") // The unique name of the function being executed. - FaaSIDKey = label.Key("faas.id") + FaaSIDKey = attribute.Key("faas.id") // The version of the function being executed. - FaaSVersionKey = label.Key("faas.version") + FaaSVersionKey = attribute.Key("faas.version") // The execution environment identifier. - FaaSInstanceKey = label.Key("faas.instance") + FaaSInstanceKey = attribute.Key("faas.instance") ) // Semantic conventions for operating system process resource attribute keys. const ( // Process identifier (PID). - ProcessPIDKey = label.Key("process.pid") + ProcessPIDKey = attribute.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 = label.Key("process.executable.name") + ProcessExecutableNameKey = attribute.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 = label.Key("process.executable.path") + ProcessExecutablePathKey = attribute.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 = label.Key("process.command") + ProcessCommandKey = attribute.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 = label.Key("process.command_line") + ProcessCommandLineKey = attribute.Key("process.command_line") // The username of the user that owns the process. - ProcessOwnerKey = label.Key("process.owner") + ProcessOwnerKey = attribute.Key("process.owner") ) // Semantic conventions for Kubernetes resource attribute keys. @@ -125,92 +125,92 @@ const ( // A uniquely identifying name for the Kubernetes cluster. Kubernetes // 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 = label.Key("k8s.cluster.name") + // GKE clusters have a name which can be used for this attribute. + K8SClusterNameKey = attribute.Key("k8s.cluster.name") // The name of the namespace that the pod is running in. - K8SNamespaceNameKey = label.Key("k8s.namespace.name") + K8SNamespaceNameKey = attribute.Key("k8s.namespace.name") // The uid of the Pod. - K8SPodUIDKey = label.Key("k8s.pod.uid") + K8SPodUIDKey = attribute.Key("k8s.pod.uid") // The name of the pod. - K8SPodNameKey = label.Key("k8s.pod.name") + K8SPodNameKey = attribute.Key("k8s.pod.name") // The name of the Container in a Pod template. - K8SContainerNameKey = label.Key("k8s.container.name") + K8SContainerNameKey = attribute.Key("k8s.container.name") // The uid of the ReplicaSet. - K8SReplicaSetUIDKey = label.Key("k8s.replicaset.uid") + K8SReplicaSetUIDKey = attribute.Key("k8s.replicaset.uid") // The name of the ReplicaSet. - K8SReplicaSetNameKey = label.Key("k8s.replicaset.name") + K8SReplicaSetNameKey = attribute.Key("k8s.replicaset.name") // The uid of the Deployment. - K8SDeploymentUIDKey = label.Key("k8s.deployment.uid") + K8SDeploymentUIDKey = attribute.Key("k8s.deployment.uid") // The name of the deployment. - K8SDeploymentNameKey = label.Key("k8s.deployment.name") + K8SDeploymentNameKey = attribute.Key("k8s.deployment.name") // The uid of the StatefulSet. - K8SStatefulSetUIDKey = label.Key("k8s.statefulset.uid") + K8SStatefulSetUIDKey = attribute.Key("k8s.statefulset.uid") // The name of the StatefulSet. - K8SStatefulSetNameKey = label.Key("k8s.statefulset.name") + K8SStatefulSetNameKey = attribute.Key("k8s.statefulset.name") // The uid of the DaemonSet. - K8SDaemonSetUIDKey = label.Key("k8s.daemonset.uid") + K8SDaemonSetUIDKey = attribute.Key("k8s.daemonset.uid") // The name of the DaemonSet. - K8SDaemonSetNameKey = label.Key("k8s.daemonset.name") + K8SDaemonSetNameKey = attribute.Key("k8s.daemonset.name") // The uid of the Job. - K8SJobUIDKey = label.Key("k8s.job.uid") + K8SJobUIDKey = attribute.Key("k8s.job.uid") // The name of the Job. - K8SJobNameKey = label.Key("k8s.job.name") + K8SJobNameKey = attribute.Key("k8s.job.name") // The uid of the CronJob. - K8SCronJobUIDKey = label.Key("k8s.cronjob.uid") + K8SCronJobUIDKey = attribute.Key("k8s.cronjob.uid") // The name of the CronJob. - K8SCronJobNameKey = label.Key("k8s.cronjob.name") + K8SCronJobNameKey = attribute.Key("k8s.cronjob.name") ) // Semantic conventions for host resource attribute keys. const ( // A uniquely identifying name for the host: 'hostname', FQDN, or user specified name - HostNameKey = label.Key("host.name") + HostNameKey = attribute.Key("host.name") // Unique host ID. For cloud environments this will be the instance ID. - HostIDKey = label.Key("host.id") + HostIDKey = attribute.Key("host.id") // Type of host. For cloud environments this will be the machine type. - HostTypeKey = label.Key("host.type") + HostTypeKey = attribute.Key("host.type") // Name of the OS or VM image the host is running. - HostImageNameKey = label.Key("host.image.name") + HostImageNameKey = attribute.Key("host.image.name") // Identifier of the image the host is running. - HostImageIDKey = label.Key("host.image.id") + HostImageIDKey = attribute.Key("host.image.id") // Version of the image the host is running. - HostImageVersionKey = label.Key("host.image.version") + HostImageVersionKey = attribute.Key("host.image.version") ) // Semantic conventions for cloud environment resource attribute keys. const ( // Name of the cloud provider. - CloudProviderKey = label.Key("cloud.provider") + CloudProviderKey = attribute.Key("cloud.provider") // The account ID from the cloud provider used for authorization. - CloudAccountIDKey = label.Key("cloud.account.id") + CloudAccountIDKey = attribute.Key("cloud.account.id") // Geographical region where this resource is. - CloudRegionKey = label.Key("cloud.region") + CloudRegionKey = attribute.Key("cloud.region") // Zone of the region where this resource is. - CloudZoneKey = label.Key("cloud.zone") + CloudZoneKey = attribute.Key("cloud.zone") ) // Semantic conventions for common cloud provider resource attributes. @@ -223,5 +223,5 @@ var ( // Semantic conventions for deployment attributes. const ( // Name of the deployment environment (aka deployment tier); e.g. (staging, production). - DeploymentEnvironmentKey = label.Key("deployment.environment") + DeploymentEnvironmentKey = attribute.Key("deployment.environment") ) diff --git a/semconv/trace.go b/semconv/trace.go index 5f780943cda..a90b471c02d 100644 --- a/semconv/trace.go +++ b/semconv/trace.go @@ -14,31 +14,31 @@ package semconv // import "go.opentelemetry.io/otel/semconv" -import "go.opentelemetry.io/otel/label" +import "go.opentelemetry.io/otel/attribute" // Semantic conventions for attribute keys used for network related // operations. const ( // Transport protocol used. - NetTransportKey = label.Key("net.transport") + NetTransportKey = attribute.Key("net.transport") // Remote address of the peer. - NetPeerIPKey = label.Key("net.peer.ip") + NetPeerIPKey = attribute.Key("net.peer.ip") // Remote port number. - NetPeerPortKey = label.Key("net.peer.port") + NetPeerPortKey = attribute.Key("net.peer.port") // Remote hostname or similar. - NetPeerNameKey = label.Key("net.peer.name") + NetPeerNameKey = attribute.Key("net.peer.name") // Local host IP. Useful in case of a multi-IP host. - NetHostIPKey = label.Key("net.host.ip") + NetHostIPKey = attribute.Key("net.host.ip") // Local host port. - NetHostPortKey = label.Key("net.host.port") + NetHostPortKey = attribute.Key("net.host.port") // Local hostname or similar. - NetHostNameKey = label.Key("net.host.name") + NetHostNameKey = attribute.Key("net.host.name") ) // Semantic conventions for common transport protocol attributes. @@ -56,7 +56,7 @@ var ( const ( // Service name of the remote service. Should equal the actual // `service.name` resource attribute of the remote service, if any. - PeerServiceKey = label.Key("peer.service") + PeerServiceKey = attribute.Key("peer.service") ) // Semantic conventions for attribute keys used to identify an authorized @@ -64,67 +64,67 @@ const ( const ( // Username or the client identifier extracted from the access token or // authorization header in the inbound request from outside the system. - EnduserIDKey = label.Key("enduser.id") + EnduserIDKey = attribute.Key("enduser.id") // Actual or assumed role the client is making the request with. - EnduserRoleKey = label.Key("enduser.role") + EnduserRoleKey = attribute.Key("enduser.role") // Scopes or granted authorities the client currently possesses. - EnduserScopeKey = label.Key("enduser.scope") + EnduserScopeKey = attribute.Key("enduser.scope") ) // Semantic conventions for attribute keys for HTTP. const ( // HTTP request method. - HTTPMethodKey = label.Key("http.method") + HTTPMethodKey = attribute.Key("http.method") // Full HTTP request URL in the form: // scheme://host[:port]/path?query[#fragment]. - HTTPURLKey = label.Key("http.url") + HTTPURLKey = attribute.Key("http.url") // The full request target as passed in a HTTP request line or // equivalent, e.g. "/path/12314/?q=ddds#123". - HTTPTargetKey = label.Key("http.target") + HTTPTargetKey = attribute.Key("http.target") // The value of the HTTP host header. - HTTPHostKey = label.Key("http.host") + HTTPHostKey = attribute.Key("http.host") // The URI scheme identifying the used protocol. - HTTPSchemeKey = label.Key("http.scheme") + HTTPSchemeKey = attribute.Key("http.scheme") // HTTP response status code. - HTTPStatusCodeKey = label.Key("http.status_code") + HTTPStatusCodeKey = attribute.Key("http.status_code") // Kind of HTTP protocol used. - HTTPFlavorKey = label.Key("http.flavor") + HTTPFlavorKey = attribute.Key("http.flavor") // Value of the HTTP User-Agent header sent by the client. - HTTPUserAgentKey = label.Key("http.user_agent") + HTTPUserAgentKey = attribute.Key("http.user_agent") // The primary server name of the matched virtual host. - HTTPServerNameKey = label.Key("http.server_name") + HTTPServerNameKey = attribute.Key("http.server_name") // The matched route served (path template). For example, // "/users/:userID?". - HTTPRouteKey = label.Key("http.route") + HTTPRouteKey = attribute.Key("http.route") // The IP address of the original client behind all proxies, if known // (e.g. from X-Forwarded-For). - HTTPClientIPKey = label.Key("http.client_ip") + HTTPClientIPKey = attribute.Key("http.client_ip") // The size of the request payload body in bytes. - HTTPRequestContentLengthKey = label.Key("http.request_content_length") + HTTPRequestContentLengthKey = attribute.Key("http.request_content_length") // The size of the uncompressed request payload body after transport decoding. // Not set if transport encoding not used. - HTTPRequestContentLengthUncompressedKey = label.Key("http.request_content_length_uncompressed") + HTTPRequestContentLengthUncompressedKey = attribute.Key("http.request_content_length_uncompressed") // The size of the response payload body in bytes. - HTTPResponseContentLengthKey = label.Key("http.response_content_length") + HTTPResponseContentLengthKey = attribute.Key("http.response_content_length") // The size of the uncompressed response payload body after transport decoding. // Not set if transport encoding not used. - HTTPResponseContentLengthUncompressedKey = label.Key("http.response_content_length_uncompressed") + HTTPResponseContentLengthUncompressedKey = attribute.Key("http.response_content_length_uncompressed") ) // Semantic conventions for common HTTP attributes. @@ -144,13 +144,13 @@ var ( // Semantic conventions for attribute keys for database connections. const ( // Identifier for the database system (DBMS) being used. - DBSystemKey = label.Key("db.system") + DBSystemKey = attribute.Key("db.system") // Database Connection String with embedded credentials removed. - DBConnectionStringKey = label.Key("db.connection_string") + DBConnectionStringKey = attribute.Key("db.connection_string") // Username for accessing database. - DBUserKey = label.Key("db.user") + DBUserKey = attribute.Key("db.user") ) // Semantic conventions for common database system attributes. @@ -180,56 +180,56 @@ var ( // Semantic conventions for attribute keys for database calls. const ( // Database instance name. - DBNameKey = label.Key("db.name") + DBNameKey = attribute.Key("db.name") // A database statement for the given database type. - DBStatementKey = label.Key("db.statement") + DBStatementKey = attribute.Key("db.statement") // A database operation for the given database type. - DBOperationKey = label.Key("db.operation") + DBOperationKey = attribute.Key("db.operation") ) // Database technology-specific attributes const ( // Name of the Cassandra keyspace accessed. Use instead of `db.name`. - DBCassandraKeyspaceKey = label.Key("db.cassandra.keyspace") + DBCassandraKeyspaceKey = attribute.Key("db.cassandra.keyspace") // HBase namespace accessed. Use instead of `db.name`. - DBHBaseNamespaceKey = label.Key("db.hbase.namespace") + DBHBaseNamespaceKey = attribute.Key("db.hbase.namespace") // Index of Redis database accessed. Use instead of `db.name`. - DBRedisDBIndexKey = label.Key("db.redis.database_index") + DBRedisDBIndexKey = attribute.Key("db.redis.database_index") // Collection being accessed within the database in `db.name`. - DBMongoDBCollectionKey = label.Key("db.mongodb.collection") + DBMongoDBCollectionKey = attribute.Key("db.mongodb.collection") ) // Semantic conventions for attribute keys for RPC. const ( // A string identifying the remoting system. - RPCSystemKey = label.Key("rpc.system") + RPCSystemKey = attribute.Key("rpc.system") // The full name of the service being called. - RPCServiceKey = label.Key("rpc.service") + RPCServiceKey = attribute.Key("rpc.service") // The name of the method being called. - RPCMethodKey = label.Key("rpc.method") + RPCMethodKey = attribute.Key("rpc.method") // Name of message transmitted or received. - RPCNameKey = label.Key("name") + RPCNameKey = attribute.Key("name") // Type of message transmitted or received. - RPCMessageTypeKey = label.Key("message.type") + RPCMessageTypeKey = attribute.Key("message.type") // Identifier of message transmitted or received. - RPCMessageIDKey = label.Key("message.id") + RPCMessageIDKey = attribute.Key("message.id") // The compressed size of the message transmitted or received in bytes. - RPCMessageCompressedSizeKey = label.Key("message.compressed_size") + RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size") // The uncompressed size of the message transmitted or received in // bytes. - RPCMessageUncompressedSizeKey = label.Key("message.uncompressed_size") + RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size") ) // Semantic conventions for common RPC attributes. @@ -249,44 +249,44 @@ var ( const ( // A unique identifier describing the messaging system. For example, // kafka, rabbitmq or activemq. - MessagingSystemKey = label.Key("messaging.system") + MessagingSystemKey = attribute.Key("messaging.system") // The message destination name, e.g. MyQueue or MyTopic. - MessagingDestinationKey = label.Key("messaging.destination") + MessagingDestinationKey = attribute.Key("messaging.destination") // The kind of message destination. - MessagingDestinationKindKey = label.Key("messaging.destination_kind") + MessagingDestinationKindKey = attribute.Key("messaging.destination_kind") // Describes if the destination is temporary or not. - MessagingTempDestinationKey = label.Key("messaging.temp_destination") + MessagingTempDestinationKey = attribute.Key("messaging.temp_destination") // The name of the transport protocol. - MessagingProtocolKey = label.Key("messaging.protocol") + MessagingProtocolKey = attribute.Key("messaging.protocol") // The version of the transport protocol. - MessagingProtocolVersionKey = label.Key("messaging.protocol_version") + MessagingProtocolVersionKey = attribute.Key("messaging.protocol_version") // Messaging service URL. - MessagingURLKey = label.Key("messaging.url") + MessagingURLKey = attribute.Key("messaging.url") // Identifier used by the messaging system for a message. - MessagingMessageIDKey = label.Key("messaging.message_id") + MessagingMessageIDKey = attribute.Key("messaging.message_id") // Identifier used by the messaging system for a conversation. - MessagingConversationIDKey = label.Key("messaging.conversation_id") + MessagingConversationIDKey = attribute.Key("messaging.conversation_id") // The (uncompressed) size of the message payload in bytes. - MessagingMessagePayloadSizeBytesKey = label.Key("messaging.message_payload_size_bytes") + MessagingMessagePayloadSizeBytesKey = attribute.Key("messaging.message_payload_size_bytes") // The compressed size of the message payload in bytes. - MessagingMessagePayloadCompressedSizeBytesKey = label.Key("messaging.message_payload_compressed_size_bytes") + MessagingMessagePayloadCompressedSizeBytesKey = attribute.Key("messaging.message_payload_compressed_size_bytes") // Identifies which part and kind of message consumption is being // preformed. - MessagingOperationKey = label.Key("messaging.operation") + MessagingOperationKey = attribute.Key("messaging.operation") // RabbitMQ specific attribute describing the destination routing key. - MessagingRabbitMQRoutingKeyKey = label.Key("messaging.rabbitmq.routing_key") + MessagingRabbitMQRoutingKeyKey = attribute.Key("messaging.rabbitmq.routing_key") ) // Semantic conventions for common messaging system attributes. @@ -309,34 +309,34 @@ var ( const ( // Type of the trigger on which the function is executed. - FaaSTriggerKey = label.Key("faas.trigger") + FaaSTriggerKey = attribute.Key("faas.trigger") // String containing the execution identifier of the function. - FaaSExecutionKey = label.Key("faas.execution") + FaaSExecutionKey = attribute.Key("faas.execution") // A boolean indicating that the serverless function is executed // for the first time (aka cold start). - FaaSColdstartKey = label.Key("faas.coldstart") + FaaSColdstartKey = attribute.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 = label.Key("faas.document.collection") + FaaSDocumentCollectionKey = attribute.Key("faas.document.collection") // The type of the operation that was performed on the data. - FaaSDocumentOperationKey = label.Key("faas.document.operation") + FaaSDocumentOperationKey = attribute.Key("faas.document.operation") // A string containing the time when the data was accessed. - FaaSDocumentTimeKey = label.Key("faas.document.time") + FaaSDocumentTimeKey = attribute.Key("faas.document.time") // The document name/table subjected to the operation. - FaaSDocumentNameKey = label.Key("faas.document.name") + FaaSDocumentNameKey = attribute.Key("faas.document.name") // The function invocation time. - FaaSTimeKey = label.Key("faas.time") + FaaSTimeKey = attribute.Key("faas.time") // The schedule period as Cron Expression. - FaaSCronKey = label.Key("faas.cron") + FaaSCronKey = attribute.Key("faas.cron") ) // Semantic conventions for common FaaS system attributes. diff --git a/trace/config.go b/trace/config.go index 9a343633d57..c320805901c 100644 --- a/trace/config.go +++ b/trace/config.go @@ -17,7 +17,7 @@ package trace import ( "time" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) // TracerConfig is a group of options for a Tracer. @@ -44,7 +44,7 @@ type TracerOption interface { // SpanConfig is a group of options for a Span. type SpanConfig struct { // Attributes describe the associated qualities of a Span. - Attributes []label.KeyValue + Attributes []attribute.KeyValue // Timestamp is a time in a Span life-cycle. Timestamp time.Time // Links are the associations a Span has with other Spans. @@ -104,12 +104,12 @@ type LifeCycleOption interface { EventOption } -type attributeSpanOption []label.KeyValue +type attributeSpanOption []attribute.KeyValue func (o attributeSpanOption) ApplySpan(c *SpanConfig) { o.apply(c) } func (o attributeSpanOption) ApplyEvent(c *SpanConfig) { o.apply(c) } func (o attributeSpanOption) apply(c *SpanConfig) { - c.Attributes = append(c.Attributes, []label.KeyValue(o)...) + c.Attributes = append(c.Attributes, []attribute.KeyValue(o)...) } // WithAttributes adds the attributes related to a span life-cycle event. @@ -121,7 +121,7 @@ func (o attributeSpanOption) apply(c *SpanConfig) { // If multiple of these options are passed the attributes of each successive // option will extend the attributes instead of overwriting. There is no // guarantee of uniqueness in the resulting attributes. -func WithAttributes(attributes ...label.KeyValue) LifeCycleOption { +func WithAttributes(attributes ...attribute.KeyValue) LifeCycleOption { return attributeSpanOption(attributes) } diff --git a/trace/config_test.go b/trace/config_test.go index e8fc99c89fe..b1e79d04f7b 100644 --- a/trace/config_test.go +++ b/trace/config_test.go @@ -20,24 +20,24 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/otel/label" + "go.opentelemetry.io/otel/attribute" ) func TestNewSpanConfig(t *testing.T) { - k1v1 := label.String("key1", "value1") - k1v2 := label.String("key1", "value2") - k2v2 := label.String("key2", "value2") + k1v1 := attribute.String("key1", "value1") + k1v2 := attribute.String("key1", "value2") + k2v2 := attribute.String("key2", "value2") timestamp0 := time.Unix(0, 0) timestamp1 := time.Unix(0, 0) link1 := Link{ SpanContext: SpanContext{TraceID: TraceID([16]byte{1, 1}), SpanID: SpanID{3}}, - Attributes: []label.KeyValue{k1v1}, + Attributes: []attribute.KeyValue{k1v1}, } link2 := Link{ SpanContext: SpanContext{TraceID: TraceID([16]byte{1, 1}), SpanID: SpanID{3}}, - Attributes: []label.KeyValue{k1v2, k2v2}, + Attributes: []attribute.KeyValue{k1v2, k2v2}, } tests := []struct { @@ -54,7 +54,7 @@ func TestNewSpanConfig(t *testing.T) { WithAttributes(k1v1), }, &SpanConfig{ - Attributes: []label.KeyValue{k1v1}, + Attributes: []attribute.KeyValue{k1v1}, }, }, { @@ -66,7 +66,7 @@ func TestNewSpanConfig(t *testing.T) { }, &SpanConfig{ // No uniqueness is guaranteed by the API. - Attributes: []label.KeyValue{k1v1, k1v2, k2v2}, + Attributes: []attribute.KeyValue{k1v1, k1v2, k2v2}, }, }, { @@ -75,7 +75,7 @@ func TestNewSpanConfig(t *testing.T) { }, &SpanConfig{ // No uniqueness is guaranteed by the API. - Attributes: []label.KeyValue{k1v1, k1v2, k2v2}, + Attributes: []attribute.KeyValue{k1v1, k1v2, k2v2}, }, }, { @@ -180,7 +180,7 @@ func TestNewSpanConfig(t *testing.T) { WithSpanKind(SpanKindConsumer), }, &SpanConfig{ - Attributes: []label.KeyValue{k1v1}, + Attributes: []attribute.KeyValue{k1v1}, Timestamp: timestamp0, Links: []Link{link1, link2}, Record: true, diff --git a/trace/trace.go b/trace/trace.go index 1c1e85ad9d4..9b390082299 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -23,8 +23,8 @@ import ( "strings" "time" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" ) const ( @@ -183,9 +183,9 @@ func decodeHex(h string, b []byte) error { // Trace state must be valid according to the W3C Trace Context specification at all times. All // mutating operations validate their input and, in case of valid parameters, return a new TraceState. type TraceState struct { //nolint:golint - // TODO @matej-g: Consider implementing this as label.Set, see + // TODO @matej-g: Consider implementing this as attribute.Set, see // comment https://github.com/open-telemetry/opentelemetry-go/pull/1340#discussion_r540599226 - kvs []label.KeyValue + kvs []attribute.KeyValue } var _ json.Marshaler = TraceState{} @@ -219,9 +219,9 @@ func (ts TraceState) String() string { // Get returns a value for given key from the trace state. // If no key is found or provided key is invalid, returns an empty value. -func (ts TraceState) Get(key label.Key) label.Value { +func (ts TraceState) Get(key attribute.Key) attribute.Value { if !isTraceStateKeyValid(key) { - return label.Value{} + return attribute.Value{} } for _, kv := range ts.kvs { @@ -230,13 +230,13 @@ func (ts TraceState) Get(key label.Key) label.Value { } } - return label.Value{} + return attribute.Value{} } // Insert adds a new key/value, if one doesn't exists; otherwise updates the existing entry. // The new or updated entry is always inserted at the beginning of the TraceState, i.e. // on the left side, as per the W3C Trace Context specification requirement. -func (ts TraceState) Insert(entry label.KeyValue) (TraceState, error) { +func (ts TraceState) Insert(entry attribute.KeyValue) (TraceState, error) { if !isTraceStateKeyValueValid(entry) { return ts, errInvalidTraceStateKeyValue } @@ -246,7 +246,7 @@ func (ts TraceState) Insert(entry label.KeyValue) (TraceState, error) { return ts, errInvalidTraceStateMembersNumber } - ckvs = append(ckvs, label.KeyValue{}) + ckvs = append(ckvs, attribute.KeyValue{}) copy(ckvs[1:], ckvs) ckvs[0] = entry @@ -254,7 +254,7 @@ func (ts TraceState) Insert(entry label.KeyValue) (TraceState, error) { } // Delete removes specified entry from the trace state. -func (ts TraceState) Delete(key label.Key) (TraceState, error) { +func (ts TraceState) Delete(key attribute.Key) (TraceState, error) { if !isTraceStateKeyValid(key) { return ts, errInvalidTraceStateKeyValue } @@ -267,8 +267,8 @@ func (ts TraceState) IsEmpty() bool { return len(ts.kvs) == 0 } -func (ts TraceState) copyKVsAndDeleteEntry(key label.Key) []label.KeyValue { - ckvs := make([]label.KeyValue, len(ts.kvs)) +func (ts TraceState) copyKVsAndDeleteEntry(key attribute.Key) []attribute.KeyValue { + ckvs := make([]attribute.KeyValue, len(ts.kvs)) copy(ckvs, ts.kvs) for i, kv := range ts.kvs { if kv.Key == key { @@ -282,7 +282,7 @@ func (ts TraceState) copyKVsAndDeleteEntry(key label.Key) []label.KeyValue { // TraceStateFromKeyValues is a convenience method to create a new TraceState from // provided key/value pairs. -func TraceStateFromKeyValues(kvs ...label.KeyValue) (TraceState, error) { //nolint:golint +func TraceStateFromKeyValues(kvs ...attribute.KeyValue) (TraceState, error) { //nolint:golint if len(kvs) == 0 { return TraceState{}, nil } @@ -291,7 +291,7 @@ func TraceStateFromKeyValues(kvs ...label.KeyValue) (TraceState, error) { //noli return TraceState{}, errInvalidTraceStateMembersNumber } - km := make(map[label.Key]bool) + km := make(map[attribute.Key]bool) for _, kv := range kvs { if !isTraceStateKeyValueValid(kv) { return TraceState{}, errInvalidTraceStateKeyValue @@ -303,16 +303,16 @@ func TraceStateFromKeyValues(kvs ...label.KeyValue) (TraceState, error) { //noli km[kv.Key] = true } - ckvs := make([]label.KeyValue, len(kvs)) + ckvs := make([]attribute.KeyValue, len(kvs)) copy(ckvs, kvs) return TraceState{ckvs}, nil } -func isTraceStateKeyValid(key label.Key) bool { +func isTraceStateKeyValid(key attribute.Key) bool { return keyFormatRegExp.MatchString(string(key)) } -func isTraceStateKeyValueValid(kv label.KeyValue) bool { +func isTraceStateKeyValueValid(kv attribute.KeyValue) bool { return isTraceStateKeyValid(kv.Key) && valueFormatRegExp.MatchString(kv.Value.Emit()) } @@ -438,7 +438,7 @@ type Span interface { // SetAttributes sets kv as attributes of the Span. If a key from kv // already exists for an attribute of the Span it will be overwritten with // the value contained in kv. - SetAttributes(kv ...label.KeyValue) + SetAttributes(kv ...attribute.KeyValue) } // Event is a thing that happened during a Span's lifetime. @@ -447,7 +447,7 @@ type Event struct { Name string // Attributes describe the aspects of the event. - Attributes []label.KeyValue + Attributes []attribute.KeyValue // Time at which this event was recorded. Time time.Time @@ -470,7 +470,7 @@ type Event struct { // track the relationship. type Link struct { SpanContext - Attributes []label.KeyValue + Attributes []attribute.KeyValue } // SpanKind is the role a Span plays in a Trace. diff --git a/trace/trace_noop.go b/trace/trace_noop.go index 6f18a948196..e47d506979a 100644 --- a/trace/trace_noop.go +++ b/trace/trace_noop.go @@ -17,8 +17,8 @@ package trace // import "go.opentelemetry.io/otel/trace" import ( "context" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/label" ) // NewNoopTracerProvider returns an implementation of TracerProvider that @@ -66,7 +66,7 @@ func (noopSpan) SetStatus(codes.Code, string) {} func (noopSpan) SetError(bool) {} // SetAttributes does nothing. -func (noopSpan) SetAttributes(...label.KeyValue) {} +func (noopSpan) SetAttributes(...attribute.KeyValue) {} // End does nothing. func (noopSpan) End(...SpanOption) {} diff --git a/trace/trace_test.go b/trace/trace_test.go index 2b6ecd64c04..f9635fd67b3 100644 --- a/trace/trace_test.go +++ b/trace/trace_test.go @@ -19,10 +19,10 @@ import ( "fmt" "testing" - "go.opentelemetry.io/otel/label" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "go.opentelemetry.io/otel/attribute" ) type testSpan struct { @@ -452,10 +452,10 @@ func TestTraceStateString(t *testing.T) { { name: "Non-empty trace state", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3@vendor", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3@vendor", "val3"), }, }, expectedStr: "key1=val1,key2=val2,key3@vendor=val3", @@ -478,7 +478,7 @@ func TestTraceStateGet(t *testing.T) { testCases := []struct { name string traceState TraceState - key label.Key + key attribute.Key expectedValue string }{ { @@ -513,60 +513,60 @@ func TestTraceStateDelete(t *testing.T) { testCases := []struct { name string traceState TraceState - key label.Key + key attribute.Key expectedTraceState TraceState expectedErr error }{ { name: "OK case", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, key: "key2", expectedTraceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key3", "val3"), }, }, }, { name: "Non-existing key", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, key: "keyx", expectedTraceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, }, { name: "Invalid key", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, key: "in va lid", expectedTraceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, expectedErr: errInvalidTraceStateKeyValue, @@ -592,58 +592,58 @@ func TestTraceStateInsert(t *testing.T) { testCases := []struct { name string traceState TraceState - keyValue label.KeyValue + keyValue attribute.KeyValue expectedTraceState TraceState expectedErr error }{ { name: "OK case - add new", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, - keyValue: label.String("key4@vendor", "val4"), + keyValue: attribute.String("key4@vendor", "val4"), expectedTraceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key4@vendor", "val4"), - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key4@vendor", "val4"), + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, }, { name: "OK case - replace", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key2", "val2"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key2", "val2"), + attribute.String("key3", "val3"), }, }, - keyValue: label.String("key2", "valX"), + keyValue: attribute.String("key2", "valX"), expectedTraceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key2", "valX"), - label.String("key1", "val1"), - label.String("key3", "val3"), + kvs: []attribute.KeyValue{ + attribute.String("key2", "valX"), + attribute.String("key1", "val1"), + attribute.String("key3", "val3"), }, }, }, { name: "Invalid key/value", traceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), }, }, - keyValue: label.String("key!", "val!"), + keyValue: attribute.String("key!", "val!"), expectedTraceState: TraceState{ - kvs: []label.KeyValue{ - label.String("key1", "val1"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), }, }, expectedErr: errInvalidTraceStateKeyValue, @@ -651,7 +651,7 @@ func TestTraceStateInsert(t *testing.T) { { name: "Too many entries", traceState: TraceState{kvsWithMaxMembers}, - keyValue: label.String("keyx", "valx"), + keyValue: attribute.String("keyx", "valx"), expectedTraceState: TraceState{kvsWithMaxMembers}, expectedErr: errInvalidTraceStateMembersNumber, }, @@ -675,7 +675,7 @@ func TestTraceStateInsert(t *testing.T) { func TestTraceStateFromKeyValues(t *testing.T) { testCases := []struct { name string - kvs []label.KeyValue + kvs []attribute.KeyValue expectedTraceState TraceState expectedErr error }{ @@ -690,9 +690,9 @@ func TestTraceStateFromKeyValues(t *testing.T) { }, { name: "Too many entries", - kvs: func() []label.KeyValue { + kvs: func() []attribute.KeyValue { kvs := kvsWithMaxMembers - kvs = append(kvs, label.String("keyx", "valX")) + kvs = append(kvs, attribute.String("keyx", "valX")) return kvs }(), expectedTraceState: TraceState{}, @@ -700,17 +700,17 @@ func TestTraceStateFromKeyValues(t *testing.T) { }, { name: "Duplicate", - kvs: []label.KeyValue{ - label.String("key1", "val1"), - label.String("key1", "val2"), + kvs: []attribute.KeyValue{ + attribute.String("key1", "val1"), + attribute.String("key1", "val2"), }, expectedTraceState: TraceState{}, expectedErr: errInvalidTraceStateDuplicate, }, { name: "Invalid key/value", - kvs: []label.KeyValue{ - label.String("key!", "val!"), + kvs: []attribute.KeyValue{ + attribute.String("key!", "val!"), }, expectedTraceState: TraceState{}, expectedErr: errInvalidTraceStateKeyValue, @@ -755,10 +755,10 @@ func assertTraceStateEqual(got TraceState, want TraceState) bool { return true } -var kvsWithMaxMembers = func() []label.KeyValue { - kvs := make([]label.KeyValue, traceStateMaxListMembers) +var kvsWithMaxMembers = func() []attribute.KeyValue { + kvs := make([]attribute.KeyValue, traceStateMaxListMembers) for i := 0; i < traceStateMaxListMembers; i++ { - kvs[i] = label.String(fmt.Sprintf("key%d", i+1), + kvs[i] = attribute.String(fmt.Sprintf("key%d", i+1), fmt.Sprintf("value%d", i+1)) } return kvs