1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-03-19 21:08:07 +02:00

Rename otel/label -> otel/attribute (#1541)

* Rename otel/label -> otel/attr

Leave the imported name alone, to avoid a large diff and conflicts

* Better import comment

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* otel/attr -> otel/attribute

* Missed the changelog entry

* Get rid of import renaming

* Merge remaining conflicts

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
This commit is contained in:
Punya Biswal 2021-02-18 12:59:37 -05:00 committed by GitHub
parent 1b5b662136
commit ecf65d7968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
123 changed files with 1715 additions and 1715 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -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"

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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.

View File

@ -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)

View File

@ -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"

View File

@ -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: "<nil>",
},
{
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)
}

View File

@ -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

View File

@ -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", 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", 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,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)

View File

@ -1,6 +1,6 @@
// Code generated by "stringer -type=Type"; DO NOT EDIT.
package label
package attribute
import "strconv"

View File

@ -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"

View File

@ -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)

View File

@ -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,
})

View File

@ -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")
}

View File

@ -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),
}),
)
}

View File

@ -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" {

View File

@ -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)),
}
}

View File

@ -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...)
}

View File

@ -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,
},
}

View File

@ -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()}),

View File

@ -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.

View File

@ -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)

View File

@ -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

View File

@ -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")

View File

@ -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()

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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}),

View File

@ -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

View File

@ -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))
}

View File

@ -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) {

View File

@ -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)

View File

@ -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",

View File

@ -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() {

View File

@ -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",

View File

@ -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...)

View File

@ -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) {

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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,

View File

@ -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)
}

View File

@ -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"),
},
},
},

View File

@ -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),

View File

@ -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,

View File

@ -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()

View File

@ -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,

View File

@ -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,
}))

View File

@ -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)
}

View File

@ -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()

View File

@ -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)
}

View File

@ -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...)

View File

@ -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

View File

@ -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),
},
})
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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) {
}

View File

@ -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

View File

@ -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) {

View File

@ -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...)
}

View File

@ -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
}

View File

@ -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{

View File

@ -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
}

View File

@ -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

View File

@ -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...))

View File

@ -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 {

View File

@ -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"),
},
}

View File

@ -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 {

View File

@ -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",

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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())

View File

@ -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,

View File

@ -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

View File

@ -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()

View File

@ -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)

View File

@ -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(

View File

@ -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{

View File

@ -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())

View File

@ -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))
}

View File

@ -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

View File

@ -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{

View File

@ -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),

View File

@ -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())

View File

@ -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
// ...

View File

@ -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
}
)

View File

@ -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)

View File

@ -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 {

View File

@ -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...)
},

View File

@ -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)))
}
}

View File

@ -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}
}

View File

@ -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")
})),
)

Some files were not shown because too many files have changed in this diff Show More