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 - Replaced interface `oteltest.SpanRecorder` with its existing implementation
`StandardSpanRecorder` (#1542). `StandardSpanRecorder` (#1542).
- Renamed the `otel/label` package to `otel/attribute`. (#1541)
### Added ### Added

View File

@ -12,40 +12,40 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label_test package attribute_test
import ( import (
"testing" "testing"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
type test struct{} type test struct{}
var ( var (
arrayVal = []string{"one", "two"} arrayVal = []string{"one", "two"}
arrayKeyVal = label.Array("array", arrayVal) arrayKeyVal = attribute.Array("array", arrayVal)
boolVal = true boolVal = true
boolKeyVal = label.Bool("bool", boolVal) boolKeyVal = attribute.Bool("bool", boolVal)
intVal = int(1) intVal = int(1)
intKeyVal = label.Int("int", intVal) intKeyVal = attribute.Int("int", intVal)
int8Val = int8(1) int8Val = int8(1)
int8KeyVal = label.Int("int8", int(int8Val)) int8KeyVal = attribute.Int("int8", int(int8Val))
int16Val = int16(1) int16Val = int16(1)
int16KeyVal = label.Int("int16", int(int16Val)) int16KeyVal = attribute.Int("int16", int(int16Val))
int64Val = int64(1) int64Val = int64(1)
int64KeyVal = label.Int64("int64", int64Val) int64KeyVal = attribute.Int64("int64", int64Val)
float64Val = float64(1.0) float64Val = float64(1.0)
float64KeyVal = label.Float64("float64", float64Val) float64KeyVal = attribute.Float64("float64", float64Val)
stringVal = "string" stringVal = "string"
stringKeyVal = label.String("string", stringVal) stringKeyVal = attribute.String("string", stringVal)
bytesVal = []byte("bytes") bytesVal = []byte("bytes")
structVal = test{} structVal = test{}
@ -54,112 +54,112 @@ var (
func BenchmarkArrayKey(b *testing.B) { func BenchmarkArrayKey(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Array("array", arrayVal) _ = attribute.Array("array", arrayVal)
} }
} }
func BenchmarkArrayKeyAny(b *testing.B) { func BenchmarkArrayKeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("array", arrayVal) _ = attribute.Any("array", arrayVal)
} }
} }
func BenchmarkBoolKey(b *testing.B) { func BenchmarkBoolKey(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Bool("bool", boolVal) _ = attribute.Bool("bool", boolVal)
} }
} }
func BenchmarkBoolKeyAny(b *testing.B) { func BenchmarkBoolKeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("bool", boolVal) _ = attribute.Any("bool", boolVal)
} }
} }
func BenchmarkIntKey(b *testing.B) { func BenchmarkIntKey(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Int("int", intVal) _ = attribute.Int("int", intVal)
} }
} }
func BenchmarkIntKeyAny(b *testing.B) { func BenchmarkIntKeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("int", intVal) _ = attribute.Any("int", intVal)
} }
} }
func BenchmarkInt8KeyAny(b *testing.B) { func BenchmarkInt8KeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("int8", int8Val) _ = attribute.Any("int8", int8Val)
} }
} }
func BenchmarkInt16KeyAny(b *testing.B) { func BenchmarkInt16KeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("int16", int16Val) _ = attribute.Any("int16", int16Val)
} }
} }
func BenchmarkInt64Key(b *testing.B) { func BenchmarkInt64Key(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Int64("int64", int64Val) _ = attribute.Int64("int64", int64Val)
} }
} }
func BenchmarkInt64KeyAny(b *testing.B) { func BenchmarkInt64KeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("int64", int64Val) _ = attribute.Any("int64", int64Val)
} }
} }
func BenchmarkFloat64Key(b *testing.B) { func BenchmarkFloat64Key(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Float64("float64", float64Val) _ = attribute.Float64("float64", float64Val)
} }
} }
func BenchmarkFloat64KeyAny(b *testing.B) { func BenchmarkFloat64KeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("float64", float64Val) _ = attribute.Any("float64", float64Val)
} }
} }
func BenchmarkStringKey(b *testing.B) { func BenchmarkStringKey(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.String("string", stringVal) _ = attribute.String("string", stringVal)
} }
} }
func BenchmarkStringKeyAny(b *testing.B) { func BenchmarkStringKeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("string", stringVal) _ = attribute.Any("string", stringVal)
} }
} }
func BenchmarkBytesKeyAny(b *testing.B) { func BenchmarkBytesKeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = label.Any("bytes", bytesVal) _ = attribute.Any("bytes", bytesVal)
} }
} }
func BenchmarkStructKeyAny(b *testing.B) { func BenchmarkStructKeyAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { 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 // See the License for the specific language governing permissions and
// limitations under the License. // 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 // 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 // may be introduced in subsequent minor version releases as we work to track
// the evolving OpenTelemetry specification and user feedback. // 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 // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label // import "go.opentelemetry.io/otel/label" package attribute // import "go.opentelemetry.io/otel/attribute"
import ( import (
"bytes" "bytes"
@ -28,7 +28,7 @@ type (
Encoder interface { Encoder interface {
// Encode returns the serialized encoding of the label // Encode returns the serialized encoding of the label
// set using its Iterator. This result may be cached // set using its Iterator. This result may be cached
// by a label.Set. // by a attribute.Set.
Encode(iterator Iterator) string Encode(iterator Iterator) string
// ID returns a value that is unique for each class of // 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 // See the License for the specific language governing permissions and
// limitations under the License. // 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, // Iterator allows iterating over the set of labels in order,
// sorted by key. // sorted by key.
@ -55,7 +55,7 @@ func (i *Iterator) Attribute() KeyValue {
return i.Label() 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. // after Next returns true.
func (i *Iterator) IndexedLabel() (int, KeyValue) { func (i *Iterator) IndexedLabel() (int, KeyValue) {
return i.idx, i.Label() return i.idx, i.Label()

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label_test package attribute_test
import ( import (
"fmt" "fmt"
@ -20,13 +20,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
func TestIterator(t *testing.T) { func TestIterator(t *testing.T) {
one := label.String("one", "1") one := attribute.String("one", "1")
two := label.Int("two", 2) two := attribute.Int("two", 2)
lbl := label.NewSet(one, two) lbl := attribute.NewSet(one, two)
iter := lbl.Iter() iter := lbl.Iter()
require.Equal(t, 2, iter.Len()) require.Equal(t, 2, iter.Len())
@ -49,7 +49,7 @@ func TestIterator(t *testing.T) {
} }
func TestEmptyIterator(t *testing.T) { func TestEmptyIterator(t *testing.T) {
lbl := label.NewSet() lbl := attribute.NewSet()
iter := lbl.Iter() iter := lbl.Iter()
require.Equal(t, 0, iter.Len()) require.Equal(t, 0, iter.Len())
require.False(t, iter.Next()) require.False(t, iter.Next())
@ -64,9 +64,9 @@ func TestMergedIterator(t *testing.T) {
expect []string expect []string
} }
makeLabels := func(keys []string, num int) (result []label.KeyValue) { makeLabels := func(keys []string, num int) (result []attribute.KeyValue) {
for _, k := range keys { for _, k := range keys {
result = append(result, label.Int(k, num)) result = append(result, attribute.Int(k, num))
} }
return return
} }
@ -131,10 +131,10 @@ func TestMergedIterator(t *testing.T) {
labels1 := makeLabels(input.keys1, 1) labels1 := makeLabels(input.keys1, 1)
labels2 := makeLabels(input.keys2, 2) labels2 := makeLabels(input.keys2, 2)
set1 := label.NewSet(labels1...) set1 := attribute.NewSet(labels1...)
set2 := label.NewSet(labels2...) set2 := attribute.NewSet(labels2...)
merge := label.NewMergeIterator(&set1, &set2) merge := attribute.NewMergeIterator(&set1, &set2)
var result []string var result []string

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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 // 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. // 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 // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label_test package attribute_test
import ( import (
"encoding/json" "encoding/json"
@ -20,28 +20,28 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
func TestDefined(t *testing.T) { func TestDefined(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
k label.Key k attribute.Key
want bool want bool
}{ }{
{ {
name: "Key.Defined() returns true when len(v.Name) != 0", name: "Key.Defined() returns true when len(v.Name) != 0",
k: label.Key("foo"), k: attribute.Key("foo"),
want: true, want: true,
}, },
{ {
name: "Key.Defined() returns false when len(v.Name) == 0", name: "Key.Defined() returns false when len(v.Name) == 0",
k: label.Key(""), k: attribute.Key(""),
want: false, want: false,
}, },
} { } {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
//func (k label.Key) Defined() bool { //func (k attribute.Key) Defined() bool {
have := testcase.k.Defined() have := testcase.k.Defined()
if have != testcase.want { if have != testcase.want {
t.Errorf("Want: %v, but have: %v", testcase.want, have) t.Errorf("Want: %v, but have: %v", testcase.want, have)
@ -51,9 +51,9 @@ func TestDefined(t *testing.T) {
} }
func TestJSONValue(t *testing.T) { func TestJSONValue(t *testing.T) {
var kvs interface{} = [2]label.KeyValue{ var kvs interface{} = [2]attribute.KeyValue{
label.String("A", "B"), attribute.String("A", "B"),
label.Int64("C", 1), attribute.Int64("C", 1),
} }
data, err := json.Marshal(kvs) data, err := json.Marshal(kvs)
@ -66,32 +66,32 @@ func TestJSONValue(t *testing.T) {
func TestEmit(t *testing.T) { func TestEmit(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
v label.Value v attribute.Value
want string want string
}{ }{
{ {
name: `test Key.Emit() can emit a string representing self.BOOL`, name: `test Key.Emit() can emit a string representing self.BOOL`,
v: label.BoolValue(true), v: attribute.BoolValue(true),
want: "true", want: "true",
}, },
{ {
name: `test Key.Emit() can emit a string representing self.INT64`, name: `test Key.Emit() can emit a string representing self.INT64`,
v: label.Int64Value(42), v: attribute.Int64Value(42),
want: "42", want: "42",
}, },
{ {
name: `test Key.Emit() can emit a string representing self.FLOAT64`, name: `test Key.Emit() can emit a string representing self.FLOAT64`,
v: label.Float64Value(42.1), v: attribute.Float64Value(42.1),
want: "42.1", want: "42.1",
}, },
{ {
name: `test Key.Emit() can emit a string representing self.STRING`, name: `test Key.Emit() can emit a string representing self.STRING`,
v: label.StringValue("foo"), v: attribute.StringValue("foo"),
want: "foo", want: "foo",
}, },
} { } {
t.Run(testcase.name, func(t *testing.T) { 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() have := testcase.v.Emit()
if have != testcase.want { if have != testcase.want {
t.Errorf("Want: %s, but have: %s", testcase.want, have) 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 // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label // import "go.opentelemetry.io/otel/label" package attribute // import "go.opentelemetry.io/otel/attribute"
import ( import (
"encoding/json" "encoding/json"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label_test package attribute_test
import ( import (
"strings" "strings"
@ -20,60 +20,60 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
func TestKeyValueConstructors(t *testing.T) { func TestKeyValueConstructors(t *testing.T) {
tt := []struct { tt := []struct {
name string name string
actual label.KeyValue actual attribute.KeyValue
expected label.KeyValue expected attribute.KeyValue
}{ }{
{ {
name: "Bool", name: "Bool",
actual: label.Bool("k1", true), actual: attribute.Bool("k1", true),
expected: label.KeyValue{ expected: attribute.KeyValue{
Key: "k1", Key: "k1",
Value: label.BoolValue(true), Value: attribute.BoolValue(true),
}, },
}, },
{ {
name: "Int64", name: "Int64",
actual: label.Int64("k1", 123), actual: attribute.Int64("k1", 123),
expected: label.KeyValue{ expected: attribute.KeyValue{
Key: "k1", Key: "k1",
Value: label.Int64Value(123), Value: attribute.Int64Value(123),
}, },
}, },
{ {
name: "Float64", name: "Float64",
actual: label.Float64("k1", 123.5), actual: attribute.Float64("k1", 123.5),
expected: label.KeyValue{ expected: attribute.KeyValue{
Key: "k1", Key: "k1",
Value: label.Float64Value(123.5), Value: attribute.Float64Value(123.5),
}, },
}, },
{ {
name: "String", name: "String",
actual: label.String("k1", "123.5"), actual: attribute.String("k1", "123.5"),
expected: label.KeyValue{ expected: attribute.KeyValue{
Key: "k1", Key: "k1",
Value: label.StringValue("123.5"), Value: attribute.StringValue("123.5"),
}, },
}, },
{ {
name: "Int", name: "Int",
actual: label.Int("k1", 123), actual: attribute.Int("k1", 123),
expected: label.KeyValue{ expected: attribute.KeyValue{
Key: "k1", Key: "k1",
Value: label.IntValue(123), Value: attribute.IntValue(123),
}, },
}, },
} }
for _, test := range tt { for _, test := range tt {
t.Run(test.name, func(t *testing.T) { 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) t.Fatal(diff)
} }
}) })
@ -97,60 +97,60 @@ func TestAny(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
key string key string
value interface{} value interface{}
wantType label.Type wantType attribute.Type
wantValue interface{} wantValue interface{}
}{ }{
{ {
key: "bool type inferred", key: "bool type inferred",
value: true, value: true,
wantType: label.BOOL, wantType: attribute.BOOL,
wantValue: true, wantValue: true,
}, },
{ {
key: "int64 type inferred", key: "int64 type inferred",
value: int64(42), value: int64(42),
wantType: label.INT64, wantType: attribute.INT64,
wantValue: int64(42), wantValue: int64(42),
}, },
{ {
key: "float64 type inferred", key: "float64 type inferred",
value: float64(42.1), value: float64(42.1),
wantType: label.FLOAT64, wantType: attribute.FLOAT64,
wantValue: 42.1, wantValue: 42.1,
}, },
{ {
key: "string type inferred", key: "string type inferred",
value: "foo", value: "foo",
wantType: label.STRING, wantType: attribute.STRING,
wantValue: "foo", wantValue: "foo",
}, },
{ {
key: "stringer type inferred", key: "stringer type inferred",
value: builder, value: builder,
wantType: label.STRING, wantType: attribute.STRING,
wantValue: "foo", wantValue: "foo",
}, },
{ {
key: "unknown value serialized as %v", key: "unknown value serialized as %v",
value: nil, value: nil,
wantType: label.STRING, wantType: attribute.STRING,
wantValue: "<nil>", wantValue: "<nil>",
}, },
{ {
key: "JSON struct serialized correctly", key: "JSON struct serialized correctly",
value: &jsonifyStruct, value: &jsonifyStruct,
wantType: label.STRING, wantType: attribute.STRING,
wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`, wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`,
}, },
{ {
key: "Invalid JSON struct falls back to string", key: "Invalid JSON struct falls back to string",
value: &invalidStruct, value: &invalidStruct,
wantType: label.STRING, wantType: attribute.STRING,
wantValue: "&{(0+0i)}", wantValue: "&{(0+0i)}",
}, },
} { } {
t.Logf("Running test case %s", testcase.key) 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 { if keyValue.Value.Type() != testcase.wantType {
t.Errorf("wrong value type, got %#v, expected %#v", 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 // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label // import "go.opentelemetry.io/otel/label" package attribute // import "go.opentelemetry.io/otel/attribute"
import ( import (
"encoding/json" "encoding/json"
@ -295,7 +295,7 @@ func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
// - allocating a `Set` for storing the return value of this // - allocating a `Set` for storing the return value of this
// constructor. // 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. // This value should not be copied after its first use.
// //
// The second `[]KeyValue` return value is a list of labels that were // 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 // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label_test package attribute_test
import ( import (
"regexp" "regexp"
"testing" "testing"
"go.opentelemetry.io/otel/label"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
) )
type testCase struct { type testCase struct {
kvs []label.KeyValue kvs []attribute.KeyValue
keyRe *regexp.Regexp keyRe *regexp.Regexp
@ -32,14 +32,14 @@ type testCase struct {
fullEnc string fullEnc string
} }
func expect(enc string, kvs ...label.KeyValue) testCase { func expect(enc string, kvs ...attribute.KeyValue) testCase {
return testCase{ return testCase{
kvs: kvs, kvs: kvs,
encoding: enc, encoding: enc,
} }
} }
func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase { func expectFiltered(enc, filter, fullEnc string, kvs ...attribute.KeyValue) testCase {
return testCase{ return testCase{
kvs: kvs, kvs: kvs,
keyRe: regexp.MustCompile(filter), keyRe: regexp.MustCompile(filter),
@ -50,26 +50,26 @@ func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase
func TestSetDedup(t *testing.T) { func TestSetDedup(t *testing.T) {
cases := []testCase{ cases := []testCase{
expect("A=B", label.String("A", "2"), label.String("A", "B")), expect("A=B", attribute.String("A", "2"), attribute.String("A", "B")),
expect("A=B", label.String("A", "2"), label.Int("A", 1), label.String("A", "B")), expect("A=B", attribute.String("A", "2"), attribute.Int("A", 1), attribute.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", "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", attribute.String("A", "1"), attribute.String("C", "D"), attribute.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", attribute.String("A", "2"), attribute.String("A", "B"), attribute.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", attribute.Float64("C", 1.2), attribute.String("A", "2"), attribute.String("A", "B"), attribute.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", 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", 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", 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", 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", "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{} s2d := map[string][]attribute.Distinct{}
d2s := map[label.Distinct][]string{} d2s := map[attribute.Distinct][]string{}
for _, tc := range cases { for _, tc := range cases {
cpy := make([]label.KeyValue, len(tc.kvs)) cpy := make([]attribute.KeyValue, len(tc.kvs))
copy(cpy, 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. // Ensure that the input was reordered but no elements went missing.
require.ElementsMatch(t, tc.kvs, cpy) require.ElementsMatch(t, tc.kvs, cpy)
@ -129,19 +129,19 @@ func TestSetDedup(t *testing.T) {
} }
func TestUniqueness(t *testing.T) { func TestUniqueness(t *testing.T) {
short := []label.KeyValue{ short := []attribute.KeyValue{
label.String("A", "0"), attribute.String("A", "0"),
label.String("B", "2"), attribute.String("B", "2"),
label.String("A", "1"), attribute.String("A", "1"),
} }
long := []label.KeyValue{ long := []attribute.KeyValue{
label.String("B", "2"), attribute.String("B", "2"),
label.String("C", "5"), attribute.String("C", "5"),
label.String("B", "2"), attribute.String("B", "2"),
label.String("C", "1"), attribute.String("C", "1"),
label.String("A", "4"), attribute.String("A", "4"),
label.String("C", "3"), attribute.String("C", "3"),
label.String("A", "1"), attribute.String("A", "1"),
} }
cases := []testCase{ cases := []testCase{
expectFiltered("A=1", "^A$", "B=2", short...), 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("C=3", "C", "A=1,B=2", long...),
expectFiltered("", "D", "A=1,B=2,C=3", long...), expectFiltered("", "D", "A=1,B=2,C=3", long...),
} }
enc := label.DefaultEncoder() enc := attribute.DefaultEncoder()
for _, tc := range cases { for _, tc := range cases {
cpy := make([]label.KeyValue, len(tc.kvs)) cpy := make([]attribute.KeyValue, len(tc.kvs))
copy(cpy, 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)) 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.encoding, distinct.Encoded(enc))
require.Equal(t, tc.fullEnc, full.Encoded(enc)) require.Equal(t, tc.fullEnc, full.Encoded(enc))
@ -171,7 +171,7 @@ func TestUniqueness(t *testing.T) {
} }
func TestLookup(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") value, has := set.Value("C")
require.True(t, has) require.True(t, has)

View File

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

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label // import "go.opentelemetry.io/otel/label" package attribute // import "go.opentelemetry.io/otel/attribute"
import ( import (
"encoding/json" "encoding/json"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package label_test package attribute_test
import ( import (
"reflect" "reflect"
@ -20,46 +20,46 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
func TestValue(t *testing.T) { func TestValue(t *testing.T) {
k := label.Key("test") k := attribute.Key("test")
bli := getBitlessInfo(42) bli := getBitlessInfo(42)
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
value label.Value value attribute.Value
wantType label.Type wantType attribute.Type
wantValue interface{} wantValue interface{}
}{ }{
{ {
name: "Key.Bool() correctly returns keys's internal bool value", name: "Key.Bool() correctly returns keys's internal bool value",
value: k.Bool(true).Value, value: k.Bool(true).Value,
wantType: label.BOOL, wantType: attribute.BOOL,
wantValue: true, wantValue: true,
}, },
{ {
name: "Key.Array([]bool) correctly return key's internal bool values", name: "Key.Array([]bool) correctly return key's internal bool values",
value: k.Array([]bool{true, false}).Value, value: k.Array([]bool{true, false}).Value,
wantType: label.ARRAY, wantType: attribute.ARRAY,
wantValue: [2]bool{true, false}, wantValue: [2]bool{true, false},
}, },
{ {
name: "Key.Int64() correctly returns keys's internal int64 value", name: "Key.Int64() correctly returns keys's internal int64 value",
value: k.Int64(42).Value, value: k.Int64(42).Value,
wantType: label.INT64, wantType: attribute.INT64,
wantValue: int64(42), wantValue: int64(42),
}, },
{ {
name: "Key.Float64() correctly returns keys's internal float64 value", name: "Key.Float64() correctly returns keys's internal float64 value",
value: k.Float64(42.1).Value, value: k.Float64(42.1).Value,
wantType: label.FLOAT64, wantType: attribute.FLOAT64,
wantValue: 42.1, wantValue: 42.1,
}, },
{ {
name: "Key.String() correctly returns keys's internal string value", name: "Key.String() correctly returns keys's internal string value",
value: k.String("foo").Value, value: k.String("foo").Value,
wantType: label.STRING, wantType: attribute.STRING,
wantValue: "foo", wantValue: "foo",
}, },
{ {
@ -71,31 +71,31 @@ func TestValue(t *testing.T) {
{ {
name: "Key.Array([]int64) correctly returns keys's internal int64 values", name: "Key.Array([]int64) correctly returns keys's internal int64 values",
value: k.Array([]int64{42, 43}).Value, value: k.Array([]int64{42, 43}).Value,
wantType: label.ARRAY, wantType: attribute.ARRAY,
wantValue: [2]int64{42, 43}, wantValue: [2]int64{42, 43},
}, },
{ {
name: "Key.Array([]float64) correctly returns keys's internal float64 values", name: "Key.Array([]float64) correctly returns keys's internal float64 values",
value: k.Array([]float64{42, 43}).Value, value: k.Array([]float64{42, 43}).Value,
wantType: label.ARRAY, wantType: attribute.ARRAY,
wantValue: [2]float64{42, 43}, wantValue: [2]float64{42, 43},
}, },
{ {
name: "Key.Array([]string) correctly return key's internal string values", name: "Key.Array([]string) correctly return key's internal string values",
value: k.Array([]string{"foo", "bar"}).Value, value: k.Array([]string{"foo", "bar"}).Value,
wantType: label.ARRAY, wantType: attribute.ARRAY,
wantValue: [2]string{"foo", "bar"}, wantValue: [2]string{"foo", "bar"},
}, },
{ {
name: "Key.Array([]int) correctly returns keys's internal signed integral values", name: "Key.Array([]int) correctly returns keys's internal signed integral values",
value: k.Array([]int{42, 43}).Value, value: k.Array([]int{42, 43}).Value,
wantType: label.ARRAY, wantType: attribute.ARRAY,
wantValue: [2]int{42, 43}, wantValue: [2]int{42, 43},
}, },
{ {
name: "Key.Array([][]int) refuses to create multi-dimensional array", name: "Key.Array([][]int) refuses to create multi-dimensional array",
value: k.Array([][]int{{1, 2}, {3, 4}}).Value, value: k.Array([][]int{{1, 2}, {3, 4}}).Value,
wantType: label.INVALID, wantType: attribute.INVALID,
wantValue: nil, wantValue: nil,
}, },
} { } {
@ -103,7 +103,7 @@ func TestValue(t *testing.T) {
if testcase.value.Type() != testcase.wantType { if testcase.value.Type() != testcase.wantType {
t.Errorf("wrong value type, got %#v, expected %#v", 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 continue
} }
got := testcase.value.AsInterface() got := testcase.value.AsInterface()
@ -116,7 +116,7 @@ func TestValue(t *testing.T) {
type bitlessInfo struct { type bitlessInfo struct {
intValue int intValue int
uintValue uint uintValue uint
signedType label.Type signedType attribute.Type
signedValue interface{} signedValue interface{}
} }
@ -124,13 +124,13 @@ func getBitlessInfo(i int) bitlessInfo {
return bitlessInfo{ return bitlessInfo{
intValue: i, intValue: i,
uintValue: uint(i), uintValue: uint(i),
signedType: label.INT64, signedType: attribute.INT64,
signedValue: int64(i), signedValue: int64(i),
} }
} }
func TestAsArrayValue(t *testing.T) { 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. // Ensure the returned dynamic type is stable.
if got, want := reflect.TypeOf(v).Kind(), reflect.Array; got != want { if got, want := reflect.TypeOf(v).Kind(), reflect.Array; got != want {
t.Errorf("AsArray() returned %T, want %T", 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 ( import (
"context" "context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/label"
) )
// Set returns a copy of the set of baggage key-values in ctx. // 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 // 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 conversion is unnecessary and there is no performance hit calling
// this. // this.
m := baggage.MapFromContext(ctx) m := baggage.MapFromContext(ctx)
values := make([]label.KeyValue, 0, m.Len()) values := make([]attribute.KeyValue, 0, m.Len())
m.Foreach(func(kv label.KeyValue) bool { m.Foreach(func(kv attribute.KeyValue) bool {
values = append(values, kv) values = append(values, kv)
return true 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 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. // 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) v, _ := baggage.MapFromContext(ctx).Value(key)
return v return v
} }
// ContextWithValues returns a copy of parent with pairs updated in the baggage. // 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{ m := baggage.MapFromContext(parent).Apply(baggage.MapUpdate{
MultiKV: pairs, 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 // ContextWithoutValues returns a copy of parent in which the values related
// to keys have been removed from the baggage. // 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{ m := baggage.MapFromContext(parent).Apply(baggage.MapUpdate{
DropMultiK: keys, DropMultiK: keys,
}) })

View File

@ -18,8 +18,8 @@ import (
"context" "context"
"testing" "testing"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/label"
) )
func TestBaggage(t *testing.T) { 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()) 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")) ctx = ContextWithValues(ctx, first.Bool(true), second.String("2"))
m := baggage.MapFromContext(ctx) m := baggage.MapFromContext(ctx)
v, ok := m.Value(first) v, ok := m.Value(first)
@ -59,11 +59,11 @@ func TestBaggage(t *testing.T) {
} }
v = Value(ctx, first) 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") t.Fatal("Value failed to get correct first value")
} }
v = Value(ctx, second) 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") t.Fatal("Value failed to get correct second value")
} }

View File

@ -21,9 +21,9 @@ import (
octrace "go.opencensus.io/trace" octrace "go.opencensus.io/trace"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/bridge/opencensus/utils" "go.opentelemetry.io/otel/bridge/opencensus/utils"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -114,29 +114,29 @@ func (s *span) AddAttributes(attributes ...octrace.Attribute) {
s.otSpan.SetAttributes(convertAttributes(attributes)...) s.otSpan.SetAttributes(convertAttributes(attributes)...)
} }
func convertAttributes(attributes []octrace.Attribute) []label.KeyValue { func convertAttributes(attributes []octrace.Attribute) []attribute.KeyValue {
otAttributes := make([]label.KeyValue, len(attributes)) otAttributes := make([]attribute.KeyValue, len(attributes))
for i, a := range attributes { for i, a := range attributes {
otAttributes[i] = label.KeyValue{ otAttributes[i] = attribute.KeyValue{
Key: label.Key(a.Key()), Key: attribute.Key(a.Key()),
Value: convertValue(a.Value()), Value: convertValue(a.Value()),
} }
} }
return otAttributes return otAttributes
} }
func convertValue(ocval interface{}) label.Value { func convertValue(ocval interface{}) attribute.Value {
switch v := ocval.(type) { switch v := ocval.(type) {
case bool: case bool:
return label.BoolValue(v) return attribute.BoolValue(v)
case int64: case int64:
return label.Int64Value(v) return attribute.Int64Value(v)
case float64: case float64:
return label.Float64Value(v) return attribute.Float64Value(v)
case string: case string:
return label.StringValue(v) return attribute.StringValue(v)
default: 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 ( var (
uncompressedKey = label.Key("uncompressed byte size") uncompressedKey = attribute.Key("uncompressed byte size")
compressedKey = label.Key("compressed byte size") compressedKey = attribute.Key("compressed byte size")
) )
func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) { func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
s.otSpan.AddEvent("message send", s.otSpan.AddEvent("message send",
trace.WithAttributes( trace.WithAttributes(
label.KeyValue{ attribute.KeyValue{
Key: uncompressedKey, Key: uncompressedKey,
Value: label.Int64Value(uncompressedByteSize), Value: attribute.Int64Value(uncompressedByteSize),
}, },
label.KeyValue{ attribute.KeyValue{
Key: compressedKey, 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) { func (s *span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
s.otSpan.AddEvent("message receive", s.otSpan.AddEvent("message receive",
trace.WithAttributes( trace.WithAttributes(
label.KeyValue{ attribute.KeyValue{
Key: uncompressedKey, Key: uncompressedKey,
Value: label.Int64Value(uncompressedByteSize), Value: attribute.Int64Value(uncompressedByteSize),
}, },
label.KeyValue{ attribute.KeyValue{
Key: compressedKey, Key: compressedKey,
Value: label.Int64Value(compressedByteSize), Value: attribute.Int64Value(compressedByteSize),
}), }),
) )
} }

View File

@ -20,9 +20,9 @@ import (
octrace "go.opencensus.io/trace" octrace "go.opencensus.io/trace"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/bridge/opencensus/utils" "go.opentelemetry.io/otel/bridge/opencensus/utils"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -218,16 +218,16 @@ func TestSetThings(t *testing.T) {
t.Errorf("Got code %v, expected foo", s.StatusMessage()) 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()) 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()) 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()) 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()) t.Errorf("Got attributes[string] %v, expected stringval", v.AsString())
} }
@ -238,22 +238,22 @@ func TestSetThings(t *testing.T) {
annotatefEvent := s.Events()[1] annotatefEvent := s.Events()[1]
sendEvent := s.Events()[2] sendEvent := s.Events()[2]
receiveEvent := s.Events()[3] 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()) t.Errorf("Got annotateEvent.Attributes[string] = %v, expected annotateval", v.AsString())
} }
if annotateEvent.Name != "annotate" { if annotateEvent.Name != "annotate" {
t.Errorf("Got annotateEvent.Name = %v, expected annotate", annotateEvent.Name) 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()) 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()) t.Errorf("Got annotatefEvent.Attributes[float64] = %v, expected 12.345", v.AsFloat64())
} }
if annotatefEvent.Name != "annotate67890" { if annotatefEvent.Name != "annotate67890" {
t.Errorf("Got annotatefEvent.Name = %v, expected annotate67890", annotatefEvent.Name) 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()) t.Errorf("Got annotateEvent.Attributes[string] = %v, expected annotateval", v.AsString())
} }
if sendEvent.Name != "message send" { if sendEvent.Name != "message send" {

View File

@ -26,12 +26,12 @@ import (
otlog "github.com/opentracing/opentracing-go/log" otlog "github.com/opentracing/opentracing-go/log"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/bridge/opentracing/migration" "go.opentelemetry.io/otel/bridge/opentracing/migration"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/internal/trace/noop" "go.opentelemetry.io/otel/internal/trace/noop"
otelparent "go.opentelemetry.io/otel/internal/trace/parent" otelparent "go.opentelemetry.io/otel/internal/trace/parent"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace" "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) { 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()) return handler(string(kv.Key), kv.Value.Emit())
}) })
} }
func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) { func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
crk := http.CanonicalHeaderKey(restrictedKey) 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 { func (c *bridgeSpanContext) baggageItem(restrictedKey string) string {
crk := http.CanonicalHeaderKey(restrictedKey) crk := http.CanonicalHeaderKey(restrictedKey)
val, _ := c.baggageItems.Value(label.Key(crk)) val, _ := c.baggageItems.Value(attribute.Key(crk))
return val.Emit() return val.Emit()
} }
@ -161,7 +161,7 @@ func (s *bridgeSpan) LogFields(fields ...otlog.Field) {
} }
type bridgeFieldEncoder struct { type bridgeFieldEncoder struct {
pairs []label.KeyValue pairs []attribute.KeyValue
} }
var _ otlog.Encoder = &bridgeFieldEncoder{} var _ otlog.Encoder = &bridgeFieldEncoder{}
@ -214,7 +214,7 @@ func (e *bridgeFieldEncoder) emitCommon(key string, value interface{}) {
e.pairs = append(e.pairs, otTagToOTelLabel(key, value)) e.pairs = append(e.pairs, otTagToOTelLabel(key, value))
} }
func otLogFieldsToOTelLabels(fields []otlog.Field) []label.KeyValue { func otLogFieldsToOTelLabels(fields []otlog.Field) []attribute.KeyValue {
encoder := &bridgeFieldEncoder{} encoder := &bridgeFieldEncoder{}
for _, field := range fields { for _, field := range fields {
field.Marshal(encoder) 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. // context, so we don't care about the old hooks.
clearCtx, _, _ := baggage.ContextWithNoHooks(ctx) clearCtx, _, _ := baggage.ContextWithNoHooks(ctx)
m := baggage.MapFromContext(clearCtx) 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()) bSpan.setBaggageItemOnly(string(kv.Key), kv.Value.Emit())
return true return true
}) })
@ -385,9 +385,9 @@ func (t *BridgeTracer) baggageGetHook(ctx context.Context, m baggage.Map) baggag
if len(items) == 0 { if len(items) == 0 {
return m return m
} }
kv := make([]label.KeyValue, 0, len(items)) kv := make([]attribute.KeyValue, 0, len(items))
for k, v := range 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}) return m.Apply(baggage.MapUpdate{MultiKV: kv})
} }
@ -474,10 +474,10 @@ func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) co
return ctx 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 kind := trace.SpanKindInternal
err := false err := false
var pairs []label.KeyValue var pairs []attribute.KeyValue
for k, v := range tags { for k, v := range tags {
switch k { switch k {
case string(otext.SpanKind): case string(otext.SpanKind):
@ -504,7 +504,7 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.Ke
return pairs, kind, err 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: // Note that some conversions are not obvious:
// - int -> int64 // - int -> int64
// - uint -> string // - uint -> string
@ -512,7 +512,7 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.Ke
// - uint32 -> int64 // - uint32 -> int64
// - uint64 -> string // - uint64 -> string
// - float32 -> float64 // - float32 -> float64
func otTagToOTelLabel(k string, v interface{}) label.KeyValue { func otTagToOTelLabel(k string, v interface{}) attribute.KeyValue {
key := otTagToOTelLabelKey(k) key := otTagToOTelLabelKey(k)
switch val := v.(type) { switch val := v.(type) {
case bool: case bool:
@ -540,8 +540,8 @@ func otTagToOTelLabel(k string, v interface{}) label.KeyValue {
} }
} }
func otTagToOTelLabelKey(k string) label.Key { func otTagToOTelLabelKey(k string) attribute.Key {
return label.Key(k) return attribute.Key(k)
} }
func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpanContext, []trace.Link) { 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 { func otSpanReferenceTypeToOTelLinkAttributes(refType ot.SpanReferenceType) []attribute.KeyValue {
return []label.KeyValue{ return []attribute.KeyValue{
label.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)), attribute.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)),
} }
} }

View File

@ -21,22 +21,22 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/baggage"
otelparent "go.opentelemetry.io/otel/internal/trace/parent" otelparent "go.opentelemetry.io/otel/internal/trace/parent"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/bridge/opentracing/migration" "go.opentelemetry.io/otel/bridge/opentracing/migration"
) )
var ( var (
ComponentKey = label.Key("component") ComponentKey = attribute.Key("component")
ServiceKey = label.Key("service") ServiceKey = attribute.Key("service")
StatusCodeKey = label.Key("status.code") StatusCodeKey = attribute.Key("status.code")
StatusMessageKey = label.Key("status.message") StatusMessageKey = attribute.Key("status.message")
ErrorKey = label.Key("error") ErrorKey = attribute.Key("error")
NameKey = label.Key("name") NameKey = attribute.Key("name")
) )
type MockContextKeyValue struct { type MockContextKeyValue struct {
@ -221,7 +221,7 @@ func (s *MockSpan) SetError(v bool) {
s.SetAttributes(ErrorKey.Bool(v)) s.SetAttributes(ErrorKey.Bool(v))
} }
func (s *MockSpan) SetAttributes(attributes ...label.KeyValue) { func (s *MockSpan) SetAttributes(attributes ...attribute.KeyValue) {
s.applyUpdate(baggage.MapUpdate{ s.applyUpdate(baggage.MapUpdate{
MultiKV: attributes, MultiKV: attributes,
}) })
@ -255,8 +255,8 @@ func (s *MockSpan) RecordError(err error, opts ...trace.EventOption) {
s.SetStatus(codes.Error, "") s.SetStatus(codes.Error, "")
opts = append(opts, trace.WithAttributes( opts = append(opts, trace.WithAttributes(
label.String("error.type", reflect.TypeOf(err).String()), attribute.String("error.type", reflect.TypeOf(err).String()),
label.String("error.message", err.Error()), attribute.String("error.message", err.Error()),
)) ))
s.AddEvent("error", opts...) s.AddEvent("error", opts...)
} }

View File

@ -22,8 +22,8 @@ import (
ot "github.com/opentracing/opentracing-go" ot "github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
otelbaggage "go.opentelemetry.io/otel/internal/baggage" otelbaggage "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/bridge/opentracing/internal" "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 value := bio.baggageItems[idx].value
otSpan.SetBaggageItem(otKey, 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) otRecording := make(map[string]string)
otSpan.Context().ForeachBaggageItem(func(key, value string) bool { otSpan.Context().ForeachBaggageItem(func(key, value string) bool {
@ -597,7 +597,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont
return true return true
}) })
otelRecording := make(map[string]string) 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() otelRecording[string(kv.Key)] = kv.Value.Emit()
return true return true
}) })
@ -721,62 +721,62 @@ func TestOtTagToOTelLabel_CheckTypeConversions(t *testing.T) {
tableTest := []struct { tableTest := []struct {
key string key string
value interface{} value interface{}
expectedValueType label.Type expectedValueType attribute.Type
}{ }{
{ {
key: "bool to bool", key: "bool to bool",
value: true, value: true,
expectedValueType: label.BOOL, expectedValueType: attribute.BOOL,
}, },
{ {
key: "int to int64", key: "int to int64",
value: 123, value: 123,
expectedValueType: label.INT64, expectedValueType: attribute.INT64,
}, },
{ {
key: "uint to string", key: "uint to string",
value: uint(1234), value: uint(1234),
expectedValueType: label.STRING, expectedValueType: attribute.STRING,
}, },
{ {
key: "int32 to int64", key: "int32 to int64",
value: int32(12345), value: int32(12345),
expectedValueType: label.INT64, expectedValueType: attribute.INT64,
}, },
{ {
key: "uint32 to int64", key: "uint32 to int64",
value: uint32(123456), value: uint32(123456),
expectedValueType: label.INT64, expectedValueType: attribute.INT64,
}, },
{ {
key: "int64 to int64", key: "int64 to int64",
value: int64(1234567), value: int64(1234567),
expectedValueType: label.INT64, expectedValueType: attribute.INT64,
}, },
{ {
key: "uint64 to string", key: "uint64 to string",
value: uint64(12345678), value: uint64(12345678),
expectedValueType: label.STRING, expectedValueType: attribute.STRING,
}, },
{ {
key: "float32 to float64", key: "float32 to float64",
value: float32(3.14), value: float32(3.14),
expectedValueType: label.FLOAT64, expectedValueType: attribute.FLOAT64,
}, },
{ {
key: "float64 to float64", key: "float64 to float64",
value: float64(3.14), value: float64(3.14),
expectedValueType: label.FLOAT64, expectedValueType: attribute.FLOAT64,
}, },
{ {
key: "string to string", key: "string to string",
value: "string_value", value: "string_value",
expectedValueType: label.STRING, expectedValueType: attribute.STRING,
}, },
{ {
key: "unexpected type to string", key: "unexpected type to string",
value: struct{}{}, value: struct{}{},
expectedValueType: label.STRING, expectedValueType: attribute.STRING,
}, },
} }

View File

@ -21,8 +21,8 @@ import (
"log" "log"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/trace/jaeger" "go.opentelemetry.io/otel/exporters/trace/jaeger"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
) )
@ -34,9 +34,9 @@ func initTracer() func() {
jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"), jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"),
jaeger.WithProcess(jaeger.Process{ jaeger.WithProcess(jaeger.Process{
ServiceName: "trace-demo", ServiceName: "trace-demo",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("exporter", "jaeger"), attribute.String("exporter", "jaeger"),
label.Float64("float", 312.23), attribute.Float64("float", 312.23),
}, },
}), }),
jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),

View File

@ -18,12 +18,12 @@ import (
"context" "context"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
var ( var (
lemonsKey = label.Key("ex.com/lemons") lemonsKey = attribute.Key("ex.com/lemons")
) )
// SubOperation is an example to demonstrate the use of named tracer. // SubOperation is an example to demonstrate the use of named tracer.

View File

@ -19,18 +19,18 @@ import (
"log" "log"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/example/namedtracer/foo" "go.opentelemetry.io/otel/example/namedtracer/foo"
"go.opentelemetry.io/otel/exporters/stdout" "go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
var ( var (
fooKey = label.Key("ex.com/foo") fooKey = attribute.Key("ex.com/foo")
barKey = label.Key("ex.com/bar") barKey = attribute.Key("ex.com/bar")
anotherKey = label.Key("ex.com/another") anotherKey = attribute.Key("ex.com/another")
) )
var tp *sdktrace.TracerProvider var tp *sdktrace.TracerProvider
@ -68,7 +68,7 @@ func main() {
var span trace.Span var span trace.Span
ctx, span = tracer.Start(ctx, "operation") ctx, span = tracer.Start(ctx, "operation")
defer span.End() 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")) span.SetAttributes(anotherKey.String("yes"))
if err := foo.SubOperation(ctx); err != nil { if err := foo.SubOperation(ctx); err != nil {
panic(err) panic(err)

View File

@ -26,9 +26,9 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/propagation"
@ -109,10 +109,10 @@ func main() {
// labels represent additional key-value descriptors that can be bound to a // labels represent additional key-value descriptors that can be bound to a
// metric observer or recorder. // metric observer or recorder.
commonLabels := []label.KeyValue{ commonLabels := []attribute.KeyValue{
label.String("labelA", "chocolate"), attribute.String("labelA", "chocolate"),
label.String("labelB", "raspberry"), attribute.String("labelB", "raspberry"),
label.String("labelC", "vanilla"), attribute.String("labelC", "vanilla"),
} }
// Recorder metric example // Recorder metric example

View File

@ -23,10 +23,10 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/metric/prometheus" "go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
@ -41,7 +41,7 @@ func initMeter() {
res, err := resource.New( res, err := resource.New(
ctx, ctx,
resource.WithAttributes(label.String("R", "V")), resource.WithAttributes(attribute.String("R", "V")),
) )
if err != nil { if err != nil {
log.Fatal("could not initialize resource:", err) log.Fatal("could not initialize resource:", err)
@ -94,8 +94,8 @@ func initMeter() {
func main() { func main() {
initMeter() initMeter()
labels := []label.KeyValue{ labels := []attribute.KeyValue{
label.String("label1", "value1"), attribute.String("label1", "value1"),
} }
meter := global.Meter("ex.com/prom-collector") meter := global.Meter("ex.com/prom-collector")

View File

@ -22,14 +22,14 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/metric/prometheus" "go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/global"
) )
var ( var (
lemonsKey = label.Key("ex.com/lemons") lemonsKey = attribute.Key("ex.com/lemons")
) )
func initMeter() { func initMeter() {
@ -51,7 +51,7 @@ func main() {
meter := global.Meter("ex.com/basic") meter := global.Meter("ex.com/basic")
observerLock := new(sync.RWMutex) observerLock := new(sync.RWMutex)
observerValueToReport := new(float64) observerValueToReport := new(float64)
observerLabelsToReport := new([]label.KeyValue) observerLabelsToReport := new([]attribute.KeyValue)
cb := func(_ context.Context, result metric.Float64ObserverResult) { cb := func(_ context.Context, result metric.Float64ObserverResult) {
(*observerLock).RLock() (*observerLock).RLock()
value := *observerValueToReport value := *observerValueToReport
@ -66,8 +66,8 @@ func main() {
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two") valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
counter := metric.Must(meter).NewFloat64Counter("ex.com.three") 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")} commonLabels := []attribute.KeyValue{lemonsKey.Int(10), attribute.String("A", "1"), attribute.String("B", "2"), attribute.String("C", "3")}
notSoCommonLabels := []label.KeyValue{lemonsKey.Int(13)} notSoCommonLabels := []attribute.KeyValue{lemonsKey.Int(13)}
ctx := context.Background() ctx := context.Background()

View File

@ -22,8 +22,8 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/metric/prometheus" "go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
@ -41,7 +41,7 @@ func ExampleNewExportPipeline() {
res, err := resource.New( res, err := resource.New(
context.Background(), context.Background(),
resource.WithoutBuiltin(), // Test-only! resource.WithoutBuiltin(), // Test-only!
resource.WithAttributes(label.String("R", "V")), resource.WithAttributes(attribute.String("R", "V")),
) )
if err != nil { if err != nil {
panic(err) panic(err)
@ -68,8 +68,8 @@ func ExampleNewExportPipeline() {
metric.WithDescription("Records values"), metric.WithDescription("Records values"),
) )
counter.Add(ctx, 100, label.String("key", "value")) counter.Add(ctx, 100, attribute.String("key", "value"))
recorder.Record(ctx, 100, label.String("key", "value")) recorder.Record(ctx, 100, attribute.String("key", "value"))
// GET the HTTP endpoint // GET the HTTP endpoint
var input bytes.Buffer var input bytes.Buffer

View File

@ -27,7 +27,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/number" "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 // Duplicate keys are resolved by taking the record label value over
// the resource value. // the resource value.
mi := label.NewMergeIterator(record.Labels(), record.Resource().LabelSet()) mi := attribute.NewMergeIterator(record.Labels(), record.Resource().LabelSet())
for mi.Next() { for mi.Next() {
label := mi.Label() label := mi.Label()
if keys != nil { if keys != nil {

View File

@ -26,8 +26,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/metric/prometheus" "go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
@ -43,7 +43,7 @@ func TestPrometheusExporter(t *testing.T) {
DefaultHistogramBoundaries: []float64{-0.5, 1}, DefaultHistogramBoundaries: []float64{-0.5, 1},
}, },
controller.WithCollectPeriod(0), controller.WithCollectPeriod(0),
controller.WithResource(resource.NewWithAttributes(label.String("R", "V"))), controller.WithResource(resource.NewWithAttributes(attribute.String("R", "V"))),
) )
require.NoError(t, err) require.NoError(t, err)
@ -52,9 +52,9 @@ func TestPrometheusExporter(t *testing.T) {
counter := metric.Must(meter).NewFloat64Counter("counter") counter := metric.Must(meter).NewFloat64Counter("counter")
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder") valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
labels := []label.KeyValue{ labels := []attribute.KeyValue{
label.Key("A").String("B"), attribute.Key("A").String("B"),
label.Key("C").String("D"), attribute.Key("C").String("D"),
} }
ctx := context.Background() ctx := context.Background()
@ -144,14 +144,14 @@ func TestPrometheusStatefulness(t *testing.T) {
metric.WithDescription("Counts things"), 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 require.Equal(t, `# HELP a_counter Counts things
# TYPE a_counter counter # TYPE a_counter counter
a_counter{key="value"} 100 a_counter{key="value"} 100
`, scrape()) `, 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 require.Equal(t, `# HELP a_counter Counts things
# TYPE a_counter counter # TYPE a_counter counter

View File

@ -19,8 +19,8 @@ import (
"fmt" "fmt"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric" exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
@ -66,14 +66,14 @@ func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelect
metric.CounterInstrumentKind, metric.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
) )
res := resource.NewWithAttributes(label.String("a", "b")) res := resource.NewWithAttributes(attribute.String("a", "b"))
agg := sum.New(1) agg := sum.New(1)
if err := agg[0].Update(context.Background(), number.NewInt64Number(42), &desc); err != nil { if err := agg[0].Update(context.Background(), number.NewInt64Number(42), &desc); err != nil {
return err return err
} }
start := time.Date(2020, time.December, 8, 19, 15, 0, 0, time.UTC) 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) 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) rec := exportmetric.NewRecord(&desc, &labels, res, agg[0].Aggregation(), start, end)
return recordFunc(rec) return recordFunc(rec)
} }
@ -92,7 +92,7 @@ func SingleSpanSnapshot() []*exporttrace.SpanSnapshot {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.December, 8, 20, 23, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.December, 0, 20, 24, 0, 0, time.UTC),
Attributes: []label.KeyValue{}, Attributes: []attribute.KeyValue{},
MessageEvents: []trace.Event{}, MessageEvents: []trace.Event{},
Links: []trace.Link{}, Links: []trace.Link{},
StatusCode: codes.Ok, StatusCode: codes.Ok,
@ -102,7 +102,7 @@ func SingleSpanSnapshot() []*exporttrace.SpanSnapshot {
DroppedMessageEventCount: 0, DroppedMessageEventCount: 0,
DroppedLinkCount: 0, DroppedLinkCount: 0,
ChildSpanCount: 0, ChildSpanCount: 0,
Resource: resource.NewWithAttributes(label.String("a", "b")), Resource: resource.NewWithAttributes(attribute.String("a", "b")),
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: "bar", Name: "bar",
Version: "0.0.0", Version: "0.0.0",

View File

@ -23,9 +23,9 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" 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"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric" 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, tp1 := sdktrace.NewTracerProvider(append(pOpts,
sdktrace.WithResource(resource.NewWithAttributes( sdktrace.WithResource(resource.NewWithAttributes(
label.String("rk1", "rv11)"), attribute.String("rk1", "rv11)"),
label.Int64("rk2", 5), attribute.Int64("rk2", 5),
)))...) )))...)
tp2 := sdktrace.NewTracerProvider(append(pOpts, tp2 := sdktrace.NewTracerProvider(append(pOpts,
sdktrace.WithResource(resource.NewWithAttributes( sdktrace.WithResource(resource.NewWithAttributes(
label.String("rk1", "rv12)"), attribute.String("rk1", "rv12)"),
label.Float64("rk3", 6.5), attribute.Float64("rk3", 6.5),
)))...) )))...)
tr1 := tp1.Tracer("test-tracer1") tr1 := tp1.Tracer("test-tracer1")
@ -66,11 +66,11 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr
m := 4 m := 4
for i := 0; i < m; i++ { for i := 0; i < m; i++ {
_, span := tr1.Start(ctx, "AlwaysSample") _, span := tr1.Start(ctx, "AlwaysSample")
span.SetAttributes(label.Int64("i", int64(i))) span.SetAttributes(attribute.Int64("i", int64(i)))
span.End() span.End()
_, span = tr2.Start(ctx, "AlwaysSample") _, span = tr2.Start(ctx, "AlwaysSample")
span.SetAttributes(label.Int64("i", int64(i))) span.SetAttributes(attribute.Int64("i", int64(i)))
span.End() span.End()
} }
@ -80,7 +80,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr
require.NoError(t, cont.Start(ctx)) require.NoError(t, cont.Start(ctx))
meter := cont.MeterProvider().Meter("test-meter") meter := cont.MeterProvider().Meter("test-meter")
labels := []label.KeyValue{label.Bool("test", true)} labels := []attribute.KeyValue{attribute.Bool("test", true)}
type data struct { type data struct {
iKind metric.InstrumentKind iKind metric.InstrumentKind

View File

@ -17,14 +17,14 @@ package transform
import ( import (
"reflect" "reflect"
"go.opentelemetry.io/otel/attribute"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
) )
// Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values. // 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 { if len(attrs) == 0 {
return nil return nil
} }
@ -50,29 +50,29 @@ func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue {
return out return out
} }
func toAttribute(v label.KeyValue) *commonpb.KeyValue { func toAttribute(v attribute.KeyValue) *commonpb.KeyValue {
result := &commonpb.KeyValue{ result := &commonpb.KeyValue{
Key: string(v.Key), Key: string(v.Key),
Value: new(commonpb.AnyValue), Value: new(commonpb.AnyValue),
} }
switch v.Value.Type() { switch v.Value.Type() {
case label.BOOL: case attribute.BOOL:
result.Value.Value = &commonpb.AnyValue_BoolValue{ result.Value.Value = &commonpb.AnyValue_BoolValue{
BoolValue: v.Value.AsBool(), BoolValue: v.Value.AsBool(),
} }
case label.INT64: case attribute.INT64:
result.Value.Value = &commonpb.AnyValue_IntValue{ result.Value.Value = &commonpb.AnyValue_IntValue{
IntValue: v.Value.AsInt64(), IntValue: v.Value.AsInt64(),
} }
case label.FLOAT64: case attribute.FLOAT64:
result.Value.Value = &commonpb.AnyValue_DoubleValue{ result.Value.Value = &commonpb.AnyValue_DoubleValue{
DoubleValue: v.Value.AsFloat64(), DoubleValue: v.Value.AsFloat64(),
} }
case label.STRING: case attribute.STRING:
result.Value.Value = &commonpb.AnyValue_StringValue{ result.Value.Value = &commonpb.AnyValue_StringValue{
StringValue: v.Value.AsString(), StringValue: v.Value.AsString(),
} }
case label.ARRAY: case attribute.ARRAY:
result.Value.Value = &commonpb.AnyValue_ArrayValue{ result.Value.Value = &commonpb.AnyValue_ArrayValue{
ArrayValue: &commonpb.ArrayValue{ ArrayValue: &commonpb.ArrayValue{
Values: arrayValues(v), Values: arrayValues(v),
@ -86,7 +86,7 @@ func toAttribute(v label.KeyValue) *commonpb.KeyValue {
return result return result
} }
func arrayValues(kv label.KeyValue) []*commonpb.AnyValue { func arrayValues(kv attribute.KeyValue) []*commonpb.AnyValue {
a := kv.Value.AsArray() a := kv.Value.AsArray()
aType := reflect.TypeOf(a) aType := reflect.TypeOf(a)
var valueFunc func(reflect.Value) *commonpb.AnyValue var valueFunc func(reflect.Value) *commonpb.AnyValue

View File

@ -19,12 +19,12 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/attribute"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
"go.opentelemetry.io/otel/label"
) )
type attributeTest struct { type attributeTest struct {
attrs []label.KeyValue attrs []attribute.KeyValue
expected []*commonpb.KeyValue expected []*commonpb.KeyValue
} }
@ -32,12 +32,12 @@ func TestAttributes(t *testing.T) {
for _, test := range []attributeTest{ for _, test := range []attributeTest{
{nil, nil}, {nil, nil},
{ {
[]label.KeyValue{ []attribute.KeyValue{
label.Int("int to int", 123), attribute.Int("int to int", 123),
label.Int64("int64 to int64", 1234567), attribute.Int64("int64 to int64", 1234567),
label.Float64("float64 to double", 1.61), attribute.Float64("float64 to double", 1.61),
label.String("string to string", "string"), attribute.String("string to string", "string"),
label.Bool("bool to bool", true), attribute.Bool("bool to bool", true),
}, },
[]*commonpb.KeyValue{ []*commonpb.KeyValue{
{ {
@ -111,8 +111,8 @@ func TestArrayAttributes(t *testing.T) {
for _, test := range []attributeTest{ for _, test := range []attributeTest{
{nil, nil}, {nil, nil},
{ {
[]label.KeyValue{ []attribute.KeyValue{
label.Array("invalid", [][]string{{"1", "2"}, {"a"}}), attribute.Array("invalid", [][]string{{"1", "2"}, {"a"}}),
}, },
[]*commonpb.KeyValue{ []*commonpb.KeyValue{
{ {
@ -126,12 +126,12 @@ func TestArrayAttributes(t *testing.T) {
}, },
}, },
{ {
[]label.KeyValue{ []attribute.KeyValue{
label.Array("bool array to bool array", []bool{true, false}), attribute.Array("bool array to bool array", []bool{true, false}),
label.Array("int array to int64 array", []int{1, 2, 3}), attribute.Array("int array to int64 array", []int{1, 2, 3}),
label.Array("int64 array to int64 array", []int64{1, 2, 3}), attribute.Array("int64 array to int64 array", []int64{1, 2, 3}),
label.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}), attribute.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.Array("string array to string array", []string{"foo", "bar", "baz"}),
}, },
[]*commonpb.KeyValue{ []*commonpb.KeyValue{
newOTelBoolArray("bool array to bool array", []bool{true, false}), newOTelBoolArray("bool array to bool array", []bool{true, false}),

View File

@ -24,11 +24,11 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/attribute"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" 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" 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" resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "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. // group by unique Resource string.
grouped := make(map[label.Distinct]resourceBatch) grouped := make(map[attribute.Distinct]resourceBatch)
for res := range in { for res := range in {
if res.Err != nil { if res.Err != nil {
errStrings = append(errStrings, res.Err.Error()) 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. // 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() l := iter.Len()
if l == 0 { if l == 0 {
return nil return nil

View File

@ -24,9 +24,9 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" 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" 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"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -55,7 +55,7 @@ const (
func TestStringKeyValues(t *testing.T) { func TestStringKeyValues(t *testing.T) {
tests := []struct { tests := []struct {
kvs []label.KeyValue kvs []attribute.KeyValue
expected []*commonpb.StringKeyValue expected []*commonpb.StringKeyValue
}{ }{
{ {
@ -63,21 +63,21 @@ func TestStringKeyValues(t *testing.T) {
nil, nil,
}, },
{ {
[]label.KeyValue{}, []attribute.KeyValue{},
nil, nil,
}, },
{ {
[]label.KeyValue{ []attribute.KeyValue{
label.Bool("true", true), attribute.Bool("true", true),
label.Int64("one", 1), attribute.Int64("one", 1),
label.Int64("two", 2), attribute.Int64("two", 2),
label.Float64("three", 3), attribute.Float64("three", 3),
label.Int("four", 4), attribute.Int("four", 4),
label.Int("five", 5), attribute.Int("five", 5),
label.Float64("six", 6), attribute.Float64("six", 6),
label.Int("seven", 7), attribute.Int("seven", 7),
label.Int("eight", 8), attribute.Int("eight", 8),
label.String("the", "final word"), attribute.String("the", "final word"),
}, },
[]*commonpb.StringKeyValue{ []*commonpb.StringKeyValue{
{Key: "eight", Value: "8"}, {Key: "eight", Value: "8"},
@ -95,7 +95,7 @@ func TestStringKeyValues(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
labels := label.NewSet(test.kvs...) labels := attribute.NewSet(test.kvs...)
assert.Equal(t, test.expected, stringKeyValues(labels.Iter())) assert.Equal(t, test.expected, stringKeyValues(labels.Iter()))
} }
} }
@ -123,7 +123,7 @@ func TestMinMaxSumCountValue(t *testing.T) {
func TestMinMaxSumCountDatapoints(t *testing.T) { func TestMinMaxSumCountDatapoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet() labels := attribute.NewSet()
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc)) mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc))
assert.NoError(t, mmsc.Update(context.Background(), 1, &desc)) assert.NoError(t, mmsc.Update(context.Background(), 1, &desc))
@ -162,7 +162,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) {
func TestSumIntDataPoints(t *testing.T) { func TestSumIntDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet() labels := attribute.NewSet()
s, ckpt := metrictest.Unslice2(sumAgg.New(2)) s, ckpt := metrictest.Unslice2(sumAgg.New(2))
assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc)) assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc))
require.NoError(t, s.SynchronizedMove(ckpt, &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc))
@ -190,7 +190,7 @@ func TestSumIntDataPoints(t *testing.T) {
func TestSumFloatDataPoints(t *testing.T) { func TestSumFloatDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind)
labels := label.NewSet() labels := attribute.NewSet()
s, ckpt := metrictest.Unslice2(sumAgg.New(2)) s, ckpt := metrictest.Unslice2(sumAgg.New(2))
assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc)) assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc))
require.NoError(t, s.SynchronizedMove(ckpt, &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc))
@ -219,7 +219,7 @@ func TestSumFloatDataPoints(t *testing.T) {
func TestLastValueIntDataPoints(t *testing.T) { func TestLastValueIntDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet() labels := attribute.NewSet()
s, ckpt := metrictest.Unslice2(lvAgg.New(2)) s, ckpt := metrictest.Unslice2(lvAgg.New(2))
assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc)) assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc))
require.NoError(t, s.SynchronizedMove(ckpt, &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc))
@ -245,7 +245,7 @@ func TestLastValueIntDataPoints(t *testing.T) {
func TestExactIntDataPoints(t *testing.T) { func TestExactIntDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet() labels := attribute.NewSet()
e, ckpt := metrictest.Unslice2(arrAgg.New(2)) e, ckpt := metrictest.Unslice2(arrAgg.New(2))
assert.NoError(t, e.Update(context.Background(), number.Number(100), &desc)) assert.NoError(t, e.Update(context.Background(), number.Number(100), &desc))
require.NoError(t, e.SynchronizedMove(ckpt, &desc)) require.NoError(t, e.SynchronizedMove(ckpt, &desc))
@ -271,7 +271,7 @@ func TestExactIntDataPoints(t *testing.T) {
func TestExactFloatDataPoints(t *testing.T) { func TestExactFloatDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind)
labels := label.NewSet() labels := attribute.NewSet()
e, ckpt := metrictest.Unslice2(arrAgg.New(2)) e, ckpt := metrictest.Unslice2(arrAgg.New(2))
assert.NoError(t, e.Update(context.Background(), number.NewFloat64Number(100), &desc)) assert.NoError(t, e.Update(context.Background(), number.NewFloat64Number(100), &desc))
require.NoError(t, e.SynchronizedMove(ckpt, &desc)) require.NoError(t, e.SynchronizedMove(ckpt, &desc))
@ -297,7 +297,7 @@ func TestExactFloatDataPoints(t *testing.T) {
func TestSumErrUnknownValueType(t *testing.T) { func TestSumErrUnknownValueType(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1)) desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1))
labels := label.NewSet() labels := attribute.NewSet()
s := &sumAgg.New(1)[0] s := &sumAgg.New(1)[0]
record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd) record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd)
value, err := s.Sum() value, err := s.Sum()
@ -382,7 +382,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{}
func TestRecordAggregatorIncompatibleErrors(t *testing.T) { func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
labels := label.NewSet() labels := attribute.NewSet()
res := resource.Empty() res := resource.Empty()
test := &testAgg{ test := &testAgg{
kind: kind, kind: kind,
@ -419,7 +419,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
func TestRecordAggregatorUnexpectedErrors(t *testing.T) { func TestRecordAggregatorUnexpectedErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
labels := label.NewSet() labels := attribute.NewSet()
res := resource.Empty() res := resource.Empty()
return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd)) return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd))
} }

View File

@ -19,7 +19,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
) )
@ -38,7 +38,7 @@ func TestEmptyResource(t *testing.T) {
*/ */
func TestResourceAttributes(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() got := Resource(resource.NewWithAttributes(attrs...)).GetAttributes()
if !assert.Len(t, attrs, 2) { if !assert.Len(t, attrs, 2) {

View File

@ -15,10 +15,10 @@
package transform package transform
import ( import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" 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" export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
@ -35,10 +35,10 @@ func SpanData(sdl []*export.SpanSnapshot) []*tracepb.ResourceSpans {
return nil return nil
} }
rsm := make(map[label.Distinct]*tracepb.ResourceSpans) rsm := make(map[attribute.Distinct]*tracepb.ResourceSpans)
type ilsKey struct { type ilsKey struct {
r label.Distinct r attribute.Distinct
il instrumentation.Library il instrumentation.Library
} }
ilsm := make(map[ilsKey]*tracepb.InstrumentationLibrarySpans) ilsm := make(map[ilsKey]*tracepb.InstrumentationLibrarySpans)

View File

@ -24,8 +24,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1" 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/trace"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
@ -77,12 +77,12 @@ func TestEmptySpanEvent(t *testing.T) {
} }
func TestSpanEvent(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) eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
got := spanEvents([]trace.Event{ got := spanEvents([]trace.Event{
{ {
Name: "test 1", Name: "test 1",
Attributes: []label.KeyValue{}, Attributes: []attribute.KeyValue{},
Time: eventTime, Time: eventTime,
}, },
{ {
@ -121,7 +121,7 @@ func TestEmptyLinks(t *testing.T) {
} }
func TestLinks(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{ l := []trace.Link{
{}, {},
{ {
@ -199,7 +199,7 @@ func TestSpanData(t *testing.T) {
// March 31, 2020 5:01:26 1234nanos (UTC) // March 31, 2020 5:01:26 1234nanos (UTC)
startTime := time.Unix(1585674086, 1234) startTime := time.Unix(1585674086, 1234)
endTime := startTime.Add(10 * time.Second) 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{ spanData := &export.SpanSnapshot{
SpanContext: trace.SpanContext{ SpanContext: trace.SpanContext{
TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, 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, EndTime: endTime,
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{Time: startTime, {Time: startTime,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("CompressedByteSize", 512), attribute.Int64("CompressedByteSize", 512),
}, },
}, },
{Time: endTime, {Time: endTime,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("MessageEventType", "Recv"), attribute.String("MessageEventType", "Recv"),
}, },
}, },
}, },
@ -230,8 +230,8 @@ func TestSpanData(t *testing.T) {
SpanID: trace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, SpanID: trace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
TraceFlags: 0, TraceFlags: 0,
}, },
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("LinkType", "Parent"), attribute.String("LinkType", "Parent"),
}, },
}, },
{ {
@ -240,21 +240,21 @@ func TestSpanData(t *testing.T) {
SpanID: trace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, SpanID: trace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7},
TraceFlags: 0, TraceFlags: 0,
}, },
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("LinkType", "Child"), attribute.String("LinkType", "Child"),
}, },
}, },
}, },
StatusCode: codes.Error, StatusCode: codes.Error,
StatusMessage: "utterly unrecognized", StatusMessage: "utterly unrecognized",
HasRemoteParent: true, HasRemoteParent: true,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("timeout_ns", 12e9), attribute.Int64("timeout_ns", 12e9),
}, },
DroppedAttributeCount: 1, DroppedAttributeCount: 1,
DroppedMessageEventCount: 2, DroppedMessageEventCount: 2,
DroppedLinkCount: 3, 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{ InstrumentationLibrary: instrumentation.Library{
Name: "go.opentelemetry.io/test/otel", Name: "go.opentelemetry.io/test/otel",
Version: "v0.0.1", Version: "v0.0.1",

View File

@ -23,11 +23,11 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" 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" 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" 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"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric" metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
@ -73,15 +73,15 @@ type record struct {
nKind number.Kind nKind number.Kind
resource *resource.Resource resource *resource.Resource
opts []metric.InstrumentOption opts []metric.InstrumentOption
labels []label.KeyValue labels []attribute.KeyValue
} }
var ( var (
baseKeyValues = []label.KeyValue{label.String("host", "test.com")} baseKeyValues = []attribute.KeyValue{attribute.String("host", "test.com")}
cpuKey = label.Key("CPU") cpuKey = attribute.Key("CPU")
testInstA = resource.NewWithAttributes(label.String("instance", "tester-a")) testInstA = resource.NewWithAttributes(attribute.String("instance", "tester-a"))
testInstB = resource.NewWithAttributes(label.String("instance", "tester-b")) testInstB = resource.NewWithAttributes(attribute.String("instance", "tester-b"))
testHistogramBoundaries = []float64{2.0, 4.0, 8.0} 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) { func runMetricExportTests(t *testing.T, opts []otlp.ExporterOption, rs []record, expected []metricpb.ResourceMetrics) {
exp, driver := newExporter(t, opts...) exp, driver := newExporter(t, opts...)
recs := map[label.Distinct][]metricsdk.Record{} recs := map[attribute.Distinct][]metricsdk.Record{}
resources := map[label.Distinct]*resource.Resource{} resources := map[attribute.Distinct]*resource.Resource{}
for _, r := range rs { for _, r := range rs {
lcopy := make([]label.KeyValue, len(r.labels)) lcopy := make([]attribute.KeyValue, len(r.labels))
copy(lcopy, r.labels) copy(lcopy, r.labels)
desc := metric.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...) desc := metric.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...)
labs := label.NewSet(lcopy...) labs := attribute.NewSet(lcopy...)
var agg, ckpt metricsdk.Aggregator var agg, ckpt metricsdk.Aggregator
if r.iKind.Adding() { if r.iKind.Adding() {

View File

@ -21,11 +21,11 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" 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" 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" 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/trace"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace" tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
@ -64,13 +64,13 @@ func TestExportSpans(t *testing.T) {
Name: "parent process", Name: "parent process",
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("user", "alice"), attribute.String("user", "alice"),
label.Bool("authenticated", true), attribute.Bool("authenticated", true),
}, },
StatusCode: codes.Ok, StatusCode: codes.Ok,
StatusMessage: "Ok", StatusMessage: "Ok",
Resource: resource.NewWithAttributes(label.String("instance", "tester-a")), Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: "lib-a", Name: "lib-a",
Version: "v0.1.0", Version: "v0.1.0",
@ -86,13 +86,13 @@ func TestExportSpans(t *testing.T) {
Name: "secondary parent process", Name: "secondary parent process",
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("user", "alice"), attribute.String("user", "alice"),
label.Bool("authenticated", true), attribute.Bool("authenticated", true),
}, },
StatusCode: codes.Ok, StatusCode: codes.Ok,
StatusMessage: "Ok", StatusMessage: "Ok",
Resource: resource.NewWithAttributes(label.String("instance", "tester-a")), Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: "lib-b", Name: "lib-b",
Version: "v0.1.0", Version: "v0.1.0",
@ -109,13 +109,13 @@ func TestExportSpans(t *testing.T) {
Name: "internal process", Name: "internal process",
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("user", "alice"), attribute.String("user", "alice"),
label.Bool("authenticated", true), attribute.Bool("authenticated", true),
}, },
StatusCode: codes.Ok, StatusCode: codes.Ok,
StatusMessage: "Ok", StatusMessage: "Ok",
Resource: resource.NewWithAttributes(label.String("instance", "tester-a")), Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: "lib-a", Name: "lib-a",
Version: "v0.1.0", Version: "v0.1.0",
@ -131,13 +131,13 @@ func TestExportSpans(t *testing.T) {
Name: "parent process", Name: "parent process",
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("user", "bob"), attribute.String("user", "bob"),
label.Bool("authenticated", false), attribute.Bool("authenticated", false),
}, },
StatusCode: codes.Error, StatusCode: codes.Error,
StatusMessage: "Unauthenticated", StatusMessage: "Unauthenticated",
Resource: resource.NewWithAttributes(label.String("instance", "tester-b")), Resource: resource.NewWithAttributes(attribute.String("instance", "tester-b")),
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: "lib-a", Name: "lib-a",
Version: "v1.1.0", Version: "v1.1.0",

View File

@ -28,11 +28,11 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/encoding/gzip" "google.golang.org/grpc/encoding/gzip"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/exporters/otlp"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1" 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/internal/otlptest"
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
"go.opentelemetry.io/otel/label"
exporttrace "go.opentelemetry.io/otel/sdk/export/trace" exporttrace "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
) )
@ -344,12 +344,12 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
defer func() { _ = tp.Shutdown(ctx) }() defer func() { _ = tp.Shutdown(ctx) }()
tr := tp.Tracer("test-tracer") tr := tp.Tracer("test-tracer")
testKvs := []label.KeyValue{ testKvs := []attribute.KeyValue{
label.Int("Int", 1), attribute.Int("Int", 1),
label.Int64("Int64", int64(3)), attribute.Int64("Int64", int64(3)),
label.Float64("Float64", 2.22), attribute.Float64("Float64", 2.22),
label.Bool("Bool", true), attribute.Bool("Bool", true),
label.String("String", "test"), attribute.String("String", "test"),
} }
_, span := tr.Start(ctx, "AlwaysSample") _, span := tr.Start(ctx, "AlwaysSample")
span.SetAttributes(testKvs...) span.SetAttributes(testKvs...)

View File

@ -18,14 +18,14 @@ import (
"io" "io"
"os" "os"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
var ( var (
defaultWriter = os.Stdout defaultWriter = os.Stdout
defaultPrettyPrint = false defaultPrettyPrint = false
defaultTimestamps = true defaultTimestamps = true
defaultLabelEncoder = label.DefaultEncoder() defaultLabelEncoder = attribute.DefaultEncoder()
defaultDisableTraceExport = false defaultDisableTraceExport = false
defaultDisableMetricExport = false defaultDisableMetricExport = false
) )
@ -44,7 +44,7 @@ type Config struct {
Timestamps bool Timestamps bool
// LabelEncoder encodes the labels. // LabelEncoder encodes the labels.
LabelEncoder label.Encoder LabelEncoder attribute.Encoder
// DisableTraceExport prevents any export of trace telemetry. // DisableTraceExport prevents any export of trace telemetry.
DisableTraceExport bool DisableTraceExport bool
@ -112,12 +112,12 @@ func (o timestampsOption) Apply(config *Config) {
} }
// WithLabelEncoder sets the label encoder used in export. // WithLabelEncoder sets the label encoder used in export.
func WithLabelEncoder(enc label.Encoder) Option { func WithLabelEncoder(enc attribute.Encoder) Option {
return labelEncoderOption{enc} return labelEncoderOption{enc}
} }
type labelEncoderOption struct { type labelEncoderOption struct {
LabelEncoder label.Encoder LabelEncoder attribute.Encoder
} }
func (o labelEncoderOption) Apply(config *Config) { func (o labelEncoderOption) Apply(config *Config) {

View File

@ -19,8 +19,8 @@ import (
"log" "log"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/stdout" "go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
@ -45,7 +45,7 @@ var (
loopCounter = metric.Must(meter).NewInt64Counter("function.loops") loopCounter = metric.Must(meter).NewInt64Counter("function.loops")
paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param") 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 { func add(ctx context.Context, x, y int64) int64 {

View File

@ -21,7 +21,7 @@ import (
"strings" "strings"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric" exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/aggregation"
@ -61,14 +61,14 @@ func (e *metricExporter) Export(_ context.Context, checkpointSet exportmetric.Ch
kind := desc.NumberKind() kind := desc.NumberKind()
encodedResource := record.Resource().Encoded(e.config.LabelEncoder) encodedResource := record.Resource().Encoded(e.config.LabelEncoder)
var instLabels []label.KeyValue var instLabels []attribute.KeyValue
if name := desc.InstrumentationName(); name != "" { 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 != "" { 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) encodedInstLabels := instSet.Encoded(e.config.LabelEncoder)
var expose line var expose line

View File

@ -26,8 +26,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/stdout" "go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -46,7 +46,7 @@ type testFixture struct {
output *bytes.Buffer 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 { func newFixture(t *testing.T, opts ...stdout.Option) testFixture {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
@ -135,7 +135,7 @@ func TestStdoutCounterFormat(t *testing.T) {
aggregatortest.CheckedUpdate(fix.t, cagg, number.NewInt64Number(123), &desc) aggregatortest.CheckedUpdate(fix.t, cagg, number.NewInt64Number(123), &desc)
require.NoError(t, cagg.SynchronizedMove(ckpt, &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) fix.Export(checkpointSet)
@ -153,7 +153,7 @@ func TestStdoutLastValueFormat(t *testing.T) {
aggregatortest.CheckedUpdate(fix.t, lvagg, number.NewFloat64Number(123.456), &desc) aggregatortest.CheckedUpdate(fix.t, lvagg, number.NewFloat64Number(123.456), &desc)
require.NoError(t, lvagg.SynchronizedMove(ckpt, &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) fix.Export(checkpointSet)
@ -173,7 +173,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) {
aggregatortest.CheckedUpdate(fix.t, magg, number.NewFloat64Number(876.543), &desc) aggregatortest.CheckedUpdate(fix.t, magg, number.NewFloat64Number(876.543), &desc)
require.NoError(t, magg.SynchronizedMove(ckpt, &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) fix.Export(checkpointSet)
@ -194,7 +194,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) {
require.NoError(t, aagg.SynchronizedMove(ckpt, &desc)) 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) fix.Export(checkpointSet)
@ -244,7 +244,7 @@ func TestStdoutLastValueNotSet(t *testing.T) {
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc)) 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) fix.Export(checkpointSet)
@ -255,9 +255,9 @@ func TestStdoutResource(t *testing.T) {
type testCase struct { type testCase struct {
expect string expect string
res *resource.Resource 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{ return testCase{
expect: expect, expect: expect,
res: res, res: res,
@ -266,23 +266,23 @@ func TestStdoutResource(t *testing.T) {
} }
testCases := []testCase{ testCases := []testCase{
newCase("R1=V1,R2=V2,A=B,C=D", newCase("R1=V1,R2=V2,A=B,C=D",
resource.NewWithAttributes(label.String("R1", "V1"), label.String("R2", "V2")), resource.NewWithAttributes(attribute.String("R1", "V1"), attribute.String("R2", "V2")),
label.String("A", "B"), attribute.String("A", "B"),
label.String("C", "D")), attribute.String("C", "D")),
newCase("R1=V1,R2=V2", 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", newCase("A=B,C=D",
nil, nil,
label.String("A", "B"), attribute.String("A", "B"),
label.String("C", "D"), attribute.String("C", "D"),
), ),
// We explicitly do not de-duplicate between resources // We explicitly do not de-duplicate between resources
// and metric labels in this exporter. // and metric labels in this exporter.
newCase("R1=V1,R2=V2,R1=V3,R2=V4", newCase("R1=V1,R2=V2,R1=V3,R2=V4",
resource.NewWithAttributes(label.String("R1", "V1"), label.String("R2", "V2")), resource.NewWithAttributes(attribute.String("R1", "V1"), attribute.String("R2", "V2")),
label.String("R1", "V3"), attribute.String("R1", "V3"),
label.String("R2", "V4")), attribute.String("R2", "V4")),
} }
for _, tc := range testCases { for _, tc := range testCases {

View File

@ -22,9 +22,9 @@ import (
"testing" "testing"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/exporters/stdout" "go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace" export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
@ -42,10 +42,10 @@ func TestExporter_ExportSpan(t *testing.T) {
now := time.Now() now := time.Now()
traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10")
spanID, _ := trace.SpanIDFromHex("0102030405060708") spanID, _ := trace.SpanIDFromHex("0102030405060708")
traceState, _ := trace.TraceStateFromKeyValues(label.String("key", "val")) traceState, _ := trace.TraceStateFromKeyValues(attribute.String("key", "val"))
keyValue := "value" keyValue := "value"
doubleValue := 123.456 doubleValue := 123.456
resource := resource.NewWithAttributes(label.String("rk1", "rv11")) resource := resource.NewWithAttributes(attribute.String("rk1", "rv11"))
testSpan := &export.SpanSnapshot{ testSpan := &export.SpanSnapshot{
SpanContext: trace.SpanContext{ SpanContext: trace.SpanContext{
@ -56,13 +56,13 @@ func TestExporter_ExportSpan(t *testing.T) {
Name: "/foo", Name: "/foo",
StartTime: now, StartTime: now,
EndTime: now, EndTime: now,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("key", keyValue), attribute.String("key", keyValue),
label.Float64("double", doubleValue), attribute.Float64("double", doubleValue),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{Name: "foo", Attributes: []label.KeyValue{label.String("key", keyValue)}, Time: now}, {Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now},
{Name: "bar", Attributes: []label.KeyValue{label.Float64("double", doubleValue)}, Time: now}, {Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now},
}, },
SpanKind: trace.SpanKindInternal, SpanKind: trace.SpanKindInternal,
StatusCode: codes.Error, StatusCode: codes.Error,

View File

@ -21,7 +21,7 @@ import (
"strings" "strings"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
// Environment variable names // Environment variable names
@ -111,9 +111,9 @@ var errTagEnvironmentDefaultValueNotFound = errors.New("missing default value fo
// - comma separated list of key=value // - comma separated list of key=value
// - value can be specified using the notation ${envVar:defaultValue}, where `envVar` // - 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 // 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, ",") pairs := strings.Split(sTags, ",")
tags := make([]label.KeyValue, len(pairs)) tags := make([]attribute.KeyValue, len(pairs))
for i, p := range pairs { for i, p := range pairs {
field := strings.SplitN(p, "=", 2) field := strings.SplitN(p, "=", 2)
if len(field) != 2 { if len(field) != 2 {
@ -139,24 +139,24 @@ func parseTags(sTags string) ([]label.KeyValue, error) {
return tags, nil return tags, nil
} }
func parseKeyValue(k, v string) label.KeyValue { func parseKeyValue(k, v string) attribute.KeyValue {
return label.KeyValue{ return attribute.KeyValue{
Key: label.Key(k), Key: attribute.Key(k),
Value: parseValue(v), 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 { 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 { 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 { if v, err := strconv.ParseBool(str); err == nil {
return label.BoolValue(v) return attribute.BoolValue(v)
} }
// Fallback // 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/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
ottest "go.opentelemetry.io/otel/internal/internaltest" ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/label"
) )
func Test_parseTags(t *testing.T) { func Test_parseTags(t *testing.T) {
@ -38,78 +38,78 @@ func Test_parseTags(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
tagStr string tagStr string
expectedTags []label.KeyValue expectedTags []attribute.KeyValue
expectedError error expectedError error
}{ }{
{ {
name: "string", name: "string",
tagStr: "key=value", tagStr: "key=value",
expectedTags: []label.KeyValue{ expectedTags: []attribute.KeyValue{
{ {
Key: "key", Key: "key",
Value: label.StringValue("value"), Value: attribute.StringValue("value"),
}, },
}, },
}, },
{ {
name: "int64", name: "int64",
tagStr: "k=9223372036854775807,k2=-9223372036854775808", tagStr: "k=9223372036854775807,k2=-9223372036854775808",
expectedTags: []label.KeyValue{ expectedTags: []attribute.KeyValue{
{ {
Key: "k", Key: "k",
Value: label.Int64Value(math.MaxInt64), Value: attribute.Int64Value(math.MaxInt64),
}, },
{ {
Key: "k2", Key: "k2",
Value: label.Int64Value(math.MinInt64), Value: attribute.Int64Value(math.MinInt64),
}, },
}, },
}, },
{ {
name: "float64", name: "float64",
tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2", tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2",
expectedTags: []label.KeyValue{ expectedTags: []attribute.KeyValue{
{ {
Key: "k", Key: "k",
Value: label.Float64Value(math.MaxFloat64), Value: attribute.Float64Value(math.MaxFloat64),
}, },
{ {
Key: "k2", Key: "k2",
Value: label.Float64Value(math.SmallestNonzeroFloat64), Value: attribute.Float64Value(math.SmallestNonzeroFloat64),
}, },
{ {
Key: "k3", Key: "k3",
Value: label.Float64Value(-1.2), Value: attribute.Float64Value(-1.2),
}, },
}, },
}, },
{ {
name: "multiple type values", name: "multiple type values",
tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}", tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}",
expectedTags: []label.KeyValue{ expectedTags: []attribute.KeyValue{
{ {
Key: "k", Key: "k",
Value: label.StringValue("v"), Value: attribute.StringValue("v"),
}, },
{ {
Key: "k2", Key: "k2",
Value: label.Int64Value(123), Value: attribute.Int64Value(123),
}, },
{ {
Key: "k3", Key: "k3",
Value: label.StringValue("v3"), Value: attribute.StringValue("v3"),
}, },
{ {
Key: "k4", Key: "k4",
Value: label.Float64Value(-1.2), Value: attribute.Float64Value(-1.2),
}, },
{ {
Key: "k5", Key: "k5",
Value: label.StringValue("not-default"), Value: attribute.StringValue("not-default"),
}, },
{ {
Key: "k6", Key: "k6",
Value: label.StringValue("default"), Value: attribute.StringValue("default"),
}, },
}, },
}, },
@ -144,52 +144,52 @@ func Test_parseValue(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
str string str string
expected label.Value expected attribute.Value
}{ }{
{ {
name: "bool: true", name: "bool: true",
str: "true", str: "true",
expected: label.BoolValue(true), expected: attribute.BoolValue(true),
}, },
{ {
name: "bool: false", name: "bool: false",
str: "false", str: "false",
expected: label.BoolValue(false), expected: attribute.BoolValue(false),
}, },
{ {
name: "int64: 012340", name: "int64: 012340",
str: "012340", str: "012340",
expected: label.Int64Value(12340), expected: attribute.Int64Value(12340),
}, },
{ {
name: "int64: -012340", name: "int64: -012340",
str: "-012340", str: "-012340",
expected: label.Int64Value(-12340), expected: attribute.Int64Value(-12340),
}, },
{ {
name: "int64: 0", name: "int64: 0",
str: "0", str: "0",
expected: label.Int64Value(0), expected: attribute.Int64Value(0),
}, },
{ {
name: "float64: -0.1", name: "float64: -0.1",
str: "-0.1", str: "-0.1",
expected: label.Float64Value(-0.1), expected: attribute.Float64Value(-0.1),
}, },
{ {
name: "float64: 00.001", name: "float64: 00.001",
str: "00.001", str: "00.001",
expected: label.Float64Value(0.001), expected: attribute.Float64Value(0.001),
}, },
{ {
name: "float64: 1E23", name: "float64: 1E23",
str: "1E23", str: "1E23",
expected: label.Float64Value(1e23), expected: attribute.Float64Value(1e23),
}, },
{ {
name: "string: foo", name: "string: foo",
str: "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", tags: "key=value,key2=123",
expectedProcess: Process{ expectedProcess: Process{
ServiceName: "test-service", ServiceName: "test-service",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("key", "value"), attribute.String("key", "value"),
label.Int64("key2", 123), attribute.Int64("key2", 123),
}, },
}, },
}, },
@ -455,16 +455,16 @@ func TestWithProcessFromEnv(t *testing.T) {
options: options{ options: options{
Process: Process{ Process: Process{
ServiceName: "old-name", ServiceName: "old-name",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("old-key", "old-value"), attribute.String("old-key", "old-value"),
}, },
}, },
}, },
expectedOptions: options{ expectedOptions: options{
Process: Process{ Process: Process{
ServiceName: "service-name", ServiceName: "service-name",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("key", "value"), attribute.String("key", "value"),
}, },
}, },
}, },
@ -476,16 +476,16 @@ func TestWithProcessFromEnv(t *testing.T) {
options: options{ options: options{
Process: Process{ Process: Process{
ServiceName: "old-name", ServiceName: "old-name",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("old-key", "old-value"), attribute.String("old-key", "old-value"),
}, },
}, },
}, },
expectedOptions: options{ expectedOptions: options{
Process: Process{ Process: Process{
ServiceName: "old-name", ServiceName: "old-name",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("old-key", "old-value"), attribute.String("old-key", "old-value"),
}, },
}, },
}, },

View File

@ -23,9 +23,9 @@ import (
"google.golang.org/api/support/bundler" "google.golang.org/api/support/bundler"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" 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" export "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
@ -193,7 +193,7 @@ type Process struct {
ServiceName string ServiceName string
// Tags are added to Jaeger Process exports // 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 // 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 var tag *gen.Tag
switch keyValue.Value.Type() { switch keyValue.Value.Type() {
case label.STRING: case attribute.STRING:
s := keyValue.Value.AsString() s := keyValue.Value.AsString()
tag = &gen.Tag{ tag = &gen.Tag{
Key: string(keyValue.Key), Key: string(keyValue.Key),
VStr: &s, VStr: &s,
VType: gen.TagType_STRING, VType: gen.TagType_STRING,
} }
case label.BOOL: case attribute.BOOL:
b := keyValue.Value.AsBool() b := keyValue.Value.AsBool()
tag = &gen.Tag{ tag = &gen.Tag{
Key: string(keyValue.Key), Key: string(keyValue.Key),
VBool: &b, VBool: &b,
VType: gen.TagType_BOOL, VType: gen.TagType_BOOL,
} }
case label.INT64: case attribute.INT64:
i := keyValue.Value.AsInt64() i := keyValue.Value.AsInt64()
tag = &gen.Tag{ tag = &gen.Tag{
Key: string(keyValue.Key), Key: string(keyValue.Key),
VLong: &i, VLong: &i,
VType: gen.TagType_LONG, VType: gen.TagType_LONG,
} }
case label.FLOAT64: case attribute.FLOAT64:
f := keyValue.Value.AsFloat64() f := keyValue.Value.AsFloat64()
tag = &gen.Tag{ tag = &gen.Tag{
Key: string(keyValue.Key), Key: string(keyValue.Key),

View File

@ -28,10 +28,10 @@ import (
"google.golang.org/api/support/bundler" "google.golang.org/api/support/bundler"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger"
ottest "go.opentelemetry.io/otel/internal/internaltest" ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace" export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
@ -203,8 +203,8 @@ func TestNewRawExporter(t *testing.T) {
WithProcess( WithProcess(
Process{ Process{
ServiceName: "jaeger-test", ServiceName: "jaeger-test",
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String("key", "val"), attribute.String("key", "val"),
}, },
}, },
), ),
@ -329,8 +329,8 @@ func TestExporter_ExportSpan(t *testing.T) {
withTestCollectorEndpoint(), withTestCollectorEndpoint(),
WithProcess(Process{ WithProcess(Process{
ServiceName: serviceName, ServiceName: serviceName,
Tags: []label.KeyValue{ Tags: []attribute.KeyValue{
label.String(tagKey, tagVal), attribute.String(tagKey, tagVal),
}, },
}), }),
) )
@ -396,18 +396,18 @@ func Test_spanSnapshotToThrift(t *testing.T) {
}, },
}, },
}, },
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("key", keyValue), attribute.String("key", keyValue),
label.Float64("double", doubleValue), attribute.Float64("double", doubleValue),
label.Int64("int", intValue), attribute.Int64("int", intValue),
}, },
MessageEvents: []trace.Event{ 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, StatusCode: codes.Error,
StatusMessage: statusMessage, StatusMessage: statusMessage,
SpanKind: trace.SpanKindClient, 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{ InstrumentationLibrary: instrumentation.Library{
Name: instrLibName, Name: instrLibName,
Version: instrLibVersion, Version: instrLibVersion,

View File

@ -21,7 +21,7 @@ import (
zkmodel "github.com/openzipkin/zipkin-go/model" 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" export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -127,7 +127,7 @@ func toZipkinAnnotations(events []trace.Event) []zkmodel.Annotation {
return annotations return annotations
} }
func attributesToJSONMapString(attributes []label.KeyValue) string { func attributesToJSONMapString(attributes []attribute.KeyValue) string {
m := make(map[string]interface{}, len(attributes)) m := make(map[string]interface{}, len(attributes))
for _, attribute := range attributes { for _, attribute := range attributes {
m[(string)(attribute.Key)] = attribute.Value.AsInterface() m[(string)(attribute.Key)] = attribute.Value.AsInterface()

View File

@ -24,8 +24,8 @@ import (
zkmodel "github.com/openzipkin/zipkin-go/model" zkmodel "github.com/openzipkin/zipkin-go/model"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace" export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
@ -44,16 +44,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -77,16 +77,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -109,16 +109,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -141,16 +141,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -173,16 +173,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -205,16 +205,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -237,16 +237,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -269,9 +269,9 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("attr1", 42), attribute.Int64("attr1", 42),
label.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: nil, MessageEvents: nil,
StatusCode: codes.Error, StatusCode: codes.Error,
@ -288,15 +288,15 @@ func TestModelConversion(t *testing.T) {
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("error", "false"), attribute.String("error", "false"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []trace.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Int64("eventattr1", 123), attribute.Int64("eventattr1", 123),
}, },
}, },
{ {
@ -677,11 +677,11 @@ func Test_toZipkinTags(t *testing.T) {
{ {
name: "attributes", name: "attributes",
data: &export.SpanSnapshot{ data: &export.SpanSnapshot{
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("key", keyValue), attribute.String("key", keyValue),
label.Float64("double", doubleValue), attribute.Float64("double", doubleValue),
label.Int64("uint", uintValue), attribute.Int64("uint", uintValue),
label.Bool("ok", true), attribute.Bool("ok", true),
}, },
}, },
want: map[string]string{ want: map[string]string{
@ -704,8 +704,8 @@ func Test_toZipkinTags(t *testing.T) {
{ {
name: "omit-noerror", name: "omit-noerror",
data: &export.SpanSnapshot{ data: &export.SpanSnapshot{
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.Bool("error", false), attribute.Bool("error", false),
}, },
}, },
want: map[string]string{ want: map[string]string{
@ -716,9 +716,9 @@ func Test_toZipkinTags(t *testing.T) {
{ {
name: "statusCode", name: "statusCode",
data: &export.SpanSnapshot{ data: &export.SpanSnapshot{
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("key", keyValue), attribute.String("key", keyValue),
label.Bool("error", true), attribute.Bool("error", true),
}, },
StatusCode: codes.Error, StatusCode: codes.Error,
StatusMessage: statusMessage, StatusMessage: statusMessage,
@ -743,7 +743,7 @@ func Test_toZipkinTags(t *testing.T) {
{ {
name: "instrLib-noversion", name: "instrLib-noversion",
data: &export.SpanSnapshot{ data: &export.SpanSnapshot{
Attributes: []label.KeyValue{}, Attributes: []attribute.KeyValue{},
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: instrLibName, Name: instrLibName,
}, },
@ -757,7 +757,7 @@ func Test_toZipkinTags(t *testing.T) {
{ {
name: "instrLib-with-version", name: "instrLib-with-version",
data: &export.SpanSnapshot{ data: &export.SpanSnapshot{
Attributes: []label.KeyValue{}, Attributes: []attribute.KeyValue{},
InstrumentationLibrary: instrumentation.Library{ InstrumentationLibrary: instrumentation.Library{
Name: instrLibName, Name: instrLibName,
Version: instrLibVersion, Version: instrLibVersion,

View File

@ -18,11 +18,11 @@ package baggage
import ( import (
"context" "context"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
type rawMap map[label.Key]label.Value type rawMap map[attribute.Key]attribute.Value
type keySet map[label.Key]struct{} type keySet map[attribute.Key]struct{}
// Map is an immutable storage for correlations. // Map is an immutable storage for correlations.
type Map struct { type Map struct {
@ -35,18 +35,18 @@ type MapUpdate struct {
// DropSingleK contains a single key to be dropped from // DropSingleK contains a single key to be dropped from
// correlations. Use this to avoid an overhead of a slice // correlations. Use this to avoid an overhead of a slice
// allocation if there is only one key to drop. // allocation if there is only one key to drop.
DropSingleK label.Key DropSingleK attribute.Key
// DropMultiK contains all the keys to be dropped from // DropMultiK contains all the keys to be dropped from
// correlations. // correlations.
DropMultiK []label.Key DropMultiK []attribute.Key
// SingleKV contains a single key-value pair to be added to // SingleKV contains a single key-value pair to be added to
// correlations. Use this to avoid an overhead of a slice // correlations. Use this to avoid an overhead of a slice
// allocation if there is only one key-value pair to add. // 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 // MultiKV contains all the key-value pairs to be added to
// correlations. // correlations.
MultiKV []label.KeyValue MultiKV []attribute.KeyValue
} }
func newMap(raw rawMap) Map { func newMap(raw rawMap) Map {
@ -104,7 +104,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
deletionsCount++ deletionsCount++
} }
if deletionsCount > 0 { if deletionsCount > 0 {
delSet = make(map[label.Key]struct{}, deletionsCount) delSet = make(map[attribute.Key]struct{}, deletionsCount)
for _, k := range update.DropMultiK { for _, k := range update.DropMultiK {
delSet[k] = struct{}{} delSet[k] = struct{}{}
} }
@ -118,7 +118,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
additionsCount++ additionsCount++
} }
if additionsCount > 0 { if additionsCount > 0 {
addSet = make(map[label.Key]struct{}, additionsCount) addSet = make(map[attribute.Key]struct{}, additionsCount)
for _, k := range update.MultiKV { for _, k := range update.MultiKV {
addSet[k.Key] = struct{}{} 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 gets a value from correlations map and returns a boolean
// value indicating whether the key exist in the map. // 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] value, ok := m.m[k]
return value, ok return value, ok
} }
// HasValue returns a boolean value indicating whether the key exist // HasValue returns a boolean value indicating whether the key exist
// in the map. // in the map.
func (m Map) HasValue(k label.Key) bool { func (m Map) HasValue(k attribute.Key) bool {
_, has := m.Value(k) _, has := m.Value(k)
return has return has
} }
@ -169,9 +169,9 @@ func (m Map) Len() int {
// Foreach calls a passed callback once on each key-value pair until // 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 // all the key-value pairs of the map were iterated or the callback
// returns false, whichever happens first. // 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 { for k, v := range m.m {
if !f(label.KeyValue{ if !f(attribute.KeyValue{
Key: k, Key: k,
Value: v, Value: v,
}) { }) {
@ -316,7 +316,7 @@ func ContextWithNoCorrelationData(ctx context.Context) context.Context {
// NewContext returns a context with the map from passed context // NewContext returns a context with the map from passed context
// updated with the passed key-value pairs. // 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{ return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{
MultiKV: keyvalues, MultiKV: keyvalues,
})) }))

View File

@ -18,14 +18,14 @@ import (
"fmt" "fmt"
"testing" "testing"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
type testCase struct { type testCase struct {
name string name string
value MapUpdate value MapUpdate
init []int init []int
wantKVs []label.KeyValue wantKVs []attribute.KeyValue
} }
func TestMap(t *testing.T) { func TestMap(t *testing.T) {
@ -46,7 +46,7 @@ func TestMap(t *testing.T) {
} }
} }
// test Foreach() // test Foreach()
got.Foreach(func(kv label.KeyValue) bool { got.Foreach(func(kv attribute.KeyValue) bool {
for _, want := range testcase.wantKVs { for _, want := range testcase.wantKVs {
if kv == want { if kv == want {
return false return false
@ -85,192 +85,192 @@ func getTestCases() []testCase {
return []testCase{ return []testCase{
{ {
name: "map with MultiKV", name: "map with MultiKV",
value: MapUpdate{MultiKV: []label.KeyValue{ value: MapUpdate{MultiKV: []attribute.KeyValue{
label.Int64("key1", 1), attribute.Int64("key1", 1),
label.String("key2", "val2")}, attribute.String("key2", "val2")},
}, },
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.Int64("key1", 1), attribute.Int64("key1", 1),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
{ {
name: "map with SingleKV", name: "map with SingleKV",
value: MapUpdate{SingleKV: label.String("key1", "val1")}, value: MapUpdate{SingleKV: attribute.String("key1", "val1")},
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
}, },
}, },
{ {
name: "map with both add fields", name: "map with both add fields",
value: MapUpdate{SingleKV: label.Int64("key1", 3), value: MapUpdate{SingleKV: attribute.Int64("key1", 3),
MultiKV: []label.KeyValue{ MultiKV: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2")}, attribute.String("key2", "val2")},
}, },
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
{ {
name: "map with empty MapUpdate", name: "map with empty MapUpdate",
value: MapUpdate{}, value: MapUpdate{},
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{}, wantKVs: []attribute.KeyValue{},
}, },
{ {
name: "map with DropSingleK", name: "map with DropSingleK",
value: MapUpdate{DropSingleK: label.Key("key1")}, value: MapUpdate{DropSingleK: attribute.Key("key1")},
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{}, wantKVs: []attribute.KeyValue{},
}, },
{ {
name: "map with DropMultiK", name: "map with DropMultiK",
value: MapUpdate{DropMultiK: []label.Key{ value: MapUpdate{DropMultiK: []attribute.Key{
label.Key("key1"), label.Key("key2"), attribute.Key("key1"), attribute.Key("key2"),
}}, }},
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{}, wantKVs: []attribute.KeyValue{},
}, },
{ {
name: "map with both drop fields", name: "map with both drop fields",
value: MapUpdate{ value: MapUpdate{
DropSingleK: label.Key("key1"), DropSingleK: attribute.Key("key1"),
DropMultiK: []label.Key{ DropMultiK: []attribute.Key{
label.Key("key1"), attribute.Key("key1"),
label.Key("key2"), attribute.Key("key2"),
}, },
}, },
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{}, wantKVs: []attribute.KeyValue{},
}, },
{ {
name: "map with all fields", name: "map with all fields",
value: MapUpdate{ value: MapUpdate{
DropSingleK: label.Key("key1"), DropSingleK: attribute.Key("key1"),
DropMultiK: []label.Key{ DropMultiK: []attribute.Key{
label.Key("key1"), attribute.Key("key1"),
label.Key("key2"), attribute.Key("key2"),
}, },
SingleKV: label.String("key4", "val4"), SingleKV: attribute.String("key4", "val4"),
MultiKV: []label.KeyValue{ MultiKV: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
label.String("key3", "val3"), attribute.String("key3", "val3"),
}, },
}, },
init: []int{}, init: []int{},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
label.String("key3", "val3"), attribute.String("key3", "val3"),
label.String("key4", "val4"), attribute.String("key4", "val4"),
}, },
}, },
{ {
name: "Existing map with MultiKV", name: "Existing map with MultiKV",
value: MapUpdate{MultiKV: []label.KeyValue{ value: MapUpdate{MultiKV: []attribute.KeyValue{
label.Int64("key1", 1), attribute.Int64("key1", 1),
label.String("key2", "val2")}, attribute.String("key2", "val2")},
}, },
init: []int{5}, init: []int{5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.Int64("key1", 1), attribute.Int64("key1", 1),
label.String("key2", "val2"), attribute.String("key2", "val2"),
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with SingleKV", name: "Existing map with SingleKV",
value: MapUpdate{SingleKV: label.String("key1", "val1")}, value: MapUpdate{SingleKV: attribute.String("key1", "val1")},
init: []int{5}, init: []int{5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with both add fields", name: "Existing map with both add fields",
value: MapUpdate{SingleKV: label.Int64("key1", 3), value: MapUpdate{SingleKV: attribute.Int64("key1", 3),
MultiKV: []label.KeyValue{ MultiKV: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2")}, attribute.String("key2", "val2")},
}, },
init: []int{5}, init: []int{5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with empty MapUpdate", name: "Existing map with empty MapUpdate",
value: MapUpdate{}, value: MapUpdate{},
init: []int{5}, init: []int{5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with DropSingleK", name: "Existing map with DropSingleK",
value: MapUpdate{DropSingleK: label.Key("key1")}, value: MapUpdate{DropSingleK: attribute.Key("key1")},
init: []int{1, 5}, init: []int{1, 5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with DropMultiK", name: "Existing map with DropMultiK",
value: MapUpdate{DropMultiK: []label.Key{ value: MapUpdate{DropMultiK: []attribute.Key{
label.Key("key1"), label.Key("key2"), attribute.Key("key1"), attribute.Key("key2"),
}}, }},
init: []int{1, 5}, init: []int{1, 5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with both drop fields", name: "Existing map with both drop fields",
value: MapUpdate{ value: MapUpdate{
DropSingleK: label.Key("key1"), DropSingleK: attribute.Key("key1"),
DropMultiK: []label.Key{ DropMultiK: []attribute.Key{
label.Key("key1"), attribute.Key("key1"),
label.Key("key2"), attribute.Key("key2"),
}, },
}, },
init: []int{1, 2, 5}, init: []int{1, 2, 5},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.Int("key5", 5), attribute.Int("key5", 5),
}, },
}, },
{ {
name: "Existing map with all the fields", name: "Existing map with all the fields",
value: MapUpdate{ value: MapUpdate{
DropSingleK: label.Key("key1"), DropSingleK: attribute.Key("key1"),
DropMultiK: []label.Key{ DropMultiK: []attribute.Key{
label.Key("key1"), attribute.Key("key1"),
label.Key("key2"), attribute.Key("key2"),
label.Key("key5"), attribute.Key("key5"),
label.Key("key6"), attribute.Key("key6"),
}, },
SingleKV: label.String("key4", "val4"), SingleKV: attribute.String("key4", "val4"),
MultiKV: []label.KeyValue{ MultiKV: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
label.String("key3", "val3"), attribute.String("key3", "val3"),
}, },
}, },
init: []int{5, 6, 7}, init: []int{5, 6, 7},
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
label.String("key3", "val3"), attribute.String("key3", "val3"),
label.String("key4", "val4"), attribute.String("key4", "val4"),
label.Int("key7", 7), attribute.Int("key7", 7),
}, },
}, },
} }
@ -279,7 +279,7 @@ func getTestCases() []testCase {
func makeTestMap(ints []int) Map { func makeTestMap(ints []int) Map {
r := make(rawMap, len(ints)) r := make(rawMap, len(ints))
for _, v := range 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) return newMap(r)
} }

View File

@ -19,8 +19,8 @@ import (
"testing" "testing"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/label"
metricglobal "go.opentelemetry.io/otel/metric/global" metricglobal "go.opentelemetry.io/otel/metric/global"
) )
@ -31,7 +31,7 @@ func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
global.ResetForTest() global.ResetForTest()
ctx := context.Background() ctx := context.Background()
sdk := metricglobal.Meter("test") sdk := metricglobal.Meter("test")
labs := []label.KeyValue{label.String("A", "B")} labs := []attribute.KeyValue{attribute.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.counter") cnt := Must(sdk).NewInt64Counter("int64.counter")
b.ResetTimer() b.ResetTimer()

View File

@ -20,7 +20,7 @@ import (
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/registry" "go.opentelemetry.io/otel/metric/registry"
@ -109,7 +109,7 @@ type syncHandle struct {
delegate unsafe.Pointer // (*metric.BoundInstrumentImpl) delegate unsafe.Pointer // (*metric.BoundInstrumentImpl)
inst *syncImpl inst *syncImpl
labels []label.KeyValue labels []attribute.KeyValue
initialize sync.Once initialize sync.Once
} }
@ -228,7 +228,7 @@ func (inst *syncImpl) Implementation() interface{} {
return inst 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 { if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
return (*implPtr).Bind(labels) return (*implPtr).Bind(labels)
} }
@ -300,13 +300,13 @@ func (obs *asyncImpl) setDelegate(d metric.MeterImpl) {
// Metric updates // 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 { if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil {
(*delegatePtr).RecordBatch(ctx, labels, measurements...) (*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 { if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
(*instPtr).RecordOne(ctx, number, labels) (*instPtr).RecordOne(ctx, number, labels)
} }

View File

@ -21,8 +21,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
metricglobal "go.opentelemetry.io/otel/metric/global" metricglobal "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
@ -40,9 +40,9 @@ func TestDirect(t *testing.T) {
ctx := context.Background() ctx := context.Background()
meter1 := metricglobal.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0")) meter1 := metricglobal.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0"))
meter2 := metricglobal.Meter("test2") meter2 := metricglobal.Meter("test2")
labels1 := []label.KeyValue{label.String("A", "B")} labels1 := []attribute.KeyValue{attribute.String("A", "B")}
labels2 := []label.KeyValue{label.String("C", "D")} labels2 := []attribute.KeyValue{attribute.String("C", "D")}
labels3 := []label.KeyValue{label.String("E", "F")} labels3 := []attribute.KeyValue{attribute.String("E", "F")}
counter := Must(meter1).NewInt64Counter("test.counter") counter := Must(meter1).NewInt64Counter("test.counter")
counter.Add(ctx, 1, labels1...) counter.Add(ctx, 1, labels1...)
@ -139,7 +139,7 @@ func TestBound(t *testing.T) {
// vs. the above, to cover all the instruments. // vs. the above, to cover all the instruments.
ctx := context.Background() ctx := context.Background()
glob := metricglobal.Meter("test") glob := metricglobal.Meter("test")
labels1 := []label.KeyValue{label.String("A", "B")} labels1 := []attribute.KeyValue{attribute.String("A", "B")}
counter := Must(glob).NewFloat64Counter("test.counter") counter := Must(glob).NewFloat64Counter("test.counter")
boundC := counter.Bind(labels1...) boundC := counter.Bind(labels1...)
@ -183,7 +183,7 @@ func TestUnbind(t *testing.T) {
global.ResetForTest() global.ResetForTest()
glob := metricglobal.Meter("test") glob := metricglobal.Meter("test")
labels1 := []label.KeyValue{label.String("A", "B")} labels1 := []attribute.KeyValue{attribute.String("A", "B")}
counter := Must(glob).NewFloat64Counter("test.counter") counter := Must(glob).NewFloat64Counter("test.counter")
boundC := counter.Bind(labels1...) boundC := counter.Bind(labels1...)

View File

@ -21,7 +21,7 @@ import (
"sync" "sync"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "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. // the SDK to provide support for running observer callbacks.
type AsyncCollector interface { type AsyncCollector interface {
// CollectAsync passes a batch of observations to the MeterImpl. // 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 // AsyncInstrumentState manages an ordered set of asynchronous

View File

@ -17,7 +17,7 @@ package parent
import ( import (
"context" "context"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "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{ return append(links, trace.Link{
SpanContext: sc, SpanContext: sc,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("ignored-on-demand", kind), attribute.String("ignored-on-demand", kind),
}, },
}) })
} }

View File

@ -17,7 +17,7 @@ package metric // import "go.opentelemetry.io/otel/metric"
import ( import (
"context" "context"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/unit" "go.opentelemetry.io/otel/unit"
) )
@ -42,7 +42,7 @@ type Meter struct {
} }
// RecordBatch atomically records a batch of measurements. // 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 { if m.impl == nil {
return return
} }

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"errors" "errors"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
) )
@ -116,25 +116,25 @@ type BatchObserverFunc func(context.Context, BatchObserverResult)
// observations for one asynchronous integer metric instrument. // observations for one asynchronous integer metric instrument.
type Int64ObserverResult struct { type Int64ObserverResult struct {
instrument AsyncImpl instrument AsyncImpl
function func([]label.KeyValue, ...Observation) function func([]attribute.KeyValue, ...Observation)
} }
// Float64ObserverResult is passed to an observer callback to capture // Float64ObserverResult is passed to an observer callback to capture
// observations for one asynchronous floating point metric instrument. // observations for one asynchronous floating point metric instrument.
type Float64ObserverResult struct { type Float64ObserverResult struct {
instrument AsyncImpl instrument AsyncImpl
function func([]label.KeyValue, ...Observation) function func([]attribute.KeyValue, ...Observation)
} }
// BatchObserverResult is passed to a batch observer callback to // BatchObserverResult is passed to a batch observer callback to
// capture observations for multiple asynchronous instruments. // capture observations for multiple asynchronous instruments.
type BatchObserverResult struct { type BatchObserverResult struct {
function func([]label.KeyValue, ...Observation) function func([]attribute.KeyValue, ...Observation)
} }
// Observe captures a single integer value from the associated // Observe captures a single integer value from the associated
// instrument callback, with the given labels. // 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{ ir.function(labels, Observation{
instrument: ir.instrument, instrument: ir.instrument,
number: number.NewInt64Number(value), 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 // Observe captures a single floating point value from the associated
// instrument callback, with the given labels. // 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{ fr.function(labels, Observation{
instrument: fr.instrument, instrument: fr.instrument,
number: number.NewFloat64Number(value), 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 // Observe captures a multiple observations from the associated batch
// instrument callback, with the given labels. // 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...) br.function(labels, obs...)
} }
@ -173,7 +173,7 @@ type AsyncSingleRunner interface {
// receives one captured observation. (The function accepts // receives one captured observation. (The function accepts
// multiple observations so the same implementation can be // multiple observations so the same implementation can be
// used for batch runners.) // 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 AsyncRunner
} }
@ -183,7 +183,7 @@ type AsyncSingleRunner interface {
type AsyncBatchRunner interface { type AsyncBatchRunner interface {
// Run accepts a function for capturing observations of // Run accepts a function for capturing observations of
// multiple instruments. // multiple instruments.
Run(ctx context.Context, capture func([]label.KeyValue, ...Observation)) Run(ctx context.Context, capture func([]attribute.KeyValue, ...Observation))
AsyncRunner AsyncRunner
} }
@ -217,7 +217,7 @@ func (*Float64ObserverFunc) AnyRunner() {}
func (*BatchObserverFunc) AnyRunner() {} func (*BatchObserverFunc) AnyRunner() {}
// Run implements AsyncSingleRunner. // 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{ (*i)(ctx, Int64ObserverResult{
instrument: impl, instrument: impl,
function: function, function: function,
@ -225,7 +225,7 @@ func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function fu
} }
// Run implements AsyncSingleRunner. // 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{ (*f)(ctx, Float64ObserverResult{
instrument: impl, instrument: impl,
function: function, function: function,
@ -233,7 +233,7 @@ func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function
} }
// Run implements AsyncBatchRunner. // 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{ (*b)(ctx, BatchObserverResult{
function: function, function: function,
}) })
@ -442,7 +442,7 @@ func (s syncInstrument) SyncImpl() SyncImpl {
return s.instrument 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)) return newSyncBoundInstrument(s.instrument.Bind(labels))
} }
@ -454,7 +454,7 @@ func (s syncInstrument) int64Measurement(value int64) Measurement {
return newMeasurement(s.instrument, number.NewInt64Number(value)) 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) s.instrument.RecordOne(ctx, number, labels)
} }
@ -577,14 +577,14 @@ type BoundInt64Counter struct {
// Bind creates a bound instrument for this counter. The labels are // Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record. // 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) h.syncBoundInstrument = c.bind(labels)
return return
} }
// Bind creates a bound instrument for this counter. The labels are // Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record. // 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) h.syncBoundInstrument = c.bind(labels)
return 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 // Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value. // 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) c.directRecord(ctx, number.NewFloat64Number(value), labels)
} }
// Add adds the value to the counter's sum. The labels should contain // Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value. // 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) 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 // Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record. // 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) h.syncBoundInstrument = c.bind(labels)
return return
} }
// Bind creates a bound instrument for this counter. The labels are // Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record. // 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) h.syncBoundInstrument = c.bind(labels)
return 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 // Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value. // 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) c.directRecord(ctx, number.NewFloat64Number(value), labels)
} }
// Add adds the value to the counter's sum. The labels should contain // Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value. // 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) 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 // Bind creates a bound instrument for this ValueRecorder. The labels are
// associated with values recorded via subsequent calls to Record. // 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) h.syncBoundInstrument = c.bind(labels)
return return
} }
// Bind creates a bound instrument for this ValueRecorder. The labels are // Bind creates a bound instrument for this ValueRecorder. The labels are
// associated with values recorded via subsequent calls to Record. // 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) h.syncBoundInstrument = c.bind(labels)
return 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 // Record adds a new value to the list of ValueRecorder's records. The
// labels should contain the keys and values to be associated with // labels should contain the keys and values to be associated with
// this value. // 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) c.directRecord(ctx, number.NewFloat64Number(value), labels)
} }
// Record adds a new value to the ValueRecorder's distribution. The // Record adds a new value to the ValueRecorder's distribution. The
// labels should contain the keys and values to be associated with // labels should contain the keys and values to be associated with
// this value. // 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) c.directRecord(ctx, number.NewInt64Number(value), labels)
} }

View File

@ -17,7 +17,7 @@ package metric // import "go.opentelemetry.io/otel/metric"
import ( import (
"context" "context"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
) )
@ -51,9 +51,9 @@ func (noopBoundInstrument) RecordOne(context.Context, number.Number) {
func (noopBoundInstrument) Unbind() { func (noopBoundInstrument) Unbind() {
} }
func (NoopSync) Bind([]label.KeyValue) BoundSyncImpl { func (NoopSync) Bind([]attribute.KeyValue) BoundSyncImpl {
return noopBoundInstrument{} 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 ( import (
"context" "context"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
) )
@ -25,7 +25,7 @@ import (
// implementation. // implementation.
type MeterImpl interface { type MeterImpl interface {
// RecordBatch atomically records a batch of measurements. // 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 // NewSyncInstrument returns a newly constructed
// synchronous instrument implementation or an error, should // synchronous instrument implementation or an error, should
@ -60,10 +60,10 @@ type SyncImpl interface {
// Bind creates an implementation-level bound instrument, // Bind creates an implementation-level bound instrument,
// binding a label set with this instrument implementation. // 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 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 // BoundSyncImpl is the implementation-level interface to a

View File

@ -19,7 +19,7 @@ import (
"errors" "errors"
"testing" "testing"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/oteltest" "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() t.Helper()
batchesCount := len(mock.MeasurementBatches) batchesCount := len(mock.MeasurementBatches)
@ -213,7 +213,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
c := Must(meter).NewFloat64Counter("test.counter.float") c := Must(meter).NewFloat64Counter("test.counter.float")
ctx := context.Background() ctx := context.Background()
labels := []label.KeyValue{label.String("A", "B")} labels := []attribute.KeyValue{attribute.String("A", "B")}
c.Add(ctx, 1994.1, labels...) c.Add(ctx, 1994.1, labels...)
boundInstrument := c.Bind(labels...) boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, -742) boundInstrument.Add(ctx, -742)
@ -226,7 +226,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
c := Must(meter).NewInt64Counter("test.counter.int") c := Must(meter).NewInt64Counter("test.counter.int")
ctx := context.Background() 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...) c.Add(ctx, 42, labels...)
boundInstrument := c.Bind(labels...) boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, 4200) boundInstrument.Add(ctx, 4200)
@ -240,7 +240,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int") c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int")
ctx := context.Background() 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...) c.Add(ctx, 100, labels...)
boundInstrument := c.Bind(labels...) boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, -100) boundInstrument.Add(ctx, -100)
@ -253,7 +253,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float") c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float")
ctx := context.Background() 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...) c.Add(ctx, 100.1, labels...)
boundInstrument := c.Bind(labels...) boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, -76) boundInstrument.Add(ctx, -76)
@ -269,7 +269,7 @@ func TestValueRecorder(t *testing.T) {
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float") m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float")
ctx := context.Background() ctx := context.Background()
labels := []label.KeyValue{} labels := []attribute.KeyValue{}
m.Record(ctx, 42, labels...) m.Record(ctx, 42, labels...)
boundInstrument := m.Bind(labels...) boundInstrument := m.Bind(labels...)
boundInstrument.Record(ctx, 0) boundInstrument.Record(ctx, 0)
@ -282,7 +282,7 @@ func TestValueRecorder(t *testing.T) {
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int") m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int")
ctx := context.Background() ctx := context.Background()
labels := []label.KeyValue{label.Int("I", 1)} labels := []attribute.KeyValue{attribute.Int("I", 1)}
m.Record(ctx, 173, labels...) m.Record(ctx, 173, labels...)
boundInstrument := m.Bind(labels...) boundInstrument := m.Bind(labels...)
boundInstrument.Record(ctx, 80) boundInstrument.Record(ctx, 80)
@ -295,7 +295,7 @@ func TestValueRecorder(t *testing.T) {
func TestObserverInstruments(t *testing.T) { func TestObserverInstruments(t *testing.T) {
t.Run("float valueobserver", func(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() mockSDK, meter := oteltest.NewMeter()
o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(42.1, labels...) result.Observe(42.1, labels...)
@ -306,7 +306,7 @@ func TestObserverInstruments(t *testing.T) {
) )
}) })
t.Run("int valueobserver", func(t *testing.T) { t.Run("int valueobserver", func(t *testing.T) {
labels := []label.KeyValue{} labels := []attribute.KeyValue{}
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-142, labels...) result.Observe(-142, labels...)
@ -317,7 +317,7 @@ func TestObserverInstruments(t *testing.T) {
) )
}) })
t.Run("float sumobserver", func(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() mockSDK, meter := oteltest.NewMeter()
o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(42.1, labels...) result.Observe(42.1, labels...)
@ -328,7 +328,7 @@ func TestObserverInstruments(t *testing.T) {
) )
}) })
t.Run("int sumobserver", func(t *testing.T) { t.Run("int sumobserver", func(t *testing.T) {
labels := []label.KeyValue{} labels := []attribute.KeyValue{}
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-142, labels...) result.Observe(-142, labels...)
@ -339,7 +339,7 @@ func TestObserverInstruments(t *testing.T) {
) )
}) })
t.Run("float updownsumobserver", func(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() mockSDK, meter := oteltest.NewMeter()
o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(42.1, labels...) result.Observe(42.1, labels...)
@ -350,7 +350,7 @@ func TestObserverInstruments(t *testing.T) {
) )
}) })
t.Run("int updownsumobserver", func(t *testing.T) { t.Run("int updownsumobserver", func(t *testing.T) {
labels := []label.KeyValue{} labels := []attribute.KeyValue{}
mockSDK, meter := oteltest.NewMeter() mockSDK, meter := oteltest.NewMeter()
o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-142, labels...) result.Observe(-142, labels...)
@ -368,9 +368,9 @@ func TestBatchObserverInstruments(t *testing.T) {
var obs1 metric.Int64ValueObserver var obs1 metric.Int64ValueObserver
var obs2 metric.Float64ValueObserver var obs2 metric.Float64ValueObserver
labels := []label.KeyValue{ labels := []attribute.KeyValue{
label.String("A", "B"), attribute.String("A", "B"),
label.String("C", "D"), attribute.String("C", "D"),
} }
cb := Must(meter).NewBatchObserver( 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))) 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() t.Helper()
assert.Len(t, mock.MeasurementBatches, 1) assert.Len(t, mock.MeasurementBatches, 1)
if len(mock.MeasurementBatches) < 1 { if len(mock.MeasurementBatches) < 1 {
@ -435,7 +435,7 @@ type testWrappedMeter struct {
var _ metric.MeterImpl = testWrappedMeter{} 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) { func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
) )
@ -75,7 +75,7 @@ func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl {
} }
// RecordBatch implements 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...) u.impl.RecordBatch(ctx, labels, ms...)
} }

View File

@ -17,12 +17,12 @@ package oteltest // import "go.opentelemetry.io/otel/oteltest"
import ( import (
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
) )
// Event encapsulates the properties of calls to AddEvent. // Event encapsulates the properties of calls to AddEvent.
type Event struct { type Event struct {
Timestamp time.Time Timestamp time.Time
Name string Name string
Attributes map[label.Key]label.Value Attributes map[attribute.Key]attribute.Value
} }

View File

@ -20,9 +20,9 @@ import (
"testing" "testing"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/internal/matchers" "go.opentelemetry.io/otel/internal/matchers"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -200,7 +200,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) {
span.SetName("new name") span.SetName("new name")
}, },
"#SetAttributes": func(span trace.Span) { "#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{ var mechanisms = map[string]func() trace.Span{

View File

@ -19,8 +19,8 @@ import (
"sync" "sync"
"testing" "testing"
"go.opentelemetry.io/otel/attribute"
internalmetric "go.opentelemetry.io/otel/internal/metric" internalmetric "go.opentelemetry.io/otel/internal/metric"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/registry" "go.opentelemetry.io/otel/metric/registry"
@ -29,14 +29,14 @@ import (
type ( type (
Handle struct { Handle struct {
Instrument *Sync Instrument *Sync
Labels []label.KeyValue Labels []attribute.KeyValue
} }
Batch struct { Batch struct {
// Measurement needs to be aligned for 64-bit atomic operations. // Measurement needs to be aligned for 64-bit atomic operations.
Measurements []Measurement Measurements []Measurement
Ctx context.Context Ctx context.Context
Labels []label.KeyValue Labels []attribute.KeyValue
LibraryName string LibraryName string
} }
@ -90,14 +90,14 @@ func (s *Sync) Implementation() interface{} {
return s return s
} }
func (s *Sync) Bind(labels []label.KeyValue) metric.BoundSyncImpl { func (s *Sync) Bind(labels []attribute.KeyValue) metric.BoundSyncImpl {
return &Handle{ return &Handle{
Instrument: s, Instrument: s,
Labels: labels, 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) 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 (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{{ m.collect(ctx, labels, []Measurement{{
Instrument: instrument, Instrument: instrument,
Number: number, Number: number,
@ -154,7 +154,7 @@ func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metr
return a, nil 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)) mm := make([]Measurement, len(measurements))
for i := 0; i < len(measurements); i++ { for i := 0; i < len(measurements); i++ {
m := 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) 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)) mm := make([]Measurement, len(obs))
for i := 0; i < len(obs); i++ { for i := 0; i < len(obs); i++ {
o := 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) 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() m.lock.Lock()
defer m.lock.Unlock() defer m.lock.Unlock()
@ -199,13 +199,13 @@ type Measured struct {
Name string Name string
InstrumentationName string InstrumentationName string
InstrumentationVersion string InstrumentationVersion string
Labels map[label.Key]label.Value Labels map[attribute.Key]attribute.Value
Number number.Number Number number.Number
} }
// LabelsToMap converts label set to keyValue map, to be easily used in tests // LabelsToMap converts label set to keyValue map, to be easily used in tests
func LabelsToMap(kvs ...label.KeyValue) map[label.Key]label.Value { func LabelsToMap(kvs ...attribute.KeyValue) map[attribute.Key]attribute.Value {
m := map[label.Key]label.Value{} m := map[attribute.Key]attribute.Value{}
for _, label := range kvs { for _, label := range kvs {
m[label.Key] = label.Value m[label.Key] = label.Value
} }

View File

@ -20,14 +20,14 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
const ( const (
errorTypeKey = label.Key("error.type") errorTypeKey = attribute.Key("error.type")
errorMessageKey = label.Key("error.message") errorMessageKey = attribute.Key("error.message")
errorEventName = "error" errorEventName = "error"
) )
@ -45,7 +45,7 @@ type Span struct {
endTime time.Time endTime time.Time
statusCode codes.Code statusCode codes.Code
statusMessage string statusMessage string
attributes map[label.Key]label.Value attributes map[attribute.Key]attribute.Value
events []Event events []Event
links []trace.Link links []trace.Link
spanKind trace.SpanKind spanKind trace.SpanKind
@ -111,9 +111,9 @@ func (s *Span) AddEvent(name string, o ...trace.EventOption) {
c := trace.NewEventConfig(o...) 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 { 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 { for _, attr := range c.Attributes {
attributes[attr.Key] = attr.Value attributes[attr.Key] = attr.Value
} }
@ -162,7 +162,7 @@ func (s *Span) SetName(name string) {
} }
// SetAttributes sets attrs as attributes of s. // SetAttributes sets attrs as attributes of s.
func (s *Span) SetAttributes(attrs ...label.KeyValue) { func (s *Span) SetAttributes(attrs ...attribute.KeyValue) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() 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 // 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 // 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. // 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() s.lock.RLock()
defer s.lock.RUnlock() defer s.lock.RUnlock()
attributes := make(map[label.Key]label.Value) attributes := make(map[attribute.Key]attribute.Value)
for k, v := range s.attributes { for k, v := range s.attributes {
attributes[k] = v attributes[k] = v

View File

@ -22,10 +22,10 @@ import (
"testing" "testing"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
ottest "go.opentelemetry.io/otel/internal/internaltest" ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/internal/matchers" "go.opentelemetry.io/otel/internal/matchers"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -161,9 +161,9 @@ func TestSpan(t *testing.T) {
expectedEvents := []oteltest.Event{{ expectedEvents := []oteltest.Event{{
Timestamp: testTime, Timestamp: testTime,
Name: "error", Name: "error",
Attributes: map[label.Key]label.Value{ Attributes: map[attribute.Key]attribute.Value{
label.Key("error.type"): label.StringValue(s.typ), attribute.Key("error.type"): attribute.StringValue(s.typ),
label.Key("error.message"): label.StringValue(s.msg), attribute.Key("error.message"): attribute.StringValue(s.msg),
}, },
}} }}
e.Expect(subject.Events()).ToEqual(expectedEvents) e.Expect(subject.Events()).ToEqual(expectedEvents)
@ -191,9 +191,9 @@ func TestSpan(t *testing.T) {
expectedEvents := []oteltest.Event{{ expectedEvents := []oteltest.Event{{
Timestamp: testTime, Timestamp: testTime,
Name: "error", Name: "error",
Attributes: map[label.Key]label.Value{ Attributes: map[attribute.Key]attribute.Value{
label.Key("error.type"): label.StringValue("go.opentelemetry.io/otel/internal/internaltest.TestError"), attribute.Key("error.type"): attribute.StringValue("go.opentelemetry.io/otel/internal/internaltest.TestError"),
label.Key("error.message"): label.StringValue(errMsg), attribute.Key("error.message"): attribute.StringValue(errMsg),
}, },
}} }}
e.Expect(subject.Events()).ToEqual(expectedEvents) e.Expect(subject.Events()).ToEqual(expectedEvents)
@ -330,7 +330,7 @@ func TestSpan(t *testing.T) {
subject, ok := span.(*oteltest.Span) subject, ok := span.(*oteltest.Span)
e.Expect(ok).ToBeTrue() 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) { 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) subject, ok := span.(*oteltest.Span)
e.Expect(ok).ToBeTrue() e.Expect(ok).ToBeTrue()
attr1 := label.String("key1", "value1") attr1 := attribute.String("key1", "value1")
attr2 := label.String("key2", "value2") attr2 := attribute.String("key2", "value2")
attr3 := label.String("key3", "value3") attr3 := attribute.String("key3", "value3")
unexpectedAttr := attr2.Key.String("unexpected") unexpectedAttr := attr2.Key.String("unexpected")
subject.SetAttributes(attr1, unexpectedAttr, attr3) subject.SetAttributes(attr1, unexpectedAttr, attr3)
@ -370,7 +370,7 @@ func TestSpan(t *testing.T) {
subject, ok := span.(*oteltest.Span) subject, ok := span.(*oteltest.Span)
e.Expect(ok).ToBeTrue() e.Expect(ok).ToBeTrue()
expectedAttr := label.String("key", "value") expectedAttr := attribute.String("key", "value")
subject.SetAttributes(expectedAttr) subject.SetAttributes(expectedAttr)
subject.End() subject.End()
@ -400,7 +400,7 @@ func TestSpan(t *testing.T) {
go func() { go func() {
defer wg.Done() defer wg.Done()
subject.SetAttributes(label.String("key", "value")) subject.SetAttributes(attribute.String("key", "value"))
}() }()
go func() { go func() {
@ -458,9 +458,9 @@ func TestSpan(t *testing.T) {
e.Expect(ok).ToBeTrue() e.Expect(ok).ToBeTrue()
event1Name := "event1" event1Name := "event1"
event1Attributes := []label.KeyValue{ event1Attributes := []attribute.KeyValue{
label.String("event1Attr1", "foo"), attribute.String("event1Attr1", "foo"),
label.String("event1Attr2", "bar"), attribute.String("event1Attr2", "bar"),
} }
event1Start := time.Now() event1Start := time.Now()
@ -469,8 +469,8 @@ func TestSpan(t *testing.T) {
event2Timestamp := time.Now().AddDate(5, 0, 0) event2Timestamp := time.Now().AddDate(5, 0, 0)
event2Name := "event1" event2Name := "event1"
event2Attributes := []label.KeyValue{ event2Attributes := []attribute.KeyValue{
label.String("event2Attr", "abc"), attribute.String("event2Attr", "abc"),
} }
subject.AddEvent(event2Name, trace.WithTimestamp(event2Timestamp), trace.WithAttributes(event2Attributes...)) subject.AddEvent(event2Name, trace.WithTimestamp(event2Timestamp), trace.WithAttributes(event2Attributes...))

View File

@ -18,7 +18,7 @@ import (
"context" "context"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -46,7 +46,7 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanOptio
span := &Span{ span := &Span{
tracer: t, tracer: t,
startTime: startTime, startTime: startTime,
attributes: make(map[label.Key]label.Value), attributes: make(map[attribute.Key]attribute.Value),
links: []trace.Link{}, links: []trace.Link{},
spanKind: c.SpanKind, spanKind: c.SpanKind,
} }
@ -54,17 +54,17 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanOptio
if c.NewRoot { if c.NewRoot {
span.spanContext = trace.SpanContext{} span.spanContext = trace.SpanContext{}
iodKey := label.Key("ignored-on-demand") iodKey := attribute.Key("ignored-on-demand")
if lsc := trace.SpanContextFromContext(ctx); lsc.IsValid() { if lsc := trace.SpanContextFromContext(ctx); lsc.IsValid() {
span.links = append(span.links, trace.Link{ span.links = append(span.links, trace.Link{
SpanContext: lsc, SpanContext: lsc,
Attributes: []label.KeyValue{iodKey.String("current")}, Attributes: []attribute.KeyValue{iodKey.String("current")},
}) })
} }
if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() { if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() {
span.links = append(span.links, trace.Link{ span.links = append(span.links, trace.Link{
SpanContext: rsc, SpanContext: rsc,
Attributes: []label.KeyValue{iodKey.String("remote")}, Attributes: []attribute.KeyValue{iodKey.String("remote")},
}) })
} }
} else { } else {

View File

@ -22,8 +22,8 @@ import (
"testing" "testing"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/matchers" "go.opentelemetry.io/otel/internal/matchers"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -67,8 +67,8 @@ func TestTracer(t *testing.T) {
e := matchers.NewExpecter(t) e := matchers.NewExpecter(t)
attr1 := label.String("a", "1") attr1 := attribute.String("a", "1")
attr2 := label.String("b", "2") attr2 := attribute.String("b", "2")
subject := tp.Tracer(t.Name()) subject := tp.Tracer(t.Name())
_, span := subject.Start(context.Background(), "test", trace.WithAttributes(attr1, attr2)) _, span := subject.Start(context.Background(), "test", trace.WithAttributes(attr1, attr2))
@ -200,14 +200,14 @@ func TestTracer(t *testing.T) {
expectedLinks := []trace.Link{ expectedLinks := []trace.Link{
{ {
SpanContext: parentSpanContext, SpanContext: parentSpanContext,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("ignored-on-demand", "current"), attribute.String("ignored-on-demand", "current"),
}, },
}, },
{ {
SpanContext: remoteParentSpanContext, SpanContext: remoteParentSpanContext,
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("ignored-on-demand", "remote"), attribute.String("ignored-on-demand", "remote"),
}, },
}, },
} }
@ -225,16 +225,16 @@ func TestTracer(t *testing.T) {
_, span := subject.Start(context.Background(), "link1") _, span := subject.Start(context.Background(), "link1")
link1 := trace.Link{ link1 := trace.Link{
SpanContext: span.SpanContext(), SpanContext: span.SpanContext(),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("a", "1"), attribute.String("a", "1"),
}, },
} }
_, span = subject.Start(context.Background(), "link2") _, span = subject.Start(context.Background(), "link2")
link2 := trace.Link{ link2 := trace.Link{
SpanContext: span.SpanContext(), SpanContext: span.SpanContext(),
Attributes: []label.KeyValue{ Attributes: []attribute.KeyValue{
label.String("b", "2"), attribute.String("b", "2"),
}, },
} }

View File

@ -19,8 +19,8 @@ import (
"net/url" "net/url"
"strings" "strings"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/label"
) )
const baggageHeader = "baggage" const baggageHeader = "baggage"
@ -38,7 +38,7 @@ func (b Baggage) Inject(ctx context.Context, carrier TextMapCarrier) {
baggageMap := baggage.MapFromContext(ctx) baggageMap := baggage.MapFromContext(ctx)
firstIter := true firstIter := true
var headerValueBuilder strings.Builder var headerValueBuilder strings.Builder
baggageMap.Foreach(func(kv label.KeyValue) bool { baggageMap.Foreach(func(kv attribute.KeyValue) bool {
if !firstIter { if !firstIter {
headerValueBuilder.WriteRune(',') headerValueBuilder.WriteRune(',')
} }
@ -62,7 +62,7 @@ func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context
} }
baggageValues := strings.Split(bVal, ",") baggageValues := strings.Split(bVal, ",")
keyValues := make([]label.KeyValue, 0, len(baggageValues)) keyValues := make([]attribute.KeyValue, 0, len(baggageValues))
for _, baggageValue := range baggageValues { for _, baggageValue := range baggageValues {
valueAndProps := strings.Split(baggageValue, ";") valueAndProps := strings.Split(baggageValue, ";")
if len(valueAndProps) < 1 { if len(valueAndProps) < 1 {
@ -92,7 +92,7 @@ func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context
trimmedValueWithProps.WriteString(prop) trimmedValueWithProps.WriteString(prop)
} }
keyValues = append(keyValues, label.String(trimmedName, trimmedValueWithProps.String())) keyValues = append(keyValues, attribute.String(trimmedName, trimmedValueWithProps.String()))
} }
if len(keyValues) > 0 { if len(keyValues) > 0 {

View File

@ -22,8 +22,8 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/baggage" "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/propagation"
) )
@ -32,54 +32,54 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
header string header string
wantKVs []label.KeyValue wantKVs []attribute.KeyValue
}{ }{
{ {
name: "valid w3cHeader", name: "valid w3cHeader",
header: "key1=val1,key2=val2", header: "key1=val1,key2=val2",
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
{ {
name: "valid w3cHeader with spaces", name: "valid w3cHeader with spaces",
header: "key1 = val1, key2 =val2 ", header: "key1 = val1, key2 =val2 ",
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
{ {
name: "valid w3cHeader with properties", name: "valid w3cHeader with properties",
header: "key1=val1,key2=val2;prop=1", header: "key1=val1,key2=val2;prop=1",
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2;prop=1"), attribute.String("key2", "val2;prop=1"),
}, },
}, },
{ {
name: "valid header with url-escaped comma", name: "valid header with url-escaped comma",
header: "key1=val1,key2=val2%2Cval3", header: "key1=val1,key2=val2%2Cval3",
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2,val3"), attribute.String("key2", "val2,val3"),
}, },
}, },
{ {
name: "valid header with an invalid header", name: "valid header with an invalid header",
header: "key1=val1,key2=val2,a,val3", header: "key1=val1,key2=val2,a,val3",
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
{ {
name: "valid header with no value", name: "valid header with no value",
header: "key1=,key2=val2", header: "key1=,key2=val2",
wantKVs: []label.KeyValue{ wantKVs: []attribute.KeyValue{
label.String("key1", ""), attribute.String("key1", ""),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
} }
@ -101,9 +101,9 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) {
) )
} }
totalDiff := "" totalDiff := ""
wantBaggage.Foreach(func(keyValue label.KeyValue) bool { wantBaggage.Foreach(func(keyValue attribute.KeyValue) bool {
val, _ := gotBaggage.Value(keyValue.Key) 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 != "" { if diff != "" {
totalDiff += diff + "\n" totalDiff += diff + "\n"
} }
@ -121,7 +121,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
header string header string
hasKVs []label.KeyValue hasKVs []attribute.KeyValue
}{ }{
{ {
name: "no key values", name: "no key values",
@ -130,17 +130,17 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
{ {
name: "invalid header with existing context", name: "invalid header with existing context",
header: "header2", header: "header2",
hasKVs: []label.KeyValue{ hasKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
{ {
name: "empty header value", name: "empty header value",
header: "", header: "",
hasKVs: []label.KeyValue{ hasKVs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
}, },
} }
@ -162,9 +162,9 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
) )
} }
totalDiff := "" totalDiff := ""
wantBaggage.Foreach(func(keyValue label.KeyValue) bool { wantBaggage.Foreach(func(keyValue attribute.KeyValue) bool {
val, _ := gotBaggage.Value(keyValue.Key) 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 != "" { if diff != "" {
totalDiff += diff + "\n" totalDiff += diff + "\n"
} }
@ -178,33 +178,33 @@ func TestInjectBaggageToHTTPReq(t *testing.T) {
propagator := propagation.Baggage{} propagator := propagation.Baggage{}
tests := []struct { tests := []struct {
name string name string
kvs []label.KeyValue kvs []attribute.KeyValue
wantInHeader []string wantInHeader []string
wantedLen int wantedLen int
}{ }{
{ {
name: "two simple values", name: "two simple values",
kvs: []label.KeyValue{ kvs: []attribute.KeyValue{
label.String("key1", "val1"), attribute.String("key1", "val1"),
label.String("key2", "val2"), attribute.String("key2", "val2"),
}, },
wantInHeader: []string{"key1=val1", "key2=val2"}, wantInHeader: []string{"key1=val1", "key2=val2"},
}, },
{ {
name: "two values with escaped chars", name: "two values with escaped chars",
kvs: []label.KeyValue{ kvs: []attribute.KeyValue{
label.String("key1", "val1,val2"), attribute.String("key1", "val1,val2"),
label.String("key2", "val3=4"), attribute.String("key2", "val3=4"),
}, },
wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"}, wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"},
}, },
{ {
name: "values of non-string types", name: "values of non-string types",
kvs: []label.KeyValue{ kvs: []attribute.KeyValue{
label.Bool("key1", true), attribute.Bool("key1", true),
label.Int("key2", 123), attribute.Int("key2", 123),
label.Int64("key3", 123), attribute.Int64("key3", 123),
label.Float64("key4", 123.567), attribute.Float64("key4", 123.567),
}, },
wantInHeader: []string{ wantInHeader: []string{
"key1=true", "key1=true",

View File

@ -21,7 +21,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -151,14 +151,14 @@ func parseTraceState(in string) trace.TraceState {
return trace.TraceState{} return trace.TraceState{}
} }
kvs := []label.KeyValue{} kvs := []attribute.KeyValue{}
for _, entry := range strings.Split(in, ",") { for _, entry := range strings.Split(in, ",") {
parts := strings.SplitN(entry, "=", 2) parts := strings.SplitN(entry, "=", 2)
if len(parts) != 2 { if len(parts) != 2 {
// Parse failure, abort! // Parse failure, abort!
return trace.TraceState{} 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 // Ignoring error here as "failure to parse tracestate MUST NOT

View File

@ -21,7 +21,7 @@ import (
"github.com/google/go-cmp/cmp" "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/oteltest"
"go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
@ -280,7 +280,7 @@ func TestTraceStatePropagation(t *testing.T) {
prop := propagation.TraceContext{} prop := propagation.TraceContext{}
stateHeader := "tracestate" stateHeader := "tracestate"
parentHeader := "traceparent" 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 { if err != nil {
t.Fatalf("Unable to construct expected TraceState: %s", err.Error()) t.Fatalf("Unable to construct expected TraceState: %s", err.Error())
} }
@ -341,7 +341,7 @@ func TestTraceStatePropagation(t *testing.T) {
if diff := cmp.Diff( if diff := cmp.Diff(
trace.RemoteSpanContextFromContext(ctx), trace.RemoteSpanContextFromContext(ctx),
tt.wantSc, tt.wantSc,
cmp.AllowUnexported(label.Value{}), cmp.AllowUnexported(attribute.Value{}),
cmp.AllowUnexported(trace.TraceState{}), cmp.AllowUnexported(trace.TraceState{}),
); diff != "" { ); diff != "" {
t.Errorf("Extracted tracestate: -got +want %s", diff) t.Errorf("Extracted tracestate: -got +want %s", diff)

View File

@ -21,7 +21,7 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/aggregation"
@ -267,7 +267,7 @@ type CheckpointSet interface {
// steps. // steps.
type Metadata struct { type Metadata struct {
descriptor *metric.Descriptor descriptor *metric.Descriptor
labels *label.Set labels *attribute.Set
resource *resource.Resource resource *resource.Resource
} }
@ -295,7 +295,7 @@ func (m Metadata) Descriptor() *metric.Descriptor {
// Labels describes the labels associated with the instrument and the // Labels describes the labels associated with the instrument and the
// aggregated data. // aggregated data.
func (m Metadata) Labels() *label.Set { func (m Metadata) Labels() *attribute.Set {
return m.labels return m.labels
} }
@ -308,7 +308,7 @@ func (m Metadata) Resource() *resource.Resource {
// Accumulations to send to Processors. The Descriptor, Labels, Resource, // Accumulations to send to Processors. The Descriptor, Labels, Resource,
// and Aggregator represent aggregate metric events received over a single // and Aggregator represent aggregate metric events received over a single
// collection period. // 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{ return Accumulation{
Metadata: Metadata{ Metadata: Metadata{
descriptor: descriptor, descriptor: descriptor,
@ -328,7 +328,7 @@ func (r Accumulation) Aggregator() Aggregator {
// NewRecord allows Processor implementations to construct export // NewRecord allows Processor implementations to construct export
// records. The Descriptor, Labels, and Aggregator represent // records. The Descriptor, Labels, and Aggregator represent
// aggregate metric events received over a single collection period. // 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{ return Record{
Metadata: Metadata{ Metadata: Metadata{
descriptor: descriptor, descriptor: descriptor,

View File

@ -17,18 +17,18 @@ package metric
import ( import (
"testing" "testing"
"go.opentelemetry.io/otel/label"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
) )
var testSlice = []label.KeyValue{ var testSlice = []attribute.KeyValue{
label.String("bar", "baz"), attribute.String("bar", "baz"),
label.Int("foo", 42), attribute.Int("foo", 42),
} }
func newIter(slice []label.KeyValue) label.Iterator { func newIter(slice []attribute.KeyValue) attribute.Iterator {
labels := label.NewSet(slice...) labels := attribute.NewSet(slice...)
return labels.Iter() return labels.Iter()
} }
@ -37,17 +37,17 @@ func TestLabelIterator(t *testing.T) {
require.Equal(t, 2, iter.Len()) require.Equal(t, 2, iter.Len())
require.True(t, iter.Next()) 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() idx, kv := iter.IndexedLabel()
require.Equal(t, 0, idx) 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.Equal(t, 2, iter.Len())
require.True(t, iter.Next()) 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() idx, kv = iter.IndexedLabel()
require.Equal(t, 1, idx) 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.Equal(t, 2, iter.Len())
require.False(t, iter.Next()) require.False(t, iter.Next())

View File

@ -21,7 +21,7 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -31,7 +31,7 @@ import (
type mapkey struct { type mapkey struct {
desc *metric.Descriptor desc *metric.Descriptor
distinct label.Distinct distinct attribute.Distinct
} }
// CheckpointSet is useful for testing Exporters. // 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, // If there is an existing record with the same descriptor and labels,
// the stored aggregator will be returned and should be merged. // 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) { func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...attribute.KeyValue) (agg export.Aggregator, added bool) {
elabels := label.NewSet(labels...) elabels := attribute.NewSet(labels...)
key := mapkey{ key := mapkey{
desc: desc, desc: desc,

View File

@ -18,8 +18,8 @@ import (
"context" "context"
"time" "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/sdk/instrumentation" "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 // The wall clock time of EndTime will be adjusted to always be offset
// from StartTime by the duration of the span. // from StartTime by the duration of the span.
EndTime time.Time EndTime time.Time
Attributes []label.KeyValue Attributes []attribute.KeyValue
MessageEvents []trace.Event MessageEvents []trace.Event
Links []trace.Link Links []trace.Link
StatusCode codes.Code StatusCode codes.Code

View File

@ -20,7 +20,7 @@ import (
"math/rand" "math/rand"
"testing" "testing"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/global"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -59,8 +59,8 @@ func (f *benchFixture) meterMust() metric.MeterMust {
return metric.Must(f.meter) return metric.Must(f.meter)
} }
func makeManyLabels(n int) [][]label.KeyValue { func makeManyLabels(n int) [][]attribute.KeyValue {
r := make([][]label.KeyValue, n) r := make([][]attribute.KeyValue, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
r[i] = makeLabels(1) r[i] = makeLabels(1)
@ -69,9 +69,9 @@ func makeManyLabels(n int) [][]label.KeyValue {
return r return r
} }
func makeLabels(n int) []label.KeyValue { func makeLabels(n int) []attribute.KeyValue {
used := map[string]bool{} used := map[string]bool{}
l := make([]label.KeyValue, n) l := make([]attribute.KeyValue, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
var k string var k string
for { for {
@ -81,7 +81,7 @@ func makeLabels(n int) []label.KeyValue {
break 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 return l
} }
@ -120,7 +120,7 @@ func BenchmarkInt64CounterAddWithLabels_16(b *testing.B) {
} }
// Note: performance does not depend on label set size for the // 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) { func BenchmarkAcquireNewHandle(b *testing.B) {
fix := newFixture(b) fix := newFixture(b)
@ -168,10 +168,10 @@ func BenchmarkAcquireReleaseExistingHandle(b *testing.B) {
// Iterators // Iterators
var benchmarkIteratorVar label.KeyValue var benchmarkIteratorVar attribute.KeyValue
func benchmarkIterator(b *testing.B, n int) { func benchmarkIterator(b *testing.B, n int) {
labels := label.NewSet(makeLabels(n)...) labels := attribute.NewSet(makeLabels(n)...)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
iter := labels.Iter() iter := labels.Iter()
@ -217,7 +217,7 @@ func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) {
sdk := global.Meter("test") sdk := global.Meter("test")
global.SetMeterProvider(fix) global.SetMeterProvider(fix)
labs := []label.KeyValue{label.String("A", "B")} labs := []attribute.KeyValue{attribute.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.sum") cnt := Must(sdk).NewInt64Counter("int64.sum")
b.ResetTimer() b.ResetTimer()
@ -520,7 +520,7 @@ func BenchmarkRepeatedDirectCalls(b *testing.B) {
fix := newFixture(b) fix := newFixture(b)
c := fix.meterMust().NewInt64Counter("int64.sum") c := fix.meterMust().NewInt64Counter("int64.sum")
k := label.String("bench", "true") k := attribute.String("bench", "true")
b.ResetTimer() b.ResetTimer()

View File

@ -19,12 +19,12 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
) )
func TestWithResource(t *testing.T) { func TestWithResource(t *testing.T) {
r := resource.NewWithAttributes(label.String("A", "a")) r := resource.NewWithAttributes(attribute.String("A", "a"))
c := &Config{} c := &Config{}
WithResource(r).Apply(c) WithResource(r).Apply(c)

View File

@ -23,7 +23,7 @@ import (
"github.com/stretchr/testify/require" "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"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/aggregation"
@ -35,7 +35,7 @@ import (
) )
func getMap(t *testing.T, cont *controller.Controller) map[string]float64 { 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( require.NoError(t, cont.ForEach(
export.CumulativeExportKindSelector(), export.CumulativeExportKindSelector(),
@ -70,16 +70,16 @@ func TestControllerUsesResource(t *testing.T) {
{ {
name: "uses default if no resource option", name: "uses default if no resource option",
options: nil, options: nil,
wanted: resource.Default().Encoded(label.DefaultEncoder())}, wanted: resource.Default().Encoded(attribute.DefaultEncoder())},
{ {
name: "explicit resource", 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"}, wanted: "R=S"},
{ {
name: "last resource wins", name: "last resource wins",
options: []controller.Option{ options: []controller.Option{
controller.WithResource(resource.Default()), controller.WithResource(resource.Default()),
controller.WithResource(resource.NewWithAttributes(label.String("R", "S"))), controller.WithResource(resource.NewWithAttributes(attribute.String("R", "S"))),
}, },
wanted: "R=S", wanted: "R=S",
}, },
@ -128,7 +128,7 @@ func TestStartNoExporter(t *testing.T) {
func(ctx context.Context, result metric.Int64ObserverResult) { func(ctx context.Context, result metric.Int64ObserverResult) {
calls++ calls++
checkTestContext(t, ctx) 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{ return &blockingExporter{
exporter: processortest.NewExporter( exporter: processortest.NewExporter(
export.CumulativeExportKindSelector(), export.CumulativeExportKindSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
), ),
} }
} }
@ -332,7 +332,7 @@ func TestExportTimeout(t *testing.T) {
func TestCollectAfterStopThenStartAgain(t *testing.T) { func TestCollectAfterStopThenStartAgain(t *testing.T) {
exp := processortest.NewExporter( exp := processortest.NewExporter(
export.CumulativeExportKindSelector(), export.CumulativeExportKindSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
) )
cont := controller.New( cont := controller.New(
processor.New( processor.New(

View File

@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/require" "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"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
@ -47,20 +47,20 @@ func TestPullNoCollect(t *testing.T) {
meter := puller.MeterProvider().Meter("nocache") meter := puller.MeterProvider().Meter("nocache")
counter := metric.Must(meter).NewInt64Counter("counter.sum") 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)) 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.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
"counter.sum/A=B/": 10, "counter.sum/A=B/": 10,
}, records.Map()) }, records.Map())
counter.Add(ctx, 10, label.String("A", "B")) counter.Add(ctx, 10, attribute.String("A", "B"))
require.NoError(t, puller.Collect(ctx)) 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.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
@ -85,21 +85,21 @@ func TestPullWithCollect(t *testing.T) {
meter := puller.MeterProvider().Meter("nocache") meter := puller.MeterProvider().Meter("nocache")
counter := metric.Must(meter).NewInt64Counter("counter.sum") 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)) 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.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
"counter.sum/A=B/": 10, "counter.sum/A=B/": 10,
}, records.Map()) }, records.Map())
counter.Add(ctx, 10, label.String("A", "B")) counter.Add(ctx, 10, attribute.String("A", "B"))
// Cached value! // Cached value!
require.NoError(t, puller.Collect(ctx)) 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.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
@ -111,7 +111,7 @@ func TestPullWithCollect(t *testing.T) {
// Re-computed value! // Re-computed value!
require.NoError(t, puller.Collect(ctx)) 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.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{

View File

@ -26,7 +26,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/aggregation"
@ -37,7 +37,7 @@ import (
"go.opentelemetry.io/otel/sdk/resource" "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 { type handler struct {
sync.Mutex sync.Mutex
@ -68,7 +68,7 @@ func init() {
func newExporter() *processortest.Exporter { func newExporter() *processortest.Exporter {
return processortest.NewExporter( return processortest.NewExporter(
export.StatelessExportKindSelector(), export.StatelessExportKindSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
) )
} }
@ -76,7 +76,7 @@ func newCheckpointer() export.Checkpointer {
return processortest.Checkpointer( return processortest.Checkpointer(
processortest.NewProcessor( processortest.NewProcessor(
processortest.AggregatorSelector(), processortest.AggregatorSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
), ),
) )
} }
@ -205,7 +205,7 @@ func TestPushExportError(t *testing.T) {
require.NoError(t, p.Start(ctx)) require.NoError(t, p.Start(ctx))
runtime.Gosched() runtime.Gosched()
counter1.Add(ctx, 3, label.String("X", "Y")) counter1.Add(ctx, 3, attribute.String("X", "Y"))
counter2.Add(ctx, 5) counter2.Add(ctx, 5)
require.Equal(t, 0, exporter.ExportCount()) require.Equal(t, 0, exporter.ExportCount())

View File

@ -24,7 +24,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -35,7 +35,7 @@ import (
) )
var Must = metric.Must var Must = metric.Must
var testResource = resource.NewWithAttributes(label.String("R", "V")) var testResource = resource.NewWithAttributes(attribute.String("R", "V"))
type handler struct { type handler struct {
sync.Mutex sync.Mutex
@ -209,19 +209,19 @@ func TestSDKLabelsDeduplication(t *testing.T) {
keySets = 2 keySets = 2
repeats = 3 repeats = 3
) )
var keysA []label.Key var keysA []attribute.Key
var keysB []label.Key var keysB []attribute.Key
for i := 0; i < maxKeys; i++ { for i := 0; i < maxKeys; i++ {
keysA = append(keysA, label.Key(fmt.Sprintf("A%03d", i))) keysA = append(keysA, attribute.Key(fmt.Sprintf("A%03d", i)))
keysB = append(keysB, label.Key(fmt.Sprintf("B%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++ { for numKeys := 0; numKeys < maxKeys; numKeys++ {
var kvsA []label.KeyValue var kvsA []attribute.KeyValue
var kvsB []label.KeyValue var kvsB []attribute.KeyValue
for r := 0; r < repeats; r++ { for r := 0; r < repeats; r++ {
for i := 0; i < numKeys; i++ { for i := 0; i < numKeys; i++ {
kvsA = append(kvsA, keysA[i].Int(r)) kvsA = append(kvsA, keysA[i].Int(r))
@ -229,8 +229,8 @@ func TestSDKLabelsDeduplication(t *testing.T) {
} }
} }
var expectA []label.KeyValue var expectA []attribute.KeyValue
var expectB []label.KeyValue var expectB []attribute.KeyValue
for i := 0; i < numKeys; i++ { for i := 0; i < numKeys; i++ {
expectA = append(expectA, keysA[i].Int(repeats-1)) expectA = append(expectA, keysA[i].Int(repeats-1))
expectB = append(expectB, keysB[i].Int(repeats-1)) expectB = append(expectB, keysB[i].Int(repeats-1))
@ -251,7 +251,7 @@ func TestSDKLabelsDeduplication(t *testing.T) {
sdk.Collect(ctx) sdk.Collect(ctx)
var actual [][]label.KeyValue var actual [][]attribute.KeyValue
for _, rec := range processor.accumulations { for _, rec := range processor.accumulations {
sum, _ := rec.Aggregator().(aggregation.Sum).Sum() sum, _ := rec.Aggregator().(aggregation.Sum).Sum()
require.Equal(t, sum, number.NewInt64Number(2)) require.Equal(t, sum, number.NewInt64Number(2))
@ -263,32 +263,32 @@ func TestSDKLabelsDeduplication(t *testing.T) {
require.ElementsMatch(t, allExpect, actual) require.ElementsMatch(t, allExpect, actual)
} }
func newSetIter(kvs ...label.KeyValue) label.Iterator { func newSetIter(kvs ...attribute.KeyValue) attribute.Iterator {
labels := label.NewSet(kvs...) labels := attribute.NewSet(kvs...)
return labels.Iter() return labels.Iter()
} }
func TestDefaultLabelEncoder(t *testing.T) { 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) 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) 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) require.Equal(t, `\,=\\,\\=\=`, encoded)
// Note: the label encoder does not sort or de-dup values, // Note: the label encoder does not sort or de-dup values,
// that is done in Labels(...). // that is done in Labels(...).
encoded = encoder.Encode(newSetIter( encoded = encoder.Encode(newSetIter(
label.Int("I", 1), attribute.Int("I", 1),
label.Int64("I64", 1), attribute.Int64("I64", 1),
label.Float64("F64", 1), attribute.Float64("F64", 1),
label.Float64("F64", 1), attribute.Float64("F64", 1),
label.String("S", "1"), attribute.String("S", "1"),
label.Bool("B", true), attribute.Bool("B", true),
)) ))
require.Equal(t, "B=true,F64=1,I=1,I64=1,S=1", encoded) 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 mult := 1
_ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) { _ = 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 // last value wins
result.Observe(float64(-mult), label.String("A", "B")) result.Observe(float64(-mult), attribute.String("A", "B"))
result.Observe(float64(-mult), label.String("C", "D")) result.Observe(float64(-mult), attribute.String("C", "D"))
}) })
_ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) { _ = 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)) result.Observe(int64(mult))
// last value wins // last value wins
result.Observe(int64(mult), label.String("A", "B")) result.Observe(int64(mult), attribute.String("A", "B"))
result.Observe(int64(mult)) result.Observe(int64(mult))
}) })
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { _ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(float64(mult), label.String("A", "B")) result.Observe(float64(mult), attribute.String("A", "B"))
result.Observe(float64(2*mult), label.String("A", "B")) result.Observe(float64(2*mult), attribute.String("A", "B"))
result.Observe(float64(mult), label.String("C", "D")) result.Observe(float64(mult), attribute.String("C", "D"))
}) })
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { _ = 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)) result.Observe(int64(mult))
// last value wins // last value wins
result.Observe(int64(mult), label.String("A", "B")) result.Observe(int64(mult), attribute.String("A", "B"))
result.Observe(int64(mult)) result.Observe(int64(mult))
}) })
_ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) { _ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(float64(mult), label.String("A", "B")) result.Observe(float64(mult), attribute.String("A", "B"))
result.Observe(float64(-2*mult), label.String("A", "B")) result.Observe(float64(-2*mult), attribute.String("A", "B"))
result.Observe(float64(mult), label.String("C", "D")) result.Observe(float64(mult), attribute.String("C", "D"))
}) })
_ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { _ = 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)) result.Observe(int64(mult))
// last value wins // last value wins
result.Observe(int64(mult), label.String("A", "B")) result.Observe(int64(mult), attribute.String("A", "B"))
result.Observe(int64(-mult)) result.Observe(int64(-mult))
}) })
@ -347,7 +347,7 @@ func TestObserverCollection(t *testing.T) {
collected := sdk.Collect(ctx) collected := sdk.Collect(ctx)
require.Equal(t, collected, len(processor.accumulations)) require.Equal(t, collected, len(processor.accumulations))
out := processortest.NewOutput(label.DefaultEncoder()) out := processortest.NewOutput(attribute.DefaultEncoder())
for _, rec := range processor.accumulations { for _, rec := range processor.accumulations {
require.NoError(t, out.AddAccumulation(rec)) 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. // 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) { _ = 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()) 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()) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
}) })
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) { _ = 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()) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
result.Observe(-1) result.Observe(-1)
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush()) require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
@ -412,8 +412,8 @@ func TestObserverBatch(t *testing.T) {
var batch = Must(meter).NewBatchObserver( var batch = Must(meter).NewBatchObserver(
func(_ context.Context, result metric.BatchObserverResult) { func(_ context.Context, result metric.BatchObserverResult) {
result.Observe( result.Observe(
[]label.KeyValue{ []attribute.KeyValue{
label.String("A", "B"), attribute.String("A", "B"),
}, },
floatValueObs.Observation(1), floatValueObs.Observation(1),
floatValueObs.Observation(-1), floatValueObs.Observation(-1),
@ -425,8 +425,8 @@ func TestObserverBatch(t *testing.T) {
intUpDownSumObs.Observation(-100), intUpDownSumObs.Observation(-100),
) )
result.Observe( result.Observe(
[]label.KeyValue{ []attribute.KeyValue{
label.String("C", "D"), attribute.String("C", "D"),
}, },
floatValueObs.Observation(-1), floatValueObs.Observation(-1),
floatSumObs.Observation(-1), floatSumObs.Observation(-1),
@ -452,7 +452,7 @@ func TestObserverBatch(t *testing.T) {
require.Equal(t, collected, len(processor.accumulations)) require.Equal(t, collected, len(processor.accumulations))
out := processortest.NewOutput(label.DefaultEncoder()) out := processortest.NewOutput(attribute.DefaultEncoder())
for _, rec := range processor.accumulations { for _, rec := range processor.accumulations {
require.NoError(t, out.AddAccumulation(rec)) require.NoError(t, out.AddAccumulation(rec))
} }
@ -485,9 +485,9 @@ func TestRecordBatch(t *testing.T) {
sdk.RecordBatch( sdk.RecordBatch(
ctx, ctx,
[]label.KeyValue{ []attribute.KeyValue{
label.String("A", "B"), attribute.String("A", "B"),
label.String("C", "D"), attribute.String("C", "D"),
}, },
counter1.Measurement(1), counter1.Measurement(1),
counter2.Measurement(2), counter2.Measurement(2),
@ -497,7 +497,7 @@ func TestRecordBatch(t *testing.T) {
sdk.Collect(ctx) sdk.Collect(ctx)
out := processortest.NewOutput(label.DefaultEncoder()) out := processortest.NewOutput(attribute.DefaultEncoder())
for _, rec := range processor.accumulations { for _, rec := range processor.accumulations {
require.NoError(t, out.AddAccumulation(rec)) require.NoError(t, out.AddAccumulation(rec))
} }
@ -517,8 +517,8 @@ func TestRecordPersistence(t *testing.T) {
meter, sdk, processor := newSDK(t) meter, sdk, processor := newSDK(t)
c := Must(meter).NewFloat64Counter("name.sum") c := Must(meter).NewFloat64Counter("name.sum")
b := c.Bind(label.String("bound", "true")) b := c.Bind(attribute.String("bound", "true"))
uk := label.String("bound", "false") uk := attribute.String("bound", "false")
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
c.Add(ctx, 1, uk) c.Add(ctx, 1, uk)
@ -579,7 +579,7 @@ func TestSyncInAsync(t *testing.T) {
sdk.Collect(ctx) sdk.Collect(ctx)
out := processortest.NewOutput(label.DefaultEncoder()) out := processortest.NewOutput(attribute.DefaultEncoder())
for _, rec := range processor.accumulations { for _, rec := range processor.accumulations {
require.NoError(t, out.AddAccumulation(rec)) require.NoError(t, out.AddAccumulation(rec))
} }

View File

@ -20,7 +20,7 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/aggregation"
@ -48,13 +48,13 @@ type (
// instead of the descriptor pointer. See // instead of the descriptor pointer. See
// https://github.com/open-telemetry/opentelemetry-go/issues/862. // https://github.com/open-telemetry/opentelemetry-go/issues/862.
descriptor *metric.Descriptor descriptor *metric.Descriptor
distinct label.Distinct distinct attribute.Distinct
resource label.Distinct resource attribute.Distinct
} }
stateValue struct { stateValue struct {
// labels corresponds to the stateKey.distinct field. // labels corresponds to the stateKey.distinct field.
labels *label.Set labels *attribute.Set
// resource corresponds to the stateKey.resource field. // resource corresponds to the stateKey.resource field.
resource *resource.Resource resource *resource.Resource

View File

@ -24,7 +24,7 @@ import (
"github.com/stretchr/testify/require" "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"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" 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)) 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 { func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...attribute.KeyValue) export.Accumulation {
ls := label.NewSet(labs...) ls := attribute.NewSet(labs...)
var agg export.Aggregator var agg export.Aggregator
selector.AggregatorFor(desc, &agg) selector.AggregatorFor(desc, &agg)
require.NoError(t, agg.Update(context.Background(), asNumber(desc.NumberKind(), value), desc)) 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 // Note: this selector uses the instrument name to dictate
// aggregation kind. // aggregation kind.
selector := processorTest.AggregatorSelector() selector := processorTest.AggregatorSelector()
res := resource.NewWithAttributes(label.String("R", "V")) res := resource.NewWithAttributes(attribute.String("R", "V"))
labs1 := []label.KeyValue{label.String("L1", "V")} labs1 := []attribute.KeyValue{attribute.String("L1", "V")}
labs2 := []label.KeyValue{label.String("L2", "V")} labs2 := []attribute.KeyValue{attribute.String("L2", "V")}
testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) { testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) {
processor := basic.New(selector, export.ConstantExportKindSelector(ekind), basic.WithMemory(hasMemory)) processor := basic.New(selector, export.ConstantExportKindSelector(ekind), basic.WithMemory(hasMemory))
@ -183,7 +183,7 @@ func testProcessor(
} }
// Test the final checkpoint state. // Test the final checkpoint state.
records1 := processorTest.NewOutput(label.DefaultEncoder()) records1 := processorTest.NewOutput(attribute.DefaultEncoder())
err = checkpointSet.ForEach(export.ConstantExportKindSelector(ekind), records1.AddRecord) err = checkpointSet.ForEach(export.ConstantExportKindSelector(ekind), records1.AddRecord)
// Test for an allowed error: // Test for an allowed error:
@ -297,7 +297,7 @@ func TestBasicInconsistent(t *testing.T) {
b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector())
desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) 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)) require.Equal(t, basic.ErrInconsistentState, b.Process(accum))
// Test invalid kind: // Test invalid kind:
@ -320,7 +320,7 @@ func TestBasicTimestamps(t *testing.T) {
afterNew := time.Now() afterNew := time.Now()
desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) 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.StartCollection()
_ = b.Process(accum) _ = b.Process(accum)
@ -362,7 +362,7 @@ func TestBasicTimestamps(t *testing.T) {
} }
func TestStatefulNoMemoryCumulative(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() ekindSel := export.CumulativeExportKindSelector()
desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, number.Int64Kind)
@ -377,17 +377,17 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
require.NoError(t, processor.FinishCollection()) require.NoError(t, processor.FinishCollection())
// Verify zero elements // Verify zero elements
records := processorTest.NewOutput(label.DefaultEncoder()) records := processorTest.NewOutput(attribute.DefaultEncoder())
require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord))
require.EqualValues(t, map[string]float64{}, records.Map()) require.EqualValues(t, map[string]float64{}, records.Map())
// Add 10 // Add 10
processor.StartCollection() 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()) require.NoError(t, processor.FinishCollection())
// Verify one element // Verify one element
records = processorTest.NewOutput(label.DefaultEncoder()) records = processorTest.NewOutput(attribute.DefaultEncoder())
require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
"inst.sum/A=B/R=V": float64(i * 10), "inst.sum/A=B/R=V": float64(i * 10),
@ -396,7 +396,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
} }
func TestStatefulNoMemoryDelta(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() ekindSel := export.DeltaExportKindSelector()
desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, number.Int64Kind)
@ -411,17 +411,17 @@ func TestStatefulNoMemoryDelta(t *testing.T) {
require.NoError(t, processor.FinishCollection()) require.NoError(t, processor.FinishCollection())
// Verify zero elements // Verify zero elements
records := processorTest.NewOutput(label.DefaultEncoder()) records := processorTest.NewOutput(attribute.DefaultEncoder())
require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord))
require.EqualValues(t, map[string]float64{}, records.Map()) require.EqualValues(t, map[string]float64{}, records.Map())
// Add 10 // Add 10
processor.StartCollection() 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()) require.NoError(t, processor.FinishCollection())
// Verify one element // Verify one element
records = processorTest.NewOutput(label.DefaultEncoder()) records = processorTest.NewOutput(attribute.DefaultEncoder())
require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
"inst.sum/A=B/R=V": 10, "inst.sum/A=B/R=V": 10,
@ -435,7 +435,7 @@ func TestMultiObserverSum(t *testing.T) {
export.DeltaExportKindSelector(), 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) desc := metric.NewDescriptor("observe.sum", metric.SumObserverInstrumentKind, number.Int64Kind)
selector := processorTest.AggregatorSelector() selector := processorTest.AggregatorSelector()
@ -445,9 +445,9 @@ func TestMultiObserverSum(t *testing.T) {
for i := 1; i < 3; i++ { for i := 1; i < 3; i++ {
// Add i*10*3 times // Add i*10*3 times
processor.StartCollection() 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")))
_ = 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), label.String("A", "B"))) _ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), attribute.String("A", "B")))
require.NoError(t, processor.FinishCollection()) require.NoError(t, processor.FinishCollection())
// Multiplier is 1 for deltas, otherwise i. // Multiplier is 1 for deltas, otherwise i.
@ -457,7 +457,7 @@ func TestMultiObserverSum(t *testing.T) {
} }
// Verify one element // Verify one element
records := processorTest.NewOutput(label.DefaultEncoder()) records := processorTest.NewOutput(attribute.DefaultEncoder())
require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord)) require.NoError(t, checkpointSet.ForEach(ekindSel, records.AddRecord))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{
"observe.sum/A=B/R=V": float64(3 * 10 * multiplier), "observe.sum/A=B/R=V": float64(3 * 10 * multiplier),
@ -494,7 +494,7 @@ func TestSumObserverEndToEnd(t *testing.T) {
accum.Collect(ctx) accum.Collect(ctx)
require.NoError(t, proc.FinishCollection()) 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.NoError(t, exporter.Export(ctx, data))
require.EqualValues(t, map[string]float64{ require.EqualValues(t, map[string]float64{

View File

@ -21,7 +21,7 @@ import (
"sync" "sync"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -40,14 +40,14 @@ type (
// attributes. // attributes.
mapKey struct { mapKey struct {
desc *metric.Descriptor desc *metric.Descriptor
labels label.Distinct labels attribute.Distinct
resource label.Distinct resource attribute.Distinct
} }
// mapValue is value stored in a processor used to produce a // mapValue is value stored in a processor used to produce a
// CheckpointSet. // CheckpointSet.
mapValue struct { mapValue struct {
labels *label.Set labels *attribute.Set
resource *resource.Resource resource *resource.Resource
aggregator export.Aggregator aggregator export.Aggregator
} }
@ -55,7 +55,7 @@ type (
// Output implements export.CheckpointSet. // Output implements export.CheckpointSet.
Output struct { Output struct {
m map[mapKey]mapValue m map[mapKey]mapValue
labelEncoder label.Encoder labelEncoder attribute.Encoder
sync.RWMutex sync.RWMutex
} }
@ -101,7 +101,7 @@ type (
// //
// Where in the example A=1,B=2 is the encoded labels and R=V is the // Where in the example A=1,B=2 is the encoded labels and R=V is the
// encoded resource value. // encoded resource value.
func NewProcessor(selector export.AggregatorSelector, encoder label.Encoder) *Processor { func NewProcessor(selector export.AggregatorSelector, encoder attribute.Encoder) *Processor {
return &Processor{ return &Processor{
AggregatorSelector: selector, AggregatorSelector: selector,
output: NewOutput(encoder), 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 // (from an Accumulator) or an expected set of Records (from a
// Processor). If testing with an Accumulator, it may be simpler to // Processor). If testing with an Accumulator, it may be simpler to
// use the test Processor in this package. // use the test Processor in this package.
func NewOutput(labelEncoder label.Encoder) *Output { func NewOutput(labelEncoder attribute.Encoder) *Output {
return &Output{ return &Output{
m: make(map[mapKey]mapValue), m: make(map[mapKey]mapValue),
labelEncoder: labelEncoder, 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 // Where in the example A=1,B=2 is the encoded labels and R=V is the
// encoded resource value. // encoded resource value.
func NewExporter(selector export.ExportKindSelector, encoder label.Encoder) *Exporter { func NewExporter(selector export.ExportKindSelector, encoder attribute.Encoder) *Exporter {
return &Exporter{ return &Exporter{
ExportKindSelector: selector, ExportKindSelector: selector,
output: NewOutput(encoder), output: NewOutput(encoder),

View File

@ -20,7 +20,7 @@ import (
"github.com/stretchr/testify/require" "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"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
metricsdk "go.opentelemetry.io/otel/sdk/metric" metricsdk "go.opentelemetry.io/otel/sdk/metric"
@ -32,7 +32,7 @@ func generateTestData(proc export.Processor) {
ctx := context.Background() ctx := context.Background()
accum := metricsdk.NewAccumulator( accum := metricsdk.NewAccumulator(
proc, proc,
resource.NewWithAttributes(label.String("R", "V")), resource.NewWithAttributes(attribute.String("R", "V")),
) )
meter := metric.WrapMeterImpl(accum, "testing") meter := metric.WrapMeterImpl(accum, "testing")
@ -40,13 +40,13 @@ func generateTestData(proc export.Processor) {
_ = metric.Must(meter).NewInt64SumObserver("observer.sum", _ = metric.Must(meter).NewInt64SumObserver("observer.sum",
func(_ context.Context, result metric.Int64ObserverResult) { func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(10, label.String("K1", "V1")) result.Observe(10, attribute.String("K1", "V1"))
result.Observe(11, label.String("K1", "V2")) result.Observe(11, attribute.String("K1", "V2"))
}, },
) )
counter.Add(ctx, 100, label.String("K1", "V1")) counter.Add(ctx, 100, attribute.String("K1", "V1"))
counter.Add(ctx, 101, label.String("K1", "V2")) counter.Add(ctx, 101, attribute.String("K1", "V2"))
accum.Collect(ctx) accum.Collect(ctx)
} }
@ -56,7 +56,7 @@ func TestProcessorTesting(t *testing.T) {
// generate Accumulations. // generate Accumulations.
testProc := processorTest.NewProcessor( testProc := processorTest.NewProcessor(
processorTest.AggregatorSelector(), processorTest.AggregatorSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
) )
checkpointer := processorTest.Checkpointer(testProc) checkpointer := processorTest.Checkpointer(testProc)
@ -75,7 +75,7 @@ func TestProcessorTesting(t *testing.T) {
// Export the data and validate it again. // Export the data and validate it again.
exporter := processorTest.NewExporter( exporter := processorTest.NewExporter(
export.StatelessExportKindSelector(), export.StatelessExportKindSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
) )
err := exporter.Export(context.Background(), checkpointer.CheckpointSet()) 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. evolving OpenTelemetry specification and user feedback.
The metrics Processor component this package implements applies a 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 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 inherent dimensionality in the data, as a way to control the cost of
collecting high cardinality metric data. 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 func(label kv.KeyValue) bool {
// return true to keep this label, false to drop this label // 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" package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer"
import ( import (
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
) )
@ -31,7 +31,7 @@ type (
// LabelFilterSelector is the interface used to configure a // LabelFilterSelector is the interface used to configure a
// specific Filter to an instrument. // specific Filter to an instrument.
LabelFilterSelector interface { 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" "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"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
metricsdk "go.opentelemetry.io/otel/sdk/metric" metricsdk "go.opentelemetry.io/otel/sdk/metric"
@ -31,22 +31,22 @@ import (
) )
var ( var (
kvs1 = []label.KeyValue{ kvs1 = []attribute.KeyValue{
label.Int("A", 1), attribute.Int("A", 1),
label.Int("B", 2), attribute.Int("B", 2),
label.Int("C", 3), attribute.Int("C", 3),
} }
kvs2 = []label.KeyValue{ kvs2 = []attribute.KeyValue{
label.Int("A", 1), attribute.Int("A", 1),
label.Int("B", 0), attribute.Int("B", 0),
label.Int("C", 3), attribute.Int("C", 3),
} }
) )
type testFilter struct{} type testFilter struct{}
func (testFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter { func (testFilter) LabelFilterFor(_ *metric.Descriptor) attribute.Filter {
return func(label label.KeyValue) bool { return func(label attribute.KeyValue) bool {
return label.Key == "A" || label.Key == "C" return label.Key == "A" || label.Key == "C"
} }
} }
@ -71,11 +71,11 @@ func generateData(impl metric.MeterImpl) {
func TestFilterProcessor(t *testing.T) { func TestFilterProcessor(t *testing.T) {
testProc := processorTest.NewProcessor( testProc := processorTest.NewProcessor(
processorTest.AggregatorSelector(), processorTest.AggregatorSelector(),
label.DefaultEncoder(), attribute.DefaultEncoder(),
) )
accum := metricsdk.NewAccumulator( accum := metricsdk.NewAccumulator(
reducer.New(testFilter{}, processorTest.Checkpointer(testProc)), reducer.New(testFilter{}, processorTest.Checkpointer(testProc)),
resource.NewWithAttributes(label.String("R", "V")), resource.NewWithAttributes(attribute.String("R", "V")),
) )
generateData(accum) generateData(accum)
@ -92,9 +92,9 @@ func TestFilterBasicProcessor(t *testing.T) {
basicProc := basic.New(processorTest.AggregatorSelector(), export.CumulativeExportKindSelector()) basicProc := basic.New(processorTest.AggregatorSelector(), export.CumulativeExportKindSelector())
accum := metricsdk.NewAccumulator( accum := metricsdk.NewAccumulator(
reducer.New(testFilter{}, basicProc), 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) generateData(accum)

View File

@ -22,8 +22,8 @@ import (
"sync/atomic" "sync/atomic"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
internal "go.opentelemetry.io/otel/internal/metric" internal "go.opentelemetry.io/otel/internal/metric"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -63,7 +63,7 @@ type (
// asyncSortSlice has a single purpose - as a temporary // asyncSortSlice has a single purpose - as a temporary
// place for sorting during labels creation to avoid // place for sorting during labels creation to avoid
// allocation. It is cleared after use. // allocation. It is cleared after use.
asyncSortSlice label.Sortable asyncSortSlice attribute.Sortable
// resource is applied to all records in this Accumulator. // resource is applied to all records in this Accumulator.
resource *resource.Resource resource *resource.Resource
@ -77,7 +77,7 @@ type (
// its InstrumentID and the encoded form of its labels. // its InstrumentID and the encoded form of its labels.
mapkey struct { mapkey struct {
descriptor *metric.Descriptor descriptor *metric.Descriptor
ordered label.Distinct ordered attribute.Distinct
} }
// record maintains the state of one metric instrument. Due // record maintains the state of one metric instrument. Due
@ -99,18 +99,18 @@ type (
// storage is the stored label set for this record, // storage is the stored label set for this record,
// except in cases where a label set is shared due to // except in cases where a label set is shared due to
// batch recording. // batch recording.
storage label.Set storage attribute.Set
// labels is the processed label set for this record. // labels is the processed label set for this record.
// this may refer to the `storage` field in another // this may refer to the `storage` field in another
// record if this label set is shared resulting from // record if this label set is shared resulting from
// `RecordBatch`. // `RecordBatch`.
labels *label.Set labels *attribute.Set
// sortSlice has a single purpose - as a temporary // sortSlice has a single purpose - as a temporary
// place for sorting during labels creation to avoid // place for sorting during labels creation to avoid
// allocation. // allocation.
sortSlice label.Sortable sortSlice attribute.Sortable
// inst is a pointer to the corresponding instrument. // inst is a pointer to the corresponding instrument.
inst *syncInstrument inst *syncInstrument
@ -131,12 +131,12 @@ type (
instrument instrument
// recorders maps ordered labels to the pair of // recorders maps ordered labels to the pair of
// labelset and recorder // labelset and recorder
recorders map[label.Distinct]*labeledRecorder recorders map[attribute.Distinct]*labeledRecorder
} }
labeledRecorder struct { labeledRecorder struct {
observedEpoch int64 observedEpoch int64
labels *label.Set labels *attribute.Set
observed export.Aggregator observed export.Aggregator
} }
) )
@ -162,7 +162,7 @@ func (s *syncInstrument) Implementation() interface{} {
return s 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 { if err := aggregator.RangeTest(num, &a.descriptor); err != nil {
otel.Handle(err) otel.Handle(err)
return 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()] lrec, ok := a.recorders[labels.Equivalent()]
if ok { if ok {
// Note: SynchronizedMove(nil) can't return an error // 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 var rec export.Aggregator
a.meter.processor.AggregatorFor(&a.descriptor, &rec) a.meter.processor.AggregatorFor(&a.descriptor, &rec)
if a.recorders == nil { 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 // This may store nil recorder in the map, thus disabling the
// asyncInstrument for the labelset for good. This is intentional, // 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 // support re-use of the orderedLabels computed by a previous
// measurement in the same batch. This performs two allocations // measurement in the same batch. This performs two allocations
// in the common case. // 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 rec *record
var equiv label.Distinct var equiv attribute.Distinct
if labelPtr == nil { if labelPtr == nil {
// This memory allocation may not be used, but it's // This memory allocation may not be used, but it's
// needed for the `sortSlice` field, to avoid an // needed for the `sortSlice` field, to avoid an
// allocation while sorting. // allocation while sorting.
rec = &record{} rec = &record{}
rec.storage = label.NewSetWithSortable(kvs, &rec.sortSlice) rec.storage = attribute.NewSetWithSortable(kvs, &rec.sortSlice)
rec.labels = &rec.storage rec.labels = &rec.storage
equiv = rec.storage.Equivalent() equiv = rec.storage.Equivalent()
} else { } 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) 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) h := s.acquireHandle(kvs, nil)
defer h.Unbind() defer h.Unbind()
h.RecordOne(ctx, num) h.RecordOne(ctx, num)
@ -396,8 +396,8 @@ func (m *Accumulator) collectSyncInstruments() int {
} }
// CollectAsync implements internal.AsyncCollector. // CollectAsync implements internal.AsyncCollector.
func (m *Accumulator) CollectAsync(kv []label.KeyValue, obs ...metric.Observation) { func (m *Accumulator) CollectAsync(kv []attribute.KeyValue, obs ...metric.Observation) {
labels := label.NewSetWithSortable(kv, &m.asyncSortSlice) labels := attribute.NewSetWithSortable(kv, &m.asyncSortSlice)
for _, ob := range obs { for _, ob := range obs {
if a := m.fromAsync(ob.AsyncImpl()); a != nil { 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. // 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 // Labels will be computed the first time acquireHandle is
// called. Subsequent calls to acquireHandle will re-use the // called. Subsequent calls to acquireHandle will re-use the
// previously computed value instead of recomputing the // previously computed value instead of recomputing the
// ordered labels. // ordered labels.
var labelsPtr *label.Set var labelsPtr *attribute.Set
for i, meas := range measurements { for i, meas := range measurements {
s := m.fromSync(meas.SyncImpl()) s := m.fromSync(meas.SyncImpl())
if s == nil { if s == nil {

View File

@ -31,7 +31,7 @@ import (
"testing" "testing"
"time" "time"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
@ -75,7 +75,7 @@ type (
testImpl struct { testImpl struct {
newInstrument func(meter metric.Meter, name string) SyncImpler newInstrument func(meter metric.Meter, name string) SyncImpler
getUpdateValue func() number.Number 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{} newStore func() interface{}
// storeCollect and storeExpect are the same for // storeCollect and storeExpect are the same for
@ -105,7 +105,7 @@ func concurrency() int {
return concurrencyPerCPU * runtime.NumCPU() return concurrencyPerCPU * runtime.NumCPU()
} }
func canonicalizeLabels(ls []label.KeyValue) string { func canonicalizeLabels(ls []attribute.KeyValue) string {
copy := append(ls[0:0:0], ls...) copy := append(ls[0:0:0], ls...)
sort.SliceStable(copy, func(i, j int) bool { sort.SliceStable(copy, func(i, j int) bool {
return copy[i].Key < copy[j].Key return copy[i].Key < copy[j].Key
@ -128,9 +128,9 @@ func getPeriod() time.Duration {
return time.Duration(dur) return time.Duration(dur)
} }
func (f *testFixture) someLabels() []label.KeyValue { func (f *testFixture) someLabels() []attribute.KeyValue {
n := 1 + rand.Intn(3) n := 1 + rand.Intn(3)
l := make([]label.KeyValue, n) l := make([]attribute.KeyValue, n)
for { for {
oused := map[string]bool{} oused := map[string]bool{}
@ -143,7 +143,7 @@ func (f *testFixture) someLabels() []label.KeyValue {
break 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) lc := canonicalizeLabels(l)
f.lock.Lock() 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 := inst.(metric.Int64Counter)
counter.Add(ctx, value.AsInt64(), labels...) 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 := inst.(metric.Float64Counter)
counter.Add(ctx, value.AsFloat64(), labels...) counter.Add(ctx, value.AsFloat64(), labels...)
}, },
@ -425,7 +425,7 @@ func intLastValueTestImpl() testImpl {
r1 := rand.Int63() r1 := rand.Int63()
return number.NewInt64Number(rand.Int63() - r1) 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 := inst.(metric.Int64ValueRecorder)
valuerecorder.Record(ctx, value.AsInt64(), labels...) valuerecorder.Record(ctx, value.AsInt64(), labels...)
}, },
@ -466,7 +466,7 @@ func floatLastValueTestImpl() testImpl {
getUpdateValue: func() number.Number { getUpdateValue: func() number.Number {
return number.NewFloat64Number((-0.5 + rand.Float64()) * 100000) 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 := inst.(metric.Float64ValueRecorder)
valuerecorder.Record(ctx, value.AsFloat64(), labels...) valuerecorder.Record(ctx, value.AsFloat64(), labels...)
}, },

View File

@ -19,7 +19,7 @@ import (
"math/rand" "math/rand"
"testing" "testing"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
) )
@ -27,8 +27,8 @@ const conflict = 0.5
func makeLabels(n int) (_, _ *resource.Resource) { func makeLabels(n int) (_, _ *resource.Resource) {
used := map[string]bool{} used := map[string]bool{}
l1 := make([]label.KeyValue, n) l1 := make([]attribute.KeyValue, n)
l2 := make([]label.KeyValue, n) l2 := make([]attribute.KeyValue, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
var k string var k string
for { for {
@ -38,12 +38,12 @@ func makeLabels(n int) (_, _ *resource.Resource) {
break 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 { if rand.Float64() < conflict {
l2[i] = l1[i] l2[i] = l1[i]
} else { } 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" "path/filepath"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/semconv" "go.opentelemetry.io/otel/semconv"
) )
@ -41,7 +41,7 @@ type (
Host struct{} Host struct{}
stringDetector struct { stringDetector struct {
K label.Key K attribute.Key
F func() (string, error) 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 // StringDetector returns a Detector that will produce a *Resource
// containing the string as a value corresponding to k. // 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} return stringDetector{K: k, F: f}
} }

View File

@ -22,13 +22,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
) )
func TestBuiltinStringDetector(t *testing.T) { func TestBuiltinStringDetector(t *testing.T) {
E := fmt.Errorf("no K") 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 return "", E
}).Detect(context.Background()) }).Detect(context.Background())
require.True(t, errors.Is(err, E)) require.True(t, errors.Is(err, E))
@ -40,8 +40,8 @@ func TestBuiltinStringConfig(t *testing.T) {
res, err := resource.New( res, err := resource.New(
context.Background(), context.Background(),
resource.WithoutBuiltin(), resource.WithoutBuiltin(),
resource.WithAttributes(label.String("A", "B")), resource.WithAttributes(attribute.String("A", "B")),
resource.WithDetectors(resource.StringDetector(label.Key("K"), func() (string, error) { resource.WithDetectors(resource.StringDetector(attribute.Key("K"), func() (string, error) {
return "", fmt.Errorf("K-IS-MISSING") return "", fmt.Errorf("K-IS-MISSING")
})), })),
) )

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