1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-03-03 14:52:56 +02:00

Unify api/label and api/kv in new label package (#1060)

* Move `api/label` to `label`

* Move `api/kv` package contents into `label` package

* Unify label package name

* Move `api/internal/rawhelpers.go` to `internal`

* Propagate replacing `api/kv` with `label` pkg

* golint

* Fix over-aggressive change

* Update Changelog
This commit is contained in:
Tyler Yahn 2020-08-17 20:25:03 -07:00 committed by GitHub
parent e44c9dee78
commit f995380e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
112 changed files with 1582 additions and 1611 deletions

View File

@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The environment variable used for resource detection has been changed from `OTEL_RESOURCE_LABELS` to `OTEL_RESOURCE_ATTRIBUTES` (#1042)
- Replace `WithSyncer` with `WithBatcher` in examples. (#1044)
- Replace the `google.golang.org/grpc/codes` dependency in the API with an equivalent `go.opentelemetry.io/otel/codes` package. (#1046)
- Merge the `go.opentelemetry.io/otel/api/label` and `go.opentelemetry.io/otel/api/kv` into the new `go.opentelemetry.io/otel/label` package. (#1060)
- Unify Callback Function Naming.
Rename `*Callback` with `*Func`. (#1061)

View File

@ -20,10 +20,10 @@ import (
"testing"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/internal/matchers"
"go.opentelemetry.io/otel/label"
)
type Harness struct {
@ -195,7 +195,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) {
span.SetName("new name")
},
"#SetAttributes": func(span trace.Span) {
span.SetAttributes(kv.String("key1", "value"), kv.Int("key2", 123))
span.SetAttributes(label.String("key1", "value"), label.Int("key2", 123))
},
}
var mechanisms = map[string]func() trace.Span{

View File

@ -17,7 +17,7 @@ package correlation
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
type correlationsType struct{}
@ -150,7 +150,7 @@ func ContextWithMap(ctx context.Context, m Map) context.Context {
// NewContext returns a context with the map from passed context
// updated with the passed key-value pairs.
func NewContext(ctx context.Context, keyvalues ...kv.KeyValue) context.Context {
func NewContext(ctx context.Context, keyvalues ...label.KeyValue) context.Context {
return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{
MultiKV: keyvalues,
}))

View File

@ -19,8 +19,8 @@ import (
"net/url"
"strings"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/label"
)
// Temporary header name until W3C finalizes format.
@ -45,7 +45,7 @@ func (CorrelationContext) Inject(ctx context.Context, supplier propagation.HTTPS
correlationCtx := MapFromContext(ctx)
firstIter := true
var headerValueBuilder strings.Builder
correlationCtx.Foreach(func(kv kv.KeyValue) bool {
correlationCtx.Foreach(func(kv label.KeyValue) bool {
if !firstIter {
headerValueBuilder.WriteRune(',')
}
@ -69,7 +69,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP
}
contextValues := strings.Split(correlationContext, ",")
keyValues := make([]kv.KeyValue, 0, len(contextValues))
keyValues := make([]label.KeyValue, 0, len(contextValues))
for _, contextValue := range contextValues {
valueAndProps := strings.Split(contextValue, ";")
if len(valueAndProps) < 1 {
@ -99,7 +99,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP
trimmedValueWithProps.WriteString(prop)
}
keyValues = append(keyValues, kv.Key(trimmedName).String(trimmedValueWithProps.String()))
keyValues = append(keyValues, label.String(trimmedName, trimmedValueWithProps.String()))
}
if len(keyValues) > 0 {

View File

@ -23,8 +23,8 @@ import (
"github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/api/correlation"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/label"
)
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
@ -32,54 +32,54 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
tests := []struct {
name string
header string
wantKVs []kv.KeyValue
wantKVs []label.KeyValue
}{
{
name: "valid w3cHeader",
header: "key1=val1,key2=val2",
wantKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
wantKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2"),
},
},
{
name: "valid w3cHeader with spaces",
header: "key1 = val1, key2 =val2 ",
wantKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
wantKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2"),
},
},
{
name: "valid w3cHeader with properties",
header: "key1=val1,key2=val2;prop=1",
wantKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2;prop=1"),
wantKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2;prop=1"),
},
},
{
name: "valid header with url-escaped comma",
header: "key1=val1,key2=val2%2Cval3",
wantKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2,val3"),
wantKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2,val3"),
},
},
{
name: "valid header with an invalid header",
header: "key1=val1,key2=val2,a,val3",
wantKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
wantKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2"),
},
},
{
name: "valid header with no value",
header: "key1=,key2=val2",
wantKVs: []kv.KeyValue{
kv.Key("key1").String(""),
kv.Key("key2").String("val2"),
wantKVs: []label.KeyValue{
label.String("key1", ""),
label.String("key2", "val2"),
},
},
}
@ -101,9 +101,9 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
)
}
totalDiff := ""
wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool {
wantCorCtx.Foreach(func(keyValue label.KeyValue) bool {
val, _ := gotCorCtx.Value(keyValue.Key)
diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(kv.Value{}))
diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{}))
if diff != "" {
totalDiff += diff + "\n"
}
@ -121,7 +121,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
tests := []struct {
name string
header string
hasKVs []kv.KeyValue
hasKVs []label.KeyValue
}{
{
name: "no key values",
@ -130,17 +130,17 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
{
name: "invalid header with existing context",
header: "header2",
hasKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
hasKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2"),
},
},
{
name: "empty header value",
header: "",
hasKVs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
hasKVs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2"),
},
},
}
@ -162,9 +162,9 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
)
}
totalDiff := ""
wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool {
wantCorCtx.Foreach(func(keyValue label.KeyValue) bool {
val, _ := gotCorCtx.Value(keyValue.Key)
diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(kv.Value{}))
diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{}))
if diff != "" {
totalDiff += diff + "\n"
}
@ -179,38 +179,38 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
props := propagation.New(propagation.WithInjectors(propagator))
tests := []struct {
name string
kvs []kv.KeyValue
kvs []label.KeyValue
wantInHeader []string
wantedLen int
}{
{
name: "two simple values",
kvs: []kv.KeyValue{
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
kvs: []label.KeyValue{
label.String("key1", "val1"),
label.String("key2", "val2"),
},
wantInHeader: []string{"key1=val1", "key2=val2"},
},
{
name: "two values with escaped chars",
kvs: []kv.KeyValue{
kv.Key("key1").String("val1,val2"),
kv.Key("key2").String("val3=4"),
kvs: []label.KeyValue{
label.String("key1", "val1,val2"),
label.String("key2", "val3=4"),
},
wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"},
},
{
name: "values of non-string types",
kvs: []kv.KeyValue{
kv.Key("key1").Bool(true),
kv.Key("key2").Int(123),
kv.Key("key3").Int64(123),
kv.Key("key4").Int32(123),
kv.Key("key5").Uint(123),
kv.Key("key6").Uint32(123),
kv.Key("key7").Uint64(123),
kv.Key("key8").Float64(123.567),
kv.Key("key9").Float32(123.567),
kvs: []label.KeyValue{
label.Bool("key1", true),
label.Int("key2", 123),
label.Int64("key3", 123),
label.Int32("key4", 123),
label.Uint("key5", 123),
label.Uint32("key6", 123),
label.Uint64("key7", 123),
label.Float64("key8", 123.567),
label.Float32("key9", 123.567),
},
wantInHeader: []string{
"key1=true",

View File

@ -14,12 +14,10 @@
package correlation
import (
"go.opentelemetry.io/otel/api/kv"
)
import "go.opentelemetry.io/otel/label"
type rawMap map[kv.Key]kv.Value
type keySet map[kv.Key]struct{}
type rawMap map[label.Key]label.Value
type keySet map[label.Key]struct{}
// Map is an immutable storage for correlations.
type Map struct {
@ -32,18 +30,18 @@ type MapUpdate struct {
// DropSingleK contains a single key to be dropped from
// correlations. Use this to avoid an overhead of a slice
// allocation if there is only one key to drop.
DropSingleK kv.Key
DropSingleK label.Key
// DropMultiK contains all the keys to be dropped from
// correlations.
DropMultiK []kv.Key
DropMultiK []label.Key
// SingleKV contains a single key-value pair to be added to
// correlations. Use this to avoid an overhead of a slice
// allocation if there is only one key-value pair to add.
SingleKV kv.KeyValue
SingleKV label.KeyValue
// MultiKV contains all the key-value pairs to be added to
// correlations.
MultiKV []kv.KeyValue
MultiKV []label.KeyValue
}
func newMap(raw rawMap) Map {
@ -101,7 +99,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
deletionsCount++
}
if deletionsCount > 0 {
delSet = make(map[kv.Key]struct{}, deletionsCount)
delSet = make(map[label.Key]struct{}, deletionsCount)
for _, k := range update.DropMultiK {
delSet[k] = struct{}{}
}
@ -115,7 +113,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
additionsCount++
}
if additionsCount > 0 {
addSet = make(map[kv.Key]struct{}, additionsCount)
addSet = make(map[label.Key]struct{}, additionsCount)
for _, k := range update.MultiKV {
addSet[k.Key] = struct{}{}
}
@ -146,14 +144,14 @@ func getNewMapSize(m rawMap, delSet, addSet keySet) int {
// Value gets a value from correlations map and returns a boolean
// value indicating whether the key exist in the map.
func (m Map) Value(k kv.Key) (kv.Value, bool) {
func (m Map) Value(k label.Key) (label.Value, bool) {
value, ok := m.m[k]
return value, ok
}
// HasValue returns a boolean value indicating whether the key exist
// in the map.
func (m Map) HasValue(k kv.Key) bool {
func (m Map) HasValue(k label.Key) bool {
_, has := m.Value(k)
return has
}
@ -166,9 +164,9 @@ func (m Map) Len() int {
// Foreach calls a passed callback once on each key-value pair until
// all the key-value pairs of the map were iterated or the callback
// returns false, whichever happens first.
func (m Map) Foreach(f func(kv kv.KeyValue) bool) {
func (m Map) Foreach(f func(label.KeyValue) bool) {
for k, v := range m.m {
if !f(kv.KeyValue{
if !f(label.KeyValue{
Key: k,
Value: v,
}) {

View File

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

View File

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

View File

@ -20,9 +20,9 @@ import (
"sync/atomic"
"unsafe"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/metric/registry"
"go.opentelemetry.io/otel/label"
)
// This file contains the forwarding implementation of metric.Provider
@ -108,7 +108,7 @@ type syncHandle struct {
delegate unsafe.Pointer // (*metric.HandleImpl)
inst *syncImpl
labels []kv.KeyValue
labels []label.KeyValue
initialize sync.Once
}
@ -227,7 +227,7 @@ func (inst *syncImpl) Implementation() interface{} {
return inst
}
func (inst *syncImpl) Bind(labels []kv.KeyValue) metric.BoundSyncImpl {
func (inst *syncImpl) Bind(labels []label.KeyValue) metric.BoundSyncImpl {
if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
return (*implPtr).Bind(labels)
}
@ -299,13 +299,13 @@ func (obs *asyncImpl) setDelegate(d metric.MeterImpl) {
// Metric updates
func (m *meterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measurements ...metric.Measurement) {
func (m *meterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) {
if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil {
(*delegatePtr).RecordBatch(ctx, labels, measurements...)
}
}
func (inst *syncImpl) RecordOne(ctx context.Context, number metric.Number, labels []kv.KeyValue) {
func (inst *syncImpl) RecordOne(ctx context.Context, number metric.Number, labels []label.KeyValue) {
if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
(*instPtr).RecordOne(ctx, number, labels)
}

View File

@ -23,9 +23,9 @@ import (
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/global/internal"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
metrictest "go.opentelemetry.io/otel/internal/metric"
"go.opentelemetry.io/otel/label"
)
var Must = metric.Must
@ -35,7 +35,7 @@ type measured struct {
Name string
InstrumentationName string
InstrumentationVersion string
Labels map[kv.Key]kv.Value
Labels map[label.Key]label.Value
Number metric.Number
}
@ -55,10 +55,10 @@ func asStructs(batches []metrictest.Batch) []measured {
return r
}
func asMap(kvs ...kv.KeyValue) map[kv.Key]kv.Value {
m := map[kv.Key]kv.Value{}
for _, kv := range kvs {
m[kv.Key] = kv.Value
func asMap(kvs ...label.KeyValue) map[label.Key]label.Value {
m := map[label.Key]label.Value{}
for _, label := range kvs {
m[label.Key] = label.Value
}
return m
}
@ -72,9 +72,9 @@ func TestDirect(t *testing.T) {
ctx := context.Background()
meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0"))
meter2 := global.Meter("test2")
labels1 := []kv.KeyValue{kv.String("A", "B")}
labels2 := []kv.KeyValue{kv.String("C", "D")}
labels3 := []kv.KeyValue{kv.String("E", "F")}
labels1 := []label.KeyValue{label.String("A", "B")}
labels2 := []label.KeyValue{label.String("C", "D")}
labels3 := []label.KeyValue{label.String("E", "F")}
counter := Must(meter1).NewInt64Counter("test.counter")
counter.Add(ctx, 1, labels1...)
@ -171,7 +171,7 @@ func TestBound(t *testing.T) {
// vs. the above, to cover all the instruments.
ctx := context.Background()
glob := global.Meter("test")
labels1 := []kv.KeyValue{kv.String("A", "B")}
labels1 := []label.KeyValue{label.String("A", "B")}
counter := Must(glob).NewFloat64Counter("test.counter")
boundC := counter.Bind(labels1...)
@ -215,7 +215,7 @@ func TestUnbind(t *testing.T) {
internal.ResetForTest()
glob := global.Meter("test")
labels1 := []kv.KeyValue{kv.String("A", "B")}
labels1 := []label.KeyValue{label.String("A", "B")}
counter := Must(glob).NewFloat64Counter("test.counter")
boundC := counter.Bind(labels1...)

View File

@ -20,10 +20,10 @@ import (
"fmt"
"testing"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/unit"
mockTest "go.opentelemetry.io/otel/internal/metric"
"go.opentelemetry.io/otel/label"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
@ -99,7 +99,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := mockTest.NewMeter()
c := Must(meter).NewFloat64Counter("test.counter.float")
ctx := context.Background()
labels := []kv.KeyValue{kv.String("A", "B")}
labels := []label.KeyValue{label.String("A", "B")}
c.Add(ctx, 1994.1, labels...)
boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, -742)
@ -112,7 +112,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := mockTest.NewMeter()
c := Must(meter).NewInt64Counter("test.counter.int")
ctx := context.Background()
labels := []kv.KeyValue{kv.String("A", "B"), kv.String("C", "D")}
labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")}
c.Add(ctx, 42, labels...)
boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, 4200)
@ -126,7 +126,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := mockTest.NewMeter()
c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int")
ctx := context.Background()
labels := []kv.KeyValue{kv.String("A", "B"), kv.String("C", "D")}
labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")}
c.Add(ctx, 100, labels...)
boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, -100)
@ -139,7 +139,7 @@ func TestCounter(t *testing.T) {
mockSDK, meter := mockTest.NewMeter()
c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float")
ctx := context.Background()
labels := []kv.KeyValue{kv.String("A", "B"), kv.String("C", "D")}
labels := []label.KeyValue{label.String("A", "B"), label.String("C", "D")}
c.Add(ctx, 100.1, labels...)
boundInstrument := c.Bind(labels...)
boundInstrument.Add(ctx, -76)
@ -155,7 +155,7 @@ func TestValueRecorder(t *testing.T) {
mockSDK, meter := mockTest.NewMeter()
m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float")
ctx := context.Background()
labels := []kv.KeyValue{}
labels := []label.KeyValue{}
m.Record(ctx, 42, labels...)
boundInstrument := m.Bind(labels...)
boundInstrument.Record(ctx, 0)
@ -168,7 +168,7 @@ func TestValueRecorder(t *testing.T) {
mockSDK, meter := mockTest.NewMeter()
m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int")
ctx := context.Background()
labels := []kv.KeyValue{kv.Int("I", 1)}
labels := []label.KeyValue{label.Int("I", 1)}
m.Record(ctx, 173, labels...)
boundInstrument := m.Bind(labels...)
boundInstrument.Record(ctx, 80)
@ -181,7 +181,7 @@ func TestValueRecorder(t *testing.T) {
func TestObserverInstruments(t *testing.T) {
t.Run("float valueobserver", func(t *testing.T) {
labels := []kv.KeyValue{kv.String("O", "P")}
labels := []label.KeyValue{label.String("O", "P")}
mockSDK, meter := mockTest.NewMeter()
o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(42.1, labels...)
@ -192,7 +192,7 @@ func TestObserverInstruments(t *testing.T) {
)
})
t.Run("int valueobserver", func(t *testing.T) {
labels := []kv.KeyValue{}
labels := []label.KeyValue{}
mockSDK, meter := mockTest.NewMeter()
o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-142, labels...)
@ -203,7 +203,7 @@ func TestObserverInstruments(t *testing.T) {
)
})
t.Run("float sumobserver", func(t *testing.T) {
labels := []kv.KeyValue{kv.String("O", "P")}
labels := []label.KeyValue{label.String("O", "P")}
mockSDK, meter := mockTest.NewMeter()
o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(42.1, labels...)
@ -214,7 +214,7 @@ func TestObserverInstruments(t *testing.T) {
)
})
t.Run("int sumobserver", func(t *testing.T) {
labels := []kv.KeyValue{}
labels := []label.KeyValue{}
mockSDK, meter := mockTest.NewMeter()
o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-142, labels...)
@ -225,7 +225,7 @@ func TestObserverInstruments(t *testing.T) {
)
})
t.Run("float updownsumobserver", func(t *testing.T) {
labels := []kv.KeyValue{kv.String("O", "P")}
labels := []label.KeyValue{label.String("O", "P")}
mockSDK, meter := mockTest.NewMeter()
o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(42.1, labels...)
@ -236,7 +236,7 @@ func TestObserverInstruments(t *testing.T) {
)
})
t.Run("int updownsumobserver", func(t *testing.T) {
labels := []kv.KeyValue{}
labels := []label.KeyValue{}
mockSDK, meter := mockTest.NewMeter()
o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-142, labels...)
@ -248,7 +248,7 @@ func TestObserverInstruments(t *testing.T) {
})
}
func checkSyncBatches(t *testing.T, ctx context.Context, labels []kv.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, instrument metric.InstrumentImpl, expected ...float64) {
func checkSyncBatches(t *testing.T, ctx context.Context, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, instrument metric.InstrumentImpl, expected ...float64) {
t.Helper()
if len(mock.MeasurementBatches) != 3 {
t.Errorf("Expected 3 recorded measurement batches, got %d", len(mock.MeasurementBatches))
@ -296,9 +296,9 @@ func TestBatchObserverInstruments(t *testing.T) {
var obs1 metric.Int64ValueObserver
var obs2 metric.Float64ValueObserver
labels := []kv.KeyValue{
kv.String("A", "B"),
kv.String("C", "D"),
labels := []label.KeyValue{
label.String("A", "B"),
label.String("C", "D"),
}
cb := Must(meter).NewBatchObserver(
@ -335,7 +335,7 @@ func TestBatchObserverInstruments(t *testing.T) {
require.Equal(t, 0, m2.Number.CompareNumber(metric.Float64NumberKind, number(t, metric.Float64NumberKind, 42)))
}
func checkObserverBatch(t *testing.T, labels []kv.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, observer metric.AsyncImpl, expected float64) {
func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, observer metric.AsyncImpl, expected float64) {
t.Helper()
assert.Len(t, mock.MeasurementBatches, 1)
if len(mock.MeasurementBatches) < 1 {
@ -374,7 +374,7 @@ type testWrappedMeter struct {
var _ metric.MeterImpl = testWrappedMeter{}
func (testWrappedMeter) RecordBatch(context.Context, []kv.KeyValue, ...metric.Measurement) {
func (testWrappedMeter) RecordBatch(context.Context, []label.KeyValue, ...metric.Measurement) {
}
func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {

View File

@ -17,7 +17,7 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// The file is organized as follows:
@ -57,25 +57,25 @@ type BatchObserverFunc func(context.Context, BatchObserverResult)
// observations for one asynchronous integer metric instrument.
type Int64ObserverResult struct {
instrument AsyncImpl
function func([]kv.KeyValue, ...Observation)
function func([]label.KeyValue, ...Observation)
}
// Float64ObserverResult is passed to an observer callback to capture
// observations for one asynchronous floating point metric instrument.
type Float64ObserverResult struct {
instrument AsyncImpl
function func([]kv.KeyValue, ...Observation)
function func([]label.KeyValue, ...Observation)
}
// BatchObserverResult is passed to a batch observer callback to
// capture observations for multiple asynchronous instruments.
type BatchObserverResult struct {
function func([]kv.KeyValue, ...Observation)
function func([]label.KeyValue, ...Observation)
}
// Observe captures a single integer value from the associated
// instrument callback, with the given labels.
func (ir Int64ObserverResult) Observe(value int64, labels ...kv.KeyValue) {
func (ir Int64ObserverResult) Observe(value int64, labels ...label.KeyValue) {
ir.function(labels, Observation{
instrument: ir.instrument,
number: NewInt64Number(value),
@ -84,7 +84,7 @@ func (ir Int64ObserverResult) Observe(value int64, labels ...kv.KeyValue) {
// Observe captures a single floating point value from the associated
// instrument callback, with the given labels.
func (fr Float64ObserverResult) Observe(value float64, labels ...kv.KeyValue) {
func (fr Float64ObserverResult) Observe(value float64, labels ...label.KeyValue) {
fr.function(labels, Observation{
instrument: fr.instrument,
number: NewFloat64Number(value),
@ -93,7 +93,7 @@ func (fr Float64ObserverResult) Observe(value float64, labels ...kv.KeyValue) {
// Observe captures a multiple observations from the associated batch
// instrument callback, with the given labels.
func (br BatchObserverResult) Observe(labels []kv.KeyValue, obs ...Observation) {
func (br BatchObserverResult) Observe(labels []label.KeyValue, obs ...Observation) {
br.function(labels, obs...)
}
@ -114,7 +114,7 @@ type AsyncSingleRunner interface {
// receives one captured observation. (The function accepts
// multiple observations so the same implementation can be
// used for batch runners.)
Run(ctx context.Context, single AsyncImpl, capture func([]kv.KeyValue, ...Observation))
Run(ctx context.Context, single AsyncImpl, capture func([]label.KeyValue, ...Observation))
AsyncRunner
}
@ -124,7 +124,7 @@ type AsyncSingleRunner interface {
type AsyncBatchRunner interface {
// Run accepts a function for capturing observations of
// multiple instruments.
Run(ctx context.Context, capture func([]kv.KeyValue, ...Observation))
Run(ctx context.Context, capture func([]label.KeyValue, ...Observation))
AsyncRunner
}
@ -158,7 +158,7 @@ func (*Float64ObserverFunc) AnyRunner() {}
func (*BatchObserverFunc) AnyRunner() {}
// Run implements AsyncSingleRunner.
func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) {
(*i)(ctx, Int64ObserverResult{
instrument: impl,
function: function,
@ -166,7 +166,7 @@ func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function fu
}
// Run implements AsyncSingleRunner.
func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) {
(*f)(ctx, Float64ObserverResult{
instrument: impl,
function: function,
@ -174,7 +174,7 @@ func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function
}
// Run implements AsyncBatchRunner.
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]kv.KeyValue, ...Observation)) {
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]label.KeyValue, ...Observation)) {
(*b)(ctx, BatchObserverResult{
function: function,
})

View File

@ -17,7 +17,7 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// Float64Counter is a metric that accumulates float64 values.
@ -46,14 +46,14 @@ type BoundInt64Counter struct {
// Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record.
func (c Float64Counter) Bind(labels ...kv.KeyValue) (h BoundFloat64Counter) {
func (c Float64Counter) Bind(labels ...label.KeyValue) (h BoundFloat64Counter) {
h.syncBoundInstrument = c.bind(labels)
return
}
// Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record.
func (c Int64Counter) Bind(labels ...kv.KeyValue) (h BoundInt64Counter) {
func (c Int64Counter) Bind(labels ...label.KeyValue) (h BoundInt64Counter) {
h.syncBoundInstrument = c.bind(labels)
return
}
@ -72,13 +72,13 @@ func (c Int64Counter) Measurement(value int64) Measurement {
// Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value.
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...kv.KeyValue) {
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...label.KeyValue) {
c.directRecord(ctx, NewFloat64Number(value), labels)
}
// Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value.
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...kv.KeyValue) {
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...label.KeyValue) {
c.directRecord(ctx, NewInt64Number(value), labels)
}

View File

@ -17,7 +17,7 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// The file is organized as follows:
@ -52,7 +52,7 @@ type Meter struct {
}
// RecordBatch atomically records a batch of measurements.
func (m Meter) RecordBatch(ctx context.Context, ls []kv.KeyValue, ms ...Measurement) {
func (m Meter) RecordBatch(ctx context.Context, ls []label.KeyValue, ms ...Measurement) {
if m.impl == nil {
return
}

View File

@ -17,7 +17,7 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
type NoopProvider struct{}
@ -50,9 +50,9 @@ func (noopBoundInstrument) RecordOne(context.Context, Number) {
func (noopBoundInstrument) Unbind() {
}
func (NoopSync) Bind([]kv.KeyValue) BoundSyncImpl {
func (NoopSync) Bind([]label.KeyValue) BoundSyncImpl {
return noopBoundInstrument{}
}
func (NoopSync) RecordOne(context.Context, Number, []kv.KeyValue) {
func (NoopSync) RecordOne(context.Context, Number, []label.KeyValue) {
}

View File

@ -21,7 +21,7 @@ import (
"math"
"sync/atomic"
"go.opentelemetry.io/otel/api/internal"
"go.opentelemetry.io/otel/internal"
)
// NumberKind describes the data type of the Number.

View File

@ -19,8 +19,8 @@ import (
"fmt"
"sync"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
)
// Provider is a standard metric.Provider for wrapping `MeterImpl`
@ -75,7 +75,7 @@ func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl {
}
// RecordBatch implements metric.MeterImpl.
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, ms ...metric.Measurement) {
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, ms ...metric.Measurement) {
u.impl.RecordBatch(ctx, labels, ms...)
}

View File

@ -17,14 +17,14 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// MeterImpl is the interface an SDK must implement to supply a Meter
// implementation.
type MeterImpl interface {
// RecordBatch atomically records a batch of measurements.
RecordBatch(context.Context, []kv.KeyValue, ...Measurement)
RecordBatch(context.Context, []label.KeyValue, ...Measurement)
// NewSyncInstrument returns a newly constructed
// synchronous instrument implementation or an error, should
@ -59,10 +59,10 @@ type SyncImpl interface {
// Bind creates an implementation-level bound instrument,
// binding a label set with this instrument implementation.
Bind(labels []kv.KeyValue) BoundSyncImpl
Bind(labels []label.KeyValue) BoundSyncImpl
// RecordOne captures a single synchronous metric event.
RecordOne(ctx context.Context, number Number, labels []kv.KeyValue)
RecordOne(ctx context.Context, number Number, labels []label.KeyValue)
}
// BoundSyncImpl is the implementation-level interface to a

View File

@ -18,7 +18,7 @@ import (
"context"
"errors"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
@ -82,7 +82,7 @@ func (s syncInstrument) SyncImpl() SyncImpl {
return s.instrument
}
func (s syncInstrument) bind(labels []kv.KeyValue) syncBoundInstrument {
func (s syncInstrument) bind(labels []label.KeyValue) syncBoundInstrument {
return newSyncBoundInstrument(s.instrument.Bind(labels))
}
@ -94,7 +94,7 @@ func (s syncInstrument) int64Measurement(value int64) Measurement {
return newMeasurement(s.instrument, NewInt64Number(value))
}
func (s syncInstrument) directRecord(ctx context.Context, number Number, labels []kv.KeyValue) {
func (s syncInstrument) directRecord(ctx context.Context, number Number, labels []label.KeyValue) {
s.instrument.RecordOne(ctx, number, labels)
}

View File

@ -17,7 +17,7 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// Float64UpDownCounter is a metric instrument that sums floating
@ -47,14 +47,14 @@ type BoundInt64UpDownCounter struct {
// Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record.
func (c Float64UpDownCounter) Bind(labels ...kv.KeyValue) (h BoundFloat64UpDownCounter) {
func (c Float64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundFloat64UpDownCounter) {
h.syncBoundInstrument = c.bind(labels)
return
}
// Bind creates a bound instrument for this counter. The labels are
// associated with values recorded via subsequent calls to Record.
func (c Int64UpDownCounter) Bind(labels ...kv.KeyValue) (h BoundInt64UpDownCounter) {
func (c Int64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundInt64UpDownCounter) {
h.syncBoundInstrument = c.bind(labels)
return
}
@ -73,13 +73,13 @@ func (c Int64UpDownCounter) Measurement(value int64) Measurement {
// Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value.
func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...kv.KeyValue) {
func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...label.KeyValue) {
c.directRecord(ctx, NewFloat64Number(value), labels)
}
// Add adds the value to the counter's sum. The labels should contain
// the keys and values to be associated with this value.
func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...kv.KeyValue) {
func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...label.KeyValue) {
c.directRecord(ctx, NewInt64Number(value), labels)
}

View File

@ -17,7 +17,7 @@ package metric
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// Float64ValueRecorder is a metric that records float64 values.
@ -46,14 +46,14 @@ type BoundInt64ValueRecorder struct {
// Bind creates a bound instrument for this ValueRecorder. The labels are
// associated with values recorded via subsequent calls to Record.
func (c Float64ValueRecorder) Bind(labels ...kv.KeyValue) (h BoundFloat64ValueRecorder) {
func (c Float64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundFloat64ValueRecorder) {
h.syncBoundInstrument = c.bind(labels)
return
}
// Bind creates a bound instrument for this ValueRecorder. The labels are
// associated with values recorded via subsequent calls to Record.
func (c Int64ValueRecorder) Bind(labels ...kv.KeyValue) (h BoundInt64ValueRecorder) {
func (c Int64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundInt64ValueRecorder) {
h.syncBoundInstrument = c.bind(labels)
return
}
@ -73,14 +73,14 @@ func (c Int64ValueRecorder) Measurement(value int64) Measurement {
// Record adds a new value to the list of ValueRecorder's records. The
// labels should contain the keys and values to be associated with
// this value.
func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...kv.KeyValue) {
func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...label.KeyValue) {
c.directRecord(ctx, NewFloat64Number(value), labels)
}
// Record adds a new value to the ValueRecorder's distribution. The
// labels should contain the keys and values to be associated with
// this value.
func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...kv.KeyValue) {
func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...label.KeyValue) {
c.directRecord(ctx, NewInt64Number(value), labels)
}

View File

@ -18,8 +18,8 @@ import (
"context"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
)
type Provider interface {
@ -103,10 +103,10 @@ type Span interface {
End(options ...EndOption)
// AddEvent adds an event to the span.
AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue)
AddEvent(ctx context.Context, name string, attrs ...label.KeyValue)
// AddEventWithTimestamp adds an event with a custom timestamp
// to the span.
AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue)
AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue)
// IsRecording returns true if the span is active and recording events is enabled.
IsRecording() bool
@ -131,7 +131,7 @@ type Span interface {
SetName(name string)
// Set span attributes
SetAttributes(...kv.KeyValue)
SetAttributes(...label.KeyValue)
// Set singular span attribute, with type inference.
SetAttribute(string, interface{})
@ -143,7 +143,7 @@ type StartOption func(*StartConfig)
// StartConfig provides options to set properties of span at the time of starting
// a new span.
type StartConfig struct {
Attributes []kv.KeyValue
Attributes []label.KeyValue
StartTime time.Time
Links []Link
Record bool
@ -164,7 +164,7 @@ type StartConfig struct {
// be correlated.
type Link struct {
SpanContext
Attributes []kv.KeyValue
Attributes []label.KeyValue
}
// SpanKind represents the role of a Span inside a Trace. Often, this defines how a Span
@ -232,7 +232,7 @@ func WithStartTime(t time.Time) StartOption {
// WithAttributes sets attributes to span. These attributes provides additional
// data about the span.
// Multiple `WithAttributes` options appends the attributes preserving the order.
func WithAttributes(attrs ...kv.KeyValue) StartOption {
func WithAttributes(attrs ...label.KeyValue) StartOption {
return func(c *StartConfig) {
c.Attributes = append(c.Attributes, attrs...)
}
@ -259,7 +259,7 @@ func WithNewRoot() StartOption {
}
// LinkedTo allows instantiating a Span with initial Links.
func LinkedTo(sc SpanContext, attrs ...kv.KeyValue) StartOption {
func LinkedTo(sc SpanContext, attrs ...label.KeyValue) StartOption {
return func(c *StartConfig) {
c.Links = append(c.Links, Link{sc, attrs})
}

View File

@ -19,9 +19,9 @@ import (
"testing"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
)
func TestSetCurrentSpanOverridesPreviouslySetSpan(t *testing.T) {
@ -93,7 +93,7 @@ func (mockSpan) SetError(v bool) {
}
// SetAttributes does nothing.
func (mockSpan) SetAttributes(attributes ...kv.KeyValue) {
func (mockSpan) SetAttributes(attributes ...label.KeyValue) {
}
// SetAttribute does nothing.
@ -114,9 +114,9 @@ func (mockSpan) Tracer() trace.Tracer {
}
// Event does nothing.
func (mockSpan) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) {
func (mockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) {
}
// AddEventWithTimestamp does nothing.
func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) {
func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) {
}

View File

@ -18,8 +18,8 @@ import (
"context"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
)
type NoopSpan struct {
@ -46,7 +46,7 @@ func (NoopSpan) SetError(v bool) {
}
// SetAttributes does nothing.
func (NoopSpan) SetAttributes(attributes ...kv.KeyValue) {
func (NoopSpan) SetAttributes(attributes ...label.KeyValue) {
}
// SetAttribute does nothing.
@ -67,11 +67,11 @@ func (NoopSpan) Tracer() Tracer {
}
// AddEvent does nothing.
func (NoopSpan) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) {
func (NoopSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) {
}
// AddEventWithTimestamp does nothing.
func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) {
func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) {
}
// SetName does nothing.

View File

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

View File

@ -21,14 +21,14 @@ import (
"sync"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
)
const (
errorTypeKey = kv.Key("error.type")
errorMessageKey = kv.Key("error.message")
errorTypeKey = label.Key("error.type")
errorMessageKey = label.Key("error.message")
errorEventName = "error"
)
@ -45,9 +45,9 @@ type Span struct {
endTime time.Time
statusCode codes.Code
statusMessage string
attributes map[kv.Key]kv.Value
attributes map[label.Key]label.Value
events []Event
links map[trace.SpanContext][]kv.KeyValue
links map[trace.SpanContext][]label.KeyValue
spanKind trace.SpanKind
}
@ -110,11 +110,11 @@ func (s *Span) RecordError(ctx context.Context, err error, opts ...trace.ErrorOp
)
}
func (s *Span) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) {
func (s *Span) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) {
s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...)
}
func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) {
func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) {
s.lock.Lock()
defer s.lock.Unlock()
@ -122,7 +122,7 @@ func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, n
return
}
attributes := make(map[kv.Key]kv.Value)
attributes := make(map[label.Key]label.Value)
for _, attr := range attrs {
attributes[attr.Key] = attr.Value
@ -166,7 +166,7 @@ func (s *Span) SetName(name string) {
s.name = name
}
func (s *Span) SetAttributes(attrs ...kv.KeyValue) {
func (s *Span) SetAttributes(attrs ...label.KeyValue) {
s.lock.Lock()
defer s.lock.Unlock()
@ -180,7 +180,7 @@ func (s *Span) SetAttributes(attrs ...kv.KeyValue) {
}
func (s *Span) SetAttribute(k string, v interface{}) {
s.SetAttributes(kv.Any(k, v))
s.SetAttributes(label.Any(k, v))
}
// Name returns the name most recently set on the Span, either at or after creation time.
@ -199,11 +199,11 @@ func (s *Span) ParentSpanID() trace.SpanID {
// Attributes returns the attributes set on the Span, either at or after creation time.
// If the same attribute key was set multiple times, the last call will be used.
// Attributes cannot be changed after End has been called on the Span.
func (s *Span) Attributes() map[kv.Key]kv.Value {
func (s *Span) Attributes() map[label.Key]label.Value {
s.lock.RLock()
defer s.lock.RUnlock()
attributes := make(map[kv.Key]kv.Value)
attributes := make(map[label.Key]label.Value)
for k, v := range s.attributes {
attributes[k] = v
@ -220,11 +220,11 @@ func (s *Span) Events() []Event {
// Links returns the links set on the Span at creation time.
// If multiple links for the same SpanContext were set, the last link will be used.
func (s *Span) Links() map[trace.SpanContext][]kv.KeyValue {
links := make(map[trace.SpanContext][]kv.KeyValue)
func (s *Span) Links() map[trace.SpanContext][]label.KeyValue {
links := make(map[trace.SpanContext][]label.KeyValue)
for sc, attributes := range s.links {
links[sc] = append([]kv.KeyValue{}, attributes...)
links[sc] = append([]label.KeyValue{}, attributes...)
}
return links

View File

@ -22,12 +22,12 @@ import (
"testing"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/api/trace/tracetest"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/internal/matchers"
ottest "go.opentelemetry.io/otel/internal/testing"
"go.opentelemetry.io/otel/label"
)
func TestSpan(t *testing.T) {
@ -161,9 +161,9 @@ func TestSpan(t *testing.T) {
expectedEvents := []tracetest.Event{{
Timestamp: testTime,
Name: "error",
Attributes: map[kv.Key]kv.Value{
kv.Key("error.type"): kv.StringValue(s.typ),
kv.Key("error.message"): kv.StringValue(s.msg),
Attributes: map[label.Key]label.Value{
label.Key("error.type"): label.StringValue(s.typ),
label.Key("error.message"): label.StringValue(s.msg),
},
}}
e.Expect(subject.Events()).ToEqual(expectedEvents)
@ -192,9 +192,9 @@ func TestSpan(t *testing.T) {
expectedEvents := []tracetest.Event{{
Timestamp: testTime,
Name: "error",
Attributes: map[kv.Key]kv.Value{
kv.Key("error.type"): kv.StringValue("go.opentelemetry.io/otel/internal/testing.TestError"),
kv.Key("error.message"): kv.StringValue(errMsg),
Attributes: map[label.Key]label.Value{
label.Key("error.type"): label.StringValue("go.opentelemetry.io/otel/internal/testing.TestError"),
label.Key("error.message"): label.StringValue(errMsg),
},
}}
e.Expect(subject.Events()).ToEqual(expectedEvents)
@ -331,7 +331,7 @@ func TestSpan(t *testing.T) {
subject, ok := span.(*tracetest.Span)
e.Expect(ok).ToBeTrue()
e.Expect(subject.Attributes()).ToEqual(map[kv.Key]kv.Value{})
e.Expect(subject.Attributes()).ToEqual(map[label.Key]label.Value{})
})
t.Run("returns the most recently set attributes", func(t *testing.T) {
@ -345,9 +345,9 @@ func TestSpan(t *testing.T) {
subject, ok := span.(*tracetest.Span)
e.Expect(ok).ToBeTrue()
attr1 := kv.String("key1", "value1")
attr2 := kv.String("key2", "value2")
attr3 := kv.String("key3", "value3")
attr1 := label.String("key1", "value1")
attr2 := label.String("key2", "value2")
attr3 := label.String("key3", "value3")
unexpectedAttr := attr2.Key.String("unexpected")
subject.SetAttributes(attr1, unexpectedAttr, attr3)
@ -371,7 +371,7 @@ func TestSpan(t *testing.T) {
subject, ok := span.(*tracetest.Span)
e.Expect(ok).ToBeTrue()
expectedAttr := kv.String("key", "value")
expectedAttr := label.String("key", "value")
subject.SetAttributes(expectedAttr)
subject.End()
@ -401,7 +401,7 @@ func TestSpan(t *testing.T) {
go func() {
defer wg.Done()
subject.SetAttributes(kv.String("key", "value"))
subject.SetAttributes(label.String("key", "value"))
}()
go func() {
@ -459,9 +459,9 @@ func TestSpan(t *testing.T) {
e.Expect(ok).ToBeTrue()
event1Name := "event1"
event1Attributes := []kv.KeyValue{
kv.String("event1Attr1", "foo"),
kv.String("event1Attr2", "bar"),
event1Attributes := []label.KeyValue{
label.String("event1Attr1", "foo"),
label.String("event1Attr2", "bar"),
}
event1Start := time.Now()
@ -470,8 +470,8 @@ func TestSpan(t *testing.T) {
event2Timestamp := time.Now().AddDate(5, 0, 0)
event2Name := "event1"
event2Attributes := []kv.KeyValue{
kv.String("event2Attr", "abc"),
event2Attributes := []label.KeyValue{
label.String("event2Attr", "abc"),
}
subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Name, event2Attributes...)

View File

@ -18,8 +18,8 @@ import (
"context"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
)
var _ trace.Tracer = (*Tracer)(nil)
@ -48,20 +48,20 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti
span := &Span{
tracer: t,
startTime: startTime,
attributes: make(map[kv.Key]kv.Value),
links: make(map[trace.SpanContext][]kv.KeyValue),
attributes: make(map[label.Key]label.Value),
links: make(map[trace.SpanContext][]label.KeyValue),
spanKind: c.SpanKind,
}
if c.NewRoot {
span.spanContext = trace.EmptySpanContext()
iodKey := kv.Key("ignored-on-demand")
iodKey := label.Key("ignored-on-demand")
if lsc := trace.SpanFromContext(ctx).SpanContext(); lsc.IsValid() {
span.links[lsc] = []kv.KeyValue{iodKey.String("current")}
span.links[lsc] = []label.KeyValue{iodKey.String("current")}
}
if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() {
span.links[rsc] = []kv.KeyValue{iodKey.String("remote")}
span.links[rsc] = []label.KeyValue{iodKey.String("remote")}
}
} else {
span.spanContext = t.config.SpanContextFunc(ctx)

View File

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

View File

@ -27,11 +27,11 @@ import (
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
otelglobal "go.opentelemetry.io/otel/api/global"
otelcore "go.opentelemetry.io/otel/api/kv"
otelpropagation "go.opentelemetry.io/otel/api/propagation"
oteltrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/bridge/opentracing/migration"
)
@ -58,19 +58,19 @@ func newBridgeSpanContext(otelSpanContext oteltrace.SpanContext, parentOtSpanCon
}
func (c *bridgeSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {
c.baggageItems.Foreach(func(kv otelcore.KeyValue) bool {
c.baggageItems.Foreach(func(kv label.KeyValue) bool {
return handler(string(kv.Key), kv.Value.Emit())
})
}
func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
crk := http.CanonicalHeaderKey(restrictedKey)
c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: otelcore.Key(crk).String(value)})
c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: label.String(crk, value)})
}
func (c *bridgeSpanContext) baggageItem(restrictedKey string) string {
crk := http.CanonicalHeaderKey(restrictedKey)
val, _ := c.baggageItems.Value(otelcore.Key(crk))
val, _ := c.baggageItems.Value(label.Key(crk))
return val.Emit()
}
@ -114,7 +114,7 @@ func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) {
}
func (s *bridgeSpan) logRecord(record ot.LogRecord) {
s.otelSpan.AddEventWithTimestamp(context.Background(), record.Timestamp, "", otLogFieldsToOtelCoreKeyValues(record.Fields)...)
s.otelSpan.AddEventWithTimestamp(context.Background(), record.Timestamp, "", otLogFieldsToOTelLabels(record.Fields)...)
}
func (s *bridgeSpan) Context() ot.SpanContext {
@ -135,17 +135,17 @@ func (s *bridgeSpan) SetTag(key string, value interface{}) ot.Span {
s.otelSpan.SetStatus(codes.Unknown, "")
}
default:
s.otelSpan.SetAttributes(otTagToOtelCoreKeyValue(key, value))
s.otelSpan.SetAttributes(otTagToOTelLabel(key, value))
}
return s
}
func (s *bridgeSpan) LogFields(fields ...otlog.Field) {
s.otelSpan.AddEvent(context.Background(), "", otLogFieldsToOtelCoreKeyValues(fields)...)
s.otelSpan.AddEvent(context.Background(), "", otLogFieldsToOTelLabels(fields)...)
}
type bridgeFieldEncoder struct {
pairs []otelcore.KeyValue
pairs []label.KeyValue
}
var _ otlog.Encoder = &bridgeFieldEncoder{}
@ -195,10 +195,10 @@ func (e *bridgeFieldEncoder) EmitLazyLogger(value otlog.LazyLogger) {
}
func (e *bridgeFieldEncoder) emitCommon(key string, value interface{}) {
e.pairs = append(e.pairs, otTagToOtelCoreKeyValue(key, value))
e.pairs = append(e.pairs, otTagToOTelLabel(key, value))
}
func otLogFieldsToOtelCoreKeyValues(fields []otlog.Field) []otelcore.KeyValue {
func otLogFieldsToOTelLabels(fields []otlog.Field) []label.KeyValue {
encoder := &bridgeFieldEncoder{}
for _, field := range fields {
field.Marshal(encoder)
@ -215,7 +215,7 @@ func (s *bridgeSpan) LogKV(alternatingKeyValues ...interface{}) {
}
func (s *bridgeSpan) SetBaggageItem(restrictedKey, value string) ot.Span {
s.updateOtelContext(restrictedKey, value)
s.updateOTelContext(restrictedKey, value)
s.setBaggageItemOnly(restrictedKey, value)
return s
}
@ -224,7 +224,7 @@ func (s *bridgeSpan) setBaggageItemOnly(restrictedKey, value string) {
s.ctx.setBaggageItem(restrictedKey, value)
}
func (s *bridgeSpan) updateOtelContext(restrictedKey, value string) {
func (s *bridgeSpan) updateOTelContext(restrictedKey, value string) {
if s.extraBaggageItems == nil {
s.extraBaggageItems = make(map[string]string)
}
@ -347,7 +347,7 @@ func (t *BridgeTracer) correlationSetHook(ctx context.Context) context.Context {
// context, so we don't care about the old hooks.
clearCtx, _, _ := otelcorrelation.ContextWithNoHooks(ctx)
m := otelcorrelation.MapFromContext(clearCtx)
m.Foreach(func(kv otelcore.KeyValue) bool {
m.Foreach(func(kv label.KeyValue) bool {
bSpan.setBaggageItemOnly(string(kv.Key), kv.Value.Emit())
return true
})
@ -369,9 +369,9 @@ func (t *BridgeTracer) correlationGetHook(ctx context.Context, m otelcorrelation
if len(items) == 0 {
return m
}
kv := make([]otelcore.KeyValue, 0, len(items))
kv := make([]label.KeyValue, 0, len(items))
for k, v := range items {
kv = append(kv, otelcore.String(k, v))
kv = append(kv, label.String(k, v))
}
return m.Apply(otelcorrelation.MapUpdate{MultiKV: kv})
}
@ -384,7 +384,7 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
opt.Apply(&sso)
}
parentBridgeSC, links := otSpanReferencesToParentAndLinks(sso.References)
attributes, kind, hadTrueErrorTag := otTagsToOtelAttributesKindAndError(sso.Tags)
attributes, kind, hadTrueErrorTag := otTagsToOTelAttributesKindAndError(sso.Tags)
checkCtx := migration.WithDeferredSetup(context.Background())
if parentBridgeSC != nil {
checkCtx = oteltrace.ContextWithRemoteSpanContext(checkCtx, parentBridgeSC.otelSpanContext)
@ -457,10 +457,10 @@ func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) co
return ctx
}
func otTagsToOtelAttributesKindAndError(tags map[string]interface{}) ([]otelcore.KeyValue, oteltrace.SpanKind, bool) {
func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.KeyValue, oteltrace.SpanKind, bool) {
kind := oteltrace.SpanKindInternal
err := false
var pairs []otelcore.KeyValue
var pairs []label.KeyValue
for k, v := range tags {
switch k {
case string(otext.SpanKind):
@ -481,14 +481,14 @@ func otTagsToOtelAttributesKindAndError(tags map[string]interface{}) ([]otelcore
err = true
}
default:
pairs = append(pairs, otTagToOtelCoreKeyValue(k, v))
pairs = append(pairs, otTagToOTelLabel(k, v))
}
}
return pairs, kind, err
}
func otTagToOtelCoreKeyValue(k string, v interface{}) otelcore.KeyValue {
key := otTagToOtelCoreKey(k)
func otTagToOTelLabel(k string, v interface{}) label.KeyValue {
key := otTagToOTelLabelKey(k)
switch val := v.(type) {
case bool:
return key.Bool(val)
@ -515,8 +515,8 @@ func otTagToOtelCoreKeyValue(k string, v interface{}) otelcore.KeyValue {
}
}
func otTagToOtelCoreKey(k string) otelcore.Key {
return otelcore.Key(k)
func otTagToOTelLabelKey(k string) label.Key {
return label.Key(k)
}
func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpanContext, []oteltrace.Link) {
@ -530,34 +530,34 @@ func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpa
// We ignore foreign ot span contexts,
// sorry. We have no way of getting any
// TraceID and SpanID out of it for form a
// otelcore.SpanContext for otelcore.Link. And
// OTel SpanContext for OTel Link. And
// we can't make it a parent - it also needs a
// valid otelcore.SpanContext.
// valid OTel SpanContext.
continue
}
if parent != nil {
links = append(links, otSpanReferenceToOtelLink(bridgeSC, reference.Type))
links = append(links, otSpanReferenceToOTelLink(bridgeSC, reference.Type))
} else {
if reference.Type == ot.ChildOfRef {
parent = bridgeSC
} else {
links = append(links, otSpanReferenceToOtelLink(bridgeSC, reference.Type))
links = append(links, otSpanReferenceToOTelLink(bridgeSC, reference.Type))
}
}
}
return parent, links
}
func otSpanReferenceToOtelLink(bridgeSC *bridgeSpanContext, refType ot.SpanReferenceType) oteltrace.Link {
func otSpanReferenceToOTelLink(bridgeSC *bridgeSpanContext, refType ot.SpanReferenceType) oteltrace.Link {
return oteltrace.Link{
SpanContext: bridgeSC.otelSpanContext,
Attributes: otSpanReferenceTypeToOtelLinkAttributes(refType),
Attributes: otSpanReferenceTypeToOTelLinkAttributes(refType),
}
}
func otSpanReferenceTypeToOtelLinkAttributes(refType ot.SpanReferenceType) []otelcore.KeyValue {
return []otelcore.KeyValue{
otelcore.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)),
func otSpanReferenceTypeToOTelLinkAttributes(refType ot.SpanReferenceType) []label.KeyValue {
return []label.KeyValue{
label.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)),
}
}

View File

@ -22,21 +22,21 @@ import (
"time"
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
otelcore "go.opentelemetry.io/otel/api/kv"
oteltrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/bridge/opentracing/migration"
)
var (
ComponentKey = otelcore.Key("component")
ServiceKey = otelcore.Key("service")
StatusCodeKey = otelcore.Key("status.code")
StatusMessageKey = otelcore.Key("status.message")
ErrorKey = otelcore.Key("error")
NameKey = otelcore.Key("name")
ComponentKey = label.Key("component")
ServiceKey = label.Key("service")
StatusCodeKey = label.Key("status.code")
StatusMessageKey = label.Key("status.message")
ErrorKey = label.Key("error")
NameKey = label.Key("name")
)
type MockContextKeyValue struct {
@ -225,14 +225,14 @@ func (s *MockSpan) SetError(v bool) {
s.SetAttributes(ErrorKey.Bool(v))
}
func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
func (s *MockSpan) SetAttributes(attributes ...label.KeyValue) {
s.applyUpdate(otelcorrelation.MapUpdate{
MultiKV: attributes,
})
}
func (s *MockSpan) SetAttribute(k string, v interface{}) {
s.SetAttributes(otelcore.Any(k, v))
s.SetAttributes(label.Any(k, v))
}
func (s *MockSpan) applyUpdate(update otelcorrelation.MapUpdate) {
@ -281,8 +281,8 @@ func (s *MockSpan) RecordError(ctx context.Context, err error, opts ...oteltrace
}
s.AddEventWithTimestamp(ctx, cfg.Timestamp, "error",
otelcore.String("error.type", reflect.TypeOf(err).String()),
otelcore.String("error.message", err.Error()),
label.String("error.type", reflect.TypeOf(err).String()),
label.String("error.message", err.Error()),
)
}
@ -290,11 +290,11 @@ func (s *MockSpan) Tracer() oteltrace.Tracer {
return s.officialTracer
}
func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...otelcore.KeyValue) {
func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) {
s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...)
}
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...otelcore.KeyValue) {
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) {
s.Events = append(s.Events, MockEvent{
CtxAttributes: otelcorrelation.MapFromContext(ctx),
Timestamp: timestamp,

View File

@ -23,8 +23,8 @@ import (
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
otelglobal "go.opentelemetry.io/otel/api/global"
otelcore "go.opentelemetry.io/otel/api/kv"
oteltrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/bridge/opentracing/internal"
)
@ -589,7 +589,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont
value := bio.baggageItems[idx].value
otSpan.SetBaggageItem(otKey, value)
ctx = otelcorrelation.NewContext(ctx, otelcore.String(otelKey, value))
ctx = otelcorrelation.NewContext(ctx, label.String(otelKey, value))
otRecording := make(map[string]string)
otSpan.Context().ForeachBaggageItem(func(key, value string) bool {
@ -597,7 +597,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont
return true
})
otelRecording := make(map[string]string)
otelcorrelation.MapFromContext(ctx).Foreach(func(kv otelcore.KeyValue) bool {
otelcorrelation.MapFromContext(ctx).Foreach(func(kv label.KeyValue) bool {
otelRecording[string(kv.Key)] = kv.Value.Emit()
return true
})

View File

@ -20,17 +20,17 @@ import (
"go.opentelemetry.io/otel/api/correlation"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
)
var (
fooKey = kv.Key("ex.com/foo")
barKey = kv.Key("ex.com/bar")
lemonsKey = kv.Key("ex.com/lemons")
anotherKey = kv.Key("ex.com/another")
fooKey = label.Key("ex.com/foo")
barKey = label.Key("ex.com/bar")
lemonsKey = label.Key("ex.com/lemons")
anotherKey = label.Key("ex.com/another")
)
func main() {
@ -46,7 +46,7 @@ func main() {
tracer := global.Tracer("ex.com/basic")
meter := global.Meter("ex.com/basic")
commonLabels := []kv.KeyValue{lemonsKey.Int(10), kv.String("A", "1"), kv.String("B", "2"), kv.String("C", "3")}
commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")}
oneMetricCB := func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(1, commonLabels...)
@ -72,7 +72,7 @@ func main() {
ctx, span = tracer.Start(ctx, "operation")
defer span.End()
span.AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100))
span.AddEvent(ctx, "Nice operation!", label.Int("bogons", 100))
span.SetAttributes(anotherKey.String("yes"))
meter.RecordBatch(

View File

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

View File

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

View File

@ -18,20 +18,19 @@ import (
"context"
"log"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/correlation"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/example/namedtracer/foo"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
var (
fooKey = kv.Key("ex.com/foo")
barKey = kv.Key("ex.com/bar")
anotherKey = kv.Key("ex.com/another")
fooKey = label.Key("ex.com/foo")
barKey = label.Key("ex.com/bar")
anotherKey = label.Key("ex.com/another")
)
var tp *sdktrace.Provider
@ -68,7 +67,7 @@ func main() {
var span trace.Span
ctx, span = tracer.Start(ctx, "operation")
defer span.End()
span.AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100))
span.AddEvent(ctx, "Nice operation!", label.Int("bogons", 100))
span.SetAttributes(anotherKey.String("yes"))
if err := foo.SubOperation(ctx); err != nil {
panic(err)

View File

@ -26,10 +26,10 @@ import (
"google.golang.org/grpc"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
@ -58,7 +58,7 @@ func initProvider() (*otlp.Exporter, *push.Controller) {
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithResource(resource.New(
// the service name used to display traces in backends
kv.Key(semconv.ServiceNameKey).String("test-service"),
semconv.ServiceNameKey.String("test-service"),
)),
sdktrace.WithBatcher(exp),
)
@ -92,10 +92,10 @@ func main() {
// labels represent additional key-value descriptors that can be bound to a
// metric observer or recorder.
commonLabels := []kv.KeyValue{
kv.String("labelA", "chocolate"),
kv.String("labelB", "raspberry"),
kv.String("labelC", "vanilla"),
commonLabels := []label.KeyValue{
label.String("labelA", "chocolate"),
label.String("labelB", "raspberry"),
label.String("labelC", "vanilla"),
}
// Recorder metric example

View File

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

View File

@ -22,9 +22,9 @@ import (
"net/http"
"net/http/httptest"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
"go.opentelemetry.io/otel/sdk/resource"
)
@ -40,7 +40,7 @@ func ExampleNewExportPipeline() {
// Create a meter
exporter, err := prometheus.NewExportPipeline(
prometheus.Config{},
pull.WithResource(resource.New(kv.String("R", "V"))),
pull.WithResource(resource.New(label.String("R", "V"))),
)
if err != nil {
panic(err)
@ -58,8 +58,8 @@ func ExampleNewExportPipeline() {
metric.WithDescription("Records values"),
)
counter.Add(ctx, 100, kv.String("key", "value"))
recorder.Record(ctx, 100, kv.String("key", "value"))
counter.Add(ctx, 100, label.String("key", "value"))
recorder.Record(ctx, 100, label.String("key", "value"))
// GET the HTTP endpoint
var input bytes.Buffer

View File

@ -24,8 +24,8 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/controller/pull"

View File

@ -26,9 +26,9 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
"go.opentelemetry.io/otel/sdk/resource"
)
@ -39,7 +39,7 @@ func TestPrometheusExporter(t *testing.T) {
DefaultHistogramBoundaries: []float64{-0.5, 1},
},
pull.WithCachePeriod(0),
pull.WithResource(resource.New(kv.String("R", "V"))),
pull.WithResource(resource.New(label.String("R", "V"))),
)
require.NoError(t, err)
@ -48,9 +48,9 @@ func TestPrometheusExporter(t *testing.T) {
counter := metric.Must(meter).NewFloat64Counter("counter")
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
labels := []kv.KeyValue{
kv.Key("A").String("B"),
kv.Key("C").String("D"),
labels := []label.KeyValue{
label.Key("A").String("B"),
label.Key("C").String("D"),
}
ctx := context.Background()
@ -128,14 +128,14 @@ func TestPrometheusStatefulness(t *testing.T) {
metric.WithDescription("Counts things"),
)
counter.Add(ctx, 100, kv.String("key", "value"))
counter.Add(ctx, 100, label.String("key", "value"))
require.Equal(t, `# HELP a_counter Counts things
# TYPE a_counter counter
a_counter{key="value"} 100
`, scrape())
counter.Add(ctx, 100, kv.String("key", "value"))
counter.Add(ctx, 100, label.String("key", "value"))
require.Equal(t, `# HELP a_counter Counts things
# TYPE a_counter counter

View File

@ -16,13 +16,13 @@ package transform
import (
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/sdk/resource"
)
// Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values.
func Attributes(attrs []kv.KeyValue) []*commonpb.KeyValue {
func Attributes(attrs []label.KeyValue) []*commonpb.KeyValue {
if len(attrs) == 0 {
return nil
}
@ -48,33 +48,33 @@ func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue {
return out
}
func toAttribute(v kv.KeyValue) *commonpb.KeyValue {
func toAttribute(v label.KeyValue) *commonpb.KeyValue {
result := &commonpb.KeyValue{
Key: string(v.Key),
Value: new(commonpb.AnyValue),
}
switch v.Value.Type() {
case kv.BOOL:
case label.BOOL:
result.Value.Value = &commonpb.AnyValue_BoolValue{
BoolValue: v.Value.AsBool(),
}
case kv.INT64, kv.INT32, kv.UINT32, kv.UINT64:
case label.INT64, label.INT32, label.UINT32, label.UINT64:
result.Value.Value = &commonpb.AnyValue_IntValue{
IntValue: v.Value.AsInt64(),
}
case kv.FLOAT32:
case label.FLOAT32:
result.Value.Value = &commonpb.AnyValue_DoubleValue{
DoubleValue: float64(v.Value.AsFloat32()),
}
case kv.FLOAT64:
case label.FLOAT64:
result.Value.Value = &commonpb.AnyValue_DoubleValue{
DoubleValue: v.Value.AsFloat64(),
}
case kv.STRING:
case label.STRING:
result.Value.Value = &commonpb.AnyValue_StringValue{
StringValue: v.Value.AsString(),
}
case kv.ARRAY:
case label.ARRAY:
result.Value.Value = toArrayAttribute(v)
default:
result.Value.Value = &commonpb.AnyValue_StringValue{
@ -84,7 +84,7 @@ func toAttribute(v kv.KeyValue) *commonpb.KeyValue {
return result
}
func toArrayAttribute(v kv.KeyValue) *commonpb.AnyValue_ArrayValue {
func toArrayAttribute(v label.KeyValue) *commonpb.AnyValue_ArrayValue {
array := v.Value.AsArray()
var resultValues []*commonpb.AnyValue

View File

@ -19,12 +19,12 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/api/kv"
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
"go.opentelemetry.io/otel/label"
)
type attributeTest struct {
attrs []kv.KeyValue
attrs []label.KeyValue
expected []*commonpb.KeyValue
}
@ -32,17 +32,17 @@ func TestAttributes(t *testing.T) {
for _, test := range []attributeTest{
{nil, nil},
{
[]kv.KeyValue{
kv.Int("int to int", 123),
kv.Uint("uint to int", 1234),
kv.Int32("int32 to int", 12345),
kv.Uint32("uint32 to int", 123456),
kv.Int64("int64 to int64", 1234567),
kv.Uint64("uint64 to int64", 12345678),
kv.Float32("float32 to double", 3.14),
kv.Float32("float64 to double", 1.61),
kv.String("string to string", "string"),
kv.Bool("bool to bool", true),
[]label.KeyValue{
label.Int("int to int", 123),
label.Uint("uint to int", 1234),
label.Int32("int32 to int", 12345),
label.Uint32("uint32 to int", 123456),
label.Int64("int64 to int64", 1234567),
label.Uint64("uint64 to int64", 12345678),
label.Float32("float32 to double", 3.14),
label.Float32("float64 to double", 1.61),
label.String("string to string", "string"),
label.Bool("bool to bool", true),
},
[]*commonpb.KeyValue{
{
@ -157,17 +157,17 @@ func TestArrayAttributes(t *testing.T) {
for _, test := range []attributeTest{
{nil, nil},
{
[]kv.KeyValue{
kv.Array("bool array to bool array", []bool{true, false}),
kv.Array("int array to int64 array", []int{1, 2, 3}),
kv.Array("uint array to int64 array", []uint{1, 2, 3}),
kv.Array("int32 array to int64 array", []int32{1, 2, 3}),
kv.Array("uint32 array to int64 array", []uint32{1, 2, 3}),
kv.Array("int64 array to int64 array", []int64{1, 2, 3}),
kv.Array("uint64 array to int64 array", []uint64{1, 2, 3}),
kv.Array("float32 array to double array", []float32{1.11, 2.22, 3.33}),
kv.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}),
kv.Array("string array to string array", []string{"foo", "bar", "baz"}),
[]label.KeyValue{
label.Array("bool array to bool array", []bool{true, false}),
label.Array("int array to int64 array", []int{1, 2, 3}),
label.Array("uint array to int64 array", []uint{1, 2, 3}),
label.Array("int32 array to int64 array", []int32{1, 2, 3}),
label.Array("uint32 array to int64 array", []uint32{1, 2, 3}),
label.Array("int64 array to int64 array", []int64{1, 2, 3}),
label.Array("uint64 array to int64 array", []uint64{1, 2, 3}),
label.Array("float32 array to double array", []float32{1.11, 2.22, 3.33}),
label.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}),
label.Array("string array to string array", []string{"foo", "bar", "baz"}),
},
[]*commonpb.KeyValue{
newOTelBoolArray("bool array to bool array", []bool{true, false}),

View File

@ -27,8 +27,8 @@ import (
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/instrumentation"

View File

@ -26,10 +26,9 @@ import (
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/unit"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
@ -46,7 +45,7 @@ var (
func TestStringKeyValues(t *testing.T) {
tests := []struct {
kvs []kv.KeyValue
kvs []label.KeyValue
expected []*commonpb.StringKeyValue
}{
{
@ -54,21 +53,21 @@ func TestStringKeyValues(t *testing.T) {
nil,
},
{
[]kv.KeyValue{},
[]label.KeyValue{},
nil,
},
{
[]kv.KeyValue{
kv.Bool("true", true),
kv.Int64("one", 1),
kv.Uint64("two", 2),
kv.Float64("three", 3),
kv.Int32("four", 4),
kv.Uint32("five", 5),
kv.Float32("six", 6),
kv.Int("seven", 7),
kv.Uint("eight", 8),
kv.String("the", "final word"),
[]label.KeyValue{
label.Bool("true", true),
label.Int64("one", 1),
label.Uint64("two", 2),
label.Float64("three", 3),
label.Int32("four", 4),
label.Uint32("five", 5),
label.Float32("six", 6),
label.Int("seven", 7),
label.Uint("eight", 8),
label.String("the", "final word"),
},
[]*commonpb.StringKeyValue{
{Key: "eight", Value: "8"},
@ -119,7 +118,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
description string
unit unit.Unit
numberKind metric.NumberKind
labels []kv.KeyValue
labels []label.KeyValue
expected *metricpb.MetricDescriptor
}{
{
@ -128,7 +127,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
"test-a-description",
unit.Dimensionless,
metric.Int64NumberKind,
[]kv.KeyValue{},
[]label.KeyValue{},
&metricpb.MetricDescriptor{
Name: "mmsc-test-a",
Description: "test-a-description",
@ -142,7 +141,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
"test-b-description",
unit.Bytes,
metric.Float64NumberKind, // This shouldn't change anything.
[]kv.KeyValue{kv.String("A", "1")},
[]label.KeyValue{label.String("A", "1")},
&metricpb.MetricDescriptor{
Name: "mmsc-test-b",
Description: "test-b-description",
@ -224,7 +223,7 @@ func TestSumMetricDescriptor(t *testing.T) {
description string
unit unit.Unit
numberKind metric.NumberKind
labels []kv.KeyValue
labels []label.KeyValue
expected *metricpb.MetricDescriptor
}{
{
@ -233,7 +232,7 @@ func TestSumMetricDescriptor(t *testing.T) {
"test-a-description",
unit.Dimensionless,
metric.Int64NumberKind,
[]kv.KeyValue{},
[]label.KeyValue{},
&metricpb.MetricDescriptor{
Name: "sum-test-a",
Description: "test-a-description",
@ -247,7 +246,7 @@ func TestSumMetricDescriptor(t *testing.T) {
"test-b-description",
unit.Milliseconds,
metric.Float64NumberKind,
[]kv.KeyValue{kv.String("A", "1")},
[]label.KeyValue{label.String("A", "1")},
&metricpb.MetricDescriptor{
Name: "sum-test-b",
Description: "test-b-description",

View File

@ -19,7 +19,7 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/resource"
)
@ -38,7 +38,7 @@ func TestEmptyResource(t *testing.T) {
*/
func TestResourceAttributes(t *testing.T) {
attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)}
attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)}
got := Resource(resource.New(attrs...)).GetAttributes()
if !assert.Len(t, attrs, 2) {

View File

@ -19,8 +19,8 @@ import (
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
"go.opentelemetry.io/otel/api/label"
apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
)

View File

@ -26,8 +26,8 @@ import (
"google.golang.org/grpc/codes"
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/api/kv"
apitrace "go.opentelemetry.io/otel/api/trace"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
@ -77,12 +77,12 @@ func TestEmptySpanEvent(t *testing.T) {
}
func TestSpanEvent(t *testing.T) {
attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)}
attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)}
eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
got := spanEvents([]export.Event{
{
Name: "test 1",
Attributes: []kv.KeyValue{},
Attributes: []label.KeyValue{},
Time: eventTime,
},
{
@ -121,7 +121,7 @@ func TestEmptyLinks(t *testing.T) {
}
func TestLinks(t *testing.T) {
attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)}
attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)}
l := []apitrace.Link{
{},
{
@ -283,13 +283,13 @@ func TestSpanData(t *testing.T) {
EndTime: endTime,
MessageEvents: []export.Event{
{Time: startTime,
Attributes: []kv.KeyValue{
kv.Uint64("CompressedByteSize", 512),
Attributes: []label.KeyValue{
label.Uint64("CompressedByteSize", 512),
},
},
{Time: endTime,
Attributes: []kv.KeyValue{
kv.String("MessageEventType", "Recv"),
Attributes: []label.KeyValue{
label.String("MessageEventType", "Recv"),
},
},
},
@ -300,8 +300,8 @@ func TestSpanData(t *testing.T) {
SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
TraceFlags: 0,
},
Attributes: []kv.KeyValue{
kv.String("LinkType", "Parent"),
Attributes: []label.KeyValue{
label.String("LinkType", "Parent"),
},
},
{
@ -310,21 +310,21 @@ func TestSpanData(t *testing.T) {
SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7},
TraceFlags: 0,
},
Attributes: []kv.KeyValue{
kv.String("LinkType", "Child"),
Attributes: []label.KeyValue{
label.String("LinkType", "Child"),
},
},
},
StatusCode: codes.Internal,
StatusMessage: "utterly unrecognized",
HasRemoteParent: true,
Attributes: []kv.KeyValue{
kv.Int64("timeout_ns", 12e9),
Attributes: []label.KeyValue{
label.Int64("timeout_ns", 12e9),
},
DroppedAttributeCount: 1,
DroppedMessageEventCount: 2,
DroppedLinkCount: 3,
Resource: resource.New(kv.String("rk1", "rv1"), kv.Int64("rk2", 5)),
Resource: resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5)),
InstrumentationLibrary: instrumentation.Library{
Name: "go.opentelemetry.io/test/otel",
Version: "v0.0.1",

View File

@ -27,8 +27,8 @@ import (
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
metricapi "go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporters/otlp"
@ -91,15 +91,15 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
}
tp1, err := sdktrace.NewProvider(append(pOpts,
sdktrace.WithResource(resource.New(
kv.String("rk1", "rv11)"),
kv.Int64("rk2", 5),
label.String("rk1", "rv11)"),
label.Int64("rk2", 5),
)))...)
assert.NoError(t, err)
tp2, err := sdktrace.NewProvider(append(pOpts,
sdktrace.WithResource(resource.New(
kv.String("rk1", "rv12)"),
kv.Float32("rk3", 6.5),
label.String("rk1", "rv12)"),
label.Float32("rk3", 6.5),
)))...)
assert.NoError(t, err)
@ -109,11 +109,11 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
m := 4
for i := 0; i < m; i++ {
_, span := tr1.Start(context.Background(), "AlwaysSample")
span.SetAttributes(kv.Int64("i", int64(i)))
span.SetAttributes(label.Int64("i", int64(i)))
span.End()
_, span = tr2.Start(context.Background(), "AlwaysSample")
span.SetAttributes(kv.Int64("i", int64(i)))
span.SetAttributes(label.Int64("i", int64(i)))
span.End()
}
@ -124,7 +124,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
ctx := context.Background()
meter := pusher.Provider().Meter("test-meter")
labels := []kv.KeyValue{kv.Bool("test", true)}
labels := []label.KeyValue{label.Bool("test", true)}
type data struct {
iKind metric.Kind

View File

@ -28,9 +28,8 @@ import (
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
@ -98,15 +97,15 @@ type record struct {
nKind metric.NumberKind
resource *resource.Resource
opts []metric.InstrumentOption
labels []kv.KeyValue
labels []label.KeyValue
}
var (
baseKeyValues = []kv.KeyValue{kv.String("host", "test.com")}
cpuKey = kv.Key("CPU")
baseKeyValues = []label.KeyValue{label.String("host", "test.com")}
cpuKey = label.Key("CPU")
testInstA = resource.New(kv.String("instance", "tester-a"))
testInstB = resource.New(kv.String("instance", "tester-b"))
testInstA = resource.New(label.String("instance", "tester-a"))
testInstB = resource.New(label.String("instance", "tester-b"))
md = &metricpb.MetricDescriptor{
Name: "int64-count",

View File

@ -27,8 +27,8 @@ import (
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/api/kv"
apitrace "go.opentelemetry.io/otel/api/trace"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
@ -91,13 +91,13 @@ func TestExportSpans(t *testing.T) {
Name: "parent process",
StartTime: startTime,
EndTime: endTime,
Attributes: []kv.KeyValue{
kv.String("user", "alice"),
kv.Bool("authenticated", true),
Attributes: []label.KeyValue{
label.String("user", "alice"),
label.Bool("authenticated", true),
},
StatusCode: codes.OK,
StatusMessage: "Ok",
Resource: resource.New(kv.String("instance", "tester-a")),
Resource: resource.New(label.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-a",
Version: "v0.1.0",
@ -113,13 +113,13 @@ func TestExportSpans(t *testing.T) {
Name: "secondary parent process",
StartTime: startTime,
EndTime: endTime,
Attributes: []kv.KeyValue{
kv.String("user", "alice"),
kv.Bool("authenticated", true),
Attributes: []label.KeyValue{
label.String("user", "alice"),
label.Bool("authenticated", true),
},
StatusCode: codes.OK,
StatusMessage: "Ok",
Resource: resource.New(kv.String("instance", "tester-a")),
Resource: resource.New(label.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-b",
Version: "v0.1.0",
@ -136,13 +136,13 @@ func TestExportSpans(t *testing.T) {
Name: "internal process",
StartTime: startTime,
EndTime: endTime,
Attributes: []kv.KeyValue{
kv.String("user", "alice"),
kv.Bool("authenticated", true),
Attributes: []label.KeyValue{
label.String("user", "alice"),
label.Bool("authenticated", true),
},
StatusCode: codes.OK,
StatusMessage: "Ok",
Resource: resource.New(kv.String("instance", "tester-a")),
Resource: resource.New(label.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-a",
Version: "v0.1.0",
@ -158,13 +158,13 @@ func TestExportSpans(t *testing.T) {
Name: "parent process",
StartTime: startTime,
EndTime: endTime,
Attributes: []kv.KeyValue{
kv.String("user", "bob"),
kv.Bool("authenticated", false),
Attributes: []label.KeyValue{
label.String("user", "bob"),
label.Bool("authenticated", false),
},
StatusCode: codes.Unauthenticated,
StatusMessage: "Unauthenticated",
Resource: resource.New(kv.String("instance", "tester-b")),
Resource: resource.New(label.String("instance", "tester-b")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-a",
Version: "v1.1.0",

View File

@ -18,7 +18,7 @@ import (
"io"
"os"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
)

View File

@ -19,10 +19,10 @@ import (
"log"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
)
const (
@ -44,7 +44,7 @@ var (
loopCounter = metric.Must(meter).NewInt64Counter("function.loops")
paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param")
nameKey = kv.Key("function.name")
nameKey = label.Key("function.name")
)
func add(ctx context.Context, x, y int64) int64 {

View File

@ -21,9 +21,8 @@ import (
"strings"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
apimetric "go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
)
@ -69,11 +68,11 @@ func (e *metricExporter) Export(_ context.Context, checkpointSet metric.Checkpoi
kind := desc.NumberKind()
encodedResource := record.Resource().Encoded(e.config.LabelEncoder)
var instLabels []kv.KeyValue
var instLabels []label.KeyValue
if name := desc.InstrumentationName(); name != "" {
instLabels = append(instLabels, kv.String("instrumentation.name", name))
instLabels = append(instLabels, label.String("instrumentation.name", name))
if version := desc.InstrumentationVersion(); version != "" {
instLabels = append(instLabels, kv.String("instrumentation.version", version))
instLabels = append(instLabels, label.String("instrumentation.version", version))
}
}
instSet := label.NewSet(instLabels...)

View File

@ -26,9 +26,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
@ -48,7 +48,7 @@ type testFixture struct {
output *bytes.Buffer
}
var testResource = resource.New(kv.String("R", "V"))
var testResource = resource.New(label.String("R", "V"))
func newFixture(t *testing.T, opts ...stdout.Option) testFixture {
buf := &bytes.Buffer{}
@ -145,7 +145,7 @@ func TestStdoutCounterFormat(t *testing.T) {
aggregatortest.CheckedUpdate(fix.t, cagg, metric.NewInt64Number(123), &desc)
require.NoError(t, cagg.SynchronizedMove(ckpt, &desc))
checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D"))
checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D"))
fix.Export(checkpointSet)
@ -163,7 +163,7 @@ func TestStdoutLastValueFormat(t *testing.T) {
aggregatortest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc)
require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc))
checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D"))
checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D"))
fix.Export(checkpointSet)
@ -183,7 +183,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) {
aggregatortest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(876.543), &desc)
require.NoError(t, magg.SynchronizedMove(ckpt, &desc))
checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D"))
checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D"))
fix.Export(checkpointSet)
@ -204,7 +204,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) {
require.NoError(t, aagg.SynchronizedMove(ckpt, &desc))
checkpointSet.Add(&desc, ckpt, kv.String("A", "B"), kv.String("C", "D"))
checkpointSet.Add(&desc, ckpt, label.String("A", "B"), label.String("C", "D"))
fix.Export(checkpointSet)
@ -268,7 +268,7 @@ func TestStdoutLastValueNotSet(t *testing.T) {
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc))
checkpointSet.Add(&desc, lvagg, kv.String("A", "B"), kv.String("C", "D"))
checkpointSet.Add(&desc, lvagg, label.String("A", "B"), label.String("C", "D"))
fix.Export(checkpointSet)
@ -279,9 +279,9 @@ func TestStdoutResource(t *testing.T) {
type testCase struct {
expect string
res *resource.Resource
attrs []kv.KeyValue
attrs []label.KeyValue
}
newCase := func(expect string, res *resource.Resource, attrs ...kv.KeyValue) testCase {
newCase := func(expect string, res *resource.Resource, attrs ...label.KeyValue) testCase {
return testCase{
expect: expect,
res: res,
@ -290,23 +290,23 @@ func TestStdoutResource(t *testing.T) {
}
testCases := []testCase{
newCase("R1=V1,R2=V2,A=B,C=D",
resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")),
kv.String("A", "B"),
kv.String("C", "D")),
resource.New(label.String("R1", "V1"), label.String("R2", "V2")),
label.String("A", "B"),
label.String("C", "D")),
newCase("R1=V1,R2=V2",
resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")),
resource.New(label.String("R1", "V1"), label.String("R2", "V2")),
),
newCase("A=B,C=D",
nil,
kv.String("A", "B"),
kv.String("C", "D"),
label.String("A", "B"),
label.String("C", "D"),
),
// We explicitly do not de-duplicate between resources
// and metric labels in this exporter.
newCase("R1=V1,R2=V2,R1=V3,R2=V4",
resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")),
kv.String("R1", "V3"),
kv.String("R2", "V4")),
resource.New(label.String("R1", "V1"), label.String("R2", "V2")),
label.String("R1", "V3"),
label.String("R2", "V4")),
}
for _, tc := range testCases {

View File

@ -23,9 +23,9 @@ import (
"google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/resource"
)
@ -44,7 +44,7 @@ func TestExporter_ExportSpan(t *testing.T) {
spanID, _ := trace.SpanIDFromHex("0102030405060708")
keyValue := "value"
doubleValue := 123.456
resource := resource.New(kv.String("rk1", "rv11"))
resource := resource.New(label.String("rk1", "rv11"))
testSpan := &export.SpanData{
SpanContext: trace.SpanContext{
@ -54,13 +54,13 @@ func TestExporter_ExportSpan(t *testing.T) {
Name: "/foo",
StartTime: now,
EndTime: now,
Attributes: []kv.KeyValue{
kv.String("key", keyValue),
kv.Float64("double", doubleValue),
Attributes: []label.KeyValue{
label.String("key", keyValue),
label.Float64("double", doubleValue),
},
MessageEvents: []export.Event{
{Name: "foo", Attributes: []kv.KeyValue{kv.String("key", keyValue)}, Time: now},
{Name: "bar", Attributes: []kv.KeyValue{kv.Float64("double", doubleValue)}, Time: now},
{Name: "foo", Attributes: []label.KeyValue{label.String("key", keyValue)}, Time: now},
{Name: "bar", Attributes: []label.KeyValue{label.Float64("double", doubleValue)}, Time: now},
},
SpanKind: trace.SpanKindInternal,
StatusCode: codes.Unknown,

View File

@ -21,7 +21,7 @@ import (
"strings"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// Environment variable names
@ -111,9 +111,9 @@ var errTagEnvironmentDefaultValueNotFound = errors.New("missing default value fo
// - comma separated list of key=value
// - value can be specified using the notation ${envVar:defaultValue}, where `envVar`
// is an environment variable and `defaultValue` is the value to use in case the env var is not set
func parseTags(sTags string) ([]kv.KeyValue, error) {
func parseTags(sTags string) ([]label.KeyValue, error) {
pairs := strings.Split(sTags, ",")
tags := make([]kv.KeyValue, len(pairs))
tags := make([]label.KeyValue, len(pairs))
for i, p := range pairs {
field := strings.SplitN(p, "=", 2)
if len(field) != 2 {
@ -139,24 +139,24 @@ func parseTags(sTags string) ([]kv.KeyValue, error) {
return tags, nil
}
func parseKeyValue(k, v string) kv.KeyValue {
return kv.KeyValue{
Key: kv.Key(k),
func parseKeyValue(k, v string) label.KeyValue {
return label.KeyValue{
Key: label.Key(k),
Value: parseValue(v),
}
}
func parseValue(str string) kv.Value {
func parseValue(str string) label.Value {
if v, err := strconv.ParseInt(str, 10, 64); err == nil {
return kv.Int64Value(v)
return label.Int64Value(v)
}
if v, err := strconv.ParseFloat(str, 64); err == nil {
return kv.Float64Value(v)
return label.Float64Value(v)
}
if v, err := strconv.ParseBool(str); err == nil {
return kv.BoolValue(v)
return label.BoolValue(v)
}
// Fallback
return kv.StringValue(str)
return label.StringValue(str)
}

View File

@ -22,8 +22,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
ottest "go.opentelemetry.io/otel/internal/testing"
"go.opentelemetry.io/otel/label"
)
func Test_parseTags(t *testing.T) {
@ -38,78 +38,78 @@ func Test_parseTags(t *testing.T) {
testCases := []struct {
name string
tagStr string
expectedTags []kv.KeyValue
expectedTags []label.KeyValue
expectedError error
}{
{
name: "string",
tagStr: "key=value",
expectedTags: []kv.KeyValue{
expectedTags: []label.KeyValue{
{
Key: "key",
Value: kv.StringValue("value"),
Value: label.StringValue("value"),
},
},
},
{
name: "int64",
tagStr: "k=9223372036854775807,k2=-9223372036854775808",
expectedTags: []kv.KeyValue{
expectedTags: []label.KeyValue{
{
Key: "k",
Value: kv.Int64Value(math.MaxInt64),
Value: label.Int64Value(math.MaxInt64),
},
{
Key: "k2",
Value: kv.Int64Value(math.MinInt64),
Value: label.Int64Value(math.MinInt64),
},
},
},
{
name: "float64",
tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2",
expectedTags: []kv.KeyValue{
expectedTags: []label.KeyValue{
{
Key: "k",
Value: kv.Float64Value(math.MaxFloat64),
Value: label.Float64Value(math.MaxFloat64),
},
{
Key: "k2",
Value: kv.Float64Value(math.SmallestNonzeroFloat64),
Value: label.Float64Value(math.SmallestNonzeroFloat64),
},
{
Key: "k3",
Value: kv.Float64Value(-1.2),
Value: label.Float64Value(-1.2),
},
},
},
{
name: "multiple type values",
tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}",
expectedTags: []kv.KeyValue{
expectedTags: []label.KeyValue{
{
Key: "k",
Value: kv.StringValue("v"),
Value: label.StringValue("v"),
},
{
Key: "k2",
Value: kv.Int64Value(123),
Value: label.Int64Value(123),
},
{
Key: "k3",
Value: kv.StringValue("v3"),
Value: label.StringValue("v3"),
},
{
Key: "k4",
Value: kv.Float64Value(-1.2),
Value: label.Float64Value(-1.2),
},
{
Key: "k5",
Value: kv.StringValue("not-default"),
Value: label.StringValue("not-default"),
},
{
Key: "k6",
Value: kv.StringValue("default"),
Value: label.StringValue("default"),
},
},
},
@ -144,52 +144,52 @@ func Test_parseValue(t *testing.T) {
testCases := []struct {
name string
str string
expected kv.Value
expected label.Value
}{
{
name: "bool: true",
str: "true",
expected: kv.BoolValue(true),
expected: label.BoolValue(true),
},
{
name: "bool: false",
str: "false",
expected: kv.BoolValue(false),
expected: label.BoolValue(false),
},
{
name: "int64: 012340",
str: "012340",
expected: kv.Int64Value(12340),
expected: label.Int64Value(12340),
},
{
name: "int64: -012340",
str: "-012340",
expected: kv.Int64Value(-12340),
expected: label.Int64Value(-12340),
},
{
name: "int64: 0",
str: "0",
expected: kv.Int64Value(0),
expected: label.Int64Value(0),
},
{
name: "float64: -0.1",
str: "-0.1",
expected: kv.Float64Value(-0.1),
expected: label.Float64Value(-0.1),
},
{
name: "float64: 00.001",
str: "00.001",
expected: kv.Float64Value(0.001),
expected: label.Float64Value(0.001),
},
{
name: "float64: 1E23",
str: "1E23",
expected: kv.Float64Value(1e23),
expected: label.Float64Value(1e23),
},
{
name: "string: foo",
str: "foo",
expected: kv.StringValue("foo"),
expected: label.StringValue("foo"),
},
}
@ -408,9 +408,9 @@ func TestProcessFromEnv(t *testing.T) {
tags: "key=value,key2=123",
expectedProcess: Process{
ServiceName: "test-service",
Tags: []kv.KeyValue{
kv.String("key", "value"),
kv.Int64("key2", 123),
Tags: []label.KeyValue{
label.String("key", "value"),
label.Int64("key2", 123),
},
},
},
@ -455,16 +455,16 @@ func TestWithProcessFromEnv(t *testing.T) {
options: options{
Process: Process{
ServiceName: "old-name",
Tags: []kv.KeyValue{
kv.String("old-key", "old-value"),
Tags: []label.KeyValue{
label.String("old-key", "old-value"),
},
},
},
expectedOptions: options{
Process: Process{
ServiceName: "service-name",
Tags: []kv.KeyValue{
kv.String("key", "value"),
Tags: []label.KeyValue{
label.String("key", "value"),
},
},
},
@ -476,16 +476,16 @@ func TestWithProcessFromEnv(t *testing.T) {
options: options{
Process: Process{
ServiceName: "old-name",
Tags: []kv.KeyValue{
kv.String("old-key", "old-value"),
Tags: []label.KeyValue{
label.String("old-key", "old-value"),
},
},
},
expectedOptions: options{
Process: Process{
ServiceName: "old-name",
Tags: []kv.KeyValue{
kv.String("old-key", "old-value"),
Tags: []label.KeyValue{
label.String("old-key", "old-value"),
},
},
},

View File

@ -22,9 +22,9 @@ import (
"google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
apitrace "go.opentelemetry.io/otel/api/trace"
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
@ -189,7 +189,7 @@ type Process struct {
ServiceName string
// Tags are added to Jaeger Process exports
Tags []kv.KeyValue
Tags []label.KeyValue
}
// Exporter is an implementation of trace.SpanSyncer that uploads spans to Jaeger.
@ -291,45 +291,45 @@ func spanDataToThrift(data *export.SpanData) *gen.Span {
}
}
func keyValueToTag(keyValue kv.KeyValue) *gen.Tag {
func keyValueToTag(keyValue label.KeyValue) *gen.Tag {
var tag *gen.Tag
switch keyValue.Value.Type() {
case kv.STRING:
case label.STRING:
s := keyValue.Value.AsString()
tag = &gen.Tag{
Key: string(keyValue.Key),
VStr: &s,
VType: gen.TagType_STRING,
}
case kv.BOOL:
case label.BOOL:
b := keyValue.Value.AsBool()
tag = &gen.Tag{
Key: string(keyValue.Key),
VBool: &b,
VType: gen.TagType_BOOL,
}
case kv.INT32:
case label.INT32:
i := int64(keyValue.Value.AsInt32())
tag = &gen.Tag{
Key: string(keyValue.Key),
VLong: &i,
VType: gen.TagType_LONG,
}
case kv.INT64:
case label.INT64:
i := keyValue.Value.AsInt64()
tag = &gen.Tag{
Key: string(keyValue.Key),
VLong: &i,
VType: gen.TagType_LONG,
}
case kv.UINT32:
case label.UINT32:
i := int64(keyValue.Value.AsUint32())
tag = &gen.Tag{
Key: string(keyValue.Key),
VLong: &i,
VType: gen.TagType_LONG,
}
case kv.UINT64:
case label.UINT64:
// we'll ignore the value if it overflows
if i := int64(keyValue.Value.AsUint64()); i >= 0 {
tag = &gen.Tag{
@ -338,14 +338,14 @@ func keyValueToTag(keyValue kv.KeyValue) *gen.Tag {
VType: gen.TagType_LONG,
}
}
case kv.FLOAT32:
case label.FLOAT32:
f := float64(keyValue.Value.AsFloat32())
tag = &gen.Tag{
Key: string(keyValue.Key),
VDouble: &f,
VType: gen.TagType_DOUBLE,
}
case kv.FLOAT64:
case label.FLOAT64:
f := keyValue.Value.AsFloat64()
tag = &gen.Tag{
Key: string(keyValue.Key),

View File

@ -30,11 +30,11 @@ import (
"google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
apitrace "go.opentelemetry.io/otel/api/trace"
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger"
ottest "go.opentelemetry.io/otel/internal/testing"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
@ -205,8 +205,8 @@ func TestNewRawExporter(t *testing.T) {
WithProcess(
Process{
ServiceName: "jaeger-test",
Tags: []kv.KeyValue{
kv.String("key", "val"),
Tags: []label.KeyValue{
label.String("key", "val"),
},
},
),
@ -331,8 +331,8 @@ func TestExporter_ExportSpan(t *testing.T) {
withTestCollectorEndpoint(),
WithProcess(Process{
ServiceName: serviceName,
Tags: []kv.KeyValue{
kv.String(tagKey, tagVal),
Tags: []label.KeyValue{
label.String(tagKey, tagVal),
},
}),
)
@ -400,19 +400,19 @@ func Test_spanDataToThrift(t *testing.T) {
},
},
},
Attributes: []kv.KeyValue{
kv.String("key", keyValue),
kv.Float64("double", doubleValue),
kv.Uint64("uint", uint64(uintValue)),
kv.Uint64("overflows", math.MaxUint64),
Attributes: []label.KeyValue{
label.String("key", keyValue),
label.Float64("double", doubleValue),
label.Uint64("uint", uint64(uintValue)),
label.Uint64("overflows", math.MaxUint64),
},
MessageEvents: []export.Event{
{Name: eventNameValue, Attributes: []kv.KeyValue{kv.String("k1", keyValue)}, Time: now},
{Name: eventNameValue, Attributes: []label.KeyValue{label.String("k1", keyValue)}, Time: now},
},
StatusCode: codes.Unknown,
StatusMessage: statusMessage,
SpanKind: apitrace.SpanKindClient,
Resource: resource.New(kv.String("rk1", rv1), kv.Int64("rk2", rv2)),
Resource: resource.New(label.String("rk1", rv1), label.Int64("rk2", rv2)),
InstrumentationLibrary: instrumentation.Library{
Name: instrLibName,
Version: instrLibVersion,

View File

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

View File

@ -22,8 +22,8 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/trace"
)
@ -40,16 +40,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -73,16 +73,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -105,16 +105,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -137,16 +137,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -169,16 +169,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -201,16 +201,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -233,16 +233,16 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{
@ -265,9 +265,9 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.Uint64("attr1", 42),
kv.String("attr2", "bar"),
Attributes: []label.KeyValue{
label.Uint64("attr1", 42),
label.String("attr2", "bar"),
},
MessageEvents: nil,
StatusCode: codes.NotFound,
@ -284,15 +284,15 @@ func TestModelConversion(t *testing.T) {
Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
Attributes: []kv.KeyValue{
kv.String("error", "false"),
Attributes: []label.KeyValue{
label.String("error", "false"),
},
MessageEvents: []export.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Attributes: []kv.KeyValue{
kv.Uint64("eventattr1", 123),
Attributes: []label.KeyValue{
label.Uint64("eventattr1", 123),
},
},
{

View File

@ -21,8 +21,8 @@ import (
"sync"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
)
var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
@ -32,7 +32,7 @@ var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
// the SDK to provide support for running observer callbacks.
type AsyncCollector interface {
// CollectAsync passes a batch of observations to the MeterImpl.
CollectAsync([]kv.KeyValue, ...metric.Observation)
CollectAsync([]label.KeyValue, ...metric.Observation)
}
// AsyncInstrumentState manages an ordered set of asynchronous

View File

@ -18,23 +18,23 @@ import (
"context"
"sync"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
apimetric "go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/metric/registry"
"go.opentelemetry.io/otel/label"
)
type (
Handle struct {
Instrument *Sync
Labels []kv.KeyValue
Labels []label.KeyValue
}
Batch struct {
// Measurement needs to be aligned for 64-bit atomic operations.
Measurements []Measurement
Ctx context.Context
Labels []kv.KeyValue
Labels []label.KeyValue
LibraryName string
}
@ -87,14 +87,14 @@ func (s *Sync) Implementation() interface{} {
return s
}
func (s *Sync) Bind(labels []kv.KeyValue) apimetric.BoundSyncImpl {
func (s *Sync) Bind(labels []label.KeyValue) apimetric.BoundSyncImpl {
return &Handle{
Instrument: s,
Labels: labels,
}
}
func (s *Sync) RecordOne(ctx context.Context, number apimetric.Number, labels []kv.KeyValue) {
func (s *Sync) RecordOne(ctx context.Context, number apimetric.Number, labels []label.KeyValue) {
s.meter.doRecordSingle(ctx, labels, s, number)
}
@ -105,7 +105,7 @@ func (h *Handle) RecordOne(ctx context.Context, number apimetric.Number) {
func (h *Handle) Unbind() {
}
func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []kv.KeyValue, instrument apimetric.InstrumentImpl, number apimetric.Number) {
func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []label.KeyValue, instrument apimetric.InstrumentImpl, number apimetric.Number) {
m.collect(ctx, labels, []Measurement{{
Instrument: instrument,
Number: number,
@ -151,7 +151,7 @@ func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metr
return a, nil
}
func (m *MeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measurements ...apimetric.Measurement) {
func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...apimetric.Measurement) {
mm := make([]Measurement, len(measurements))
for i := 0; i < len(measurements); i++ {
m := measurements[i]
@ -163,7 +163,7 @@ func (m *MeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measu
m.collect(ctx, labels, mm)
}
func (m *MeterImpl) CollectAsync(labels []kv.KeyValue, obs ...metric.Observation) {
func (m *MeterImpl) CollectAsync(labels []label.KeyValue, obs ...metric.Observation) {
mm := make([]Measurement, len(obs))
for i := 0; i < len(obs); i++ {
o := obs[i]
@ -175,7 +175,7 @@ func (m *MeterImpl) CollectAsync(labels []kv.KeyValue, obs ...metric.Observation
m.collect(context.Background(), labels, mm)
}
func (m *MeterImpl) collect(ctx context.Context, labels []kv.KeyValue, measurements []Measurement) {
func (m *MeterImpl) collect(ctx context.Context, labels []label.KeyValue, measurements []Measurement) {
m.lock.Lock()
defer m.lock.Unlock()

View File

@ -18,9 +18,9 @@ import (
"context"
"time"
"go.opentelemetry.io/otel/api/kv"
apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
)
// MockSpan is a mock span used in association with MockTracer for testing purpose only.
@ -34,8 +34,8 @@ type MockSpan struct {
var _ apitrace.Span = (*MockSpan)(nil)
// SpanContext returns associated kv.SpanContext. If the receiver is nil it returns
// an empty kv.SpanContext
// SpanContext returns associated label.SpanContext. If the receiver is nil it returns
// an empty label.SpanContext
func (ms *MockSpan) SpanContext() apitrace.SpanContext {
if ms == nil {
return apitrace.EmptySpanContext()
@ -59,7 +59,7 @@ func (ms *MockSpan) SetError(v bool) {
}
// SetAttributes does nothing.
func (ms *MockSpan) SetAttributes(attributes ...kv.KeyValue) {
func (ms *MockSpan) SetAttributes(attributes ...label.KeyValue) {
}
// SetAttribute does nothing.
@ -85,9 +85,9 @@ func (ms *MockSpan) Tracer() apitrace.Tracer {
}
// AddEvent does nothing.
func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...kv.KeyValue) {
func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) {
}
// AddEvent does nothing.
func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...kv.KeyValue) {
func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) {
}

View File

@ -17,8 +17,8 @@ package parent
import (
"context"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
)
func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (trace.SpanContext, bool, []trace.Link) {
@ -46,8 +46,8 @@ func addLinkIfValid(links []trace.Link, sc trace.SpanContext, kind string) []tra
}
return append(links, trace.Link{
SpanContext: sc,
Attributes: []kv.KeyValue{
kv.String("ignored-on-demand", kind),
Attributes: []label.KeyValue{
label.String("ignored-on-demand", kind),
},
})
}

View File

@ -12,61 +12,61 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package kv_test
package label_test
import (
"testing"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
type test struct{}
var (
arrayVal = []string{"one", "two"}
arrayKeyVal = kv.Array("array", arrayVal)
arrayKeyVal = label.Array("array", arrayVal)
boolVal = true
boolKeyVal = kv.Bool("bool", boolVal)
boolKeyVal = label.Bool("bool", boolVal)
intVal = int(1)
intKeyVal = kv.Int("int", intVal)
intKeyVal = label.Int("int", intVal)
int8Val = int8(1)
int8KeyVal = kv.Int("int8", int(int8Val))
int8KeyVal = label.Int("int8", int(int8Val))
int16Val = int16(1)
int16KeyVal = kv.Int("int16", int(int16Val))
int16KeyVal = label.Int("int16", int(int16Val))
int32Val = int32(1)
int32KeyVal = kv.Int32("int32", int32Val)
int32KeyVal = label.Int32("int32", int32Val)
int64Val = int64(1)
int64KeyVal = kv.Int64("int64", int64Val)
int64KeyVal = label.Int64("int64", int64Val)
uintVal = uint(1)
uintKeyVal = kv.Uint("uint", uintVal)
uintKeyVal = label.Uint("uint", uintVal)
uint8Val = uint8(1)
uint8KeyVal = kv.Uint("uint8", uint(uint8Val))
uint8KeyVal = label.Uint("uint8", uint(uint8Val))
uint16Val = uint16(1)
uint16KeyVal = kv.Uint("uint16", uint(uint16Val))
uint16KeyVal = label.Uint("uint16", uint(uint16Val))
uint32Val = uint32(1)
uint32KeyVal = kv.Uint32("uint32", uint32Val)
uint32KeyVal = label.Uint32("uint32", uint32Val)
uint64Val = uint64(1)
uint64KeyVal = kv.Uint64("uint64", uint64Val)
uint64KeyVal = label.Uint64("uint64", uint64Val)
float32Val = float32(1.0)
float32KeyVal = kv.Float32("float32", float32Val)
float32KeyVal = label.Float32("float32", float32Val)
float64Val = float64(1.0)
float64KeyVal = kv.Float64("float64", float64Val)
float64KeyVal = label.Float64("float64", float64Val)
stringVal = "string"
stringKeyVal = kv.String("string", stringVal)
stringKeyVal = label.String("string", stringVal)
bytesVal = []byte("bytes")
structVal = test{}
@ -75,196 +75,196 @@ var (
func BenchmarkArrayKey(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Array("array", arrayVal)
_ = label.Array("array", arrayVal)
}
}
func BenchmarkArrayKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("array", arrayVal)
_ = label.Any("array", arrayVal)
}
}
func BenchmarkBoolKey(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Bool("bool", boolVal)
_ = label.Bool("bool", boolVal)
}
}
func BenchmarkBoolKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("bool", boolVal)
_ = label.Any("bool", boolVal)
}
}
func BenchmarkIntKey(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Int("int", intVal)
_ = label.Int("int", intVal)
}
}
func BenchmarkIntKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("int", intVal)
_ = label.Any("int", intVal)
}
}
func BenchmarkInt8KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("int8", int8Val)
_ = label.Any("int8", int8Val)
}
}
func BenchmarkInt16KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("int16", int16Val)
_ = label.Any("int16", int16Val)
}
}
func BenchmarkInt32Key(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Int32("int32", int32Val)
_ = label.Int32("int32", int32Val)
}
}
func BenchmarkInt32KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("int32", int32Val)
_ = label.Any("int32", int32Val)
}
}
func BenchmarkInt64Key(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Int64("int64", int64Val)
_ = label.Int64("int64", int64Val)
}
}
func BenchmarkInt64KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("int64", int64Val)
_ = label.Any("int64", int64Val)
}
}
func BenchmarkUintKey(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Uint("uint", uintVal)
_ = label.Uint("uint", uintVal)
}
}
func BenchmarkUintKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("uint", uintVal)
_ = label.Any("uint", uintVal)
}
}
func BenchmarkUint8KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("uint8", uint8Val)
_ = label.Any("uint8", uint8Val)
}
}
func BenchmarkUint16KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("uint16", uint16Val)
_ = label.Any("uint16", uint16Val)
}
}
func BenchmarkUint32Key(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Uint32("uint32", uint32Val)
_ = label.Uint32("uint32", uint32Val)
}
}
func BenchmarkUint32KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("uint32", uint32Val)
_ = label.Any("uint32", uint32Val)
}
}
func BenchmarkUint64Key(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Uint64("uint64", uint64Val)
_ = label.Uint64("uint64", uint64Val)
}
}
func BenchmarkUint64KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("uint64", uint64Val)
_ = label.Any("uint64", uint64Val)
}
}
func BenchmarkFloat32Key(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Float32("float32", float32Val)
_ = label.Float32("float32", float32Val)
}
}
func BenchmarkFloat32KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("float32", float32Val)
_ = label.Any("float32", float32Val)
}
}
func BenchmarkFloat64Key(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Float64("float64", float64Val)
_ = label.Float64("float64", float64Val)
}
}
func BenchmarkFloat64KeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("float64", float64Val)
_ = label.Any("float64", float64Val)
}
}
func BenchmarkStringKey(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.String("string", stringVal)
_ = label.String("string", stringVal)
}
}
func BenchmarkStringKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("string", stringVal)
_ = label.Any("string", stringVal)
}
}
func BenchmarkBytesKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("bytes", bytesVal)
_ = label.Any("bytes", bytesVal)
}
}
func BenchmarkStructKeyAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = kv.Any("struct", structVal)
_ = label.Any("struct", structVal)
}
}

View File

@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// package kv provides basic key and value types.
package kv // import "go.opentelemetry.io/otel/api/kv"
// Package label provides key and value labels.
package label // import "go.opentelemetry.io/otel/label"

View File

@ -18,8 +18,6 @@ import (
"bytes"
"sync"
"sync/atomic"
"go.opentelemetry.io/otel/api/kv"
)
type (
@ -119,7 +117,7 @@ func (d *defaultLabelEncoder) Encode(iter Iterator) string {
_, _ = buf.WriteRune('=')
if keyValue.Value.Type() == kv.STRING {
if keyValue.Value.Type() == STRING {
copyAndEscape(buf, keyValue.Value.AsString())
} else {
_, _ = buf.WriteString(keyValue.Value.Emit())

View File

@ -14,10 +14,6 @@
package label
import (
"go.opentelemetry.io/otel/api/kv"
)
// Iterator allows iterating over the set of labels in order,
// sorted by key.
type Iterator struct {
@ -31,13 +27,13 @@ type Iterator struct {
type MergeItererator struct {
one oneIterator
two oneIterator
current kv.KeyValue
current KeyValue
}
type oneIterator struct {
iter Iterator
done bool
label kv.KeyValue
label KeyValue
}
// Next moves the iterator to the next position. Returns false if there
@ -47,21 +43,21 @@ func (i *Iterator) Next() bool {
return i.idx < i.Len()
}
// Label returns current kv.KeyValue. Must be called only after Next returns
// Label returns current KeyValue. Must be called only after Next returns
// true.
func (i *Iterator) Label() kv.KeyValue {
func (i *Iterator) Label() KeyValue {
kv, _ := i.storage.Get(i.idx)
return kv
}
// Attribute is a synonym for Label().
func (i *Iterator) Attribute() kv.KeyValue {
func (i *Iterator) Attribute() KeyValue {
return i.Label()
}
// IndexedLabel returns current index and label. Must be called only
// after Next returns true.
func (i *Iterator) IndexedLabel() (int, kv.KeyValue) {
func (i *Iterator) IndexedLabel() (int, KeyValue) {
return i.idx, i.Label()
}
@ -73,13 +69,13 @@ func (i *Iterator) Len() int {
// ToSlice is a convenience function that creates a slice of labels
// from the passed iterator. The iterator is set up to start from the
// beginning before creating the slice.
func (i *Iterator) ToSlice() []kv.KeyValue {
func (i *Iterator) ToSlice() []KeyValue {
l := i.Len()
if l == 0 {
return nil
}
i.idx = -1
slice := make([]kv.KeyValue, 0, l)
slice := make([]KeyValue, 0, l)
for i.Next() {
slice = append(slice, i.Label())
}
@ -142,6 +138,6 @@ func (m *MergeItererator) Next() bool {
}
// Label returns the current value after Next() returns true.
func (m *MergeItererator) Label() kv.KeyValue {
func (m *MergeItererator) Label() KeyValue {
return m.current
}

View File

@ -18,16 +18,14 @@ import (
"fmt"
"testing"
"go.opentelemetry.io/otel/api/kv"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/label"
)
func TestIterator(t *testing.T) {
one := kv.String("one", "1")
two := kv.Int("two", 2)
one := label.String("one", "1")
two := label.Int("two", 2)
lbl := label.NewSet(one, two)
iter := lbl.Iter()
require.Equal(t, 2, iter.Len())
@ -66,9 +64,9 @@ func TestMergedIterator(t *testing.T) {
expect []string
}
makeLabels := func(keys []string, num int) (result []kv.KeyValue) {
makeLabels := func(keys []string, num int) (result []label.KeyValue) {
for _, k := range keys {
result = append(result, kv.Int(k, num))
result = append(result, label.Int(k, num))
}
return
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package kv
package label
// Key represents the key part in key-value pairs. It's a string. The
// allowed character set in the key depends on the use of the key.
@ -21,7 +21,7 @@ type Key string
// Bool creates a KeyValue instance with a BOOL Value.
//
// If creating both key and a bool value at the same time, then
// instead of calling kv.Key(name).Bool(value) consider using a
// instead of calling Key(name).Bool(value) consider using a
// convenience function provided by the api/key package -
// key.Bool(name, value).
func (k Key) Bool(v bool) KeyValue {
@ -34,7 +34,7 @@ func (k Key) Bool(v bool) KeyValue {
// Int64 creates a KeyValue instance with an INT64 Value.
//
// If creating both key and an int64 value at the same time, then
// instead of calling kv.Key(name).Int64(value) consider using a
// instead of calling Key(name).Int64(value) consider using a
// convenience function provided by the api/key package -
// key.Int64(name, value).
func (k Key) Int64(v int64) KeyValue {
@ -47,7 +47,7 @@ func (k Key) Int64(v int64) KeyValue {
// Uint64 creates a KeyValue instance with a UINT64 Value.
//
// If creating both key and a uint64 value at the same time, then
// instead of calling kv.Key(name).Uint64(value) consider using a
// instead of calling Key(name).Uint64(value) consider using a
// convenience function provided by the api/key package -
// key.Uint64(name, value).
func (k Key) Uint64(v uint64) KeyValue {
@ -60,7 +60,7 @@ func (k Key) Uint64(v uint64) KeyValue {
// Float64 creates a KeyValue instance with a FLOAT64 Value.
//
// If creating both key and a float64 value at the same time, then
// instead of calling kv.Key(name).Float64(value) consider using a
// instead of calling Key(name).Float64(value) consider using a
// convenience function provided by the api/key package -
// key.Float64(name, value).
func (k Key) Float64(v float64) KeyValue {
@ -73,7 +73,7 @@ func (k Key) Float64(v float64) KeyValue {
// Int32 creates a KeyValue instance with an INT32 Value.
//
// If creating both key and an int32 value at the same time, then
// instead of calling kv.Key(name).Int32(value) consider using a
// instead of calling Key(name).Int32(value) consider using a
// convenience function provided by the api/key package -
// key.Int32(name, value).
func (k Key) Int32(v int32) KeyValue {
@ -86,7 +86,7 @@ func (k Key) Int32(v int32) KeyValue {
// Uint32 creates a KeyValue instance with a UINT32 Value.
//
// If creating both key and a uint32 value at the same time, then
// instead of calling kv.Key(name).Uint32(value) consider using a
// instead of calling Key(name).Uint32(value) consider using a
// convenience function provided by the api/key package -
// key.Uint32(name, value).
func (k Key) Uint32(v uint32) KeyValue {
@ -99,7 +99,7 @@ func (k Key) Uint32(v uint32) KeyValue {
// Float32 creates a KeyValue instance with a FLOAT32 Value.
//
// If creating both key and a float32 value at the same time, then
// instead of calling kv.Key(name).Float32(value) consider using a
// instead of calling Key(name).Float32(value) consider using a
// convenience function provided by the api/key package -
// key.Float32(name, value).
func (k Key) Float32(v float32) KeyValue {
@ -112,7 +112,7 @@ func (k Key) Float32(v float32) KeyValue {
// String creates a KeyValue instance with a STRING Value.
//
// If creating both key and a string value at the same time, then
// instead of calling kv.Key(name).String(value) consider using a
// instead of calling Key(name).String(value) consider using a
// convenience function provided by the api/key package -
// key.String(name, value).
func (k Key) String(v string) KeyValue {
@ -126,7 +126,7 @@ func (k Key) String(v string) KeyValue {
// Value, depending on whether the int type is 32 or 64 bits wide.
//
// If creating both key and an int value at the same time, then
// instead of calling kv.Key(name).Int(value) consider using a
// instead of calling Key(name).Int(value) consider using a
// convenience function provided by the api/key package -
// key.Int(name, value).
func (k Key) Int(v int) KeyValue {
@ -140,7 +140,7 @@ func (k Key) Int(v int) KeyValue {
// Value, depending on whether the uint type is 32 or 64 bits wide.
//
// If creating both key and a uint value at the same time, then
// instead of calling kv.Key(name).Uint(value) consider using a
// instead of calling Key(name).Uint(value) consider using a
// convenience function provided by the api/key package -
// key.Uint(name, value).
func (k Key) Uint(v uint) KeyValue {
@ -158,7 +158,7 @@ func (k Key) Defined() bool {
// Array creates a KeyValue instance with a ARRAY Value.
//
// If creating both key and a array value at the same time, then
// instead of calling kv.Key(name).String(value) consider using a
// instead of calling Key(name).String(value) consider using a
// convenience function provided by the api/key package -
// key.Array(name, value).
func (k Key) Array(v interface{}) KeyValue {

View File

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

View File

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

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package kv_test
package label_test
import (
"strings"
@ -20,100 +20,100 @@ import (
"github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
func TestKeyValueConstructors(t *testing.T) {
tt := []struct {
name string
actual kv.KeyValue
expected kv.KeyValue
actual label.KeyValue
expected label.KeyValue
}{
{
name: "Bool",
actual: kv.Bool("k1", true),
expected: kv.KeyValue{
actual: label.Bool("k1", true),
expected: label.KeyValue{
Key: "k1",
Value: kv.BoolValue(true),
Value: label.BoolValue(true),
},
},
{
name: "Int64",
actual: kv.Int64("k1", 123),
expected: kv.KeyValue{
actual: label.Int64("k1", 123),
expected: label.KeyValue{
Key: "k1",
Value: kv.Int64Value(123),
Value: label.Int64Value(123),
},
},
{
name: "Uint64",
actual: kv.Uint64("k1", 1),
expected: kv.KeyValue{
actual: label.Uint64("k1", 1),
expected: label.KeyValue{
Key: "k1",
Value: kv.Uint64Value(1),
Value: label.Uint64Value(1),
},
},
{
name: "Float64",
actual: kv.Float64("k1", 123.5),
expected: kv.KeyValue{
actual: label.Float64("k1", 123.5),
expected: label.KeyValue{
Key: "k1",
Value: kv.Float64Value(123.5),
Value: label.Float64Value(123.5),
},
},
{
name: "Int32",
actual: kv.Int32("k1", 123),
expected: kv.KeyValue{
actual: label.Int32("k1", 123),
expected: label.KeyValue{
Key: "k1",
Value: kv.Int32Value(123),
Value: label.Int32Value(123),
},
},
{
name: "Uint32",
actual: kv.Uint32("k1", 123),
expected: kv.KeyValue{
actual: label.Uint32("k1", 123),
expected: label.KeyValue{
Key: "k1",
Value: kv.Uint32Value(123),
Value: label.Uint32Value(123),
},
},
{
name: "Float32",
actual: kv.Float32("k1", 123.5),
expected: kv.KeyValue{
actual: label.Float32("k1", 123.5),
expected: label.KeyValue{
Key: "k1",
Value: kv.Float32Value(123.5),
Value: label.Float32Value(123.5),
},
},
{
name: "String",
actual: kv.String("k1", "123.5"),
expected: kv.KeyValue{
actual: label.String("k1", "123.5"),
expected: label.KeyValue{
Key: "k1",
Value: kv.StringValue("123.5"),
Value: label.StringValue("123.5"),
},
},
{
name: "Int",
actual: kv.Int("k1", 123),
expected: kv.KeyValue{
actual: label.Int("k1", 123),
expected: label.KeyValue{
Key: "k1",
Value: kv.IntValue(123),
Value: label.IntValue(123),
},
},
{
name: "Uint",
actual: kv.Uint("k1", 123),
expected: kv.KeyValue{
actual: label.Uint("k1", 123),
expected: label.KeyValue{
Key: "k1",
Value: kv.UintValue(123),
Value: label.UintValue(123),
},
},
}
for _, test := range tt {
t.Run(test.name, func(t *testing.T) {
if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(kv.Value{})); diff != "" {
if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(label.Value{})); diff != "" {
t.Fatal(diff)
}
})
@ -137,84 +137,84 @@ func TestAny(t *testing.T) {
for _, testcase := range []struct {
key string
value interface{}
wantType kv.Type
wantType label.Type
wantValue interface{}
}{
{
key: "bool type inferred",
value: true,
wantType: kv.BOOL,
wantType: label.BOOL,
wantValue: true,
},
{
key: "int64 type inferred",
value: int64(42),
wantType: kv.INT64,
wantType: label.INT64,
wantValue: int64(42),
},
{
key: "uint64 type inferred",
value: uint64(42),
wantType: kv.UINT64,
wantType: label.UINT64,
wantValue: uint64(42),
},
{
key: "float64 type inferred",
value: float64(42.1),
wantType: kv.FLOAT64,
wantType: label.FLOAT64,
wantValue: 42.1,
},
{
key: "int32 type inferred",
value: int32(42),
wantType: kv.INT32,
wantType: label.INT32,
wantValue: int32(42),
},
{
key: "uint32 type inferred",
value: uint32(42),
wantType: kv.UINT32,
wantType: label.UINT32,
wantValue: uint32(42),
},
{
key: "float32 type inferred",
value: float32(42.1),
wantType: kv.FLOAT32,
wantType: label.FLOAT32,
wantValue: float32(42.1),
},
{
key: "string type inferred",
value: "foo",
wantType: kv.STRING,
wantType: label.STRING,
wantValue: "foo",
},
{
key: "stringer type inferred",
value: builder,
wantType: kv.STRING,
wantType: label.STRING,
wantValue: "foo",
},
{
key: "unknown value serialized as %v",
value: nil,
wantType: kv.STRING,
wantType: label.STRING,
wantValue: "<nil>",
},
{
key: "JSON struct serialized correctly",
value: &jsonifyStruct,
wantType: kv.STRING,
wantType: label.STRING,
wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`,
},
{
key: "Invalid JSON struct falls back to string",
value: &invalidStruct,
wantType: kv.STRING,
wantType: label.STRING,
wantValue: "&{(0+0i)}",
},
} {
t.Logf("Running test case %s", testcase.key)
keyValue := kv.Any(testcase.key, testcase.value)
keyValue := label.Any(testcase.key, testcase.value)
if keyValue.Value.Type() != testcase.wantType {
t.Errorf("wrong value type, got %#v, expected %#v", keyValue.Value.Type(), testcase.wantType)
}

View File

@ -12,15 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package label // import "go.opentelemetry.io/otel/api/label"
package label
import (
"encoding/json"
"reflect"
"sort"
"sync"
"go.opentelemetry.io/otel/api/kv"
)
type (
@ -43,7 +41,7 @@ type (
encoded [maxConcurrentEncoders]string
}
// Distinct wraps a variable-size array of `kv.KeyValue`,
// Distinct wraps a variable-size array of `KeyValue`,
// constructed with keys in sorted order. This can be used as
// a map key or for equality checking between Sets.
Distinct struct {
@ -55,25 +53,25 @@ type (
// the filtered label set. When the filter returns false, the
// label is excluded from the filtered label set, and the
// label instead appears in the `removed` list of excluded labels.
Filter func(kv.KeyValue) bool
Filter func(KeyValue) bool
// Sortable implements `sort.Interface`, used for sorting
// `kv.KeyValue`. This is an exported type to support a
// `KeyValue`. This is an exported type to support a
// memory optimization. A pointer to one of these is needed
// for the call to `sort.Stable()`, which the caller may
// provide in order to avoid an allocation. See
// `NewSetWithSortable()`.
Sortable []kv.KeyValue
Sortable []KeyValue
)
var (
// keyValueType is used in `computeDistinctReflect`.
keyValueType = reflect.TypeOf(kv.KeyValue{})
keyValueType = reflect.TypeOf(KeyValue{})
// emptySet is returned for empty label sets.
emptySet = &Set{
equivalent: Distinct{
iface: [0]kv.KeyValue{},
iface: [0]KeyValue{},
},
}
)
@ -103,44 +101,44 @@ func (l *Set) Len() int {
}
// Get returns the KeyValue at ordered position `idx` in this set.
func (l *Set) Get(idx int) (kv.KeyValue, bool) {
func (l *Set) Get(idx int) (KeyValue, bool) {
if l == nil {
return kv.KeyValue{}, false
return KeyValue{}, false
}
value := l.equivalent.reflect()
if idx >= 0 && idx < value.Len() {
// Note: The Go compiler successfully avoids an allocation for
// the interface{} conversion here:
return value.Index(idx).Interface().(kv.KeyValue), true
return value.Index(idx).Interface().(KeyValue), true
}
return kv.KeyValue{}, false
return KeyValue{}, false
}
// Value returns the value of a specified key in this set.
func (l *Set) Value(k kv.Key) (kv.Value, bool) {
func (l *Set) Value(k Key) (Value, bool) {
if l == nil {
return kv.Value{}, false
return Value{}, false
}
rValue := l.equivalent.reflect()
vlen := rValue.Len()
idx := sort.Search(vlen, func(idx int) bool {
return rValue.Index(idx).Interface().(kv.KeyValue).Key >= k
return rValue.Index(idx).Interface().(KeyValue).Key >= k
})
if idx >= vlen {
return kv.Value{}, false
return Value{}, false
}
keyValue := rValue.Index(idx).Interface().(kv.KeyValue)
keyValue := rValue.Index(idx).Interface().(KeyValue)
if k == keyValue.Key {
return keyValue.Value, true
}
return kv.Value{}, false
return Value{}, false
}
// HasValue tests whether a key is defined in this set.
func (l *Set) HasValue(k kv.Key) bool {
func (l *Set) HasValue(k Key) bool {
if l == nil {
return false
}
@ -158,7 +156,7 @@ func (l *Set) Iter() Iterator {
// ToSlice returns the set of labels belonging to this set, sorted,
// where keys appear no more than once.
func (l *Set) ToSlice() []kv.KeyValue {
func (l *Set) ToSlice() []KeyValue {
iter := l.Iter()
return iter.ToSlice()
}
@ -239,7 +237,7 @@ func empty() Set {
//
// Except for empty sets, this method adds an additional allocation
// compared with calls that include a `*Sortable`.
func NewSet(kvs ...kv.KeyValue) Set {
func NewSet(kvs ...KeyValue) Set {
// Check for empty set.
if len(kvs) == 0 {
return empty()
@ -252,7 +250,7 @@ func NewSet(kvs ...kv.KeyValue) Set {
// `NewSetWithSortableFiltered` for more details.
//
// This call includes a `*Sortable` option as a memory optimization.
func NewSetWithSortable(kvs []kv.KeyValue, tmp *Sortable) Set {
func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set {
// Check for empty set.
if len(kvs) == 0 {
return empty()
@ -267,7 +265,7 @@ func NewSetWithSortable(kvs []kv.KeyValue, tmp *Sortable) Set {
// This call includes a `Filter` to include/exclude label keys from
// the return value. Excluded keys are returned as a slice of label
// values.
func NewSetWithFiltered(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) {
func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
// Check for empty set.
if len(kvs) == 0 {
return empty(), nil
@ -297,9 +295,9 @@ func NewSetWithFiltered(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) {
// The result maintains a cache of encoded labels, by label.EncoderID.
// This value should not be copied after its first use.
//
// The second `[]kv.KeyValue` return value is a list of labels that were
// The second `[]KeyValue` return value is a list of labels that were
// excluded by the Filter (if non-nil).
func NewSetWithSortableFiltered(kvs []kv.KeyValue, tmp *Sortable, filter Filter) (Set, []kv.KeyValue) {
func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (Set, []KeyValue) {
// Check for empty set.
if len(kvs) == 0 {
return empty(), nil
@ -339,8 +337,8 @@ func NewSetWithSortableFiltered(kvs []kv.KeyValue, tmp *Sortable, filter Filter)
// filterSet reorders `kvs` so that included keys are contiguous at
// the end of the slice, while excluded keys precede the included keys.
func filterSet(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) {
var excluded []kv.KeyValue
func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
var excluded []KeyValue
// Move labels that do not match the filter so
// they're adjacent before calling computeDistinct().
@ -365,7 +363,7 @@ func filterSet(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) {
// Filter returns a filtered copy of this `Set`. See the
// documentation for `NewSetWithSortableFiltered` for more details.
func (l *Set) Filter(re Filter) (Set, []kv.KeyValue) {
func (l *Set) Filter(re Filter) (Set, []KeyValue) {
if re == nil {
return Set{
equivalent: l.equivalent,
@ -380,7 +378,7 @@ func (l *Set) Filter(re Filter) (Set, []kv.KeyValue) {
// computeDistinct returns a `Distinct` using either the fixed- or
// reflect-oriented code path, depending on the size of the input.
// The input slice is assumed to already be sorted and de-duplicated.
func computeDistinct(kvs []kv.KeyValue) Distinct {
func computeDistinct(kvs []KeyValue) Distinct {
iface := computeDistinctFixed(kvs)
if iface == nil {
iface = computeDistinctReflect(kvs)
@ -392,46 +390,46 @@ func computeDistinct(kvs []kv.KeyValue) Distinct {
// computeDistinctFixed computes a `Distinct` for small slices. It
// returns nil if the input is too large for this code path.
func computeDistinctFixed(kvs []kv.KeyValue) interface{} {
func computeDistinctFixed(kvs []KeyValue) interface{} {
switch len(kvs) {
case 1:
ptr := new([1]kv.KeyValue)
ptr := new([1]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 2:
ptr := new([2]kv.KeyValue)
ptr := new([2]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 3:
ptr := new([3]kv.KeyValue)
ptr := new([3]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 4:
ptr := new([4]kv.KeyValue)
ptr := new([4]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 5:
ptr := new([5]kv.KeyValue)
ptr := new([5]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 6:
ptr := new([6]kv.KeyValue)
ptr := new([6]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 7:
ptr := new([7]kv.KeyValue)
ptr := new([7]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 8:
ptr := new([8]kv.KeyValue)
ptr := new([8]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 9:
ptr := new([9]kv.KeyValue)
ptr := new([9]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
case 10:
ptr := new([10]kv.KeyValue)
ptr := new([10]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
default:
@ -441,10 +439,10 @@ func computeDistinctFixed(kvs []kv.KeyValue) interface{} {
// computeDistinctReflect computes a `Distinct` using reflection,
// works for any size input.
func computeDistinctReflect(kvs []kv.KeyValue) interface{} {
func computeDistinctReflect(kvs []KeyValue) interface{} {
at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem()
for i, keyValue := range kvs {
*(at.Index(i).Addr().Interface().(*kv.KeyValue)) = keyValue
*(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue
}
return at.Interface()
}

View File

@ -18,14 +18,13 @@ import (
"regexp"
"testing"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/label"
"github.com/stretchr/testify/require"
)
type testCase struct {
kvs []kv.KeyValue
kvs []label.KeyValue
keyRe *regexp.Regexp
@ -33,14 +32,14 @@ type testCase struct {
fullEnc string
}
func expect(enc string, kvs ...kv.KeyValue) testCase {
func expect(enc string, kvs ...label.KeyValue) testCase {
return testCase{
kvs: kvs,
encoding: enc,
}
}
func expectFiltered(enc, filter, fullEnc string, kvs ...kv.KeyValue) testCase {
func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase {
return testCase{
kvs: kvs,
keyRe: regexp.MustCompile(filter),
@ -51,16 +50,16 @@ func expectFiltered(enc, filter, fullEnc string, kvs ...kv.KeyValue) testCase {
func TestSetDedup(t *testing.T) {
cases := []testCase{
expect("A=B", kv.String("A", "2"), kv.String("A", "B")),
expect("A=B", kv.String("A", "2"), kv.Int("A", 1), kv.String("A", "B")),
expect("A=B", kv.String("A", "B"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B")),
expect("A=B", label.String("A", "2"), label.String("A", "B")),
expect("A=B", label.String("A", "2"), label.Int("A", 1), label.String("A", "B")),
expect("A=B", label.String("A", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B")),
expect("A=B,C=D", kv.String("A", "1"), kv.String("C", "D"), kv.String("A", "B")),
expect("A=B,C=D", kv.String("A", "2"), kv.String("A", "B"), kv.String("C", "D")),
expect("A=B,C=D", kv.Float64("C", 1.2), kv.String("A", "2"), kv.String("A", "B"), kv.String("C", "D")),
expect("A=B,C=D", kv.String("C", "D"), kv.String("A", "B"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B")),
expect("A=B,C=D", kv.String("A", "B"), kv.String("C", "D"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B")),
expect("A=B,C=D", kv.String("A", "B"), kv.String("A", "C"), kv.String("A", "D"), kv.String("A", "B"), kv.String("C", "D")),
expect("A=B,C=D", label.String("A", "1"), label.String("C", "D"), label.String("A", "B")),
expect("A=B,C=D", label.String("A", "2"), label.String("A", "B"), label.String("C", "D")),
expect("A=B,C=D", label.Float64("C", 1.2), label.String("A", "2"), label.String("A", "B"), label.String("C", "D")),
expect("A=B,C=D", label.String("C", "D"), label.String("A", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B")),
expect("A=B,C=D", label.String("A", "B"), label.String("C", "D"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B")),
expect("A=B,C=D", label.String("A", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B"), label.String("C", "D")),
}
enc := label.DefaultEncoder()
@ -68,7 +67,7 @@ func TestSetDedup(t *testing.T) {
d2s := map[label.Distinct][]string{}
for _, tc := range cases {
cpy := make([]kv.KeyValue, len(tc.kvs))
cpy := make([]label.KeyValue, len(tc.kvs))
copy(cpy, tc.kvs)
sl := label.NewSet(cpy...)
@ -130,19 +129,19 @@ func TestSetDedup(t *testing.T) {
}
func TestUniqueness(t *testing.T) {
short := []kv.KeyValue{
kv.String("A", "0"),
kv.String("B", "2"),
kv.String("A", "1"),
short := []label.KeyValue{
label.String("A", "0"),
label.String("B", "2"),
label.String("A", "1"),
}
long := []kv.KeyValue{
kv.String("B", "2"),
kv.String("C", "5"),
kv.String("B", "2"),
kv.String("C", "1"),
kv.String("A", "4"),
kv.String("C", "3"),
kv.String("A", "1"),
long := []label.KeyValue{
label.String("B", "2"),
label.String("C", "5"),
label.String("B", "2"),
label.String("C", "1"),
label.String("A", "4"),
label.String("C", "3"),
label.String("A", "1"),
}
cases := []testCase{
expectFiltered("A=1", "^A$", "B=2", short...),
@ -158,9 +157,9 @@ func TestUniqueness(t *testing.T) {
enc := label.DefaultEncoder()
for _, tc := range cases {
cpy := make([]kv.KeyValue, len(tc.kvs))
cpy := make([]label.KeyValue, len(tc.kvs))
copy(cpy, tc.kvs)
distinct, uniq := label.NewSetWithFiltered(cpy, func(label kv.KeyValue) bool {
distinct, uniq := label.NewSetWithFiltered(cpy, func(label label.KeyValue) bool {
return tc.keyRe.MatchString(string(label.Key))
})
@ -172,7 +171,7 @@ func TestUniqueness(t *testing.T) {
}
func TestLookup(t *testing.T) {
set := label.NewSet(kv.Int("C", 3), kv.Int("A", 1), kv.Int("B", 2))
set := label.NewSet(label.Int("C", 3), label.Int("A", 1), label.Int("B", 2))
value, has := set.Value("C")
require.True(t, has)

View File

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

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package kv
package label
import (
"encoding/json"
@ -22,7 +22,7 @@ import (
"strings"
"unsafe"
"go.opentelemetry.io/otel/api/internal"
"go.opentelemetry.io/otel/internal"
)
//go:generate stringer -type=Type

View File

@ -12,78 +12,78 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package kv_test
package label_test
import (
"testing"
"unsafe"
"go.opentelemetry.io/otel/api/kv"
"github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/label"
)
func TestValue(t *testing.T) {
k := kv.Key("test")
k := label.Key("test")
bli := getBitlessInfo(42)
for _, testcase := range []struct {
name string
value kv.Value
wantType kv.Type
value label.Value
wantType label.Type
wantValue interface{}
}{
{
name: "Key.Bool() correctly returns keys's internal bool value",
value: k.Bool(true).Value,
wantType: kv.BOOL,
wantType: label.BOOL,
wantValue: true,
},
{
name: "Key.Array([]bool) correctly return key's internal bool values",
value: k.Array([]bool{true, false}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []bool{true, false},
},
{
name: "Key.Int64() correctly returns keys's internal int64 value",
value: k.Int64(42).Value,
wantType: kv.INT64,
wantType: label.INT64,
wantValue: int64(42),
},
{
name: "Key.Uint64() correctly returns keys's internal uint64 value",
value: k.Uint64(42).Value,
wantType: kv.UINT64,
wantType: label.UINT64,
wantValue: uint64(42),
},
{
name: "Key.Float64() correctly returns keys's internal float64 value",
value: k.Float64(42.1).Value,
wantType: kv.FLOAT64,
wantType: label.FLOAT64,
wantValue: 42.1,
},
{
name: "Key.Int32() correctly returns keys's internal int32 value",
value: k.Int32(42).Value,
wantType: kv.INT32,
wantType: label.INT32,
wantValue: int32(42),
},
{
name: "Key.Uint32() correctly returns keys's internal uint32 value",
value: k.Uint32(42).Value,
wantType: kv.UINT32,
wantType: label.UINT32,
wantValue: uint32(42),
},
{
name: "Key.Float32() correctly returns keys's internal float32 value",
value: k.Float32(42.1).Value,
wantType: kv.FLOAT32,
wantType: label.FLOAT32,
wantValue: float32(42.1),
},
{
name: "Key.String() correctly returns keys's internal string value",
value: k.String("foo").Value,
wantType: kv.STRING,
wantType: label.STRING,
wantValue: "foo",
},
{
@ -101,61 +101,61 @@ func TestValue(t *testing.T) {
{
name: "Key.Array([]int64) correctly returns keys's internal int64 values",
value: k.Array([]int64{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []int64{42, 43},
},
{
name: "KeyArray([]uint64) correctly returns keys's internal uint64 values",
value: k.Array([]uint64{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []uint64{42, 43},
},
{
name: "Key.Array([]float64) correctly returns keys's internal float64 values",
value: k.Array([]float64{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []float64{42, 43},
},
{
name: "Key.Array([]int32) correctly returns keys's internal int32 values",
value: k.Array([]int32{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []int32{42, 43},
},
{
name: "Key.Array([]uint32) correctly returns keys's internal uint32 values",
value: k.Array([]uint32{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []uint32{42, 43},
},
{
name: "Key.Array([]float32) correctly returns keys's internal float32 values",
value: k.Array([]float32{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []float32{42, 43},
},
{
name: "Key.Array([]string) correctly return key's internal string values",
value: k.Array([]string{"foo", "bar"}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []string{"foo", "bar"},
},
{
name: "Key.Array([]int) correctly returns keys's internal signed integral values",
value: k.Array([]int{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []int{42, 43},
},
{
name: "Key.Array([]uint) correctly returns keys's internal unsigned integral values",
value: k.Array([]uint{42, 43}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: []uint{42, 43},
},
{
name: "Key.Array([][]int) correctly return key's multi dimensional array",
value: k.Array([][]int{{1, 2}, {3, 4}}).Value,
wantType: kv.ARRAY,
wantType: label.ARRAY,
wantValue: [][]int{{1, 2}, {3, 4}},
},
} {
@ -173,8 +173,8 @@ func TestValue(t *testing.T) {
type bitlessInfo struct {
intValue int
uintValue uint
signedType kv.Type
unsignedType kv.Type
signedType label.Type
unsignedType label.Type
signedValue interface{}
unsignedValue interface{}
}
@ -184,8 +184,8 @@ func getBitlessInfo(i int) bitlessInfo {
return bitlessInfo{
intValue: i,
uintValue: uint(i),
signedType: kv.INT32,
unsignedType: kv.UINT32,
signedType: label.INT32,
unsignedType: label.UINT32,
signedValue: int32(i),
unsignedValue: uint32(i),
}
@ -193,8 +193,8 @@ func getBitlessInfo(i int) bitlessInfo {
return bitlessInfo{
intValue: i,
uintValue: uint(i),
signedType: kv.INT64,
unsignedType: kv.UINT64,
signedType: label.INT64,
unsignedType: label.UINT64,
signedValue: int64(i),
unsignedValue: uint64(i),
}

View File

@ -21,8 +21,8 @@ import (
"sync"
"time"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/resource"
)

View File

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

View File

@ -21,9 +21,8 @@ import (
"sync"
"time"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/resource"
@ -92,7 +91,7 @@ func (p *CheckpointSet) Reset() {
//
// If there is an existing record with the same descriptor and labels,
// the stored aggregator will be returned and should be merged.
func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...kv.KeyValue) (agg export.Aggregator, added bool) {
func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...label.KeyValue) (agg export.Aggregator, added bool) {
elabels := label.NewSet(labels...)
key := mapkey{

View File

@ -20,8 +20,8 @@ import (
"google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/kv"
apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
)
@ -57,7 +57,7 @@ type SpanData struct {
// The wall clock time of EndTime will be adjusted to always be offset
// from StartTime by the duration of the span.
EndTime time.Time
Attributes []kv.KeyValue
Attributes []label.KeyValue
MessageEvents []Event
Links []apitrace.Link
StatusCode codes.Code
@ -84,8 +84,8 @@ type Event struct {
// Name is the name of this event
Name string
// Attributes contains a list of kv pairs.
Attributes []kv.KeyValue
// Attributes contains a list of key-value pairs.
Attributes []label.KeyValue
// Time is the time at which this event was recorded.
Time time.Time

View File

@ -21,9 +21,8 @@ import (
"testing"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
sdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/processor/processortest"
@ -60,8 +59,8 @@ func (f *benchFixture) meterMust() metric.MeterMust {
return metric.Must(f.meter)
}
func makeManyLabels(n int) [][]kv.KeyValue {
r := make([][]kv.KeyValue, n)
func makeManyLabels(n int) [][]label.KeyValue {
r := make([][]label.KeyValue, n)
for i := 0; i < n; i++ {
r[i] = makeLabels(1)
@ -70,9 +69,9 @@ func makeManyLabels(n int) [][]kv.KeyValue {
return r
}
func makeLabels(n int) []kv.KeyValue {
func makeLabels(n int) []label.KeyValue {
used := map[string]bool{}
l := make([]kv.KeyValue, n)
l := make([]label.KeyValue, n)
for i := 0; i < n; i++ {
var k string
for {
@ -82,7 +81,7 @@ func makeLabels(n int) []kv.KeyValue {
break
}
}
l[i] = kv.Key(k).String(fmt.Sprint("v", rand.Intn(1000000000)))
l[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
}
return l
}
@ -169,7 +168,7 @@ func BenchmarkAcquireReleaseExistingHandle(b *testing.B) {
// Iterators
var benchmarkIteratorVar kv.KeyValue
var benchmarkIteratorVar label.KeyValue
func benchmarkIterator(b *testing.B, n int) {
labels := label.NewSet(makeLabels(n)...)
@ -218,7 +217,7 @@ func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) {
sdk := global.Meter("test")
global.SetMeterProvider(fix)
labs := []kv.KeyValue{kv.String("A", "B")}
labs := []label.KeyValue{label.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.counter")
b.ResetTimer()
@ -539,7 +538,7 @@ func BenchmarkRepeatedDirectCalls(b *testing.B) {
fix := newFixture(b)
c := fix.meterMust().NewInt64Counter("int64.counter")
k := kv.String("bench", "true")
k := label.String("bench", "true")
b.ResetTimer()

View File

@ -22,9 +22,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
@ -47,7 +46,7 @@ func TestPullNoCache(t *testing.T) {
meter := puller.Provider().Meter("nocache")
counter := metric.Must(meter).NewInt64Counter("counter.sum")
counter.Add(ctx, 10, kv.String("A", "B"))
counter.Add(ctx, 10, label.String("A", "B"))
require.NoError(t, puller.Collect(ctx))
records := processortest.NewOutput(label.DefaultEncoder())
@ -57,7 +56,7 @@ func TestPullNoCache(t *testing.T) {
"counter.sum/A=B/": 10,
}, records.Map())
counter.Add(ctx, 10, kv.String("A", "B"))
counter.Add(ctx, 10, label.String("A", "B"))
require.NoError(t, puller.Collect(ctx))
records = processortest.NewOutput(label.DefaultEncoder())
@ -84,7 +83,7 @@ func TestPullWithCache(t *testing.T) {
meter := puller.Provider().Meter("nocache")
counter := metric.Must(meter).NewInt64Counter("counter.sum")
counter.Add(ctx, 10, kv.String("A", "B"))
counter.Add(ctx, 10, label.String("A", "B"))
require.NoError(t, puller.Collect(ctx))
records := processortest.NewOutput(label.DefaultEncoder())
@ -94,7 +93,7 @@ func TestPullWithCache(t *testing.T) {
"counter.sum/A=B/": 10,
}, records.Map())
counter.Add(ctx, 10, kv.String("A", "B"))
counter.Add(ctx, 10, label.String("A", "B"))
// Cached value!
require.NoError(t, puller.Collect(ctx))

View File

@ -17,15 +17,14 @@ package push
import (
"testing"
"go.opentelemetry.io/otel/api/kv"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/resource"
)
func TestWithResource(t *testing.T) {
r := resource.New(kv.String("A", "a"))
r := resource.New(label.String("A", "a"))
c := &Config{}
WithResource(r).Apply(c)

View File

@ -25,9 +25,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
@ -37,7 +36,7 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
)
var testResource = resource.New(kv.String("R", "V"))
var testResource = resource.New(label.String("R", "V"))
type handler struct {
sync.Mutex
@ -201,7 +200,7 @@ func TestPushExportError(t *testing.T) {
p.Start()
runtime.Gosched()
counter1.Add(ctx, 3, kv.String("X", "Y"))
counter1.Add(ctx, 3, label.String("X", "Y"))
counter2.Add(ctx, 5)
require.Equal(t, 0, exporter.ExportCount())

View File

@ -24,9 +24,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
metricsdk "go.opentelemetry.io/otel/sdk/metric"
@ -35,7 +34,7 @@ import (
)
var Must = metric.Must
var testResource = resource.New(kv.String("R", "V"))
var testResource = resource.New(label.String("R", "V"))
type handler struct {
sync.Mutex
@ -209,19 +208,19 @@ func TestSDKLabelsDeduplication(t *testing.T) {
keySets = 2
repeats = 3
)
var keysA []kv.Key
var keysB []kv.Key
var keysA []label.Key
var keysB []label.Key
for i := 0; i < maxKeys; i++ {
keysA = append(keysA, kv.Key(fmt.Sprintf("A%03d", i)))
keysB = append(keysB, kv.Key(fmt.Sprintf("B%03d", i)))
keysA = append(keysA, label.Key(fmt.Sprintf("A%03d", i)))
keysB = append(keysB, label.Key(fmt.Sprintf("B%03d", i)))
}
var allExpect [][]kv.KeyValue
var allExpect [][]label.KeyValue
for numKeys := 0; numKeys < maxKeys; numKeys++ {
var kvsA []kv.KeyValue
var kvsB []kv.KeyValue
var kvsA []label.KeyValue
var kvsB []label.KeyValue
for r := 0; r < repeats; r++ {
for i := 0; i < numKeys; i++ {
kvsA = append(kvsA, keysA[i].Int(r))
@ -229,8 +228,8 @@ func TestSDKLabelsDeduplication(t *testing.T) {
}
}
var expectA []kv.KeyValue
var expectB []kv.KeyValue
var expectA []label.KeyValue
var expectB []label.KeyValue
for i := 0; i < numKeys; i++ {
expectA = append(expectA, keysA[i].Int(repeats-1))
expectB = append(expectB, keysB[i].Int(repeats-1))
@ -251,7 +250,7 @@ func TestSDKLabelsDeduplication(t *testing.T) {
sdk.Collect(ctx)
var actual [][]kv.KeyValue
var actual [][]label.KeyValue
for _, rec := range processor.accumulations {
sum, _ := rec.Aggregator().(aggregation.Sum).Sum()
require.Equal(t, sum, metric.NewInt64Number(2))
@ -263,7 +262,7 @@ func TestSDKLabelsDeduplication(t *testing.T) {
require.ElementsMatch(t, allExpect, actual)
}
func newSetIter(kvs ...kv.KeyValue) label.Iterator {
func newSetIter(kvs ...label.KeyValue) label.Iterator {
labels := label.NewSet(kvs...)
return labels.Iter()
}
@ -271,28 +270,28 @@ func newSetIter(kvs ...kv.KeyValue) label.Iterator {
func TestDefaultLabelEncoder(t *testing.T) {
encoder := label.DefaultEncoder()
encoded := encoder.Encode(newSetIter(kv.String("A", "B"), kv.String("C", "D")))
encoded := encoder.Encode(newSetIter(label.String("A", "B"), label.String("C", "D")))
require.Equal(t, `A=B,C=D`, encoded)
encoded = encoder.Encode(newSetIter(kv.String("A", "B,c=d"), kv.String(`C\`, "D")))
encoded = encoder.Encode(newSetIter(label.String("A", "B,c=d"), label.String(`C\`, "D")))
require.Equal(t, `A=B\,c\=d,C\\=D`, encoded)
encoded = encoder.Encode(newSetIter(kv.String(`\`, `=`), kv.String(`,`, `\`)))
encoded = encoder.Encode(newSetIter(label.String(`\`, `=`), label.String(`,`, `\`)))
require.Equal(t, `\,=\\,\\=\=`, encoded)
// Note: the label encoder does not sort or de-dup values,
// that is done in Labels(...).
encoded = encoder.Encode(newSetIter(
kv.Int("I", 1),
kv.Uint("U", 1),
kv.Int32("I32", 1),
kv.Uint32("U32", 1),
kv.Int64("I64", 1),
kv.Uint64("U64", 1),
kv.Float64("F64", 1),
kv.Float64("F64", 1),
kv.String("S", "1"),
kv.Bool("B", true),
label.Int("I", 1),
label.Uint("U", 1),
label.Int32("I32", 1),
label.Uint32("U32", 1),
label.Int64("I64", 1),
label.Uint64("U64", 1),
label.Float64("F64", 1),
label.Float64("F64", 1),
label.String("S", "1"),
label.Bool("B", true),
))
require.Equal(t, "B=true,F64=1,I=1,I32=1,I64=1,S=1,U=1,U32=1,U64=1", encoded)
}
@ -302,42 +301,42 @@ func TestObserverCollection(t *testing.T) {
meter, sdk, processor := newSDK(t)
_ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(1, kv.String("A", "B"))
result.Observe(1, label.String("A", "B"))
// last value wins
result.Observe(-1, kv.String("A", "B"))
result.Observe(-1, kv.String("C", "D"))
result.Observe(-1, label.String("A", "B"))
result.Observe(-1, label.String("C", "D"))
})
_ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-1, kv.String("A", "B"))
result.Observe(-1, label.String("A", "B"))
result.Observe(1)
// last value wins
result.Observe(1, kv.String("A", "B"))
result.Observe(1, label.String("A", "B"))
result.Observe(1)
})
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(1, kv.String("A", "B"))
result.Observe(2, kv.String("A", "B"))
result.Observe(1, kv.String("C", "D"))
result.Observe(1, label.String("A", "B"))
result.Observe(2, label.String("A", "B"))
result.Observe(1, label.String("C", "D"))
})
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(2, kv.String("A", "B"))
result.Observe(2, label.String("A", "B"))
result.Observe(1)
// last value wins
result.Observe(1, kv.String("A", "B"))
result.Observe(1, label.String("A", "B"))
result.Observe(1)
})
_ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(1, kv.String("A", "B"))
result.Observe(-2, kv.String("A", "B"))
result.Observe(1, kv.String("C", "D"))
result.Observe(1, label.String("A", "B"))
result.Observe(-2, label.String("A", "B"))
result.Observe(1, label.String("C", "D"))
})
_ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(2, kv.String("A", "B"))
result.Observe(2, label.String("A", "B"))
result.Observe(1)
// last value wins
result.Observe(1, kv.String("A", "B"))
result.Observe(1, label.String("A", "B"))
result.Observe(-1)
})
@ -376,13 +375,13 @@ func TestSumObserverInputRange(t *testing.T) {
// TODO: these tests are testing for negative values, not for _descending values_. Fix.
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(-2, kv.String("A", "B"))
result.Observe(-2, label.String("A", "B"))
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
result.Observe(-1, kv.String("C", "D"))
result.Observe(-1, label.String("C", "D"))
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
})
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(-1, kv.String("A", "B"))
result.Observe(-1, label.String("A", "B"))
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
result.Observe(-1)
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
@ -411,8 +410,8 @@ func TestObserverBatch(t *testing.T) {
var batch = Must(meter).NewBatchObserver(
func(_ context.Context, result metric.BatchObserverResult) {
result.Observe(
[]kv.KeyValue{
kv.String("A", "B"),
[]label.KeyValue{
label.String("A", "B"),
},
floatValueObs.Observation(1),
floatValueObs.Observation(-1),
@ -424,8 +423,8 @@ func TestObserverBatch(t *testing.T) {
intUpDownSumObs.Observation(-100),
)
result.Observe(
[]kv.KeyValue{
kv.String("C", "D"),
[]label.KeyValue{
label.String("C", "D"),
},
floatValueObs.Observation(-1),
floatSumObs.Observation(-1),
@ -484,9 +483,9 @@ func TestRecordBatch(t *testing.T) {
sdk.RecordBatch(
ctx,
[]kv.KeyValue{
kv.String("A", "B"),
kv.String("C", "D"),
[]label.KeyValue{
label.String("A", "B"),
label.String("C", "D"),
},
counter1.Measurement(1),
counter2.Measurement(2),
@ -516,8 +515,8 @@ func TestRecordPersistence(t *testing.T) {
meter, sdk, processor := newSDK(t)
c := Must(meter).NewFloat64Counter("name.sum")
b := c.Bind(kv.String("bound", "true"))
uk := kv.String("bound", "false")
b := c.Bind(label.String("bound", "true"))
uk := label.String("bound", "false")
for i := 0; i < 100; i++ {
c.Add(ctx, 1, uk)

View File

@ -20,8 +20,8 @@ import (
"sync"
"time"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/resource"

View File

@ -24,9 +24,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
@ -103,7 +102,7 @@ func asNumber(nkind metric.NumberKind, value int64) metric.Number {
return metric.NewFloat64Number(float64(value))
}
func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...kv.KeyValue) export.Accumulation {
func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...label.KeyValue) export.Accumulation {
ls := label.NewSet(labs...)
var agg export.Aggregator
selector.AggregatorFor(desc, &agg)
@ -122,10 +121,10 @@ func testProcessor(
// Note: this selector uses the instrument name to dictate
// aggregation kind.
selector := processorTest.AggregatorSelector()
res := resource.New(kv.String("R", "V"))
res := resource.New(label.String("R", "V"))
labs1 := []kv.KeyValue{kv.String("L1", "V")}
labs2 := []kv.KeyValue{kv.String("L2", "V")}
labs1 := []label.KeyValue{label.String("L1", "V")}
labs2 := []label.KeyValue{label.String("L2", "V")}
testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) {
processor := basic.New(selector, ekind, basic.WithMemory(hasMemory))
@ -362,7 +361,7 @@ func TestBasicTimestamps(t *testing.T) {
}
func TestStatefulNoMemoryCumulative(t *testing.T) {
res := resource.New(kv.String("R", "V"))
res := resource.New(label.String("R", "V"))
ekind := export.CumulativeExporter
desc := metric.NewDescriptor("inst.sum", metric.CounterKind, metric.Int64NumberKind)
@ -383,7 +382,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
// Add 10
processor.StartCollection()
_ = processor.Process(updateFor(t, &desc, selector, res, 10, kv.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, 10, label.String("A", "B")))
require.NoError(t, processor.FinishCollection())
// Verify one element
@ -396,7 +395,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
}
func TestStatefulNoMemoryDelta(t *testing.T) {
res := resource.New(kv.String("R", "V"))
res := resource.New(label.String("R", "V"))
ekind := export.DeltaExporter
desc := metric.NewDescriptor("inst.sum", metric.SumObserverKind, metric.Int64NumberKind)
@ -417,7 +416,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) {
// Add 10
processor.StartCollection()
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B")))
require.NoError(t, processor.FinishCollection())
// Verify one element
@ -436,7 +435,7 @@ func TestMultiObserverSum(t *testing.T) {
export.DeltaExporter,
} {
res := resource.New(kv.String("R", "V"))
res := resource.New(label.String("R", "V"))
desc := metric.NewDescriptor("observe.sum", metric.SumObserverKind, metric.Int64NumberKind)
selector := processorTest.AggregatorSelector()
@ -446,9 +445,9 @@ func TestMultiObserverSum(t *testing.T) {
for i := 1; i < 3; i++ {
// Add i*10*3 times
processor.StartCollection()
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), kv.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B")))
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B")))
require.NoError(t, processor.FinishCollection())
// Multiplier is 1 for deltas, otherwise i.

View File

@ -21,8 +21,8 @@ import (
"sync"
"time"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"

View File

@ -20,9 +20,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
metricsdk "go.opentelemetry.io/otel/sdk/metric"
processorTest "go.opentelemetry.io/otel/sdk/metric/processor/processortest"
@ -34,7 +33,7 @@ func generateTestData(proc export.Processor) {
accum := metricsdk.NewAccumulator(
proc,
metricsdk.WithResource(
resource.New(kv.String("R", "V")),
resource.New(label.String("R", "V")),
),
)
meter := metric.WrapMeterImpl(accum, "testing")
@ -43,13 +42,13 @@ func generateTestData(proc export.Processor) {
_ = metric.Must(meter).NewInt64SumObserver("observer.sum",
func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(10, kv.String("K1", "V1"))
result.Observe(11, kv.String("K1", "V2"))
result.Observe(10, label.String("K1", "V1"))
result.Observe(11, label.String("K1", "V2"))
},
)
counter.Add(ctx, 100, kv.String("K1", "V1"))
counter.Add(ctx, 101, kv.String("K1", "V2"))
counter.Add(ctx, 100, label.String("K1", "V1"))
counter.Add(ctx, 101, label.String("K1", "V2"))
accum.Collect(ctx)
}

View File

@ -15,8 +15,8 @@
package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer"
import (
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
)

View File

@ -20,9 +20,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
metricsdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
@ -32,22 +31,22 @@ import (
)
var (
kvs1 = []kv.KeyValue{
kv.Int("A", 1),
kv.Int("B", 2),
kv.Int("C", 3),
kvs1 = []label.KeyValue{
label.Int("A", 1),
label.Int("B", 2),
label.Int("C", 3),
}
kvs2 = []kv.KeyValue{
kv.Int("A", 1),
kv.Int("B", 0),
kv.Int("C", 3),
kvs2 = []label.KeyValue{
label.Int("A", 1),
label.Int("B", 0),
label.Int("C", 3),
}
)
type testFilter struct{}
func (testFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter {
return func(label kv.KeyValue) bool {
return func(label label.KeyValue) bool {
return label.Key == "A" || label.Key == "C"
}
}
@ -77,7 +76,7 @@ func TestFilterProcessor(t *testing.T) {
accum := metricsdk.NewAccumulator(
reducer.New(testFilter{}, processorTest.Checkpointer(testProc)),
metricsdk.WithResource(
resource.New(kv.String("R", "V")),
resource.New(label.String("R", "V")),
),
)
generateData(accum)
@ -96,7 +95,7 @@ func TestFilterBasicProcessor(t *testing.T) {
accum := metricsdk.NewAccumulator(
reducer.New(testFilter{}, basicProc),
metricsdk.WithResource(
resource.New(kv.String("R", "V")),
resource.New(label.String("R", "V")),
),
)
exporter := processorTest.NewExporter(basicProc, label.DefaultEncoder())

View File

@ -22,11 +22,10 @@ import (
"sync/atomic"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/label"
"go.opentelemetry.io/otel/api/metric"
api "go.opentelemetry.io/otel/api/metric"
internal "go.opentelemetry.io/otel/internal/metric"
"go.opentelemetry.io/otel/label"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator"
"go.opentelemetry.io/otel/sdk/resource"
@ -214,7 +213,7 @@ func (a *asyncInstrument) getRecorder(labels *label.Set) export.Aggregator {
// support re-use of the orderedLabels computed by a previous
// measurement in the same batch. This performs two allocations
// in the common case.
func (s *syncInstrument) acquireHandle(kvs []kv.KeyValue, labelPtr *label.Set) *record {
func (s *syncInstrument) acquireHandle(kvs []label.KeyValue, labelPtr *label.Set) *record {
var rec *record
var equiv label.Distinct
@ -287,11 +286,11 @@ func (s *syncInstrument) acquireHandle(kvs []kv.KeyValue, labelPtr *label.Set) *
}
}
func (s *syncInstrument) Bind(kvs []kv.KeyValue) api.BoundSyncImpl {
func (s *syncInstrument) Bind(kvs []label.KeyValue) api.BoundSyncImpl {
return s.acquireHandle(kvs, nil)
}
func (s *syncInstrument) RecordOne(ctx context.Context, number api.Number, kvs []kv.KeyValue) {
func (s *syncInstrument) RecordOne(ctx context.Context, number api.Number, kvs []label.KeyValue) {
h := s.acquireHandle(kvs, nil)
defer h.Unbind()
h.RecordOne(ctx, number)
@ -406,7 +405,7 @@ func (m *Accumulator) collectSyncInstruments() int {
}
// CollectAsync implements internal.AsyncCollector.
func (m *Accumulator) CollectAsync(kv []kv.KeyValue, obs ...metric.Observation) {
func (m *Accumulator) CollectAsync(kv []label.KeyValue, obs ...metric.Observation) {
labels := label.NewSetWithSortable(kv, &m.asyncSortSlice)
for _, ob := range obs {
@ -483,7 +482,7 @@ func (m *Accumulator) checkpointAsync(a *asyncInstrument) int {
}
// RecordBatch enters a batch of metric events.
func (m *Accumulator) RecordBatch(ctx context.Context, kvs []kv.KeyValue, measurements ...api.Measurement) {
func (m *Accumulator) RecordBatch(ctx context.Context, kvs []label.KeyValue, measurements ...api.Measurement) {
// Labels will be computed the first time acquireHandle is
// called. Subsequent calls to acquireHandle will re-use the
// previously computed value instead of recomputing the

View File

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

View File

@ -19,7 +19,7 @@ import (
"math/rand"
"testing"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/resource"
)
@ -27,8 +27,8 @@ const conflict = 0.5
func makeLabels(n int) (_, _ *resource.Resource) {
used := map[string]bool{}
l1 := make([]kv.KeyValue, n)
l2 := make([]kv.KeyValue, n)
l1 := make([]label.KeyValue, n)
l2 := make([]label.KeyValue, n)
for i := 0; i < n; i++ {
var k string
for {
@ -38,12 +38,12 @@ func makeLabels(n int) (_, _ *resource.Resource) {
break
}
}
l1[i] = kv.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
l1[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
if rand.Float64() < conflict {
l2[i] = l1[i]
} else {
l2[i] = kv.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
l2[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
}
}

View File

@ -20,7 +20,7 @@ import (
"os"
"strings"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/label"
)
// envVar is the environment variable name OpenTelemetry Resource information can be assigned to.
@ -50,7 +50,7 @@ func (d *FromEnv) Detect(context.Context) (*Resource, error) {
func constructOTResources(s string) (*Resource, error) {
pairs := strings.Split(s, ",")
labels := []kv.KeyValue{}
labels := []label.KeyValue{}
var invalid []string
for _, p := range pairs {
field := strings.SplitN(p, "=", 2)
@ -59,7 +59,7 @@ func constructOTResources(s string) (*Resource, error) {
continue
}
k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1])
labels = append(labels, kv.String(k, v))
labels = append(labels, label.String(k, v))
}
var err error
if len(invalid) > 0 {

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