You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +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:
@ -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)
|
- 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 `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)
|
- 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.
|
- Unify Callback Function Naming.
|
||||||
Rename `*Callback` with `*Func`. (#1061)
|
Rename `*Callback` with `*Func`. (#1061)
|
||||||
|
|
||||||
|
@ -20,10 +20,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
"go.opentelemetry.io/otel/internal/matchers"
|
"go.opentelemetry.io/otel/internal/matchers"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Harness struct {
|
type Harness struct {
|
||||||
@ -195,7 +195,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) {
|
|||||||
span.SetName("new name")
|
span.SetName("new name")
|
||||||
},
|
},
|
||||||
"#SetAttributes": func(span trace.Span) {
|
"#SetAttributes": func(span trace.Span) {
|
||||||
span.SetAttributes(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{
|
var mechanisms = map[string]func() trace.Span{
|
||||||
|
@ -17,7 +17,7 @@ package correlation
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type correlationsType struct{}
|
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
|
// NewContext returns a context with the map from passed context
|
||||||
// updated with the passed key-value pairs.
|
// updated with the passed key-value pairs.
|
||||||
func NewContext(ctx context.Context, keyvalues ...kv.KeyValue) context.Context {
|
func NewContext(ctx context.Context, keyvalues ...label.KeyValue) context.Context {
|
||||||
return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{
|
return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{
|
||||||
MultiKV: keyvalues,
|
MultiKV: keyvalues,
|
||||||
}))
|
}))
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/propagation"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Temporary header name until W3C finalizes format.
|
// Temporary header name until W3C finalizes format.
|
||||||
@ -45,7 +45,7 @@ func (CorrelationContext) Inject(ctx context.Context, supplier propagation.HTTPS
|
|||||||
correlationCtx := MapFromContext(ctx)
|
correlationCtx := MapFromContext(ctx)
|
||||||
firstIter := true
|
firstIter := true
|
||||||
var headerValueBuilder strings.Builder
|
var headerValueBuilder strings.Builder
|
||||||
correlationCtx.Foreach(func(kv kv.KeyValue) bool {
|
correlationCtx.Foreach(func(kv label.KeyValue) bool {
|
||||||
if !firstIter {
|
if !firstIter {
|
||||||
headerValueBuilder.WriteRune(',')
|
headerValueBuilder.WriteRune(',')
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP
|
|||||||
}
|
}
|
||||||
|
|
||||||
contextValues := strings.Split(correlationContext, ",")
|
contextValues := strings.Split(correlationContext, ",")
|
||||||
keyValues := make([]kv.KeyValue, 0, len(contextValues))
|
keyValues := make([]label.KeyValue, 0, len(contextValues))
|
||||||
for _, contextValue := range contextValues {
|
for _, contextValue := range contextValues {
|
||||||
valueAndProps := strings.Split(contextValue, ";")
|
valueAndProps := strings.Split(contextValue, ";")
|
||||||
if len(valueAndProps) < 1 {
|
if len(valueAndProps) < 1 {
|
||||||
@ -99,7 +99,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP
|
|||||||
trimmedValueWithProps.WriteString(prop)
|
trimmedValueWithProps.WriteString(prop)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyValues = append(keyValues, kv.Key(trimmedName).String(trimmedValueWithProps.String()))
|
keyValues = append(keyValues, label.String(trimmedName, trimmedValueWithProps.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(keyValues) > 0 {
|
if len(keyValues) > 0 {
|
||||||
|
@ -23,8 +23,8 @@ import (
|
|||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/correlation"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/propagation"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
||||||
@ -32,54 +32,54 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
wantKVs []kv.KeyValue
|
wantKVs []label.KeyValue
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "valid w3cHeader",
|
name: "valid w3cHeader",
|
||||||
header: "key1=val1,key2=val2",
|
header: "key1=val1,key2=val2",
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid w3cHeader with spaces",
|
name: "valid w3cHeader with spaces",
|
||||||
header: "key1 = val1, key2 =val2 ",
|
header: "key1 = val1, key2 =val2 ",
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid w3cHeader with properties",
|
name: "valid w3cHeader with properties",
|
||||||
header: "key1=val1,key2=val2;prop=1",
|
header: "key1=val1,key2=val2;prop=1",
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2;prop=1"),
|
label.String("key2", "val2;prop=1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid header with url-escaped comma",
|
name: "valid header with url-escaped comma",
|
||||||
header: "key1=val1,key2=val2%2Cval3",
|
header: "key1=val1,key2=val2%2Cval3",
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2,val3"),
|
label.String("key2", "val2,val3"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid header with an invalid header",
|
name: "valid header with an invalid header",
|
||||||
header: "key1=val1,key2=val2,a,val3",
|
header: "key1=val1,key2=val2,a,val3",
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid header with no value",
|
name: "valid header with no value",
|
||||||
header: "key1=,key2=val2",
|
header: "key1=,key2=val2",
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String(""),
|
label.String("key1", ""),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -101,9 +101,9 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
totalDiff := ""
|
totalDiff := ""
|
||||||
wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool {
|
wantCorCtx.Foreach(func(keyValue label.KeyValue) bool {
|
||||||
val, _ := gotCorCtx.Value(keyValue.Key)
|
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 != "" {
|
if diff != "" {
|
||||||
totalDiff += diff + "\n"
|
totalDiff += diff + "\n"
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
hasKVs []kv.KeyValue
|
hasKVs []label.KeyValue
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no key values",
|
name: "no key values",
|
||||||
@ -130,17 +130,17 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid header with existing context",
|
name: "invalid header with existing context",
|
||||||
header: "header2",
|
header: "header2",
|
||||||
hasKVs: []kv.KeyValue{
|
hasKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty header value",
|
name: "empty header value",
|
||||||
header: "",
|
header: "",
|
||||||
hasKVs: []kv.KeyValue{
|
hasKVs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -162,9 +162,9 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
totalDiff := ""
|
totalDiff := ""
|
||||||
wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool {
|
wantCorCtx.Foreach(func(keyValue label.KeyValue) bool {
|
||||||
val, _ := gotCorCtx.Value(keyValue.Key)
|
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 != "" {
|
if diff != "" {
|
||||||
totalDiff += diff + "\n"
|
totalDiff += diff + "\n"
|
||||||
}
|
}
|
||||||
@ -179,38 +179,38 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
|||||||
props := propagation.New(propagation.WithInjectors(propagator))
|
props := propagation.New(propagation.WithInjectors(propagator))
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
kvs []kv.KeyValue
|
kvs []label.KeyValue
|
||||||
wantInHeader []string
|
wantInHeader []string
|
||||||
wantedLen int
|
wantedLen int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "two simple values",
|
name: "two simple values",
|
||||||
kvs: []kv.KeyValue{
|
kvs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Key("key2").String("val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
wantInHeader: []string{"key1=val1", "key2=val2"},
|
wantInHeader: []string{"key1=val1", "key2=val2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "two values with escaped chars",
|
name: "two values with escaped chars",
|
||||||
kvs: []kv.KeyValue{
|
kvs: []label.KeyValue{
|
||||||
kv.Key("key1").String("val1,val2"),
|
label.String("key1", "val1,val2"),
|
||||||
kv.Key("key2").String("val3=4"),
|
label.String("key2", "val3=4"),
|
||||||
},
|
},
|
||||||
wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"},
|
wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "values of non-string types",
|
name: "values of non-string types",
|
||||||
kvs: []kv.KeyValue{
|
kvs: []label.KeyValue{
|
||||||
kv.Key("key1").Bool(true),
|
label.Bool("key1", true),
|
||||||
kv.Key("key2").Int(123),
|
label.Int("key2", 123),
|
||||||
kv.Key("key3").Int64(123),
|
label.Int64("key3", 123),
|
||||||
kv.Key("key4").Int32(123),
|
label.Int32("key4", 123),
|
||||||
kv.Key("key5").Uint(123),
|
label.Uint("key5", 123),
|
||||||
kv.Key("key6").Uint32(123),
|
label.Uint32("key6", 123),
|
||||||
kv.Key("key7").Uint64(123),
|
label.Uint64("key7", 123),
|
||||||
kv.Key("key8").Float64(123.567),
|
label.Float64("key8", 123.567),
|
||||||
kv.Key("key9").Float32(123.567),
|
label.Float32("key9", 123.567),
|
||||||
},
|
},
|
||||||
wantInHeader: []string{
|
wantInHeader: []string{
|
||||||
"key1=true",
|
"key1=true",
|
||||||
|
@ -14,12 +14,10 @@
|
|||||||
|
|
||||||
package correlation
|
package correlation
|
||||||
|
|
||||||
import (
|
import "go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type rawMap map[kv.Key]kv.Value
|
type rawMap map[label.Key]label.Value
|
||||||
type keySet map[kv.Key]struct{}
|
type keySet map[label.Key]struct{}
|
||||||
|
|
||||||
// Map is an immutable storage for correlations.
|
// Map is an immutable storage for correlations.
|
||||||
type Map struct {
|
type Map struct {
|
||||||
@ -32,18 +30,18 @@ type MapUpdate struct {
|
|||||||
// DropSingleK contains a single key to be dropped from
|
// DropSingleK contains a single key to be dropped from
|
||||||
// correlations. Use this to avoid an overhead of a slice
|
// correlations. Use this to avoid an overhead of a slice
|
||||||
// allocation if there is only one key to drop.
|
// allocation if there is only one key to drop.
|
||||||
DropSingleK kv.Key
|
DropSingleK label.Key
|
||||||
// DropMultiK contains all the keys to be dropped from
|
// DropMultiK contains all the keys to be dropped from
|
||||||
// correlations.
|
// correlations.
|
||||||
DropMultiK []kv.Key
|
DropMultiK []label.Key
|
||||||
|
|
||||||
// SingleKV contains a single key-value pair to be added to
|
// SingleKV contains a single key-value pair to be added to
|
||||||
// correlations. Use this to avoid an overhead of a slice
|
// correlations. Use this to avoid an overhead of a slice
|
||||||
// allocation if there is only one key-value pair to add.
|
// allocation if there is only one key-value pair to add.
|
||||||
SingleKV kv.KeyValue
|
SingleKV label.KeyValue
|
||||||
// MultiKV contains all the key-value pairs to be added to
|
// MultiKV contains all the key-value pairs to be added to
|
||||||
// correlations.
|
// correlations.
|
||||||
MultiKV []kv.KeyValue
|
MultiKV []label.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMap(raw rawMap) Map {
|
func newMap(raw rawMap) Map {
|
||||||
@ -101,7 +99,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
|
|||||||
deletionsCount++
|
deletionsCount++
|
||||||
}
|
}
|
||||||
if deletionsCount > 0 {
|
if deletionsCount > 0 {
|
||||||
delSet = make(map[kv.Key]struct{}, deletionsCount)
|
delSet = make(map[label.Key]struct{}, deletionsCount)
|
||||||
for _, k := range update.DropMultiK {
|
for _, k := range update.DropMultiK {
|
||||||
delSet[k] = struct{}{}
|
delSet[k] = struct{}{}
|
||||||
}
|
}
|
||||||
@ -115,7 +113,7 @@ func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
|
|||||||
additionsCount++
|
additionsCount++
|
||||||
}
|
}
|
||||||
if additionsCount > 0 {
|
if additionsCount > 0 {
|
||||||
addSet = make(map[kv.Key]struct{}, additionsCount)
|
addSet = make(map[label.Key]struct{}, additionsCount)
|
||||||
for _, k := range update.MultiKV {
|
for _, k := range update.MultiKV {
|
||||||
addSet[k.Key] = struct{}{}
|
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 gets a value from correlations map and returns a boolean
|
||||||
// value indicating whether the key exist in the map.
|
// value indicating whether the key exist in the map.
|
||||||
func (m Map) Value(k kv.Key) (kv.Value, bool) {
|
func (m Map) Value(k label.Key) (label.Value, bool) {
|
||||||
value, ok := m.m[k]
|
value, ok := m.m[k]
|
||||||
return value, ok
|
return value, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasValue returns a boolean value indicating whether the key exist
|
// HasValue returns a boolean value indicating whether the key exist
|
||||||
// in the map.
|
// in the map.
|
||||||
func (m Map) HasValue(k kv.Key) bool {
|
func (m Map) HasValue(k label.Key) bool {
|
||||||
_, has := m.Value(k)
|
_, has := m.Value(k)
|
||||||
return has
|
return has
|
||||||
}
|
}
|
||||||
@ -166,9 +164,9 @@ func (m Map) Len() int {
|
|||||||
// Foreach calls a passed callback once on each key-value pair until
|
// Foreach calls a passed callback once on each key-value pair until
|
||||||
// all the key-value pairs of the map were iterated or the callback
|
// all the key-value pairs of the map were iterated or the callback
|
||||||
// returns false, whichever happens first.
|
// returns false, whichever happens first.
|
||||||
func (m Map) Foreach(f func(kv kv.KeyValue) bool) {
|
func (m Map) Foreach(f func(label.KeyValue) bool) {
|
||||||
for k, v := range m.m {
|
for k, v := range m.m {
|
||||||
if !f(kv.KeyValue{
|
if !f(label.KeyValue{
|
||||||
Key: k,
|
Key: k,
|
||||||
Value: v,
|
Value: v,
|
||||||
}) {
|
}) {
|
||||||
|
@ -18,14 +18,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
value MapUpdate
|
value MapUpdate
|
||||||
init []int
|
init []int
|
||||||
wantKVs []kv.KeyValue
|
wantKVs []label.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMap(t *testing.T) {
|
func TestMap(t *testing.T) {
|
||||||
@ -46,13 +46,13 @@ func TestMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// test Foreach()
|
// test Foreach()
|
||||||
got.Foreach(func(kv kv.KeyValue) bool {
|
got.Foreach(func(kv label.KeyValue) bool {
|
||||||
for _, want := range testcase.wantKVs {
|
for _, want := range testcase.wantKVs {
|
||||||
if kv == want {
|
if kv == want {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Errorf("Expected kv %v, but not found", kv)
|
t.Errorf("Expected label %v, but not found", kv)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if l, exp := got.Len(), len(testcase.wantKVs); l != exp {
|
if l, exp := got.Len(), len(testcase.wantKVs); l != exp {
|
||||||
@ -85,192 +85,192 @@ func getTestCases() []testCase {
|
|||||||
return []testCase{
|
return []testCase{
|
||||||
{
|
{
|
||||||
name: "map with MultiKV",
|
name: "map with MultiKV",
|
||||||
value: MapUpdate{MultiKV: []kv.KeyValue{
|
value: MapUpdate{MultiKV: []label.KeyValue{
|
||||||
kv.Int64("key1", 1),
|
label.Int64("key1", 1),
|
||||||
kv.String("key2", "val2")},
|
label.String("key2", "val2")},
|
||||||
},
|
},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Int64("key1", 1),
|
label.Int64("key1", 1),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with SingleKV",
|
name: "map with SingleKV",
|
||||||
value: MapUpdate{SingleKV: kv.String("key1", "val1")},
|
value: MapUpdate{SingleKV: label.String("key1", "val1")},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.String("key1", "val1"),
|
label.String("key1", "val1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with both add fields",
|
name: "map with both add fields",
|
||||||
value: MapUpdate{SingleKV: kv.Int64("key1", 3),
|
value: MapUpdate{SingleKV: label.Int64("key1", 3),
|
||||||
MultiKV: []kv.KeyValue{
|
MultiKV: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2")},
|
label.String("key2", "val2")},
|
||||||
},
|
},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with empty MapUpdate",
|
name: "map with empty MapUpdate",
|
||||||
value: MapUpdate{},
|
value: MapUpdate{},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{},
|
wantKVs: []label.KeyValue{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with DropSingleK",
|
name: "map with DropSingleK",
|
||||||
value: MapUpdate{DropSingleK: kv.Key("key1")},
|
value: MapUpdate{DropSingleK: label.Key("key1")},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{},
|
wantKVs: []label.KeyValue{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with DropMultiK",
|
name: "map with DropMultiK",
|
||||||
value: MapUpdate{DropMultiK: []kv.Key{
|
value: MapUpdate{DropMultiK: []label.Key{
|
||||||
kv.Key("key1"), kv.Key("key2"),
|
label.Key("key1"), label.Key("key2"),
|
||||||
}},
|
}},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{},
|
wantKVs: []label.KeyValue{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with both drop fields",
|
name: "map with both drop fields",
|
||||||
value: MapUpdate{
|
value: MapUpdate{
|
||||||
DropSingleK: kv.Key("key1"),
|
DropSingleK: label.Key("key1"),
|
||||||
DropMultiK: []kv.Key{
|
DropMultiK: []label.Key{
|
||||||
kv.Key("key1"),
|
label.Key("key1"),
|
||||||
kv.Key("key2"),
|
label.Key("key2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{},
|
wantKVs: []label.KeyValue{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map with all fields",
|
name: "map with all fields",
|
||||||
value: MapUpdate{
|
value: MapUpdate{
|
||||||
DropSingleK: kv.Key("key1"),
|
DropSingleK: label.Key("key1"),
|
||||||
DropMultiK: []kv.Key{
|
DropMultiK: []label.Key{
|
||||||
kv.Key("key1"),
|
label.Key("key1"),
|
||||||
kv.Key("key2"),
|
label.Key("key2"),
|
||||||
},
|
},
|
||||||
SingleKV: kv.String("key4", "val4"),
|
SingleKV: label.String("key4", "val4"),
|
||||||
MultiKV: []kv.KeyValue{
|
MultiKV: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
kv.String("key3", "val3"),
|
label.String("key3", "val3"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init: []int{},
|
init: []int{},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
kv.String("key3", "val3"),
|
label.String("key3", "val3"),
|
||||||
kv.String("key4", "val4"),
|
label.String("key4", "val4"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with MultiKV",
|
name: "Existing map with MultiKV",
|
||||||
value: MapUpdate{MultiKV: []kv.KeyValue{
|
value: MapUpdate{MultiKV: []label.KeyValue{
|
||||||
kv.Int64("key1", 1),
|
label.Int64("key1", 1),
|
||||||
kv.String("key2", "val2")},
|
label.String("key2", "val2")},
|
||||||
},
|
},
|
||||||
init: []int{5},
|
init: []int{5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Int64("key1", 1),
|
label.Int64("key1", 1),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with SingleKV",
|
name: "Existing map with SingleKV",
|
||||||
value: MapUpdate{SingleKV: kv.String("key1", "val1")},
|
value: MapUpdate{SingleKV: label.String("key1", "val1")},
|
||||||
init: []int{5},
|
init: []int{5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.String("key1", "val1"),
|
label.String("key1", "val1"),
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with both add fields",
|
name: "Existing map with both add fields",
|
||||||
value: MapUpdate{SingleKV: kv.Int64("key1", 3),
|
value: MapUpdate{SingleKV: label.Int64("key1", 3),
|
||||||
MultiKV: []kv.KeyValue{
|
MultiKV: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2")},
|
label.String("key2", "val2")},
|
||||||
},
|
},
|
||||||
init: []int{5},
|
init: []int{5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with empty MapUpdate",
|
name: "Existing map with empty MapUpdate",
|
||||||
value: MapUpdate{},
|
value: MapUpdate{},
|
||||||
init: []int{5},
|
init: []int{5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with DropSingleK",
|
name: "Existing map with DropSingleK",
|
||||||
value: MapUpdate{DropSingleK: kv.Key("key1")},
|
value: MapUpdate{DropSingleK: label.Key("key1")},
|
||||||
init: []int{1, 5},
|
init: []int{1, 5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with DropMultiK",
|
name: "Existing map with DropMultiK",
|
||||||
value: MapUpdate{DropMultiK: []kv.Key{
|
value: MapUpdate{DropMultiK: []label.Key{
|
||||||
kv.Key("key1"), kv.Key("key2"),
|
label.Key("key1"), label.Key("key2"),
|
||||||
}},
|
}},
|
||||||
init: []int{1, 5},
|
init: []int{1, 5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with both drop fields",
|
name: "Existing map with both drop fields",
|
||||||
value: MapUpdate{
|
value: MapUpdate{
|
||||||
DropSingleK: kv.Key("key1"),
|
DropSingleK: label.Key("key1"),
|
||||||
DropMultiK: []kv.Key{
|
DropMultiK: []label.Key{
|
||||||
kv.Key("key1"),
|
label.Key("key1"),
|
||||||
kv.Key("key2"),
|
label.Key("key2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init: []int{1, 2, 5},
|
init: []int{1, 2, 5},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.Int("key5", 5),
|
label.Int("key5", 5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Existing map with all the fields",
|
name: "Existing map with all the fields",
|
||||||
value: MapUpdate{
|
value: MapUpdate{
|
||||||
DropSingleK: kv.Key("key1"),
|
DropSingleK: label.Key("key1"),
|
||||||
DropMultiK: []kv.Key{
|
DropMultiK: []label.Key{
|
||||||
kv.Key("key1"),
|
label.Key("key1"),
|
||||||
kv.Key("key2"),
|
label.Key("key2"),
|
||||||
kv.Key("key5"),
|
label.Key("key5"),
|
||||||
kv.Key("key6"),
|
label.Key("key6"),
|
||||||
},
|
},
|
||||||
SingleKV: kv.String("key4", "val4"),
|
SingleKV: label.String("key4", "val4"),
|
||||||
MultiKV: []kv.KeyValue{
|
MultiKV: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
kv.String("key3", "val3"),
|
label.String("key3", "val3"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init: []int{5, 6, 7},
|
init: []int{5, 6, 7},
|
||||||
wantKVs: []kv.KeyValue{
|
wantKVs: []label.KeyValue{
|
||||||
kv.String("key1", ""),
|
label.String("key1", ""),
|
||||||
kv.String("key2", "val2"),
|
label.String("key2", "val2"),
|
||||||
kv.String("key3", "val3"),
|
label.String("key3", "val3"),
|
||||||
kv.String("key4", "val4"),
|
label.String("key4", "val4"),
|
||||||
kv.Int("key7", 7),
|
label.Int("key7", 7),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ func getTestCases() []testCase {
|
|||||||
func makeTestMap(ints []int) Map {
|
func makeTestMap(ints []int) Map {
|
||||||
r := make(rawMap, len(ints))
|
r := make(rawMap, len(ints))
|
||||||
for _, v := range ints {
|
for _, v := range ints {
|
||||||
r[kv.Key(fmt.Sprintf("key%d", v))] = kv.IntValue(v)
|
r[label.Key(fmt.Sprintf("key%d", v))] = label.IntValue(v)
|
||||||
}
|
}
|
||||||
return newMap(r)
|
return newMap(r)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/global/internal"
|
"go.opentelemetry.io/otel/api/global/internal"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
|
func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
|
||||||
@ -30,7 +30,7 @@ func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
|
|||||||
internal.ResetForTest()
|
internal.ResetForTest()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sdk := global.Meter("test")
|
sdk := global.Meter("test")
|
||||||
labs := []kv.KeyValue{kv.String("A", "B")}
|
labs := []label.KeyValue{label.String("A", "B")}
|
||||||
cnt := Must(sdk).NewInt64Counter("int64.counter")
|
cnt := Must(sdk).NewInt64Counter("int64.counter")
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/api/metric/registry"
|
"go.opentelemetry.io/otel/api/metric/registry"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file contains the forwarding implementation of metric.Provider
|
// This file contains the forwarding implementation of metric.Provider
|
||||||
@ -108,7 +108,7 @@ type syncHandle struct {
|
|||||||
delegate unsafe.Pointer // (*metric.HandleImpl)
|
delegate unsafe.Pointer // (*metric.HandleImpl)
|
||||||
|
|
||||||
inst *syncImpl
|
inst *syncImpl
|
||||||
labels []kv.KeyValue
|
labels []label.KeyValue
|
||||||
|
|
||||||
initialize sync.Once
|
initialize sync.Once
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ func (inst *syncImpl) Implementation() interface{} {
|
|||||||
return inst
|
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 {
|
if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||||
return (*implPtr).Bind(labels)
|
return (*implPtr).Bind(labels)
|
||||||
}
|
}
|
||||||
@ -299,13 +299,13 @@ func (obs *asyncImpl) setDelegate(d metric.MeterImpl) {
|
|||||||
|
|
||||||
// Metric updates
|
// 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 {
|
if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil {
|
||||||
(*delegatePtr).RecordBatch(ctx, labels, measurements...)
|
(*delegatePtr).RecordBatch(ctx, labels, measurements...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inst *syncImpl) RecordOne(ctx context.Context, number 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 {
|
if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
|
||||||
(*instPtr).RecordOne(ctx, number, labels)
|
(*instPtr).RecordOne(ctx, number, labels)
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ import (
|
|||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/global/internal"
|
"go.opentelemetry.io/otel/api/global/internal"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
metrictest "go.opentelemetry.io/otel/internal/metric"
|
metrictest "go.opentelemetry.io/otel/internal/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Must = metric.Must
|
var Must = metric.Must
|
||||||
@ -35,7 +35,7 @@ type measured struct {
|
|||||||
Name string
|
Name string
|
||||||
InstrumentationName string
|
InstrumentationName string
|
||||||
InstrumentationVersion string
|
InstrumentationVersion string
|
||||||
Labels map[kv.Key]kv.Value
|
Labels map[label.Key]label.Value
|
||||||
Number metric.Number
|
Number metric.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,10 +55,10 @@ func asStructs(batches []metrictest.Batch) []measured {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func asMap(kvs ...kv.KeyValue) map[kv.Key]kv.Value {
|
func asMap(kvs ...label.KeyValue) map[label.Key]label.Value {
|
||||||
m := map[kv.Key]kv.Value{}
|
m := map[label.Key]label.Value{}
|
||||||
for _, kv := range kvs {
|
for _, label := range kvs {
|
||||||
m[kv.Key] = kv.Value
|
m[label.Key] = label.Value
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
@ -72,9 +72,9 @@ func TestDirect(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0"))
|
meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0"))
|
||||||
meter2 := global.Meter("test2")
|
meter2 := global.Meter("test2")
|
||||||
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
labels1 := []label.KeyValue{label.String("A", "B")}
|
||||||
labels2 := []kv.KeyValue{kv.String("C", "D")}
|
labels2 := []label.KeyValue{label.String("C", "D")}
|
||||||
labels3 := []kv.KeyValue{kv.String("E", "F")}
|
labels3 := []label.KeyValue{label.String("E", "F")}
|
||||||
|
|
||||||
counter := Must(meter1).NewInt64Counter("test.counter")
|
counter := Must(meter1).NewInt64Counter("test.counter")
|
||||||
counter.Add(ctx, 1, labels1...)
|
counter.Add(ctx, 1, labels1...)
|
||||||
@ -171,7 +171,7 @@ func TestBound(t *testing.T) {
|
|||||||
// vs. the above, to cover all the instruments.
|
// vs. the above, to cover all the instruments.
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
glob := global.Meter("test")
|
glob := global.Meter("test")
|
||||||
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
labels1 := []label.KeyValue{label.String("A", "B")}
|
||||||
|
|
||||||
counter := Must(glob).NewFloat64Counter("test.counter")
|
counter := Must(glob).NewFloat64Counter("test.counter")
|
||||||
boundC := counter.Bind(labels1...)
|
boundC := counter.Bind(labels1...)
|
||||||
@ -215,7 +215,7 @@ func TestUnbind(t *testing.T) {
|
|||||||
internal.ResetForTest()
|
internal.ResetForTest()
|
||||||
|
|
||||||
glob := global.Meter("test")
|
glob := global.Meter("test")
|
||||||
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
labels1 := []label.KeyValue{label.String("A", "B")}
|
||||||
|
|
||||||
counter := Must(glob).NewFloat64Counter("test.counter")
|
counter := Must(glob).NewFloat64Counter("test.counter")
|
||||||
boundC := counter.Bind(labels1...)
|
boundC := counter.Bind(labels1...)
|
||||||
|
@ -20,10 +20,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/api/unit"
|
"go.opentelemetry.io/otel/api/unit"
|
||||||
mockTest "go.opentelemetry.io/otel/internal/metric"
|
mockTest "go.opentelemetry.io/otel/internal/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -99,7 +99,7 @@ func TestCounter(t *testing.T) {
|
|||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
c := Must(meter).NewFloat64Counter("test.counter.float")
|
c := Must(meter).NewFloat64Counter("test.counter.float")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
labels := []kv.KeyValue{kv.String("A", "B")}
|
labels := []label.KeyValue{label.String("A", "B")}
|
||||||
c.Add(ctx, 1994.1, labels...)
|
c.Add(ctx, 1994.1, labels...)
|
||||||
boundInstrument := c.Bind(labels...)
|
boundInstrument := c.Bind(labels...)
|
||||||
boundInstrument.Add(ctx, -742)
|
boundInstrument.Add(ctx, -742)
|
||||||
@ -112,7 +112,7 @@ func TestCounter(t *testing.T) {
|
|||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
c := Must(meter).NewInt64Counter("test.counter.int")
|
c := Must(meter).NewInt64Counter("test.counter.int")
|
||||||
ctx := context.Background()
|
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...)
|
c.Add(ctx, 42, labels...)
|
||||||
boundInstrument := c.Bind(labels...)
|
boundInstrument := c.Bind(labels...)
|
||||||
boundInstrument.Add(ctx, 4200)
|
boundInstrument.Add(ctx, 4200)
|
||||||
@ -126,7 +126,7 @@ func TestCounter(t *testing.T) {
|
|||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int")
|
c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int")
|
||||||
ctx := context.Background()
|
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...)
|
c.Add(ctx, 100, labels...)
|
||||||
boundInstrument := c.Bind(labels...)
|
boundInstrument := c.Bind(labels...)
|
||||||
boundInstrument.Add(ctx, -100)
|
boundInstrument.Add(ctx, -100)
|
||||||
@ -139,7 +139,7 @@ func TestCounter(t *testing.T) {
|
|||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float")
|
c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float")
|
||||||
ctx := context.Background()
|
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...)
|
c.Add(ctx, 100.1, labels...)
|
||||||
boundInstrument := c.Bind(labels...)
|
boundInstrument := c.Bind(labels...)
|
||||||
boundInstrument.Add(ctx, -76)
|
boundInstrument.Add(ctx, -76)
|
||||||
@ -155,7 +155,7 @@ func TestValueRecorder(t *testing.T) {
|
|||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float")
|
m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
labels := []kv.KeyValue{}
|
labels := []label.KeyValue{}
|
||||||
m.Record(ctx, 42, labels...)
|
m.Record(ctx, 42, labels...)
|
||||||
boundInstrument := m.Bind(labels...)
|
boundInstrument := m.Bind(labels...)
|
||||||
boundInstrument.Record(ctx, 0)
|
boundInstrument.Record(ctx, 0)
|
||||||
@ -168,7 +168,7 @@ func TestValueRecorder(t *testing.T) {
|
|||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int")
|
m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
labels := []kv.KeyValue{kv.Int("I", 1)}
|
labels := []label.KeyValue{label.Int("I", 1)}
|
||||||
m.Record(ctx, 173, labels...)
|
m.Record(ctx, 173, labels...)
|
||||||
boundInstrument := m.Bind(labels...)
|
boundInstrument := m.Bind(labels...)
|
||||||
boundInstrument.Record(ctx, 80)
|
boundInstrument.Record(ctx, 80)
|
||||||
@ -181,7 +181,7 @@ func TestValueRecorder(t *testing.T) {
|
|||||||
|
|
||||||
func TestObserverInstruments(t *testing.T) {
|
func TestObserverInstruments(t *testing.T) {
|
||||||
t.Run("float valueobserver", func(t *testing.T) {
|
t.Run("float valueobserver", func(t *testing.T) {
|
||||||
labels := []kv.KeyValue{kv.String("O", "P")}
|
labels := []label.KeyValue{label.String("O", "P")}
|
||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(42.1, labels...)
|
result.Observe(42.1, labels...)
|
||||||
@ -192,7 +192,7 @@ func TestObserverInstruments(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
t.Run("int valueobserver", func(t *testing.T) {
|
t.Run("int valueobserver", func(t *testing.T) {
|
||||||
labels := []kv.KeyValue{}
|
labels := []label.KeyValue{}
|
||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(-142, labels...)
|
result.Observe(-142, labels...)
|
||||||
@ -203,7 +203,7 @@ func TestObserverInstruments(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
t.Run("float sumobserver", func(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()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(42.1, labels...)
|
result.Observe(42.1, labels...)
|
||||||
@ -214,7 +214,7 @@ func TestObserverInstruments(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
t.Run("int sumobserver", func(t *testing.T) {
|
t.Run("int sumobserver", func(t *testing.T) {
|
||||||
labels := []kv.KeyValue{}
|
labels := []label.KeyValue{}
|
||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(-142, labels...)
|
result.Observe(-142, labels...)
|
||||||
@ -225,7 +225,7 @@ func TestObserverInstruments(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
t.Run("float updownsumobserver", func(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()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(42.1, labels...)
|
result.Observe(42.1, labels...)
|
||||||
@ -236,7 +236,7 @@ func TestObserverInstruments(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
t.Run("int updownsumobserver", func(t *testing.T) {
|
t.Run("int updownsumobserver", func(t *testing.T) {
|
||||||
labels := []kv.KeyValue{}
|
labels := []label.KeyValue{}
|
||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(-142, labels...)
|
result.Observe(-142, labels...)
|
||||||
@ -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()
|
t.Helper()
|
||||||
if len(mock.MeasurementBatches) != 3 {
|
if len(mock.MeasurementBatches) != 3 {
|
||||||
t.Errorf("Expected 3 recorded measurement batches, got %d", len(mock.MeasurementBatches))
|
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 obs1 metric.Int64ValueObserver
|
||||||
var obs2 metric.Float64ValueObserver
|
var obs2 metric.Float64ValueObserver
|
||||||
|
|
||||||
labels := []kv.KeyValue{
|
labels := []label.KeyValue{
|
||||||
kv.String("A", "B"),
|
label.String("A", "B"),
|
||||||
kv.String("C", "D"),
|
label.String("C", "D"),
|
||||||
}
|
}
|
||||||
|
|
||||||
cb := Must(meter).NewBatchObserver(
|
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)))
|
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()
|
t.Helper()
|
||||||
assert.Len(t, mock.MeasurementBatches, 1)
|
assert.Len(t, mock.MeasurementBatches, 1)
|
||||||
if len(mock.MeasurementBatches) < 1 {
|
if len(mock.MeasurementBatches) < 1 {
|
||||||
@ -374,7 +374,7 @@ type testWrappedMeter struct {
|
|||||||
|
|
||||||
var _ metric.MeterImpl = testWrappedMeter{}
|
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) {
|
func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {
|
||||||
|
@ -17,7 +17,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The file is organized as follows:
|
// The file is organized as follows:
|
||||||
@ -57,25 +57,25 @@ type BatchObserverFunc func(context.Context, BatchObserverResult)
|
|||||||
// observations for one asynchronous integer metric instrument.
|
// observations for one asynchronous integer metric instrument.
|
||||||
type Int64ObserverResult struct {
|
type Int64ObserverResult struct {
|
||||||
instrument AsyncImpl
|
instrument AsyncImpl
|
||||||
function func([]kv.KeyValue, ...Observation)
|
function func([]label.KeyValue, ...Observation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Float64ObserverResult is passed to an observer callback to capture
|
// Float64ObserverResult is passed to an observer callback to capture
|
||||||
// observations for one asynchronous floating point metric instrument.
|
// observations for one asynchronous floating point metric instrument.
|
||||||
type Float64ObserverResult struct {
|
type Float64ObserverResult struct {
|
||||||
instrument AsyncImpl
|
instrument AsyncImpl
|
||||||
function func([]kv.KeyValue, ...Observation)
|
function func([]label.KeyValue, ...Observation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchObserverResult is passed to a batch observer callback to
|
// BatchObserverResult is passed to a batch observer callback to
|
||||||
// capture observations for multiple asynchronous instruments.
|
// capture observations for multiple asynchronous instruments.
|
||||||
type BatchObserverResult struct {
|
type BatchObserverResult struct {
|
||||||
function func([]kv.KeyValue, ...Observation)
|
function func([]label.KeyValue, ...Observation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observe captures a single integer value from the associated
|
// Observe captures a single integer value from the associated
|
||||||
// instrument callback, with the given labels.
|
// instrument callback, with the given labels.
|
||||||
func (ir Int64ObserverResult) Observe(value int64, labels ...kv.KeyValue) {
|
func (ir Int64ObserverResult) Observe(value int64, labels ...label.KeyValue) {
|
||||||
ir.function(labels, Observation{
|
ir.function(labels, Observation{
|
||||||
instrument: ir.instrument,
|
instrument: ir.instrument,
|
||||||
number: NewInt64Number(value),
|
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
|
// Observe captures a single floating point value from the associated
|
||||||
// instrument callback, with the given labels.
|
// instrument callback, with the given labels.
|
||||||
func (fr Float64ObserverResult) Observe(value float64, labels ...kv.KeyValue) {
|
func (fr Float64ObserverResult) Observe(value float64, labels ...label.KeyValue) {
|
||||||
fr.function(labels, Observation{
|
fr.function(labels, Observation{
|
||||||
instrument: fr.instrument,
|
instrument: fr.instrument,
|
||||||
number: NewFloat64Number(value),
|
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
|
// Observe captures a multiple observations from the associated batch
|
||||||
// instrument callback, with the given labels.
|
// instrument callback, with the given labels.
|
||||||
func (br BatchObserverResult) Observe(labels []kv.KeyValue, obs ...Observation) {
|
func (br BatchObserverResult) Observe(labels []label.KeyValue, obs ...Observation) {
|
||||||
br.function(labels, obs...)
|
br.function(labels, obs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ type AsyncSingleRunner interface {
|
|||||||
// receives one captured observation. (The function accepts
|
// receives one captured observation. (The function accepts
|
||||||
// multiple observations so the same implementation can be
|
// multiple observations so the same implementation can be
|
||||||
// used for batch runners.)
|
// used for batch runners.)
|
||||||
Run(ctx context.Context, single AsyncImpl, capture func([]kv.KeyValue, ...Observation))
|
Run(ctx context.Context, single AsyncImpl, capture func([]label.KeyValue, ...Observation))
|
||||||
|
|
||||||
AsyncRunner
|
AsyncRunner
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ type AsyncSingleRunner interface {
|
|||||||
type AsyncBatchRunner interface {
|
type AsyncBatchRunner interface {
|
||||||
// Run accepts a function for capturing observations of
|
// Run accepts a function for capturing observations of
|
||||||
// multiple instruments.
|
// multiple instruments.
|
||||||
Run(ctx context.Context, capture func([]kv.KeyValue, ...Observation))
|
Run(ctx context.Context, capture func([]label.KeyValue, ...Observation))
|
||||||
|
|
||||||
AsyncRunner
|
AsyncRunner
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ func (*Float64ObserverFunc) AnyRunner() {}
|
|||||||
func (*BatchObserverFunc) AnyRunner() {}
|
func (*BatchObserverFunc) AnyRunner() {}
|
||||||
|
|
||||||
// Run implements AsyncSingleRunner.
|
// Run implements AsyncSingleRunner.
|
||||||
func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
|
func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) {
|
||||||
(*i)(ctx, Int64ObserverResult{
|
(*i)(ctx, Int64ObserverResult{
|
||||||
instrument: impl,
|
instrument: impl,
|
||||||
function: function,
|
function: function,
|
||||||
@ -166,7 +166,7 @@ func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function fu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run implements AsyncSingleRunner.
|
// Run implements AsyncSingleRunner.
|
||||||
func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
|
func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]label.KeyValue, ...Observation)) {
|
||||||
(*f)(ctx, Float64ObserverResult{
|
(*f)(ctx, Float64ObserverResult{
|
||||||
instrument: impl,
|
instrument: impl,
|
||||||
function: function,
|
function: function,
|
||||||
@ -174,7 +174,7 @@ func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run implements AsyncBatchRunner.
|
// Run implements AsyncBatchRunner.
|
||||||
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]kv.KeyValue, ...Observation)) {
|
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]label.KeyValue, ...Observation)) {
|
||||||
(*b)(ctx, BatchObserverResult{
|
(*b)(ctx, BatchObserverResult{
|
||||||
function: function,
|
function: function,
|
||||||
})
|
})
|
||||||
|
@ -17,7 +17,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Float64Counter is a metric that accumulates float64 values.
|
// 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
|
// Bind creates a bound instrument for this counter. The labels are
|
||||||
// associated with values recorded via subsequent calls to Record.
|
// associated with values recorded via subsequent calls to Record.
|
||||||
func (c Float64Counter) Bind(labels ...kv.KeyValue) (h BoundFloat64Counter) {
|
func (c Float64Counter) Bind(labels ...label.KeyValue) (h BoundFloat64Counter) {
|
||||||
h.syncBoundInstrument = c.bind(labels)
|
h.syncBoundInstrument = c.bind(labels)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind creates a bound instrument for this counter. The labels are
|
// Bind creates a bound instrument for this counter. The labels are
|
||||||
// associated with values recorded via subsequent calls to Record.
|
// associated with values recorded via subsequent calls to Record.
|
||||||
func (c Int64Counter) Bind(labels ...kv.KeyValue) (h BoundInt64Counter) {
|
func (c Int64Counter) Bind(labels ...label.KeyValue) (h BoundInt64Counter) {
|
||||||
h.syncBoundInstrument = c.bind(labels)
|
h.syncBoundInstrument = c.bind(labels)
|
||||||
return
|
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
|
// Add adds the value to the counter's sum. The labels should contain
|
||||||
// the keys and values to be associated with this value.
|
// the keys and values to be associated with this value.
|
||||||
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...kv.KeyValue) {
|
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...label.KeyValue) {
|
||||||
c.directRecord(ctx, NewFloat64Number(value), labels)
|
c.directRecord(ctx, NewFloat64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the value to the counter's sum. The labels should contain
|
// Add adds the value to the counter's sum. The labels should contain
|
||||||
// the keys and values to be associated with this value.
|
// the keys and values to be associated with this value.
|
||||||
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...kv.KeyValue) {
|
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...label.KeyValue) {
|
||||||
c.directRecord(ctx, NewInt64Number(value), labels)
|
c.directRecord(ctx, NewInt64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The file is organized as follows:
|
// The file is organized as follows:
|
||||||
@ -52,7 +52,7 @@ type Meter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RecordBatch atomically records a batch of measurements.
|
// RecordBatch atomically records a batch of measurements.
|
||||||
func (m Meter) RecordBatch(ctx context.Context, ls []kv.KeyValue, ms ...Measurement) {
|
func (m Meter) RecordBatch(ctx context.Context, ls []label.KeyValue, ms ...Measurement) {
|
||||||
if m.impl == nil {
|
if m.impl == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NoopProvider struct{}
|
type NoopProvider struct{}
|
||||||
@ -50,9 +50,9 @@ func (noopBoundInstrument) RecordOne(context.Context, Number) {
|
|||||||
func (noopBoundInstrument) Unbind() {
|
func (noopBoundInstrument) Unbind() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NoopSync) Bind([]kv.KeyValue) BoundSyncImpl {
|
func (NoopSync) Bind([]label.KeyValue) BoundSyncImpl {
|
||||||
return noopBoundInstrument{}
|
return noopBoundInstrument{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NoopSync) RecordOne(context.Context, Number, []kv.KeyValue) {
|
func (NoopSync) RecordOne(context.Context, Number, []label.KeyValue) {
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/internal"
|
"go.opentelemetry.io/otel/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NumberKind describes the data type of the Number.
|
// NumberKind describes the data type of the Number.
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider is a standard metric.Provider for wrapping `MeterImpl`
|
// Provider is a standard metric.Provider for wrapping `MeterImpl`
|
||||||
@ -75,7 +75,7 @@ func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RecordBatch implements metric.MeterImpl.
|
// RecordBatch implements metric.MeterImpl.
|
||||||
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, ms ...metric.Measurement) {
|
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, ms ...metric.Measurement) {
|
||||||
u.impl.RecordBatch(ctx, labels, ms...)
|
u.impl.RecordBatch(ctx, labels, ms...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,14 +17,14 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MeterImpl is the interface an SDK must implement to supply a Meter
|
// MeterImpl is the interface an SDK must implement to supply a Meter
|
||||||
// implementation.
|
// implementation.
|
||||||
type MeterImpl interface {
|
type MeterImpl interface {
|
||||||
// RecordBatch atomically records a batch of measurements.
|
// RecordBatch atomically records a batch of measurements.
|
||||||
RecordBatch(context.Context, []kv.KeyValue, ...Measurement)
|
RecordBatch(context.Context, []label.KeyValue, ...Measurement)
|
||||||
|
|
||||||
// NewSyncInstrument returns a newly constructed
|
// NewSyncInstrument returns a newly constructed
|
||||||
// synchronous instrument implementation or an error, should
|
// synchronous instrument implementation or an error, should
|
||||||
@ -59,10 +59,10 @@ type SyncImpl interface {
|
|||||||
|
|
||||||
// Bind creates an implementation-level bound instrument,
|
// Bind creates an implementation-level bound instrument,
|
||||||
// binding a label set with this instrument implementation.
|
// binding a label set with this instrument implementation.
|
||||||
Bind(labels []kv.KeyValue) BoundSyncImpl
|
Bind(labels []label.KeyValue) BoundSyncImpl
|
||||||
|
|
||||||
// RecordOne captures a single synchronous metric event.
|
// 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
|
// BoundSyncImpl is the implementation-level interface to a
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
|
// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
|
||||||
@ -82,7 +82,7 @@ func (s syncInstrument) SyncImpl() SyncImpl {
|
|||||||
return s.instrument
|
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))
|
return newSyncBoundInstrument(s.instrument.Bind(labels))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func (s syncInstrument) int64Measurement(value int64) Measurement {
|
|||||||
return newMeasurement(s.instrument, NewInt64Number(value))
|
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)
|
s.instrument.RecordOne(ctx, number, labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Float64UpDownCounter is a metric instrument that sums floating
|
// 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
|
// Bind creates a bound instrument for this counter. The labels are
|
||||||
// associated with values recorded via subsequent calls to Record.
|
// associated with values recorded via subsequent calls to Record.
|
||||||
func (c Float64UpDownCounter) Bind(labels ...kv.KeyValue) (h BoundFloat64UpDownCounter) {
|
func (c Float64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundFloat64UpDownCounter) {
|
||||||
h.syncBoundInstrument = c.bind(labels)
|
h.syncBoundInstrument = c.bind(labels)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind creates a bound instrument for this counter. The labels are
|
// Bind creates a bound instrument for this counter. The labels are
|
||||||
// associated with values recorded via subsequent calls to Record.
|
// associated with values recorded via subsequent calls to Record.
|
||||||
func (c Int64UpDownCounter) Bind(labels ...kv.KeyValue) (h BoundInt64UpDownCounter) {
|
func (c Int64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundInt64UpDownCounter) {
|
||||||
h.syncBoundInstrument = c.bind(labels)
|
h.syncBoundInstrument = c.bind(labels)
|
||||||
return
|
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
|
// Add adds the value to the counter's sum. The labels should contain
|
||||||
// the keys and values to be associated with this value.
|
// the keys and values to be associated with this value.
|
||||||
func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...kv.KeyValue) {
|
func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...label.KeyValue) {
|
||||||
c.directRecord(ctx, NewFloat64Number(value), labels)
|
c.directRecord(ctx, NewFloat64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the value to the counter's sum. The labels should contain
|
// Add adds the value to the counter's sum. The labels should contain
|
||||||
// the keys and values to be associated with this value.
|
// the keys and values to be associated with this value.
|
||||||
func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...kv.KeyValue) {
|
func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...label.KeyValue) {
|
||||||
c.directRecord(ctx, NewInt64Number(value), labels)
|
c.directRecord(ctx, NewInt64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Float64ValueRecorder is a metric that records float64 values.
|
// 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
|
// Bind creates a bound instrument for this ValueRecorder. The labels are
|
||||||
// associated with values recorded via subsequent calls to Record.
|
// associated with values recorded via subsequent calls to Record.
|
||||||
func (c Float64ValueRecorder) Bind(labels ...kv.KeyValue) (h BoundFloat64ValueRecorder) {
|
func (c Float64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundFloat64ValueRecorder) {
|
||||||
h.syncBoundInstrument = c.bind(labels)
|
h.syncBoundInstrument = c.bind(labels)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind creates a bound instrument for this ValueRecorder. The labels are
|
// Bind creates a bound instrument for this ValueRecorder. The labels are
|
||||||
// associated with values recorded via subsequent calls to Record.
|
// associated with values recorded via subsequent calls to Record.
|
||||||
func (c Int64ValueRecorder) Bind(labels ...kv.KeyValue) (h BoundInt64ValueRecorder) {
|
func (c Int64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundInt64ValueRecorder) {
|
||||||
h.syncBoundInstrument = c.bind(labels)
|
h.syncBoundInstrument = c.bind(labels)
|
||||||
return
|
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
|
// Record adds a new value to the list of ValueRecorder's records. The
|
||||||
// labels should contain the keys and values to be associated with
|
// labels should contain the keys and values to be associated with
|
||||||
// this value.
|
// this value.
|
||||||
func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...kv.KeyValue) {
|
func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...label.KeyValue) {
|
||||||
c.directRecord(ctx, NewFloat64Number(value), labels)
|
c.directRecord(ctx, NewFloat64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record adds a new value to the ValueRecorder's distribution. The
|
// Record adds a new value to the ValueRecorder's distribution. The
|
||||||
// labels should contain the keys and values to be associated with
|
// labels should contain the keys and values to be associated with
|
||||||
// this value.
|
// this value.
|
||||||
func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...kv.KeyValue) {
|
func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...label.KeyValue) {
|
||||||
c.directRecord(ctx, NewInt64Number(value), labels)
|
c.directRecord(ctx, NewInt64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
@ -103,10 +103,10 @@ type Span interface {
|
|||||||
End(options ...EndOption)
|
End(options ...EndOption)
|
||||||
|
|
||||||
// AddEvent adds an event to the span.
|
// 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
|
// AddEventWithTimestamp adds an event with a custom timestamp
|
||||||
// to the span.
|
// 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 returns true if the span is active and recording events is enabled.
|
||||||
IsRecording() bool
|
IsRecording() bool
|
||||||
@ -131,7 +131,7 @@ type Span interface {
|
|||||||
SetName(name string)
|
SetName(name string)
|
||||||
|
|
||||||
// Set span attributes
|
// Set span attributes
|
||||||
SetAttributes(...kv.KeyValue)
|
SetAttributes(...label.KeyValue)
|
||||||
|
|
||||||
// Set singular span attribute, with type inference.
|
// Set singular span attribute, with type inference.
|
||||||
SetAttribute(string, interface{})
|
SetAttribute(string, interface{})
|
||||||
@ -143,7 +143,7 @@ type StartOption func(*StartConfig)
|
|||||||
// StartConfig provides options to set properties of span at the time of starting
|
// StartConfig provides options to set properties of span at the time of starting
|
||||||
// a new span.
|
// a new span.
|
||||||
type StartConfig struct {
|
type StartConfig struct {
|
||||||
Attributes []kv.KeyValue
|
Attributes []label.KeyValue
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
Links []Link
|
Links []Link
|
||||||
Record bool
|
Record bool
|
||||||
@ -164,7 +164,7 @@ type StartConfig struct {
|
|||||||
// be correlated.
|
// be correlated.
|
||||||
type Link struct {
|
type Link struct {
|
||||||
SpanContext
|
SpanContext
|
||||||
Attributes []kv.KeyValue
|
Attributes []label.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpanKind represents the role of a Span inside a Trace. Often, this defines how a Span
|
// 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
|
// WithAttributes sets attributes to span. These attributes provides additional
|
||||||
// data about the span.
|
// data about the span.
|
||||||
// Multiple `WithAttributes` options appends the attributes preserving the order.
|
// 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) {
|
return func(c *StartConfig) {
|
||||||
c.Attributes = append(c.Attributes, attrs...)
|
c.Attributes = append(c.Attributes, attrs...)
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ func WithNewRoot() StartOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LinkedTo allows instantiating a Span with initial Links.
|
// 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) {
|
return func(c *StartConfig) {
|
||||||
c.Links = append(c.Links, Link{sc, attrs})
|
c.Links = append(c.Links, Link{sc, attrs})
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetCurrentSpanOverridesPreviouslySetSpan(t *testing.T) {
|
func TestSetCurrentSpanOverridesPreviouslySetSpan(t *testing.T) {
|
||||||
@ -93,7 +93,7 @@ func (mockSpan) SetError(v bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAttributes does nothing.
|
// SetAttributes does nothing.
|
||||||
func (mockSpan) SetAttributes(attributes ...kv.KeyValue) {
|
func (mockSpan) SetAttributes(attributes ...label.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttribute does nothing.
|
// SetAttribute does nothing.
|
||||||
@ -114,9 +114,9 @@ func (mockSpan) Tracer() trace.Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event does nothing.
|
// 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.
|
// 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) {
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NoopSpan struct {
|
type NoopSpan struct {
|
||||||
@ -46,7 +46,7 @@ func (NoopSpan) SetError(v bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAttributes does nothing.
|
// SetAttributes does nothing.
|
||||||
func (NoopSpan) SetAttributes(attributes ...kv.KeyValue) {
|
func (NoopSpan) SetAttributes(attributes ...label.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttribute does nothing.
|
// SetAttribute does nothing.
|
||||||
@ -67,11 +67,11 @@ func (NoopSpan) Tracer() Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent does nothing.
|
// 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.
|
// 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.
|
// SetName does nothing.
|
||||||
|
@ -17,12 +17,12 @@ package tracetest
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp.
|
// Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
Name string
|
Name string
|
||||||
Attributes map[kv.Key]kv.Value
|
Attributes map[label.Key]label.Value
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
errorTypeKey = kv.Key("error.type")
|
errorTypeKey = label.Key("error.type")
|
||||||
errorMessageKey = kv.Key("error.message")
|
errorMessageKey = label.Key("error.message")
|
||||||
errorEventName = "error"
|
errorEventName = "error"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,9 +45,9 @@ type Span struct {
|
|||||||
endTime time.Time
|
endTime time.Time
|
||||||
statusCode codes.Code
|
statusCode codes.Code
|
||||||
statusMessage string
|
statusMessage string
|
||||||
attributes map[kv.Key]kv.Value
|
attributes map[label.Key]label.Value
|
||||||
events []Event
|
events []Event
|
||||||
links map[trace.SpanContext][]kv.KeyValue
|
links map[trace.SpanContext][]label.KeyValue
|
||||||
spanKind trace.SpanKind
|
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...)
|
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()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, n
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes := make(map[kv.Key]kv.Value)
|
attributes := make(map[label.Key]label.Value)
|
||||||
|
|
||||||
for _, attr := range attrs {
|
for _, attr := range attrs {
|
||||||
attributes[attr.Key] = attr.Value
|
attributes[attr.Key] = attr.Value
|
||||||
@ -166,7 +166,7 @@ func (s *Span) SetName(name string) {
|
|||||||
s.name = name
|
s.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Span) SetAttributes(attrs ...kv.KeyValue) {
|
func (s *Span) SetAttributes(attrs ...label.KeyValue) {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ func (s *Span) SetAttributes(attrs ...kv.KeyValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Span) SetAttribute(k string, v interface{}) {
|
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.
|
// 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.
|
// 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.
|
// 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.
|
// 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()
|
s.lock.RLock()
|
||||||
defer s.lock.RUnlock()
|
defer s.lock.RUnlock()
|
||||||
|
|
||||||
attributes := make(map[kv.Key]kv.Value)
|
attributes := make(map[label.Key]label.Value)
|
||||||
|
|
||||||
for k, v := range s.attributes {
|
for k, v := range s.attributes {
|
||||||
attributes[k] = v
|
attributes[k] = v
|
||||||
@ -220,11 +220,11 @@ func (s *Span) Events() []Event {
|
|||||||
|
|
||||||
// Links returns the links set on the Span at creation time.
|
// 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.
|
// If multiple links for the same SpanContext were set, the last link will be used.
|
||||||
func (s *Span) Links() map[trace.SpanContext][]kv.KeyValue {
|
func (s *Span) Links() map[trace.SpanContext][]label.KeyValue {
|
||||||
links := make(map[trace.SpanContext][]kv.KeyValue)
|
links := make(map[trace.SpanContext][]label.KeyValue)
|
||||||
|
|
||||||
for sc, attributes := range s.links {
|
for sc, attributes := range s.links {
|
||||||
links[sc] = append([]kv.KeyValue{}, attributes...)
|
links[sc] = append([]label.KeyValue{}, attributes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return links
|
return links
|
||||||
|
@ -22,12 +22,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/api/trace/tracetest"
|
"go.opentelemetry.io/otel/api/trace/tracetest"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
"go.opentelemetry.io/otel/internal/matchers"
|
"go.opentelemetry.io/otel/internal/matchers"
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSpan(t *testing.T) {
|
func TestSpan(t *testing.T) {
|
||||||
@ -161,9 +161,9 @@ func TestSpan(t *testing.T) {
|
|||||||
expectedEvents := []tracetest.Event{{
|
expectedEvents := []tracetest.Event{{
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
Name: "error",
|
Name: "error",
|
||||||
Attributes: map[kv.Key]kv.Value{
|
Attributes: map[label.Key]label.Value{
|
||||||
kv.Key("error.type"): kv.StringValue(s.typ),
|
label.Key("error.type"): label.StringValue(s.typ),
|
||||||
kv.Key("error.message"): kv.StringValue(s.msg),
|
label.Key("error.message"): label.StringValue(s.msg),
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
e.Expect(subject.Events()).ToEqual(expectedEvents)
|
e.Expect(subject.Events()).ToEqual(expectedEvents)
|
||||||
@ -192,9 +192,9 @@ func TestSpan(t *testing.T) {
|
|||||||
expectedEvents := []tracetest.Event{{
|
expectedEvents := []tracetest.Event{{
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
Name: "error",
|
Name: "error",
|
||||||
Attributes: map[kv.Key]kv.Value{
|
Attributes: map[label.Key]label.Value{
|
||||||
kv.Key("error.type"): kv.StringValue("go.opentelemetry.io/otel/internal/testing.TestError"),
|
label.Key("error.type"): label.StringValue("go.opentelemetry.io/otel/internal/testing.TestError"),
|
||||||
kv.Key("error.message"): kv.StringValue(errMsg),
|
label.Key("error.message"): label.StringValue(errMsg),
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
e.Expect(subject.Events()).ToEqual(expectedEvents)
|
e.Expect(subject.Events()).ToEqual(expectedEvents)
|
||||||
@ -331,7 +331,7 @@ func TestSpan(t *testing.T) {
|
|||||||
subject, ok := span.(*tracetest.Span)
|
subject, ok := span.(*tracetest.Span)
|
||||||
e.Expect(ok).ToBeTrue()
|
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) {
|
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)
|
subject, ok := span.(*tracetest.Span)
|
||||||
e.Expect(ok).ToBeTrue()
|
e.Expect(ok).ToBeTrue()
|
||||||
|
|
||||||
attr1 := kv.String("key1", "value1")
|
attr1 := label.String("key1", "value1")
|
||||||
attr2 := kv.String("key2", "value2")
|
attr2 := label.String("key2", "value2")
|
||||||
attr3 := kv.String("key3", "value3")
|
attr3 := label.String("key3", "value3")
|
||||||
unexpectedAttr := attr2.Key.String("unexpected")
|
unexpectedAttr := attr2.Key.String("unexpected")
|
||||||
|
|
||||||
subject.SetAttributes(attr1, unexpectedAttr, attr3)
|
subject.SetAttributes(attr1, unexpectedAttr, attr3)
|
||||||
@ -371,7 +371,7 @@ func TestSpan(t *testing.T) {
|
|||||||
subject, ok := span.(*tracetest.Span)
|
subject, ok := span.(*tracetest.Span)
|
||||||
e.Expect(ok).ToBeTrue()
|
e.Expect(ok).ToBeTrue()
|
||||||
|
|
||||||
expectedAttr := kv.String("key", "value")
|
expectedAttr := label.String("key", "value")
|
||||||
subject.SetAttributes(expectedAttr)
|
subject.SetAttributes(expectedAttr)
|
||||||
subject.End()
|
subject.End()
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ func TestSpan(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
subject.SetAttributes(kv.String("key", "value"))
|
subject.SetAttributes(label.String("key", "value"))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -459,9 +459,9 @@ func TestSpan(t *testing.T) {
|
|||||||
e.Expect(ok).ToBeTrue()
|
e.Expect(ok).ToBeTrue()
|
||||||
|
|
||||||
event1Name := "event1"
|
event1Name := "event1"
|
||||||
event1Attributes := []kv.KeyValue{
|
event1Attributes := []label.KeyValue{
|
||||||
kv.String("event1Attr1", "foo"),
|
label.String("event1Attr1", "foo"),
|
||||||
kv.String("event1Attr2", "bar"),
|
label.String("event1Attr2", "bar"),
|
||||||
}
|
}
|
||||||
|
|
||||||
event1Start := time.Now()
|
event1Start := time.Now()
|
||||||
@ -470,8 +470,8 @@ func TestSpan(t *testing.T) {
|
|||||||
|
|
||||||
event2Timestamp := time.Now().AddDate(5, 0, 0)
|
event2Timestamp := time.Now().AddDate(5, 0, 0)
|
||||||
event2Name := "event1"
|
event2Name := "event1"
|
||||||
event2Attributes := []kv.KeyValue{
|
event2Attributes := []label.KeyValue{
|
||||||
kv.String("event2Attr", "abc"),
|
label.String("event2Attr", "abc"),
|
||||||
}
|
}
|
||||||
|
|
||||||
subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Name, event2Attributes...)
|
subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Name, event2Attributes...)
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ trace.Tracer = (*Tracer)(nil)
|
var _ trace.Tracer = (*Tracer)(nil)
|
||||||
@ -48,20 +48,20 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti
|
|||||||
span := &Span{
|
span := &Span{
|
||||||
tracer: t,
|
tracer: t,
|
||||||
startTime: startTime,
|
startTime: startTime,
|
||||||
attributes: make(map[kv.Key]kv.Value),
|
attributes: make(map[label.Key]label.Value),
|
||||||
links: make(map[trace.SpanContext][]kv.KeyValue),
|
links: make(map[trace.SpanContext][]label.KeyValue),
|
||||||
spanKind: c.SpanKind,
|
spanKind: c.SpanKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.NewRoot {
|
if c.NewRoot {
|
||||||
span.spanContext = trace.EmptySpanContext()
|
span.spanContext = trace.EmptySpanContext()
|
||||||
|
|
||||||
iodKey := kv.Key("ignored-on-demand")
|
iodKey := label.Key("ignored-on-demand")
|
||||||
if lsc := trace.SpanFromContext(ctx).SpanContext(); lsc.IsValid() {
|
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() {
|
if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() {
|
||||||
span.links[rsc] = []kv.KeyValue{iodKey.String("remote")}
|
span.links[rsc] = []label.KeyValue{iodKey.String("remote")}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
span.spanContext = t.config.SpanContextFunc(ctx)
|
span.spanContext = t.config.SpanContextFunc(ctx)
|
||||||
|
@ -23,10 +23,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/apitest"
|
"go.opentelemetry.io/otel/api/apitest"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/api/trace/tracetest"
|
"go.opentelemetry.io/otel/api/trace/tracetest"
|
||||||
"go.opentelemetry.io/otel/internal/matchers"
|
"go.opentelemetry.io/otel/internal/matchers"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTracer(t *testing.T) {
|
func TestTracer(t *testing.T) {
|
||||||
@ -68,8 +68,8 @@ func TestTracer(t *testing.T) {
|
|||||||
|
|
||||||
e := matchers.NewExpecter(t)
|
e := matchers.NewExpecter(t)
|
||||||
|
|
||||||
attr1 := kv.String("a", "1")
|
attr1 := label.String("a", "1")
|
||||||
attr2 := kv.String("b", "2")
|
attr2 := label.String("b", "2")
|
||||||
|
|
||||||
subject := tp.Tracer(t.Name())
|
subject := tp.Tracer(t.Name())
|
||||||
_, span := subject.Start(context.Background(), "test", trace.WithAttributes(attr1, attr2))
|
_, span := subject.Start(context.Background(), "test", trace.WithAttributes(attr1, attr2))
|
||||||
@ -201,14 +201,14 @@ func TestTracer(t *testing.T) {
|
|||||||
expectedLinks := []trace.Link{
|
expectedLinks := []trace.Link{
|
||||||
{
|
{
|
||||||
SpanContext: parentSpanContext,
|
SpanContext: parentSpanContext,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("ignored-on-demand", "current"),
|
label.String("ignored-on-demand", "current"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SpanContext: remoteParentSpanContext,
|
SpanContext: remoteParentSpanContext,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("ignored-on-demand", "remote"),
|
label.String("ignored-on-demand", "remote"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -233,16 +233,16 @@ func TestTracer(t *testing.T) {
|
|||||||
_, span := subject.Start(context.Background(), "link1")
|
_, span := subject.Start(context.Background(), "link1")
|
||||||
link1 := trace.Link{
|
link1 := trace.Link{
|
||||||
SpanContext: span.SpanContext(),
|
SpanContext: span.SpanContext(),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("a", "1"),
|
label.String("a", "1"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, span = subject.Start(context.Background(), "link2")
|
_, span = subject.Start(context.Background(), "link2")
|
||||||
link2 := trace.Link{
|
link2 := trace.Link{
|
||||||
SpanContext: span.SpanContext(),
|
SpanContext: span.SpanContext(),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("b", "2"),
|
label.String("b", "2"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,11 @@ import (
|
|||||||
|
|
||||||
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
||||||
otelglobal "go.opentelemetry.io/otel/api/global"
|
otelglobal "go.opentelemetry.io/otel/api/global"
|
||||||
otelcore "go.opentelemetry.io/otel/api/kv"
|
|
||||||
otelpropagation "go.opentelemetry.io/otel/api/propagation"
|
otelpropagation "go.opentelemetry.io/otel/api/propagation"
|
||||||
oteltrace "go.opentelemetry.io/otel/api/trace"
|
oteltrace "go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
|
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/bridge/opentracing/migration"
|
"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) {
|
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())
|
return handler(string(kv.Key), kv.Value.Emit())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
|
func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
|
||||||
crk := http.CanonicalHeaderKey(restrictedKey)
|
crk := http.CanonicalHeaderKey(restrictedKey)
|
||||||
c.baggageItems = c.baggageItems.Apply(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 {
|
func (c *bridgeSpanContext) baggageItem(restrictedKey string) string {
|
||||||
crk := http.CanonicalHeaderKey(restrictedKey)
|
crk := http.CanonicalHeaderKey(restrictedKey)
|
||||||
val, _ := c.baggageItems.Value(otelcore.Key(crk))
|
val, _ := c.baggageItems.Value(label.Key(crk))
|
||||||
return val.Emit()
|
return val.Emit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *bridgeSpan) logRecord(record ot.LogRecord) {
|
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 {
|
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, "")
|
s.otelSpan.SetStatus(codes.Unknown, "")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
s.otelSpan.SetAttributes(otTagToOtelCoreKeyValue(key, value))
|
s.otelSpan.SetAttributes(otTagToOTelLabel(key, value))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *bridgeSpan) LogFields(fields ...otlog.Field) {
|
func (s *bridgeSpan) LogFields(fields ...otlog.Field) {
|
||||||
s.otelSpan.AddEvent(context.Background(), "", otLogFieldsToOtelCoreKeyValues(fields)...)
|
s.otelSpan.AddEvent(context.Background(), "", otLogFieldsToOTelLabels(fields)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type bridgeFieldEncoder struct {
|
type bridgeFieldEncoder struct {
|
||||||
pairs []otelcore.KeyValue
|
pairs []label.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ otlog.Encoder = &bridgeFieldEncoder{}
|
var _ otlog.Encoder = &bridgeFieldEncoder{}
|
||||||
@ -195,10 +195,10 @@ func (e *bridgeFieldEncoder) EmitLazyLogger(value otlog.LazyLogger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *bridgeFieldEncoder) emitCommon(key string, value interface{}) {
|
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{}
|
encoder := &bridgeFieldEncoder{}
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
field.Marshal(encoder)
|
field.Marshal(encoder)
|
||||||
@ -215,7 +215,7 @@ func (s *bridgeSpan) LogKV(alternatingKeyValues ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *bridgeSpan) SetBaggageItem(restrictedKey, value string) ot.Span {
|
func (s *bridgeSpan) SetBaggageItem(restrictedKey, value string) ot.Span {
|
||||||
s.updateOtelContext(restrictedKey, value)
|
s.updateOTelContext(restrictedKey, value)
|
||||||
s.setBaggageItemOnly(restrictedKey, value)
|
s.setBaggageItemOnly(restrictedKey, value)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ func (s *bridgeSpan) setBaggageItemOnly(restrictedKey, value string) {
|
|||||||
s.ctx.setBaggageItem(restrictedKey, value)
|
s.ctx.setBaggageItem(restrictedKey, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *bridgeSpan) updateOtelContext(restrictedKey, value string) {
|
func (s *bridgeSpan) updateOTelContext(restrictedKey, value string) {
|
||||||
if s.extraBaggageItems == nil {
|
if s.extraBaggageItems == nil {
|
||||||
s.extraBaggageItems = make(map[string]string)
|
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.
|
// context, so we don't care about the old hooks.
|
||||||
clearCtx, _, _ := otelcorrelation.ContextWithNoHooks(ctx)
|
clearCtx, _, _ := otelcorrelation.ContextWithNoHooks(ctx)
|
||||||
m := otelcorrelation.MapFromContext(clearCtx)
|
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())
|
bSpan.setBaggageItemOnly(string(kv.Key), kv.Value.Emit())
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -369,9 +369,9 @@ func (t *BridgeTracer) correlationGetHook(ctx context.Context, m otelcorrelation
|
|||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
kv := make([]otelcore.KeyValue, 0, len(items))
|
kv := make([]label.KeyValue, 0, len(items))
|
||||||
for k, v := range 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})
|
return m.Apply(otelcorrelation.MapUpdate{MultiKV: kv})
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
|
|||||||
opt.Apply(&sso)
|
opt.Apply(&sso)
|
||||||
}
|
}
|
||||||
parentBridgeSC, links := otSpanReferencesToParentAndLinks(sso.References)
|
parentBridgeSC, links := otSpanReferencesToParentAndLinks(sso.References)
|
||||||
attributes, kind, hadTrueErrorTag := otTagsToOtelAttributesKindAndError(sso.Tags)
|
attributes, kind, hadTrueErrorTag := otTagsToOTelAttributesKindAndError(sso.Tags)
|
||||||
checkCtx := migration.WithDeferredSetup(context.Background())
|
checkCtx := migration.WithDeferredSetup(context.Background())
|
||||||
if parentBridgeSC != nil {
|
if parentBridgeSC != nil {
|
||||||
checkCtx = oteltrace.ContextWithRemoteSpanContext(checkCtx, parentBridgeSC.otelSpanContext)
|
checkCtx = oteltrace.ContextWithRemoteSpanContext(checkCtx, parentBridgeSC.otelSpanContext)
|
||||||
@ -457,10 +457,10 @@ func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) co
|
|||||||
return ctx
|
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
|
kind := oteltrace.SpanKindInternal
|
||||||
err := false
|
err := false
|
||||||
var pairs []otelcore.KeyValue
|
var pairs []label.KeyValue
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
switch k {
|
switch k {
|
||||||
case string(otext.SpanKind):
|
case string(otext.SpanKind):
|
||||||
@ -481,14 +481,14 @@ func otTagsToOtelAttributesKindAndError(tags map[string]interface{}) ([]otelcore
|
|||||||
err = true
|
err = true
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
pairs = append(pairs, otTagToOtelCoreKeyValue(k, v))
|
pairs = append(pairs, otTagToOTelLabel(k, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pairs, kind, err
|
return pairs, kind, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func otTagToOtelCoreKeyValue(k string, v interface{}) otelcore.KeyValue {
|
func otTagToOTelLabel(k string, v interface{}) label.KeyValue {
|
||||||
key := otTagToOtelCoreKey(k)
|
key := otTagToOTelLabelKey(k)
|
||||||
switch val := v.(type) {
|
switch val := v.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
return key.Bool(val)
|
return key.Bool(val)
|
||||||
@ -515,8 +515,8 @@ func otTagToOtelCoreKeyValue(k string, v interface{}) otelcore.KeyValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func otTagToOtelCoreKey(k string) otelcore.Key {
|
func otTagToOTelLabelKey(k string) label.Key {
|
||||||
return otelcore.Key(k)
|
return label.Key(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpanContext, []oteltrace.Link) {
|
func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpanContext, []oteltrace.Link) {
|
||||||
@ -530,34 +530,34 @@ func otSpanReferencesToParentAndLinks(references []ot.SpanReference) (*bridgeSpa
|
|||||||
// We ignore foreign ot span contexts,
|
// We ignore foreign ot span contexts,
|
||||||
// sorry. We have no way of getting any
|
// sorry. We have no way of getting any
|
||||||
// TraceID and SpanID out of it for form a
|
// 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
|
// we can't make it a parent - it also needs a
|
||||||
// valid otelcore.SpanContext.
|
// valid OTel SpanContext.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
links = append(links, otSpanReferenceToOtelLink(bridgeSC, reference.Type))
|
links = append(links, otSpanReferenceToOTelLink(bridgeSC, reference.Type))
|
||||||
} else {
|
} else {
|
||||||
if reference.Type == ot.ChildOfRef {
|
if reference.Type == ot.ChildOfRef {
|
||||||
parent = bridgeSC
|
parent = bridgeSC
|
||||||
} else {
|
} else {
|
||||||
links = append(links, otSpanReferenceToOtelLink(bridgeSC, reference.Type))
|
links = append(links, otSpanReferenceToOTelLink(bridgeSC, reference.Type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parent, links
|
return parent, links
|
||||||
}
|
}
|
||||||
|
|
||||||
func otSpanReferenceToOtelLink(bridgeSC *bridgeSpanContext, refType ot.SpanReferenceType) oteltrace.Link {
|
func otSpanReferenceToOTelLink(bridgeSC *bridgeSpanContext, refType ot.SpanReferenceType) oteltrace.Link {
|
||||||
return oteltrace.Link{
|
return oteltrace.Link{
|
||||||
SpanContext: bridgeSC.otelSpanContext,
|
SpanContext: bridgeSC.otelSpanContext,
|
||||||
Attributes: otSpanReferenceTypeToOtelLinkAttributes(refType),
|
Attributes: otSpanReferenceTypeToOTelLinkAttributes(refType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func otSpanReferenceTypeToOtelLinkAttributes(refType ot.SpanReferenceType) []otelcore.KeyValue {
|
func otSpanReferenceTypeToOTelLinkAttributes(refType ot.SpanReferenceType) []label.KeyValue {
|
||||||
return []otelcore.KeyValue{
|
return []label.KeyValue{
|
||||||
otelcore.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)),
|
label.String("ot-span-reference-type", otSpanReferenceTypeToString(refType)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,21 +22,21 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
||||||
otelcore "go.opentelemetry.io/otel/api/kv"
|
|
||||||
oteltrace "go.opentelemetry.io/otel/api/trace"
|
oteltrace "go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
|
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/bridge/opentracing/migration"
|
"go.opentelemetry.io/otel/bridge/opentracing/migration"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ComponentKey = otelcore.Key("component")
|
ComponentKey = label.Key("component")
|
||||||
ServiceKey = otelcore.Key("service")
|
ServiceKey = label.Key("service")
|
||||||
StatusCodeKey = otelcore.Key("status.code")
|
StatusCodeKey = label.Key("status.code")
|
||||||
StatusMessageKey = otelcore.Key("status.message")
|
StatusMessageKey = label.Key("status.message")
|
||||||
ErrorKey = otelcore.Key("error")
|
ErrorKey = label.Key("error")
|
||||||
NameKey = otelcore.Key("name")
|
NameKey = label.Key("name")
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockContextKeyValue struct {
|
type MockContextKeyValue struct {
|
||||||
@ -225,14 +225,14 @@ func (s *MockSpan) SetError(v bool) {
|
|||||||
s.SetAttributes(ErrorKey.Bool(v))
|
s.SetAttributes(ErrorKey.Bool(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
|
func (s *MockSpan) SetAttributes(attributes ...label.KeyValue) {
|
||||||
s.applyUpdate(otelcorrelation.MapUpdate{
|
s.applyUpdate(otelcorrelation.MapUpdate{
|
||||||
MultiKV: attributes,
|
MultiKV: attributes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockSpan) SetAttribute(k string, v interface{}) {
|
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) {
|
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",
|
s.AddEventWithTimestamp(ctx, cfg.Timestamp, "error",
|
||||||
otelcore.String("error.type", reflect.TypeOf(err).String()),
|
label.String("error.type", reflect.TypeOf(err).String()),
|
||||||
otelcore.String("error.message", err.Error()),
|
label.String("error.message", err.Error()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,11 +290,11 @@ func (s *MockSpan) Tracer() oteltrace.Tracer {
|
|||||||
return s.officialTracer
|
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...)
|
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{
|
s.Events = append(s.Events, MockEvent{
|
||||||
CtxAttributes: otelcorrelation.MapFromContext(ctx),
|
CtxAttributes: otelcorrelation.MapFromContext(ctx),
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
|
@ -23,8 +23,8 @@ import (
|
|||||||
|
|
||||||
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
||||||
otelglobal "go.opentelemetry.io/otel/api/global"
|
otelglobal "go.opentelemetry.io/otel/api/global"
|
||||||
otelcore "go.opentelemetry.io/otel/api/kv"
|
|
||||||
oteltrace "go.opentelemetry.io/otel/api/trace"
|
oteltrace "go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/bridge/opentracing/internal"
|
"go.opentelemetry.io/otel/bridge/opentracing/internal"
|
||||||
)
|
)
|
||||||
@ -589,7 +589,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont
|
|||||||
value := bio.baggageItems[idx].value
|
value := bio.baggageItems[idx].value
|
||||||
|
|
||||||
otSpan.SetBaggageItem(otKey, value)
|
otSpan.SetBaggageItem(otKey, value)
|
||||||
ctx = otelcorrelation.NewContext(ctx, otelcore.String(otelKey, value))
|
ctx = otelcorrelation.NewContext(ctx, label.String(otelKey, value))
|
||||||
|
|
||||||
otRecording := make(map[string]string)
|
otRecording := make(map[string]string)
|
||||||
otSpan.Context().ForeachBaggageItem(func(key, value string) bool {
|
otSpan.Context().ForeachBaggageItem(func(key, value string) bool {
|
||||||
@ -597,7 +597,7 @@ func (bio *baggageInteroperationTest) addAndRecordBaggage(t *testing.T, ctx cont
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
otelRecording := make(map[string]string)
|
otelRecording := make(map[string]string)
|
||||||
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()
|
otelRecording[string(kv.Key)] = kv.Value.Emit()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -20,17 +20,17 @@ import (
|
|||||||
|
|
||||||
"go.opentelemetry.io/otel/api/correlation"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporters/stdout"
|
"go.opentelemetry.io/otel/exporters/stdout"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fooKey = kv.Key("ex.com/foo")
|
fooKey = label.Key("ex.com/foo")
|
||||||
barKey = kv.Key("ex.com/bar")
|
barKey = label.Key("ex.com/bar")
|
||||||
lemonsKey = kv.Key("ex.com/lemons")
|
lemonsKey = label.Key("ex.com/lemons")
|
||||||
anotherKey = kv.Key("ex.com/another")
|
anotherKey = label.Key("ex.com/another")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -46,7 +46,7 @@ func main() {
|
|||||||
tracer := global.Tracer("ex.com/basic")
|
tracer := global.Tracer("ex.com/basic")
|
||||||
meter := global.Meter("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) {
|
oneMetricCB := func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(1, commonLabels...)
|
result.Observe(1, commonLabels...)
|
||||||
@ -72,7 +72,7 @@ func main() {
|
|||||||
ctx, span = tracer.Start(ctx, "operation")
|
ctx, span = tracer.Start(ctx, "operation")
|
||||||
defer span.End()
|
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"))
|
span.SetAttributes(anotherKey.String("yes"))
|
||||||
|
|
||||||
meter.RecordBatch(
|
meter.RecordBatch(
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/exporters/trace/jaeger"
|
"go.opentelemetry.io/otel/exporters/trace/jaeger"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
@ -34,9 +34,9 @@ func initTracer() func() {
|
|||||||
jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"),
|
jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"),
|
||||||
jaeger.WithProcess(jaeger.Process{
|
jaeger.WithProcess(jaeger.Process{
|
||||||
ServiceName: "trace-demo",
|
ServiceName: "trace-demo",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("exporter", "jaeger"),
|
label.String("exporter", "jaeger"),
|
||||||
kv.Float64("float", 312.23),
|
label.Float64("float", 312.23),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
|
jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
|
||||||
|
@ -18,12 +18,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lemonsKey = kv.Key("ex.com/lemons")
|
lemonsKey = label.Key("ex.com/lemons")
|
||||||
)
|
)
|
||||||
|
|
||||||
// SubOperation is an example to demonstrate the use of named tracer.
|
// SubOperation is an example to demonstrate the use of named tracer.
|
||||||
|
@ -18,20 +18,19 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/correlation"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/example/namedtracer/foo"
|
"go.opentelemetry.io/otel/example/namedtracer/foo"
|
||||||
"go.opentelemetry.io/otel/exporters/stdout"
|
"go.opentelemetry.io/otel/exporters/stdout"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fooKey = kv.Key("ex.com/foo")
|
fooKey = label.Key("ex.com/foo")
|
||||||
barKey = kv.Key("ex.com/bar")
|
barKey = label.Key("ex.com/bar")
|
||||||
anotherKey = kv.Key("ex.com/another")
|
anotherKey = label.Key("ex.com/another")
|
||||||
)
|
)
|
||||||
|
|
||||||
var tp *sdktrace.Provider
|
var tp *sdktrace.Provider
|
||||||
@ -68,7 +67,7 @@ func main() {
|
|||||||
var span trace.Span
|
var span trace.Span
|
||||||
ctx, span = tracer.Start(ctx, "operation")
|
ctx, span = tracer.Start(ctx, "operation")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
span.AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100))
|
span.AddEvent(ctx, "Nice operation!", label.Int("bogons", 100))
|
||||||
span.SetAttributes(anotherKey.String("yes"))
|
span.SetAttributes(anotherKey.String("yes"))
|
||||||
if err := foo.SubOperation(ctx); err != nil {
|
if err := foo.SubOperation(ctx); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -26,10 +26,10 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
apitrace "go.opentelemetry.io/otel/api/trace"
|
apitrace "go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporters/otlp"
|
"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/controller/push"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
"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.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
|
||||||
sdktrace.WithResource(resource.New(
|
sdktrace.WithResource(resource.New(
|
||||||
// the service name used to display traces in backends
|
// the service name used to display traces in backends
|
||||||
kv.Key(semconv.ServiceNameKey).String("test-service"),
|
semconv.ServiceNameKey.String("test-service"),
|
||||||
)),
|
)),
|
||||||
sdktrace.WithBatcher(exp),
|
sdktrace.WithBatcher(exp),
|
||||||
)
|
)
|
||||||
@ -92,10 +92,10 @@ func main() {
|
|||||||
|
|
||||||
// labels represent additional key-value descriptors that can be bound to a
|
// labels represent additional key-value descriptors that can be bound to a
|
||||||
// metric observer or recorder.
|
// metric observer or recorder.
|
||||||
commonLabels := []kv.KeyValue{
|
commonLabels := []label.KeyValue{
|
||||||
kv.String("labelA", "chocolate"),
|
label.String("labelA", "chocolate"),
|
||||||
kv.String("labelB", "raspberry"),
|
label.String("labelB", "raspberry"),
|
||||||
kv.String("labelC", "vanilla"),
|
label.String("labelC", "vanilla"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recorder metric example
|
// Recorder metric example
|
||||||
|
@ -23,13 +23,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lemonsKey = kv.Key("ex.com/lemons")
|
lemonsKey = label.Key("ex.com/lemons")
|
||||||
)
|
)
|
||||||
|
|
||||||
func initMeter() {
|
func initMeter() {
|
||||||
@ -51,7 +51,7 @@ func main() {
|
|||||||
meter := global.Meter("ex.com/basic")
|
meter := global.Meter("ex.com/basic")
|
||||||
observerLock := new(sync.RWMutex)
|
observerLock := new(sync.RWMutex)
|
||||||
observerValueToReport := new(float64)
|
observerValueToReport := new(float64)
|
||||||
observerLabelsToReport := new([]kv.KeyValue)
|
observerLabelsToReport := new([]label.KeyValue)
|
||||||
cb := func(_ context.Context, result metric.Float64ObserverResult) {
|
cb := func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
(*observerLock).RLock()
|
(*observerLock).RLock()
|
||||||
value := *observerValueToReport
|
value := *observerValueToReport
|
||||||
@ -66,8 +66,8 @@ func main() {
|
|||||||
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
||||||
counter := metric.Must(meter).NewFloat64Counter("ex.com.three")
|
counter := metric.Must(meter).NewFloat64Counter("ex.com.three")
|
||||||
|
|
||||||
commonLabels := []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")}
|
||||||
notSoCommonLabels := []kv.KeyValue{lemonsKey.Int(13)}
|
notSoCommonLabels := []label.KeyValue{lemonsKey.Int(13)}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
"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/metric/controller/pull"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
@ -40,7 +40,7 @@ func ExampleNewExportPipeline() {
|
|||||||
// Create a meter
|
// Create a meter
|
||||||
exporter, err := prometheus.NewExportPipeline(
|
exporter, err := prometheus.NewExportPipeline(
|
||||||
prometheus.Config{},
|
prometheus.Config{},
|
||||||
pull.WithResource(resource.New(kv.String("R", "V"))),
|
pull.WithResource(resource.New(label.String("R", "V"))),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -58,8 +58,8 @@ func ExampleNewExportPipeline() {
|
|||||||
metric.WithDescription("Records values"),
|
metric.WithDescription("Records values"),
|
||||||
)
|
)
|
||||||
|
|
||||||
counter.Add(ctx, 100, kv.String("key", "value"))
|
counter.Add(ctx, 100, label.String("key", "value"))
|
||||||
recorder.Record(ctx, 100, kv.String("key", "value"))
|
recorder.Record(ctx, 100, label.String("key", "value"))
|
||||||
|
|
||||||
// GET the HTTP endpoint
|
// GET the HTTP endpoint
|
||||||
var input bytes.Buffer
|
var input bytes.Buffer
|
||||||
|
@ -24,8 +24,8 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||||
|
@ -26,9 +26,9 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
"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/metric/controller/pull"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
DefaultHistogramBoundaries: []float64{-0.5, 1},
|
DefaultHistogramBoundaries: []float64{-0.5, 1},
|
||||||
},
|
},
|
||||||
pull.WithCachePeriod(0),
|
pull.WithCachePeriod(0),
|
||||||
pull.WithResource(resource.New(kv.String("R", "V"))),
|
pull.WithResource(resource.New(label.String("R", "V"))),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -48,9 +48,9 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
counter := metric.Must(meter).NewFloat64Counter("counter")
|
counter := metric.Must(meter).NewFloat64Counter("counter")
|
||||||
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
|
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
|
||||||
|
|
||||||
labels := []kv.KeyValue{
|
labels := []label.KeyValue{
|
||||||
kv.Key("A").String("B"),
|
label.Key("A").String("B"),
|
||||||
kv.Key("C").String("D"),
|
label.Key("C").String("D"),
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
@ -128,14 +128,14 @@ func TestPrometheusStatefulness(t *testing.T) {
|
|||||||
metric.WithDescription("Counts things"),
|
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
|
require.Equal(t, `# HELP a_counter Counts things
|
||||||
# TYPE a_counter counter
|
# TYPE a_counter counter
|
||||||
a_counter{key="value"} 100
|
a_counter{key="value"} 100
|
||||||
`, scrape())
|
`, scrape())
|
||||||
|
|
||||||
counter.Add(ctx, 100, kv.String("key", "value"))
|
counter.Add(ctx, 100, label.String("key", "value"))
|
||||||
|
|
||||||
require.Equal(t, `# HELP a_counter Counts things
|
require.Equal(t, `# HELP a_counter Counts things
|
||||||
# TYPE a_counter counter
|
# TYPE a_counter counter
|
||||||
|
@ -16,13 +16,13 @@ package transform
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values.
|
// Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values.
|
||||||
func Attributes(attrs []kv.KeyValue) []*commonpb.KeyValue {
|
func Attributes(attrs []label.KeyValue) []*commonpb.KeyValue {
|
||||||
if len(attrs) == 0 {
|
if len(attrs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -48,33 +48,33 @@ func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func toAttribute(v kv.KeyValue) *commonpb.KeyValue {
|
func toAttribute(v label.KeyValue) *commonpb.KeyValue {
|
||||||
result := &commonpb.KeyValue{
|
result := &commonpb.KeyValue{
|
||||||
Key: string(v.Key),
|
Key: string(v.Key),
|
||||||
Value: new(commonpb.AnyValue),
|
Value: new(commonpb.AnyValue),
|
||||||
}
|
}
|
||||||
switch v.Value.Type() {
|
switch v.Value.Type() {
|
||||||
case kv.BOOL:
|
case label.BOOL:
|
||||||
result.Value.Value = &commonpb.AnyValue_BoolValue{
|
result.Value.Value = &commonpb.AnyValue_BoolValue{
|
||||||
BoolValue: v.Value.AsBool(),
|
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{
|
result.Value.Value = &commonpb.AnyValue_IntValue{
|
||||||
IntValue: v.Value.AsInt64(),
|
IntValue: v.Value.AsInt64(),
|
||||||
}
|
}
|
||||||
case kv.FLOAT32:
|
case label.FLOAT32:
|
||||||
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
||||||
DoubleValue: float64(v.Value.AsFloat32()),
|
DoubleValue: float64(v.Value.AsFloat32()),
|
||||||
}
|
}
|
||||||
case kv.FLOAT64:
|
case label.FLOAT64:
|
||||||
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
||||||
DoubleValue: v.Value.AsFloat64(),
|
DoubleValue: v.Value.AsFloat64(),
|
||||||
}
|
}
|
||||||
case kv.STRING:
|
case label.STRING:
|
||||||
result.Value.Value = &commonpb.AnyValue_StringValue{
|
result.Value.Value = &commonpb.AnyValue_StringValue{
|
||||||
StringValue: v.Value.AsString(),
|
StringValue: v.Value.AsString(),
|
||||||
}
|
}
|
||||||
case kv.ARRAY:
|
case label.ARRAY:
|
||||||
result.Value.Value = toArrayAttribute(v)
|
result.Value.Value = toArrayAttribute(v)
|
||||||
default:
|
default:
|
||||||
result.Value.Value = &commonpb.AnyValue_StringValue{
|
result.Value.Value = &commonpb.AnyValue_StringValue{
|
||||||
@ -84,7 +84,7 @@ func toAttribute(v kv.KeyValue) *commonpb.KeyValue {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func toArrayAttribute(v kv.KeyValue) *commonpb.AnyValue_ArrayValue {
|
func toArrayAttribute(v label.KeyValue) *commonpb.AnyValue_ArrayValue {
|
||||||
array := v.Value.AsArray()
|
array := v.Value.AsArray()
|
||||||
var resultValues []*commonpb.AnyValue
|
var resultValues []*commonpb.AnyValue
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type attributeTest struct {
|
type attributeTest struct {
|
||||||
attrs []kv.KeyValue
|
attrs []label.KeyValue
|
||||||
expected []*commonpb.KeyValue
|
expected []*commonpb.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,17 +32,17 @@ func TestAttributes(t *testing.T) {
|
|||||||
for _, test := range []attributeTest{
|
for _, test := range []attributeTest{
|
||||||
{nil, nil},
|
{nil, nil},
|
||||||
{
|
{
|
||||||
[]kv.KeyValue{
|
[]label.KeyValue{
|
||||||
kv.Int("int to int", 123),
|
label.Int("int to int", 123),
|
||||||
kv.Uint("uint to int", 1234),
|
label.Uint("uint to int", 1234),
|
||||||
kv.Int32("int32 to int", 12345),
|
label.Int32("int32 to int", 12345),
|
||||||
kv.Uint32("uint32 to int", 123456),
|
label.Uint32("uint32 to int", 123456),
|
||||||
kv.Int64("int64 to int64", 1234567),
|
label.Int64("int64 to int64", 1234567),
|
||||||
kv.Uint64("uint64 to int64", 12345678),
|
label.Uint64("uint64 to int64", 12345678),
|
||||||
kv.Float32("float32 to double", 3.14),
|
label.Float32("float32 to double", 3.14),
|
||||||
kv.Float32("float64 to double", 1.61),
|
label.Float32("float64 to double", 1.61),
|
||||||
kv.String("string to string", "string"),
|
label.String("string to string", "string"),
|
||||||
kv.Bool("bool to bool", true),
|
label.Bool("bool to bool", true),
|
||||||
},
|
},
|
||||||
[]*commonpb.KeyValue{
|
[]*commonpb.KeyValue{
|
||||||
{
|
{
|
||||||
@ -157,17 +157,17 @@ func TestArrayAttributes(t *testing.T) {
|
|||||||
for _, test := range []attributeTest{
|
for _, test := range []attributeTest{
|
||||||
{nil, nil},
|
{nil, nil},
|
||||||
{
|
{
|
||||||
[]kv.KeyValue{
|
[]label.KeyValue{
|
||||||
kv.Array("bool array to bool array", []bool{true, false}),
|
label.Array("bool array to bool array", []bool{true, false}),
|
||||||
kv.Array("int array to int64 array", []int{1, 2, 3}),
|
label.Array("int array to int64 array", []int{1, 2, 3}),
|
||||||
kv.Array("uint array to int64 array", []uint{1, 2, 3}),
|
label.Array("uint array to int64 array", []uint{1, 2, 3}),
|
||||||
kv.Array("int32 array to int64 array", []int32{1, 2, 3}),
|
label.Array("int32 array to int64 array", []int32{1, 2, 3}),
|
||||||
kv.Array("uint32 array to int64 array", []uint32{1, 2, 3}),
|
label.Array("uint32 array to int64 array", []uint32{1, 2, 3}),
|
||||||
kv.Array("int64 array to int64 array", []int64{1, 2, 3}),
|
label.Array("int64 array to int64 array", []int64{1, 2, 3}),
|
||||||
kv.Array("uint64 array to int64 array", []uint64{1, 2, 3}),
|
label.Array("uint64 array to int64 array", []uint64{1, 2, 3}),
|
||||||
kv.Array("float32 array to double array", []float32{1.11, 2.22, 3.33}),
|
label.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}),
|
label.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.Array("string array to string array", []string{"foo", "bar", "baz"}),
|
||||||
},
|
},
|
||||||
[]*commonpb.KeyValue{
|
[]*commonpb.KeyValue{
|
||||||
newOTelBoolArray("bool array to bool array", []bool{true, false}),
|
newOTelBoolArray("bool array to bool array", []bool{true, false}),
|
||||||
|
@ -27,8 +27,8 @@ import (
|
|||||||
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
||||||
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
|
@ -26,10 +26,9 @@ import (
|
|||||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||||
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/api/unit"
|
"go.opentelemetry.io/otel/api/unit"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
||||||
@ -46,7 +45,7 @@ var (
|
|||||||
|
|
||||||
func TestStringKeyValues(t *testing.T) {
|
func TestStringKeyValues(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
kvs []kv.KeyValue
|
kvs []label.KeyValue
|
||||||
expected []*commonpb.StringKeyValue
|
expected []*commonpb.StringKeyValue
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -54,21 +53,21 @@ func TestStringKeyValues(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]kv.KeyValue{},
|
[]label.KeyValue{},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]kv.KeyValue{
|
[]label.KeyValue{
|
||||||
kv.Bool("true", true),
|
label.Bool("true", true),
|
||||||
kv.Int64("one", 1),
|
label.Int64("one", 1),
|
||||||
kv.Uint64("two", 2),
|
label.Uint64("two", 2),
|
||||||
kv.Float64("three", 3),
|
label.Float64("three", 3),
|
||||||
kv.Int32("four", 4),
|
label.Int32("four", 4),
|
||||||
kv.Uint32("five", 5),
|
label.Uint32("five", 5),
|
||||||
kv.Float32("six", 6),
|
label.Float32("six", 6),
|
||||||
kv.Int("seven", 7),
|
label.Int("seven", 7),
|
||||||
kv.Uint("eight", 8),
|
label.Uint("eight", 8),
|
||||||
kv.String("the", "final word"),
|
label.String("the", "final word"),
|
||||||
},
|
},
|
||||||
[]*commonpb.StringKeyValue{
|
[]*commonpb.StringKeyValue{
|
||||||
{Key: "eight", Value: "8"},
|
{Key: "eight", Value: "8"},
|
||||||
@ -119,7 +118,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
description string
|
description string
|
||||||
unit unit.Unit
|
unit unit.Unit
|
||||||
numberKind metric.NumberKind
|
numberKind metric.NumberKind
|
||||||
labels []kv.KeyValue
|
labels []label.KeyValue
|
||||||
expected *metricpb.MetricDescriptor
|
expected *metricpb.MetricDescriptor
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -128,7 +127,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
"test-a-description",
|
"test-a-description",
|
||||||
unit.Dimensionless,
|
unit.Dimensionless,
|
||||||
metric.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
[]kv.KeyValue{},
|
[]label.KeyValue{},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "mmsc-test-a",
|
Name: "mmsc-test-a",
|
||||||
Description: "test-a-description",
|
Description: "test-a-description",
|
||||||
@ -142,7 +141,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
"test-b-description",
|
"test-b-description",
|
||||||
unit.Bytes,
|
unit.Bytes,
|
||||||
metric.Float64NumberKind, // This shouldn't change anything.
|
metric.Float64NumberKind, // This shouldn't change anything.
|
||||||
[]kv.KeyValue{kv.String("A", "1")},
|
[]label.KeyValue{label.String("A", "1")},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "mmsc-test-b",
|
Name: "mmsc-test-b",
|
||||||
Description: "test-b-description",
|
Description: "test-b-description",
|
||||||
@ -224,7 +223,7 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
description string
|
description string
|
||||||
unit unit.Unit
|
unit unit.Unit
|
||||||
numberKind metric.NumberKind
|
numberKind metric.NumberKind
|
||||||
labels []kv.KeyValue
|
labels []label.KeyValue
|
||||||
expected *metricpb.MetricDescriptor
|
expected *metricpb.MetricDescriptor
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -233,7 +232,7 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
"test-a-description",
|
"test-a-description",
|
||||||
unit.Dimensionless,
|
unit.Dimensionless,
|
||||||
metric.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
[]kv.KeyValue{},
|
[]label.KeyValue{},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "sum-test-a",
|
Name: "sum-test-a",
|
||||||
Description: "test-a-description",
|
Description: "test-a-description",
|
||||||
@ -247,7 +246,7 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
"test-b-description",
|
"test-b-description",
|
||||||
unit.Milliseconds,
|
unit.Milliseconds,
|
||||||
metric.Float64NumberKind,
|
metric.Float64NumberKind,
|
||||||
[]kv.KeyValue{kv.String("A", "1")},
|
[]label.KeyValue{label.String("A", "1")},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "sum-test-b",
|
Name: "sum-test-b",
|
||||||
Description: "test-b-description",
|
Description: "test-b-description",
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ func TestEmptyResource(t *testing.T) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
func TestResourceAttributes(t *testing.T) {
|
func TestResourceAttributes(t *testing.T) {
|
||||||
attrs := []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()
|
got := Resource(resource.New(attrs...)).GetAttributes()
|
||||||
if !assert.Len(t, attrs, 2) {
|
if !assert.Len(t, attrs, 2) {
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
|
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
apitrace "go.opentelemetry.io/otel/api/trace"
|
apitrace "go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
)
|
)
|
||||||
|
@ -26,8 +26,8 @@ import (
|
|||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
|
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
apitrace "go.opentelemetry.io/otel/api/trace"
|
apitrace "go.opentelemetry.io/otel/api/trace"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
@ -77,12 +77,12 @@ func TestEmptySpanEvent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSpanEvent(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)
|
eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
|
||||||
got := spanEvents([]export.Event{
|
got := spanEvents([]export.Event{
|
||||||
{
|
{
|
||||||
Name: "test 1",
|
Name: "test 1",
|
||||||
Attributes: []kv.KeyValue{},
|
Attributes: []label.KeyValue{},
|
||||||
Time: eventTime,
|
Time: eventTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -121,7 +121,7 @@ func TestEmptyLinks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLinks(t *testing.T) {
|
func TestLinks(t *testing.T) {
|
||||||
attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)}
|
attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)}
|
||||||
l := []apitrace.Link{
|
l := []apitrace.Link{
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
@ -283,13 +283,13 @@ func TestSpanData(t *testing.T) {
|
|||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Time: startTime,
|
{Time: startTime,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("CompressedByteSize", 512),
|
label.Uint64("CompressedByteSize", 512),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{Time: endTime,
|
{Time: endTime,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("MessageEventType", "Recv"),
|
label.String("MessageEventType", "Recv"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -300,8 +300,8 @@ func TestSpanData(t *testing.T) {
|
|||||||
SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
|
SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
|
||||||
TraceFlags: 0,
|
TraceFlags: 0,
|
||||||
},
|
},
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("LinkType", "Parent"),
|
label.String("LinkType", "Parent"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -310,21 +310,21 @@ func TestSpanData(t *testing.T) {
|
|||||||
SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7},
|
SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7},
|
||||||
TraceFlags: 0,
|
TraceFlags: 0,
|
||||||
},
|
},
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("LinkType", "Child"),
|
label.String("LinkType", "Child"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Internal,
|
StatusCode: codes.Internal,
|
||||||
StatusMessage: "utterly unrecognized",
|
StatusMessage: "utterly unrecognized",
|
||||||
HasRemoteParent: true,
|
HasRemoteParent: true,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Int64("timeout_ns", 12e9),
|
label.Int64("timeout_ns", 12e9),
|
||||||
},
|
},
|
||||||
DroppedAttributeCount: 1,
|
DroppedAttributeCount: 1,
|
||||||
DroppedMessageEventCount: 2,
|
DroppedMessageEventCount: 2,
|
||||||
DroppedLinkCount: 3,
|
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{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "go.opentelemetry.io/test/otel",
|
Name: "go.opentelemetry.io/test/otel",
|
||||||
Version: "v0.0.1",
|
Version: "v0.0.1",
|
||||||
|
@ -27,8 +27,8 @@ import (
|
|||||||
|
|
||||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||||
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
metricapi "go.opentelemetry.io/otel/api/metric"
|
metricapi "go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/exporters/otlp"
|
"go.opentelemetry.io/otel/exporters/otlp"
|
||||||
@ -91,15 +91,15 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
|||||||
}
|
}
|
||||||
tp1, err := sdktrace.NewProvider(append(pOpts,
|
tp1, err := sdktrace.NewProvider(append(pOpts,
|
||||||
sdktrace.WithResource(resource.New(
|
sdktrace.WithResource(resource.New(
|
||||||
kv.String("rk1", "rv11)"),
|
label.String("rk1", "rv11)"),
|
||||||
kv.Int64("rk2", 5),
|
label.Int64("rk2", 5),
|
||||||
)))...)
|
)))...)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
tp2, err := sdktrace.NewProvider(append(pOpts,
|
tp2, err := sdktrace.NewProvider(append(pOpts,
|
||||||
sdktrace.WithResource(resource.New(
|
sdktrace.WithResource(resource.New(
|
||||||
kv.String("rk1", "rv12)"),
|
label.String("rk1", "rv12)"),
|
||||||
kv.Float32("rk3", 6.5),
|
label.Float32("rk3", 6.5),
|
||||||
)))...)
|
)))...)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@ -109,11 +109,11 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
|||||||
m := 4
|
m := 4
|
||||||
for i := 0; i < m; i++ {
|
for i := 0; i < m; i++ {
|
||||||
_, span := tr1.Start(context.Background(), "AlwaysSample")
|
_, span := tr1.Start(context.Background(), "AlwaysSample")
|
||||||
span.SetAttributes(kv.Int64("i", int64(i)))
|
span.SetAttributes(label.Int64("i", int64(i)))
|
||||||
span.End()
|
span.End()
|
||||||
|
|
||||||
_, span = tr2.Start(context.Background(), "AlwaysSample")
|
_, span = tr2.Start(context.Background(), "AlwaysSample")
|
||||||
span.SetAttributes(kv.Int64("i", int64(i)))
|
span.SetAttributes(label.Int64("i", int64(i)))
|
||||||
span.End()
|
span.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
meter := pusher.Provider().Meter("test-meter")
|
meter := pusher.Provider().Meter("test-meter")
|
||||||
labels := []kv.KeyValue{kv.Bool("test", true)}
|
labels := []label.KeyValue{label.Bool("test", true)}
|
||||||
|
|
||||||
type data struct {
|
type data struct {
|
||||||
iKind metric.Kind
|
iKind metric.Kind
|
||||||
|
@ -28,9 +28,8 @@ import (
|
|||||||
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
||||||
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
||||||
@ -98,15 +97,15 @@ type record struct {
|
|||||||
nKind metric.NumberKind
|
nKind metric.NumberKind
|
||||||
resource *resource.Resource
|
resource *resource.Resource
|
||||||
opts []metric.InstrumentOption
|
opts []metric.InstrumentOption
|
||||||
labels []kv.KeyValue
|
labels []label.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
baseKeyValues = []kv.KeyValue{kv.String("host", "test.com")}
|
baseKeyValues = []label.KeyValue{label.String("host", "test.com")}
|
||||||
cpuKey = kv.Key("CPU")
|
cpuKey = label.Key("CPU")
|
||||||
|
|
||||||
testInstA = resource.New(kv.String("instance", "tester-a"))
|
testInstA = resource.New(label.String("instance", "tester-a"))
|
||||||
testInstB = resource.New(kv.String("instance", "tester-b"))
|
testInstB = resource.New(label.String("instance", "tester-b"))
|
||||||
|
|
||||||
md = &metricpb.MetricDescriptor{
|
md = &metricpb.MetricDescriptor{
|
||||||
Name: "int64-count",
|
Name: "int64-count",
|
||||||
|
@ -27,8 +27,8 @@ import (
|
|||||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||||
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
||||||
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
|
tracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/trace/v1"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
apitrace "go.opentelemetry.io/otel/api/trace"
|
apitrace "go.opentelemetry.io/otel/api/trace"
|
||||||
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
|
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
@ -91,13 +91,13 @@ func TestExportSpans(t *testing.T) {
|
|||||||
Name: "parent process",
|
Name: "parent process",
|
||||||
StartTime: startTime,
|
StartTime: startTime,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("user", "alice"),
|
label.String("user", "alice"),
|
||||||
kv.Bool("authenticated", true),
|
label.Bool("authenticated", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.OK,
|
StatusCode: codes.OK,
|
||||||
StatusMessage: "Ok",
|
StatusMessage: "Ok",
|
||||||
Resource: resource.New(kv.String("instance", "tester-a")),
|
Resource: resource.New(label.String("instance", "tester-a")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-a",
|
Name: "lib-a",
|
||||||
Version: "v0.1.0",
|
Version: "v0.1.0",
|
||||||
@ -113,13 +113,13 @@ func TestExportSpans(t *testing.T) {
|
|||||||
Name: "secondary parent process",
|
Name: "secondary parent process",
|
||||||
StartTime: startTime,
|
StartTime: startTime,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("user", "alice"),
|
label.String("user", "alice"),
|
||||||
kv.Bool("authenticated", true),
|
label.Bool("authenticated", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.OK,
|
StatusCode: codes.OK,
|
||||||
StatusMessage: "Ok",
|
StatusMessage: "Ok",
|
||||||
Resource: resource.New(kv.String("instance", "tester-a")),
|
Resource: resource.New(label.String("instance", "tester-a")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-b",
|
Name: "lib-b",
|
||||||
Version: "v0.1.0",
|
Version: "v0.1.0",
|
||||||
@ -136,13 +136,13 @@ func TestExportSpans(t *testing.T) {
|
|||||||
Name: "internal process",
|
Name: "internal process",
|
||||||
StartTime: startTime,
|
StartTime: startTime,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("user", "alice"),
|
label.String("user", "alice"),
|
||||||
kv.Bool("authenticated", true),
|
label.Bool("authenticated", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.OK,
|
StatusCode: codes.OK,
|
||||||
StatusMessage: "Ok",
|
StatusMessage: "Ok",
|
||||||
Resource: resource.New(kv.String("instance", "tester-a")),
|
Resource: resource.New(label.String("instance", "tester-a")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-a",
|
Name: "lib-a",
|
||||||
Version: "v0.1.0",
|
Version: "v0.1.0",
|
||||||
@ -158,13 +158,13 @@ func TestExportSpans(t *testing.T) {
|
|||||||
Name: "parent process",
|
Name: "parent process",
|
||||||
StartTime: startTime,
|
StartTime: startTime,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("user", "bob"),
|
label.String("user", "bob"),
|
||||||
kv.Bool("authenticated", false),
|
label.Bool("authenticated", false),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Unauthenticated,
|
StatusCode: codes.Unauthenticated,
|
||||||
StatusMessage: "Unauthenticated",
|
StatusMessage: "Unauthenticated",
|
||||||
Resource: resource.New(kv.String("instance", "tester-b")),
|
Resource: resource.New(label.String("instance", "tester-b")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-a",
|
Name: "lib-a",
|
||||||
Version: "v1.1.0",
|
Version: "v1.1.0",
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporters/stdout"
|
"go.opentelemetry.io/otel/exporters/stdout"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -44,7 +44,7 @@ var (
|
|||||||
loopCounter = metric.Must(meter).NewInt64Counter("function.loops")
|
loopCounter = metric.Must(meter).NewInt64Counter("function.loops")
|
||||||
paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param")
|
paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param")
|
||||||
|
|
||||||
nameKey = kv.Key("function.name")
|
nameKey = label.Key("function.name")
|
||||||
)
|
)
|
||||||
|
|
||||||
func add(ctx context.Context, x, y int64) int64 {
|
func add(ctx context.Context, x, y int64) int64 {
|
||||||
|
@ -21,9 +21,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
apimetric "go.opentelemetry.io/otel/api/metric"
|
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"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
)
|
)
|
||||||
@ -69,11 +68,11 @@ func (e *metricExporter) Export(_ context.Context, checkpointSet metric.Checkpoi
|
|||||||
kind := desc.NumberKind()
|
kind := desc.NumberKind()
|
||||||
encodedResource := record.Resource().Encoded(e.config.LabelEncoder)
|
encodedResource := record.Resource().Encoded(e.config.LabelEncoder)
|
||||||
|
|
||||||
var instLabels []kv.KeyValue
|
var instLabels []label.KeyValue
|
||||||
if name := desc.InstrumentationName(); name != "" {
|
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 != "" {
|
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...)
|
instSet := label.NewSet(instLabels...)
|
||||||
|
@ -26,9 +26,9 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/exporters/stdout"
|
"go.opentelemetry.io/otel/exporters/stdout"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
||||||
@ -48,7 +48,7 @@ type testFixture struct {
|
|||||||
output *bytes.Buffer
|
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 {
|
func newFixture(t *testing.T, opts ...stdout.Option) testFixture {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
@ -145,7 +145,7 @@ func TestStdoutCounterFormat(t *testing.T) {
|
|||||||
aggregatortest.CheckedUpdate(fix.t, cagg, metric.NewInt64Number(123), &desc)
|
aggregatortest.CheckedUpdate(fix.t, cagg, metric.NewInt64Number(123), &desc)
|
||||||
require.NoError(t, cagg.SynchronizedMove(ckpt, &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)
|
fix.Export(checkpointSet)
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func TestStdoutLastValueFormat(t *testing.T) {
|
|||||||
aggregatortest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc)
|
aggregatortest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc)
|
||||||
require.NoError(t, lvagg.SynchronizedMove(ckpt, &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)
|
fix.Export(checkpointSet)
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) {
|
|||||||
aggregatortest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(876.543), &desc)
|
aggregatortest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(876.543), &desc)
|
||||||
require.NoError(t, magg.SynchronizedMove(ckpt, &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)
|
fix.Export(checkpointSet)
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) {
|
|||||||
|
|
||||||
require.NoError(t, aagg.SynchronizedMove(ckpt, &desc))
|
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)
|
fix.Export(checkpointSet)
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ func TestStdoutLastValueNotSet(t *testing.T) {
|
|||||||
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
|
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
|
||||||
require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc))
|
require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc))
|
||||||
|
|
||||||
checkpointSet.Add(&desc, lvagg, kv.String("A", "B"), kv.String("C", "D"))
|
checkpointSet.Add(&desc, lvagg, label.String("A", "B"), label.String("C", "D"))
|
||||||
|
|
||||||
fix.Export(checkpointSet)
|
fix.Export(checkpointSet)
|
||||||
|
|
||||||
@ -279,9 +279,9 @@ func TestStdoutResource(t *testing.T) {
|
|||||||
type testCase struct {
|
type testCase struct {
|
||||||
expect string
|
expect string
|
||||||
res *resource.Resource
|
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{
|
return testCase{
|
||||||
expect: expect,
|
expect: expect,
|
||||||
res: res,
|
res: res,
|
||||||
@ -290,23 +290,23 @@ func TestStdoutResource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
testCases := []testCase{
|
testCases := []testCase{
|
||||||
newCase("R1=V1,R2=V2,A=B,C=D",
|
newCase("R1=V1,R2=V2,A=B,C=D",
|
||||||
resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")),
|
resource.New(label.String("R1", "V1"), label.String("R2", "V2")),
|
||||||
kv.String("A", "B"),
|
label.String("A", "B"),
|
||||||
kv.String("C", "D")),
|
label.String("C", "D")),
|
||||||
newCase("R1=V1,R2=V2",
|
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",
|
newCase("A=B,C=D",
|
||||||
nil,
|
nil,
|
||||||
kv.String("A", "B"),
|
label.String("A", "B"),
|
||||||
kv.String("C", "D"),
|
label.String("C", "D"),
|
||||||
),
|
),
|
||||||
// We explicitly do not de-duplicate between resources
|
// We explicitly do not de-duplicate between resources
|
||||||
// and metric labels in this exporter.
|
// and metric labels in this exporter.
|
||||||
newCase("R1=V1,R2=V2,R1=V3,R2=V4",
|
newCase("R1=V1,R2=V2,R1=V3,R2=V4",
|
||||||
resource.New(kv.String("R1", "V1"), kv.String("R2", "V2")),
|
resource.New(label.String("R1", "V1"), label.String("R2", "V2")),
|
||||||
kv.String("R1", "V3"),
|
label.String("R1", "V3"),
|
||||||
kv.String("R2", "V4")),
|
label.String("R2", "V4")),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
@ -23,9 +23,9 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporters/stdout"
|
"go.opentelemetry.io/otel/exporters/stdout"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
@ -44,7 +44,7 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
spanID, _ := trace.SpanIDFromHex("0102030405060708")
|
spanID, _ := trace.SpanIDFromHex("0102030405060708")
|
||||||
keyValue := "value"
|
keyValue := "value"
|
||||||
doubleValue := 123.456
|
doubleValue := 123.456
|
||||||
resource := resource.New(kv.String("rk1", "rv11"))
|
resource := resource.New(label.String("rk1", "rv11"))
|
||||||
|
|
||||||
testSpan := &export.SpanData{
|
testSpan := &export.SpanData{
|
||||||
SpanContext: trace.SpanContext{
|
SpanContext: trace.SpanContext{
|
||||||
@ -54,13 +54,13 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
Name: "/foo",
|
Name: "/foo",
|
||||||
StartTime: now,
|
StartTime: now,
|
||||||
EndTime: now,
|
EndTime: now,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("key", keyValue),
|
label.String("key", keyValue),
|
||||||
kv.Float64("double", doubleValue),
|
label.Float64("double", doubleValue),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Name: "foo", Attributes: []kv.KeyValue{kv.String("key", keyValue)}, Time: now},
|
{Name: "foo", Attributes: []label.KeyValue{label.String("key", keyValue)}, Time: now},
|
||||||
{Name: "bar", Attributes: []kv.KeyValue{kv.Float64("double", doubleValue)}, Time: now},
|
{Name: "bar", Attributes: []label.KeyValue{label.Float64("double", doubleValue)}, Time: now},
|
||||||
},
|
},
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
StatusCode: codes.Unknown,
|
StatusCode: codes.Unknown,
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Environment variable names
|
// Environment variable names
|
||||||
@ -111,9 +111,9 @@ var errTagEnvironmentDefaultValueNotFound = errors.New("missing default value fo
|
|||||||
// - comma separated list of key=value
|
// - comma separated list of key=value
|
||||||
// - value can be specified using the notation ${envVar:defaultValue}, where `envVar`
|
// - value can be specified using the notation ${envVar:defaultValue}, where `envVar`
|
||||||
// is an environment variable and `defaultValue` is the value to use in case the env var is not set
|
// is an environment variable and `defaultValue` is the value to use in case the env var is not set
|
||||||
func parseTags(sTags string) ([]kv.KeyValue, error) {
|
func parseTags(sTags string) ([]label.KeyValue, error) {
|
||||||
pairs := strings.Split(sTags, ",")
|
pairs := strings.Split(sTags, ",")
|
||||||
tags := make([]kv.KeyValue, len(pairs))
|
tags := make([]label.KeyValue, len(pairs))
|
||||||
for i, p := range pairs {
|
for i, p := range pairs {
|
||||||
field := strings.SplitN(p, "=", 2)
|
field := strings.SplitN(p, "=", 2)
|
||||||
if len(field) != 2 {
|
if len(field) != 2 {
|
||||||
@ -139,24 +139,24 @@ func parseTags(sTags string) ([]kv.KeyValue, error) {
|
|||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseKeyValue(k, v string) kv.KeyValue {
|
func parseKeyValue(k, v string) label.KeyValue {
|
||||||
return kv.KeyValue{
|
return label.KeyValue{
|
||||||
Key: kv.Key(k),
|
Key: label.Key(k),
|
||||||
Value: parseValue(v),
|
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 {
|
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 {
|
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 {
|
if v, err := strconv.ParseBool(str); err == nil {
|
||||||
return kv.BoolValue(v)
|
return label.BoolValue(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
return kv.StringValue(str)
|
return label.StringValue(str)
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_parseTags(t *testing.T) {
|
func Test_parseTags(t *testing.T) {
|
||||||
@ -38,78 +38,78 @@ func Test_parseTags(t *testing.T) {
|
|||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
tagStr string
|
tagStr string
|
||||||
expectedTags []kv.KeyValue
|
expectedTags []label.KeyValue
|
||||||
expectedError error
|
expectedError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "string",
|
name: "string",
|
||||||
tagStr: "key=value",
|
tagStr: "key=value",
|
||||||
expectedTags: []kv.KeyValue{
|
expectedTags: []label.KeyValue{
|
||||||
{
|
{
|
||||||
Key: "key",
|
Key: "key",
|
||||||
Value: kv.StringValue("value"),
|
Value: label.StringValue("value"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "int64",
|
name: "int64",
|
||||||
tagStr: "k=9223372036854775807,k2=-9223372036854775808",
|
tagStr: "k=9223372036854775807,k2=-9223372036854775808",
|
||||||
expectedTags: []kv.KeyValue{
|
expectedTags: []label.KeyValue{
|
||||||
{
|
{
|
||||||
Key: "k",
|
Key: "k",
|
||||||
Value: kv.Int64Value(math.MaxInt64),
|
Value: label.Int64Value(math.MaxInt64),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k2",
|
Key: "k2",
|
||||||
Value: kv.Int64Value(math.MinInt64),
|
Value: label.Int64Value(math.MinInt64),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "float64",
|
name: "float64",
|
||||||
tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2",
|
tagStr: "k=1.797693134862315708145274237317043567981e+308,k2=4.940656458412465441765687928682213723651e-324,k3=-1.2",
|
||||||
expectedTags: []kv.KeyValue{
|
expectedTags: []label.KeyValue{
|
||||||
{
|
{
|
||||||
Key: "k",
|
Key: "k",
|
||||||
Value: kv.Float64Value(math.MaxFloat64),
|
Value: label.Float64Value(math.MaxFloat64),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k2",
|
Key: "k2",
|
||||||
Value: kv.Float64Value(math.SmallestNonzeroFloat64),
|
Value: label.Float64Value(math.SmallestNonzeroFloat64),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k3",
|
Key: "k3",
|
||||||
Value: kv.Float64Value(-1.2),
|
Value: label.Float64Value(-1.2),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple type values",
|
name: "multiple type values",
|
||||||
tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}",
|
tagStr: "k=v,k2=123, k3=v3 ,k4=-1.2, k5=${existing:default},k6=${nonExisting:default}",
|
||||||
expectedTags: []kv.KeyValue{
|
expectedTags: []label.KeyValue{
|
||||||
{
|
{
|
||||||
Key: "k",
|
Key: "k",
|
||||||
Value: kv.StringValue("v"),
|
Value: label.StringValue("v"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k2",
|
Key: "k2",
|
||||||
Value: kv.Int64Value(123),
|
Value: label.Int64Value(123),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k3",
|
Key: "k3",
|
||||||
Value: kv.StringValue("v3"),
|
Value: label.StringValue("v3"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k4",
|
Key: "k4",
|
||||||
Value: kv.Float64Value(-1.2),
|
Value: label.Float64Value(-1.2),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k5",
|
Key: "k5",
|
||||||
Value: kv.StringValue("not-default"),
|
Value: label.StringValue("not-default"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "k6",
|
Key: "k6",
|
||||||
Value: kv.StringValue("default"),
|
Value: label.StringValue("default"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -144,52 +144,52 @@ func Test_parseValue(t *testing.T) {
|
|||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
str string
|
str string
|
||||||
expected kv.Value
|
expected label.Value
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "bool: true",
|
name: "bool: true",
|
||||||
str: "true",
|
str: "true",
|
||||||
expected: kv.BoolValue(true),
|
expected: label.BoolValue(true),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bool: false",
|
name: "bool: false",
|
||||||
str: "false",
|
str: "false",
|
||||||
expected: kv.BoolValue(false),
|
expected: label.BoolValue(false),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "int64: 012340",
|
name: "int64: 012340",
|
||||||
str: "012340",
|
str: "012340",
|
||||||
expected: kv.Int64Value(12340),
|
expected: label.Int64Value(12340),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "int64: -012340",
|
name: "int64: -012340",
|
||||||
str: "-012340",
|
str: "-012340",
|
||||||
expected: kv.Int64Value(-12340),
|
expected: label.Int64Value(-12340),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "int64: 0",
|
name: "int64: 0",
|
||||||
str: "0",
|
str: "0",
|
||||||
expected: kv.Int64Value(0),
|
expected: label.Int64Value(0),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "float64: -0.1",
|
name: "float64: -0.1",
|
||||||
str: "-0.1",
|
str: "-0.1",
|
||||||
expected: kv.Float64Value(-0.1),
|
expected: label.Float64Value(-0.1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "float64: 00.001",
|
name: "float64: 00.001",
|
||||||
str: "00.001",
|
str: "00.001",
|
||||||
expected: kv.Float64Value(0.001),
|
expected: label.Float64Value(0.001),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "float64: 1E23",
|
name: "float64: 1E23",
|
||||||
str: "1E23",
|
str: "1E23",
|
||||||
expected: kv.Float64Value(1e23),
|
expected: label.Float64Value(1e23),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "string: foo",
|
name: "string: foo",
|
||||||
str: "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",
|
tags: "key=value,key2=123",
|
||||||
expectedProcess: Process{
|
expectedProcess: Process{
|
||||||
ServiceName: "test-service",
|
ServiceName: "test-service",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("key", "value"),
|
label.String("key", "value"),
|
||||||
kv.Int64("key2", 123),
|
label.Int64("key2", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -455,16 +455,16 @@ func TestWithProcessFromEnv(t *testing.T) {
|
|||||||
options: options{
|
options: options{
|
||||||
Process: Process{
|
Process: Process{
|
||||||
ServiceName: "old-name",
|
ServiceName: "old-name",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("old-key", "old-value"),
|
label.String("old-key", "old-value"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedOptions: options{
|
expectedOptions: options{
|
||||||
Process: Process{
|
Process: Process{
|
||||||
ServiceName: "service-name",
|
ServiceName: "service-name",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("key", "value"),
|
label.String("key", "value"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -476,16 +476,16 @@ func TestWithProcessFromEnv(t *testing.T) {
|
|||||||
options: options{
|
options: options{
|
||||||
Process: Process{
|
Process: Process{
|
||||||
ServiceName: "old-name",
|
ServiceName: "old-name",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("old-key", "old-value"),
|
label.String("old-key", "old-value"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedOptions: options{
|
expectedOptions: options{
|
||||||
Process: Process{
|
Process: Process{
|
||||||
ServiceName: "old-name",
|
ServiceName: "old-name",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("old-key", "old-value"),
|
label.String("old-key", "old-value"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
apitrace "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"
|
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
)
|
)
|
||||||
@ -189,7 +189,7 @@ type Process struct {
|
|||||||
ServiceName string
|
ServiceName string
|
||||||
|
|
||||||
// Tags are added to Jaeger Process exports
|
// 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.
|
// 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
|
var tag *gen.Tag
|
||||||
switch keyValue.Value.Type() {
|
switch keyValue.Value.Type() {
|
||||||
case kv.STRING:
|
case label.STRING:
|
||||||
s := keyValue.Value.AsString()
|
s := keyValue.Value.AsString()
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
VStr: &s,
|
VStr: &s,
|
||||||
VType: gen.TagType_STRING,
|
VType: gen.TagType_STRING,
|
||||||
}
|
}
|
||||||
case kv.BOOL:
|
case label.BOOL:
|
||||||
b := keyValue.Value.AsBool()
|
b := keyValue.Value.AsBool()
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
VBool: &b,
|
VBool: &b,
|
||||||
VType: gen.TagType_BOOL,
|
VType: gen.TagType_BOOL,
|
||||||
}
|
}
|
||||||
case kv.INT32:
|
case label.INT32:
|
||||||
i := int64(keyValue.Value.AsInt32())
|
i := int64(keyValue.Value.AsInt32())
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
VLong: &i,
|
VLong: &i,
|
||||||
VType: gen.TagType_LONG,
|
VType: gen.TagType_LONG,
|
||||||
}
|
}
|
||||||
case kv.INT64:
|
case label.INT64:
|
||||||
i := keyValue.Value.AsInt64()
|
i := keyValue.Value.AsInt64()
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
VLong: &i,
|
VLong: &i,
|
||||||
VType: gen.TagType_LONG,
|
VType: gen.TagType_LONG,
|
||||||
}
|
}
|
||||||
case kv.UINT32:
|
case label.UINT32:
|
||||||
i := int64(keyValue.Value.AsUint32())
|
i := int64(keyValue.Value.AsUint32())
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
VLong: &i,
|
VLong: &i,
|
||||||
VType: gen.TagType_LONG,
|
VType: gen.TagType_LONG,
|
||||||
}
|
}
|
||||||
case kv.UINT64:
|
case label.UINT64:
|
||||||
// we'll ignore the value if it overflows
|
// we'll ignore the value if it overflows
|
||||||
if i := int64(keyValue.Value.AsUint64()); i >= 0 {
|
if i := int64(keyValue.Value.AsUint64()); i >= 0 {
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
@ -338,14 +338,14 @@ func keyValueToTag(keyValue kv.KeyValue) *gen.Tag {
|
|||||||
VType: gen.TagType_LONG,
|
VType: gen.TagType_LONG,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case kv.FLOAT32:
|
case label.FLOAT32:
|
||||||
f := float64(keyValue.Value.AsFloat32())
|
f := float64(keyValue.Value.AsFloat32())
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
VDouble: &f,
|
VDouble: &f,
|
||||||
VType: gen.TagType_DOUBLE,
|
VType: gen.TagType_DOUBLE,
|
||||||
}
|
}
|
||||||
case kv.FLOAT64:
|
case label.FLOAT64:
|
||||||
f := keyValue.Value.AsFloat64()
|
f := keyValue.Value.AsFloat64()
|
||||||
tag = &gen.Tag{
|
tag = &gen.Tag{
|
||||||
Key: string(keyValue.Key),
|
Key: string(keyValue.Key),
|
||||||
|
@ -30,11 +30,11 @@ import (
|
|||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
apitrace "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"
|
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger"
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
@ -205,8 +205,8 @@ func TestNewRawExporter(t *testing.T) {
|
|||||||
WithProcess(
|
WithProcess(
|
||||||
Process{
|
Process{
|
||||||
ServiceName: "jaeger-test",
|
ServiceName: "jaeger-test",
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String("key", "val"),
|
label.String("key", "val"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -331,8 +331,8 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
withTestCollectorEndpoint(),
|
withTestCollectorEndpoint(),
|
||||||
WithProcess(Process{
|
WithProcess(Process{
|
||||||
ServiceName: serviceName,
|
ServiceName: serviceName,
|
||||||
Tags: []kv.KeyValue{
|
Tags: []label.KeyValue{
|
||||||
kv.String(tagKey, tagVal),
|
label.String(tagKey, tagVal),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -400,19 +400,19 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("key", keyValue),
|
label.String("key", keyValue),
|
||||||
kv.Float64("double", doubleValue),
|
label.Float64("double", doubleValue),
|
||||||
kv.Uint64("uint", uint64(uintValue)),
|
label.Uint64("uint", uint64(uintValue)),
|
||||||
kv.Uint64("overflows", math.MaxUint64),
|
label.Uint64("overflows", math.MaxUint64),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
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,
|
StatusCode: codes.Unknown,
|
||||||
StatusMessage: statusMessage,
|
StatusMessage: statusMessage,
|
||||||
SpanKind: apitrace.SpanKindClient,
|
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{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: instrLibName,
|
Name: instrLibName,
|
||||||
Version: instrLibVersion,
|
Version: instrLibVersion,
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
|
|
||||||
zkmodel "github.com/openzipkin/zipkin-go/model"
|
zkmodel "github.com/openzipkin/zipkin-go/model"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ func toZipkinAnnotations(events []export.Event) []zkmodel.Annotation {
|
|||||||
return annotations
|
return annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
func attributesToJSONMapString(attributes []kv.KeyValue) string {
|
func attributesToJSONMapString(attributes []label.KeyValue) string {
|
||||||
m := make(map[string]interface{}, len(attributes))
|
m := make(map[string]interface{}, len(attributes))
|
||||||
for _, attribute := range attributes {
|
for _, attribute := range attributes {
|
||||||
m[(string)(attribute.Key)] = attribute.Value.AsInterface()
|
m[(string)(attribute.Key)] = attribute.Value.AsInterface()
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,16 +40,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -73,16 +73,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -105,16 +105,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -137,16 +137,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -169,16 +169,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -201,16 +201,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -233,16 +233,16 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -265,9 +265,9 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("attr1", 42),
|
label.Uint64("attr1", 42),
|
||||||
kv.String("attr2", "bar"),
|
label.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: nil,
|
MessageEvents: nil,
|
||||||
StatusCode: codes.NotFound,
|
StatusCode: codes.NotFound,
|
||||||
@ -284,15 +284,15 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("error", "false"),
|
label.String("error", "false"),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{
|
{
|
||||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||||
Name: "ev1",
|
Name: "ev1",
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.Uint64("eventattr1", 123),
|
label.Uint64("eventattr1", 123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
|
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.
|
// the SDK to provide support for running observer callbacks.
|
||||||
type AsyncCollector interface {
|
type AsyncCollector interface {
|
||||||
// CollectAsync passes a batch of observations to the MeterImpl.
|
// CollectAsync passes a batch of observations to the MeterImpl.
|
||||||
CollectAsync([]kv.KeyValue, ...metric.Observation)
|
CollectAsync([]label.KeyValue, ...metric.Observation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsyncInstrumentState manages an ordered set of asynchronous
|
// AsyncInstrumentState manages an ordered set of asynchronous
|
||||||
|
@ -18,23 +18,23 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
apimetric "go.opentelemetry.io/otel/api/metric"
|
apimetric "go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/api/metric/registry"
|
"go.opentelemetry.io/otel/api/metric/registry"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Handle struct {
|
Handle struct {
|
||||||
Instrument *Sync
|
Instrument *Sync
|
||||||
Labels []kv.KeyValue
|
Labels []label.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
Batch struct {
|
Batch struct {
|
||||||
// Measurement needs to be aligned for 64-bit atomic operations.
|
// Measurement needs to be aligned for 64-bit atomic operations.
|
||||||
Measurements []Measurement
|
Measurements []Measurement
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
Labels []kv.KeyValue
|
Labels []label.KeyValue
|
||||||
LibraryName string
|
LibraryName string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,14 +87,14 @@ func (s *Sync) Implementation() interface{} {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sync) Bind(labels []kv.KeyValue) apimetric.BoundSyncImpl {
|
func (s *Sync) Bind(labels []label.KeyValue) apimetric.BoundSyncImpl {
|
||||||
return &Handle{
|
return &Handle{
|
||||||
Instrument: s,
|
Instrument: s,
|
||||||
Labels: labels,
|
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)
|
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 (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{{
|
m.collect(ctx, labels, []Measurement{{
|
||||||
Instrument: instrument,
|
Instrument: instrument,
|
||||||
Number: number,
|
Number: number,
|
||||||
@ -151,7 +151,7 @@ func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metr
|
|||||||
return a, nil
|
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))
|
mm := make([]Measurement, len(measurements))
|
||||||
for i := 0; i < len(measurements); i++ {
|
for i := 0; i < len(measurements); i++ {
|
||||||
m := measurements[i]
|
m := measurements[i]
|
||||||
@ -163,7 +163,7 @@ func (m *MeterImpl) RecordBatch(ctx context.Context, labels []kv.KeyValue, measu
|
|||||||
m.collect(ctx, labels, mm)
|
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))
|
mm := make([]Measurement, len(obs))
|
||||||
for i := 0; i < len(obs); i++ {
|
for i := 0; i < len(obs); i++ {
|
||||||
o := obs[i]
|
o := obs[i]
|
||||||
@ -175,7 +175,7 @@ func (m *MeterImpl) CollectAsync(labels []kv.KeyValue, obs ...metric.Observation
|
|||||||
m.collect(context.Background(), labels, mm)
|
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()
|
m.lock.Lock()
|
||||||
defer m.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
apitrace "go.opentelemetry.io/otel/api/trace"
|
apitrace "go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockSpan is a mock span used in association with MockTracer for testing purpose only.
|
// 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)
|
var _ apitrace.Span = (*MockSpan)(nil)
|
||||||
|
|
||||||
// SpanContext returns associated kv.SpanContext. If the receiver is nil it returns
|
// SpanContext returns associated label.SpanContext. If the receiver is nil it returns
|
||||||
// an empty kv.SpanContext
|
// an empty label.SpanContext
|
||||||
func (ms *MockSpan) SpanContext() apitrace.SpanContext {
|
func (ms *MockSpan) SpanContext() apitrace.SpanContext {
|
||||||
if ms == nil {
|
if ms == nil {
|
||||||
return apitrace.EmptySpanContext()
|
return apitrace.EmptySpanContext()
|
||||||
@ -59,7 +59,7 @@ func (ms *MockSpan) SetError(v bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAttributes does nothing.
|
// SetAttributes does nothing.
|
||||||
func (ms *MockSpan) SetAttributes(attributes ...kv.KeyValue) {
|
func (ms *MockSpan) SetAttributes(attributes ...label.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttribute does nothing.
|
// SetAttribute does nothing.
|
||||||
@ -85,9 +85,9 @@ func (ms *MockSpan) Tracer() apitrace.Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent does nothing.
|
// 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.
|
// 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) {
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ package parent
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (trace.SpanContext, bool, []trace.Link) {
|
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{
|
return append(links, trace.Link{
|
||||||
SpanContext: sc,
|
SpanContext: sc,
|
||||||
Attributes: []kv.KeyValue{
|
Attributes: []label.KeyValue{
|
||||||
kv.String("ignored-on-demand", kind),
|
label.String("ignored-on-demand", kind),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -12,61 +12,61 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv_test
|
package label_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
type test struct{}
|
type test struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
arrayVal = []string{"one", "two"}
|
arrayVal = []string{"one", "two"}
|
||||||
arrayKeyVal = kv.Array("array", arrayVal)
|
arrayKeyVal = label.Array("array", arrayVal)
|
||||||
|
|
||||||
boolVal = true
|
boolVal = true
|
||||||
boolKeyVal = kv.Bool("bool", boolVal)
|
boolKeyVal = label.Bool("bool", boolVal)
|
||||||
|
|
||||||
intVal = int(1)
|
intVal = int(1)
|
||||||
intKeyVal = kv.Int("int", intVal)
|
intKeyVal = label.Int("int", intVal)
|
||||||
|
|
||||||
int8Val = int8(1)
|
int8Val = int8(1)
|
||||||
int8KeyVal = kv.Int("int8", int(int8Val))
|
int8KeyVal = label.Int("int8", int(int8Val))
|
||||||
|
|
||||||
int16Val = int16(1)
|
int16Val = int16(1)
|
||||||
int16KeyVal = kv.Int("int16", int(int16Val))
|
int16KeyVal = label.Int("int16", int(int16Val))
|
||||||
|
|
||||||
int32Val = int32(1)
|
int32Val = int32(1)
|
||||||
int32KeyVal = kv.Int32("int32", int32Val)
|
int32KeyVal = label.Int32("int32", int32Val)
|
||||||
|
|
||||||
int64Val = int64(1)
|
int64Val = int64(1)
|
||||||
int64KeyVal = kv.Int64("int64", int64Val)
|
int64KeyVal = label.Int64("int64", int64Val)
|
||||||
|
|
||||||
uintVal = uint(1)
|
uintVal = uint(1)
|
||||||
uintKeyVal = kv.Uint("uint", uintVal)
|
uintKeyVal = label.Uint("uint", uintVal)
|
||||||
|
|
||||||
uint8Val = uint8(1)
|
uint8Val = uint8(1)
|
||||||
uint8KeyVal = kv.Uint("uint8", uint(uint8Val))
|
uint8KeyVal = label.Uint("uint8", uint(uint8Val))
|
||||||
|
|
||||||
uint16Val = uint16(1)
|
uint16Val = uint16(1)
|
||||||
uint16KeyVal = kv.Uint("uint16", uint(uint16Val))
|
uint16KeyVal = label.Uint("uint16", uint(uint16Val))
|
||||||
|
|
||||||
uint32Val = uint32(1)
|
uint32Val = uint32(1)
|
||||||
uint32KeyVal = kv.Uint32("uint32", uint32Val)
|
uint32KeyVal = label.Uint32("uint32", uint32Val)
|
||||||
|
|
||||||
uint64Val = uint64(1)
|
uint64Val = uint64(1)
|
||||||
uint64KeyVal = kv.Uint64("uint64", uint64Val)
|
uint64KeyVal = label.Uint64("uint64", uint64Val)
|
||||||
|
|
||||||
float32Val = float32(1.0)
|
float32Val = float32(1.0)
|
||||||
float32KeyVal = kv.Float32("float32", float32Val)
|
float32KeyVal = label.Float32("float32", float32Val)
|
||||||
|
|
||||||
float64Val = float64(1.0)
|
float64Val = float64(1.0)
|
||||||
float64KeyVal = kv.Float64("float64", float64Val)
|
float64KeyVal = label.Float64("float64", float64Val)
|
||||||
|
|
||||||
stringVal = "string"
|
stringVal = "string"
|
||||||
stringKeyVal = kv.String("string", stringVal)
|
stringKeyVal = label.String("string", stringVal)
|
||||||
|
|
||||||
bytesVal = []byte("bytes")
|
bytesVal = []byte("bytes")
|
||||||
structVal = test{}
|
structVal = test{}
|
||||||
@ -75,196 +75,196 @@ var (
|
|||||||
func BenchmarkArrayKey(b *testing.B) {
|
func BenchmarkArrayKey(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Array("array", arrayVal)
|
_ = label.Array("array", arrayVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkArrayKeyAny(b *testing.B) {
|
func BenchmarkArrayKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("array", arrayVal)
|
_ = label.Any("array", arrayVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBoolKey(b *testing.B) {
|
func BenchmarkBoolKey(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Bool("bool", boolVal)
|
_ = label.Bool("bool", boolVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBoolKeyAny(b *testing.B) {
|
func BenchmarkBoolKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("bool", boolVal)
|
_ = label.Any("bool", boolVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIntKey(b *testing.B) {
|
func BenchmarkIntKey(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Int("int", intVal)
|
_ = label.Int("int", intVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIntKeyAny(b *testing.B) {
|
func BenchmarkIntKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("int", intVal)
|
_ = label.Any("int", intVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInt8KeyAny(b *testing.B) {
|
func BenchmarkInt8KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("int8", int8Val)
|
_ = label.Any("int8", int8Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInt16KeyAny(b *testing.B) {
|
func BenchmarkInt16KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("int16", int16Val)
|
_ = label.Any("int16", int16Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInt32Key(b *testing.B) {
|
func BenchmarkInt32Key(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Int32("int32", int32Val)
|
_ = label.Int32("int32", int32Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInt32KeyAny(b *testing.B) {
|
func BenchmarkInt32KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("int32", int32Val)
|
_ = label.Any("int32", int32Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInt64Key(b *testing.B) {
|
func BenchmarkInt64Key(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Int64("int64", int64Val)
|
_ = label.Int64("int64", int64Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInt64KeyAny(b *testing.B) {
|
func BenchmarkInt64KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("int64", int64Val)
|
_ = label.Any("int64", int64Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUintKey(b *testing.B) {
|
func BenchmarkUintKey(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Uint("uint", uintVal)
|
_ = label.Uint("uint", uintVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUintKeyAny(b *testing.B) {
|
func BenchmarkUintKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("uint", uintVal)
|
_ = label.Any("uint", uintVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUint8KeyAny(b *testing.B) {
|
func BenchmarkUint8KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("uint8", uint8Val)
|
_ = label.Any("uint8", uint8Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUint16KeyAny(b *testing.B) {
|
func BenchmarkUint16KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("uint16", uint16Val)
|
_ = label.Any("uint16", uint16Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUint32Key(b *testing.B) {
|
func BenchmarkUint32Key(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Uint32("uint32", uint32Val)
|
_ = label.Uint32("uint32", uint32Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUint32KeyAny(b *testing.B) {
|
func BenchmarkUint32KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("uint32", uint32Val)
|
_ = label.Any("uint32", uint32Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUint64Key(b *testing.B) {
|
func BenchmarkUint64Key(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Uint64("uint64", uint64Val)
|
_ = label.Uint64("uint64", uint64Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUint64KeyAny(b *testing.B) {
|
func BenchmarkUint64KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("uint64", uint64Val)
|
_ = label.Any("uint64", uint64Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFloat32Key(b *testing.B) {
|
func BenchmarkFloat32Key(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Float32("float32", float32Val)
|
_ = label.Float32("float32", float32Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFloat32KeyAny(b *testing.B) {
|
func BenchmarkFloat32KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("float32", float32Val)
|
_ = label.Any("float32", float32Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFloat64Key(b *testing.B) {
|
func BenchmarkFloat64Key(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Float64("float64", float64Val)
|
_ = label.Float64("float64", float64Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFloat64KeyAny(b *testing.B) {
|
func BenchmarkFloat64KeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("float64", float64Val)
|
_ = label.Any("float64", float64Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStringKey(b *testing.B) {
|
func BenchmarkStringKey(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.String("string", stringVal)
|
_ = label.String("string", stringVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStringKeyAny(b *testing.B) {
|
func BenchmarkStringKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("string", stringVal)
|
_ = label.Any("string", stringVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBytesKeyAny(b *testing.B) {
|
func BenchmarkBytesKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("bytes", bytesVal)
|
_ = label.Any("bytes", bytesVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStructKeyAny(b *testing.B) {
|
func BenchmarkStructKeyAny(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = kv.Any("struct", structVal)
|
_ = label.Any("struct", structVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,5 +12,5 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// package kv provides basic key and value types.
|
// Package label provides key and value labels.
|
||||||
package kv // import "go.opentelemetry.io/otel/api/kv"
|
package label // import "go.opentelemetry.io/otel/label"
|
@ -18,8 +18,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -119,7 +117,7 @@ func (d *defaultLabelEncoder) Encode(iter Iterator) string {
|
|||||||
|
|
||||||
_, _ = buf.WriteRune('=')
|
_, _ = buf.WriteRune('=')
|
||||||
|
|
||||||
if keyValue.Value.Type() == kv.STRING {
|
if keyValue.Value.Type() == STRING {
|
||||||
copyAndEscape(buf, keyValue.Value.AsString())
|
copyAndEscape(buf, keyValue.Value.AsString())
|
||||||
} else {
|
} else {
|
||||||
_, _ = buf.WriteString(keyValue.Value.Emit())
|
_, _ = buf.WriteString(keyValue.Value.Emit())
|
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
package label
|
package label
|
||||||
|
|
||||||
import (
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Iterator allows iterating over the set of labels in order,
|
// Iterator allows iterating over the set of labels in order,
|
||||||
// sorted by key.
|
// sorted by key.
|
||||||
type Iterator struct {
|
type Iterator struct {
|
||||||
@ -31,13 +27,13 @@ type Iterator struct {
|
|||||||
type MergeItererator struct {
|
type MergeItererator struct {
|
||||||
one oneIterator
|
one oneIterator
|
||||||
two oneIterator
|
two oneIterator
|
||||||
current kv.KeyValue
|
current KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
type oneIterator struct {
|
type oneIterator struct {
|
||||||
iter Iterator
|
iter Iterator
|
||||||
done bool
|
done bool
|
||||||
label kv.KeyValue
|
label KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next moves the iterator to the next position. Returns false if there
|
// 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()
|
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.
|
// true.
|
||||||
func (i *Iterator) Label() kv.KeyValue {
|
func (i *Iterator) Label() KeyValue {
|
||||||
kv, _ := i.storage.Get(i.idx)
|
kv, _ := i.storage.Get(i.idx)
|
||||||
return kv
|
return kv
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute is a synonym for Label().
|
// Attribute is a synonym for Label().
|
||||||
func (i *Iterator) Attribute() kv.KeyValue {
|
func (i *Iterator) Attribute() KeyValue {
|
||||||
return i.Label()
|
return i.Label()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexedLabel returns current index and label. Must be called only
|
// IndexedLabel returns current index and label. Must be called only
|
||||||
// after Next returns true.
|
// after Next returns true.
|
||||||
func (i *Iterator) IndexedLabel() (int, kv.KeyValue) {
|
func (i *Iterator) IndexedLabel() (int, KeyValue) {
|
||||||
return i.idx, i.Label()
|
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
|
// ToSlice is a convenience function that creates a slice of labels
|
||||||
// from the passed iterator. The iterator is set up to start from the
|
// from the passed iterator. The iterator is set up to start from the
|
||||||
// beginning before creating the slice.
|
// beginning before creating the slice.
|
||||||
func (i *Iterator) ToSlice() []kv.KeyValue {
|
func (i *Iterator) ToSlice() []KeyValue {
|
||||||
l := i.Len()
|
l := i.Len()
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
i.idx = -1
|
i.idx = -1
|
||||||
slice := make([]kv.KeyValue, 0, l)
|
slice := make([]KeyValue, 0, l)
|
||||||
for i.Next() {
|
for i.Next() {
|
||||||
slice = append(slice, i.Label())
|
slice = append(slice, i.Label())
|
||||||
}
|
}
|
||||||
@ -142,6 +138,6 @@ func (m *MergeItererator) Next() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Label returns the current value after Next() returns true.
|
// Label returns the current value after Next() returns true.
|
||||||
func (m *MergeItererator) Label() kv.KeyValue {
|
func (m *MergeItererator) Label() KeyValue {
|
||||||
return m.current
|
return m.current
|
||||||
}
|
}
|
@ -18,16 +18,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIterator(t *testing.T) {
|
func TestIterator(t *testing.T) {
|
||||||
one := kv.String("one", "1")
|
one := label.String("one", "1")
|
||||||
two := kv.Int("two", 2)
|
two := label.Int("two", 2)
|
||||||
lbl := label.NewSet(one, two)
|
lbl := label.NewSet(one, two)
|
||||||
iter := lbl.Iter()
|
iter := lbl.Iter()
|
||||||
require.Equal(t, 2, iter.Len())
|
require.Equal(t, 2, iter.Len())
|
||||||
@ -66,9 +64,9 @@ func TestMergedIterator(t *testing.T) {
|
|||||||
expect []string
|
expect []string
|
||||||
}
|
}
|
||||||
|
|
||||||
makeLabels := func(keys []string, num int) (result []kv.KeyValue) {
|
makeLabels := func(keys []string, num int) (result []label.KeyValue) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
result = append(result, kv.Int(k, num))
|
result = append(result, label.Int(k, num))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv
|
package label
|
||||||
|
|
||||||
// Key represents the key part in key-value pairs. It's a string. The
|
// Key represents the key part in key-value pairs. It's a string. The
|
||||||
// allowed character set in the key depends on the use of the key.
|
// allowed character set in the key depends on the use of the key.
|
||||||
@ -21,7 +21,7 @@ type Key string
|
|||||||
// Bool creates a KeyValue instance with a BOOL Value.
|
// Bool creates a KeyValue instance with a BOOL Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a bool value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Bool(name, value).
|
// key.Bool(name, value).
|
||||||
func (k Key) Bool(v bool) KeyValue {
|
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.
|
// Int64 creates a KeyValue instance with an INT64 Value.
|
||||||
//
|
//
|
||||||
// If creating both key and an int64 value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Int64(name, value).
|
// key.Int64(name, value).
|
||||||
func (k Key) Int64(v int64) KeyValue {
|
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.
|
// Uint64 creates a KeyValue instance with a UINT64 Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a uint64 value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Uint64(name, value).
|
// key.Uint64(name, value).
|
||||||
func (k Key) Uint64(v uint64) KeyValue {
|
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.
|
// Float64 creates a KeyValue instance with a FLOAT64 Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a float64 value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Float64(name, value).
|
// key.Float64(name, value).
|
||||||
func (k Key) Float64(v float64) KeyValue {
|
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.
|
// Int32 creates a KeyValue instance with an INT32 Value.
|
||||||
//
|
//
|
||||||
// If creating both key and an int32 value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Int32(name, value).
|
// key.Int32(name, value).
|
||||||
func (k Key) Int32(v int32) KeyValue {
|
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.
|
// Uint32 creates a KeyValue instance with a UINT32 Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a uint32 value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Uint32(name, value).
|
// key.Uint32(name, value).
|
||||||
func (k Key) Uint32(v uint32) KeyValue {
|
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.
|
// Float32 creates a KeyValue instance with a FLOAT32 Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a float32 value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Float32(name, value).
|
// key.Float32(name, value).
|
||||||
func (k Key) Float32(v float32) KeyValue {
|
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.
|
// String creates a KeyValue instance with a STRING Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a string value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.String(name, value).
|
// key.String(name, value).
|
||||||
func (k Key) String(v string) KeyValue {
|
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.
|
// 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
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Int(name, value).
|
// key.Int(name, value).
|
||||||
func (k Key) Int(v int) KeyValue {
|
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.
|
// 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
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Uint(name, value).
|
// key.Uint(name, value).
|
||||||
func (k Key) Uint(v uint) KeyValue {
|
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.
|
// Array creates a KeyValue instance with a ARRAY Value.
|
||||||
//
|
//
|
||||||
// If creating both key and a array value at the same time, then
|
// 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 -
|
// convenience function provided by the api/key package -
|
||||||
// key.Array(name, value).
|
// key.Array(name, value).
|
||||||
func (k Key) Array(v interface{}) KeyValue {
|
func (k Key) Array(v interface{}) KeyValue {
|
@ -12,36 +12,36 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv_test
|
package label_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDefined(t *testing.T) {
|
func TestDefined(t *testing.T) {
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name string
|
name string
|
||||||
k kv.Key
|
k label.Key
|
||||||
want bool
|
want bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Key.Defined() returns true when len(v.Name) != 0",
|
name: "Key.Defined() returns true when len(v.Name) != 0",
|
||||||
k: kv.Key("foo"),
|
k: label.Key("foo"),
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Defined() returns false when len(v.Name) == 0",
|
name: "Key.Defined() returns false when len(v.Name) == 0",
|
||||||
k: kv.Key(""),
|
k: label.Key(""),
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(testcase.name, func(t *testing.T) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
//func (k kv.Key) Defined() bool {
|
//func (k label.Key) Defined() bool {
|
||||||
have := testcase.k.Defined()
|
have := testcase.k.Defined()
|
||||||
if have != testcase.want {
|
if have != testcase.want {
|
||||||
t.Errorf("Want: %v, but have: %v", testcase.want, have)
|
t.Errorf("Want: %v, but have: %v", testcase.want, have)
|
||||||
@ -51,9 +51,9 @@ func TestDefined(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONValue(t *testing.T) {
|
func TestJSONValue(t *testing.T) {
|
||||||
var kvs interface{} = [2]kv.KeyValue{
|
var kvs interface{} = [2]label.KeyValue{
|
||||||
kv.String("A", "B"),
|
label.String("A", "B"),
|
||||||
kv.Int64("C", 1),
|
label.Int64("C", 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(kvs)
|
data, err := json.Marshal(kvs)
|
||||||
@ -66,52 +66,52 @@ func TestJSONValue(t *testing.T) {
|
|||||||
func TestEmit(t *testing.T) {
|
func TestEmit(t *testing.T) {
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name string
|
name string
|
||||||
v kv.Value
|
v label.Value
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.BOOL`,
|
name: `test Key.Emit() can emit a string representing self.BOOL`,
|
||||||
v: kv.BoolValue(true),
|
v: label.BoolValue(true),
|
||||||
want: "true",
|
want: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.INT32`,
|
name: `test Key.Emit() can emit a string representing self.INT32`,
|
||||||
v: kv.Int32Value(42),
|
v: label.Int32Value(42),
|
||||||
want: "42",
|
want: "42",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.INT64`,
|
name: `test Key.Emit() can emit a string representing self.INT64`,
|
||||||
v: kv.Int64Value(42),
|
v: label.Int64Value(42),
|
||||||
want: "42",
|
want: "42",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.UINT32`,
|
name: `test Key.Emit() can emit a string representing self.UINT32`,
|
||||||
v: kv.Uint32Value(42),
|
v: label.Uint32Value(42),
|
||||||
want: "42",
|
want: "42",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.UINT64`,
|
name: `test Key.Emit() can emit a string representing self.UINT64`,
|
||||||
v: kv.Uint64Value(42),
|
v: label.Uint64Value(42),
|
||||||
want: "42",
|
want: "42",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.FLOAT32`,
|
name: `test Key.Emit() can emit a string representing self.FLOAT32`,
|
||||||
v: kv.Float32Value(42.1),
|
v: label.Float32Value(42.1),
|
||||||
want: "42.1",
|
want: "42.1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.FLOAT64`,
|
name: `test Key.Emit() can emit a string representing self.FLOAT64`,
|
||||||
v: kv.Float64Value(42.1),
|
v: label.Float64Value(42.1),
|
||||||
want: "42.1",
|
want: "42.1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `test Key.Emit() can emit a string representing self.STRING`,
|
name: `test Key.Emit() can emit a string representing self.STRING`,
|
||||||
v: kv.StringValue("foo"),
|
v: label.StringValue("foo"),
|
||||||
want: "foo",
|
want: "foo",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(testcase.name, func(t *testing.T) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
//proto: func (v kv.Value) Emit() string {
|
//proto: func (v label.Value) Emit() string {
|
||||||
have := testcase.v.Emit()
|
have := testcase.v.Emit()
|
||||||
if have != testcase.want {
|
if have != testcase.want {
|
||||||
t.Errorf("Want: %s, but have: %s", testcase.want, have)
|
t.Errorf("Want: %s, but have: %s", testcase.want, have)
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv
|
package label
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv_test
|
package label_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@ -20,100 +20,100 @@ import (
|
|||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestKeyValueConstructors(t *testing.T) {
|
func TestKeyValueConstructors(t *testing.T) {
|
||||||
tt := []struct {
|
tt := []struct {
|
||||||
name string
|
name string
|
||||||
actual kv.KeyValue
|
actual label.KeyValue
|
||||||
expected kv.KeyValue
|
expected label.KeyValue
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Bool",
|
name: "Bool",
|
||||||
actual: kv.Bool("k1", true),
|
actual: label.Bool("k1", true),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.BoolValue(true),
|
Value: label.BoolValue(true),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Int64",
|
name: "Int64",
|
||||||
actual: kv.Int64("k1", 123),
|
actual: label.Int64("k1", 123),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.Int64Value(123),
|
Value: label.Int64Value(123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Uint64",
|
name: "Uint64",
|
||||||
actual: kv.Uint64("k1", 1),
|
actual: label.Uint64("k1", 1),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.Uint64Value(1),
|
Value: label.Uint64Value(1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Float64",
|
name: "Float64",
|
||||||
actual: kv.Float64("k1", 123.5),
|
actual: label.Float64("k1", 123.5),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.Float64Value(123.5),
|
Value: label.Float64Value(123.5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Int32",
|
name: "Int32",
|
||||||
actual: kv.Int32("k1", 123),
|
actual: label.Int32("k1", 123),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.Int32Value(123),
|
Value: label.Int32Value(123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Uint32",
|
name: "Uint32",
|
||||||
actual: kv.Uint32("k1", 123),
|
actual: label.Uint32("k1", 123),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.Uint32Value(123),
|
Value: label.Uint32Value(123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Float32",
|
name: "Float32",
|
||||||
actual: kv.Float32("k1", 123.5),
|
actual: label.Float32("k1", 123.5),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.Float32Value(123.5),
|
Value: label.Float32Value(123.5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "String",
|
name: "String",
|
||||||
actual: kv.String("k1", "123.5"),
|
actual: label.String("k1", "123.5"),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.StringValue("123.5"),
|
Value: label.StringValue("123.5"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Int",
|
name: "Int",
|
||||||
actual: kv.Int("k1", 123),
|
actual: label.Int("k1", 123),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.IntValue(123),
|
Value: label.IntValue(123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Uint",
|
name: "Uint",
|
||||||
actual: kv.Uint("k1", 123),
|
actual: label.Uint("k1", 123),
|
||||||
expected: kv.KeyValue{
|
expected: label.KeyValue{
|
||||||
Key: "k1",
|
Key: "k1",
|
||||||
Value: kv.UintValue(123),
|
Value: label.UintValue(123),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tt {
|
for _, test := range tt {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(kv.Value{})); diff != "" {
|
if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(label.Value{})); diff != "" {
|
||||||
t.Fatal(diff)
|
t.Fatal(diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -137,84 +137,84 @@ func TestAny(t *testing.T) {
|
|||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
key string
|
key string
|
||||||
value interface{}
|
value interface{}
|
||||||
wantType kv.Type
|
wantType label.Type
|
||||||
wantValue interface{}
|
wantValue interface{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
key: "bool type inferred",
|
key: "bool type inferred",
|
||||||
value: true,
|
value: true,
|
||||||
wantType: kv.BOOL,
|
wantType: label.BOOL,
|
||||||
wantValue: true,
|
wantValue: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "int64 type inferred",
|
key: "int64 type inferred",
|
||||||
value: int64(42),
|
value: int64(42),
|
||||||
wantType: kv.INT64,
|
wantType: label.INT64,
|
||||||
wantValue: int64(42),
|
wantValue: int64(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "uint64 type inferred",
|
key: "uint64 type inferred",
|
||||||
value: uint64(42),
|
value: uint64(42),
|
||||||
wantType: kv.UINT64,
|
wantType: label.UINT64,
|
||||||
wantValue: uint64(42),
|
wantValue: uint64(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "float64 type inferred",
|
key: "float64 type inferred",
|
||||||
value: float64(42.1),
|
value: float64(42.1),
|
||||||
wantType: kv.FLOAT64,
|
wantType: label.FLOAT64,
|
||||||
wantValue: 42.1,
|
wantValue: 42.1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "int32 type inferred",
|
key: "int32 type inferred",
|
||||||
value: int32(42),
|
value: int32(42),
|
||||||
wantType: kv.INT32,
|
wantType: label.INT32,
|
||||||
wantValue: int32(42),
|
wantValue: int32(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "uint32 type inferred",
|
key: "uint32 type inferred",
|
||||||
value: uint32(42),
|
value: uint32(42),
|
||||||
wantType: kv.UINT32,
|
wantType: label.UINT32,
|
||||||
wantValue: uint32(42),
|
wantValue: uint32(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "float32 type inferred",
|
key: "float32 type inferred",
|
||||||
value: float32(42.1),
|
value: float32(42.1),
|
||||||
wantType: kv.FLOAT32,
|
wantType: label.FLOAT32,
|
||||||
wantValue: float32(42.1),
|
wantValue: float32(42.1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "string type inferred",
|
key: "string type inferred",
|
||||||
value: "foo",
|
value: "foo",
|
||||||
wantType: kv.STRING,
|
wantType: label.STRING,
|
||||||
wantValue: "foo",
|
wantValue: "foo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "stringer type inferred",
|
key: "stringer type inferred",
|
||||||
value: builder,
|
value: builder,
|
||||||
wantType: kv.STRING,
|
wantType: label.STRING,
|
||||||
wantValue: "foo",
|
wantValue: "foo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "unknown value serialized as %v",
|
key: "unknown value serialized as %v",
|
||||||
value: nil,
|
value: nil,
|
||||||
wantType: kv.STRING,
|
wantType: label.STRING,
|
||||||
wantValue: "<nil>",
|
wantValue: "<nil>",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "JSON struct serialized correctly",
|
key: "JSON struct serialized correctly",
|
||||||
value: &jsonifyStruct,
|
value: &jsonifyStruct,
|
||||||
wantType: kv.STRING,
|
wantType: label.STRING,
|
||||||
wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`,
|
wantValue: `{"Public":"foo","tagName":"baz","Empty":""}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "Invalid JSON struct falls back to string",
|
key: "Invalid JSON struct falls back to string",
|
||||||
value: &invalidStruct,
|
value: &invalidStruct,
|
||||||
wantType: kv.STRING,
|
wantType: label.STRING,
|
||||||
wantValue: "&{(0+0i)}",
|
wantValue: "&{(0+0i)}",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("Running test case %s", testcase.key)
|
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 {
|
if keyValue.Value.Type() != testcase.wantType {
|
||||||
t.Errorf("wrong value type, got %#v, expected %#v", keyValue.Value.Type(), testcase.wantType)
|
t.Errorf("wrong value type, got %#v, expected %#v", keyValue.Value.Type(), testcase.wantType)
|
||||||
}
|
}
|
@ -12,15 +12,13 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package label // import "go.opentelemetry.io/otel/api/label"
|
package label
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -43,7 +41,7 @@ type (
|
|||||||
encoded [maxConcurrentEncoders]string
|
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
|
// constructed with keys in sorted order. This can be used as
|
||||||
// a map key or for equality checking between Sets.
|
// a map key or for equality checking between Sets.
|
||||||
Distinct struct {
|
Distinct struct {
|
||||||
@ -55,25 +53,25 @@ type (
|
|||||||
// the filtered label set. When the filter returns false, the
|
// the filtered label set. When the filter returns false, the
|
||||||
// label is excluded from the filtered label set, and the
|
// label is excluded from the filtered label set, and the
|
||||||
// label instead appears in the `removed` list of excluded labels.
|
// 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
|
// 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
|
// memory optimization. A pointer to one of these is needed
|
||||||
// for the call to `sort.Stable()`, which the caller may
|
// for the call to `sort.Stable()`, which the caller may
|
||||||
// provide in order to avoid an allocation. See
|
// provide in order to avoid an allocation. See
|
||||||
// `NewSetWithSortable()`.
|
// `NewSetWithSortable()`.
|
||||||
Sortable []kv.KeyValue
|
Sortable []KeyValue
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// keyValueType is used in `computeDistinctReflect`.
|
// keyValueType is used in `computeDistinctReflect`.
|
||||||
keyValueType = reflect.TypeOf(kv.KeyValue{})
|
keyValueType = reflect.TypeOf(KeyValue{})
|
||||||
|
|
||||||
// emptySet is returned for empty label sets.
|
// emptySet is returned for empty label sets.
|
||||||
emptySet = &Set{
|
emptySet = &Set{
|
||||||
equivalent: Distinct{
|
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.
|
// 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 {
|
if l == nil {
|
||||||
return kv.KeyValue{}, false
|
return KeyValue{}, false
|
||||||
}
|
}
|
||||||
value := l.equivalent.reflect()
|
value := l.equivalent.reflect()
|
||||||
|
|
||||||
if idx >= 0 && idx < value.Len() {
|
if idx >= 0 && idx < value.Len() {
|
||||||
// Note: The Go compiler successfully avoids an allocation for
|
// Note: The Go compiler successfully avoids an allocation for
|
||||||
// the interface{} conversion here:
|
// 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.
|
// 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 {
|
if l == nil {
|
||||||
return kv.Value{}, false
|
return Value{}, false
|
||||||
}
|
}
|
||||||
rValue := l.equivalent.reflect()
|
rValue := l.equivalent.reflect()
|
||||||
vlen := rValue.Len()
|
vlen := rValue.Len()
|
||||||
|
|
||||||
idx := sort.Search(vlen, func(idx int) bool {
|
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 {
|
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 {
|
if k == keyValue.Key {
|
||||||
return keyValue.Value, true
|
return keyValue.Value, true
|
||||||
}
|
}
|
||||||
return kv.Value{}, false
|
return Value{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasValue tests whether a key is defined in this set.
|
// 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 {
|
if l == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -158,7 +156,7 @@ func (l *Set) Iter() Iterator {
|
|||||||
|
|
||||||
// ToSlice returns the set of labels belonging to this set, sorted,
|
// ToSlice returns the set of labels belonging to this set, sorted,
|
||||||
// where keys appear no more than once.
|
// where keys appear no more than once.
|
||||||
func (l *Set) ToSlice() []kv.KeyValue {
|
func (l *Set) ToSlice() []KeyValue {
|
||||||
iter := l.Iter()
|
iter := l.Iter()
|
||||||
return iter.ToSlice()
|
return iter.ToSlice()
|
||||||
}
|
}
|
||||||
@ -239,7 +237,7 @@ func empty() Set {
|
|||||||
//
|
//
|
||||||
// Except for empty sets, this method adds an additional allocation
|
// Except for empty sets, this method adds an additional allocation
|
||||||
// compared with calls that include a `*Sortable`.
|
// compared with calls that include a `*Sortable`.
|
||||||
func NewSet(kvs ...kv.KeyValue) Set {
|
func NewSet(kvs ...KeyValue) Set {
|
||||||
// Check for empty set.
|
// Check for empty set.
|
||||||
if len(kvs) == 0 {
|
if len(kvs) == 0 {
|
||||||
return empty()
|
return empty()
|
||||||
@ -252,7 +250,7 @@ func NewSet(kvs ...kv.KeyValue) Set {
|
|||||||
// `NewSetWithSortableFiltered` for more details.
|
// `NewSetWithSortableFiltered` for more details.
|
||||||
//
|
//
|
||||||
// This call includes a `*Sortable` option as a memory optimization.
|
// 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.
|
// Check for empty set.
|
||||||
if len(kvs) == 0 {
|
if len(kvs) == 0 {
|
||||||
return empty()
|
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
|
// This call includes a `Filter` to include/exclude label keys from
|
||||||
// the return value. Excluded keys are returned as a slice of label
|
// the return value. Excluded keys are returned as a slice of label
|
||||||
// values.
|
// values.
|
||||||
func NewSetWithFiltered(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) {
|
func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
|
||||||
// Check for empty set.
|
// Check for empty set.
|
||||||
if len(kvs) == 0 {
|
if len(kvs) == 0 {
|
||||||
return empty(), nil
|
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.
|
// The result maintains a cache of encoded labels, by label.EncoderID.
|
||||||
// This value should not be copied after its first use.
|
// 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).
|
// 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.
|
// Check for empty set.
|
||||||
if len(kvs) == 0 {
|
if len(kvs) == 0 {
|
||||||
return empty(), nil
|
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
|
// filterSet reorders `kvs` so that included keys are contiguous at
|
||||||
// the end of the slice, while excluded keys precede the included keys.
|
// the end of the slice, while excluded keys precede the included keys.
|
||||||
func filterSet(kvs []kv.KeyValue, filter Filter) (Set, []kv.KeyValue) {
|
func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
|
||||||
var excluded []kv.KeyValue
|
var excluded []KeyValue
|
||||||
|
|
||||||
// Move labels that do not match the filter so
|
// Move labels that do not match the filter so
|
||||||
// they're adjacent before calling computeDistinct().
|
// 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
|
// Filter returns a filtered copy of this `Set`. See the
|
||||||
// documentation for `NewSetWithSortableFiltered` for more details.
|
// 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 {
|
if re == nil {
|
||||||
return Set{
|
return Set{
|
||||||
equivalent: l.equivalent,
|
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
|
// computeDistinct returns a `Distinct` using either the fixed- or
|
||||||
// reflect-oriented code path, depending on the size of the input.
|
// reflect-oriented code path, depending on the size of the input.
|
||||||
// The input slice is assumed to already be sorted and de-duplicated.
|
// 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)
|
iface := computeDistinctFixed(kvs)
|
||||||
if iface == nil {
|
if iface == nil {
|
||||||
iface = computeDistinctReflect(kvs)
|
iface = computeDistinctReflect(kvs)
|
||||||
@ -392,46 +390,46 @@ func computeDistinct(kvs []kv.KeyValue) Distinct {
|
|||||||
|
|
||||||
// computeDistinctFixed computes a `Distinct` for small slices. It
|
// computeDistinctFixed computes a `Distinct` for small slices. It
|
||||||
// returns nil if the input is too large for this code path.
|
// 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) {
|
switch len(kvs) {
|
||||||
case 1:
|
case 1:
|
||||||
ptr := new([1]kv.KeyValue)
|
ptr := new([1]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 2:
|
case 2:
|
||||||
ptr := new([2]kv.KeyValue)
|
ptr := new([2]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 3:
|
case 3:
|
||||||
ptr := new([3]kv.KeyValue)
|
ptr := new([3]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 4:
|
case 4:
|
||||||
ptr := new([4]kv.KeyValue)
|
ptr := new([4]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 5:
|
case 5:
|
||||||
ptr := new([5]kv.KeyValue)
|
ptr := new([5]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 6:
|
case 6:
|
||||||
ptr := new([6]kv.KeyValue)
|
ptr := new([6]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 7:
|
case 7:
|
||||||
ptr := new([7]kv.KeyValue)
|
ptr := new([7]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 8:
|
case 8:
|
||||||
ptr := new([8]kv.KeyValue)
|
ptr := new([8]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 9:
|
case 9:
|
||||||
ptr := new([9]kv.KeyValue)
|
ptr := new([9]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
case 10:
|
case 10:
|
||||||
ptr := new([10]kv.KeyValue)
|
ptr := new([10]KeyValue)
|
||||||
copy((*ptr)[:], kvs)
|
copy((*ptr)[:], kvs)
|
||||||
return *ptr
|
return *ptr
|
||||||
default:
|
default:
|
||||||
@ -441,10 +439,10 @@ func computeDistinctFixed(kvs []kv.KeyValue) interface{} {
|
|||||||
|
|
||||||
// computeDistinctReflect computes a `Distinct` using reflection,
|
// computeDistinctReflect computes a `Distinct` using reflection,
|
||||||
// works for any size input.
|
// 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()
|
at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem()
|
||||||
for i, keyValue := range kvs {
|
for i, keyValue := range kvs {
|
||||||
*(at.Index(i).Addr().Interface().(*kv.KeyValue)) = keyValue
|
*(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue
|
||||||
}
|
}
|
||||||
return at.Interface()
|
return at.Interface()
|
||||||
}
|
}
|
@ -18,14 +18,13 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
kvs []kv.KeyValue
|
kvs []label.KeyValue
|
||||||
|
|
||||||
keyRe *regexp.Regexp
|
keyRe *regexp.Regexp
|
||||||
|
|
||||||
@ -33,14 +32,14 @@ type testCase struct {
|
|||||||
fullEnc string
|
fullEnc string
|
||||||
}
|
}
|
||||||
|
|
||||||
func expect(enc string, kvs ...kv.KeyValue) testCase {
|
func expect(enc string, kvs ...label.KeyValue) testCase {
|
||||||
return testCase{
|
return testCase{
|
||||||
kvs: kvs,
|
kvs: kvs,
|
||||||
encoding: enc,
|
encoding: enc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectFiltered(enc, filter, fullEnc string, kvs ...kv.KeyValue) testCase {
|
func expectFiltered(enc, filter, fullEnc string, kvs ...label.KeyValue) testCase {
|
||||||
return testCase{
|
return testCase{
|
||||||
kvs: kvs,
|
kvs: kvs,
|
||||||
keyRe: regexp.MustCompile(filter),
|
keyRe: regexp.MustCompile(filter),
|
||||||
@ -51,16 +50,16 @@ func expectFiltered(enc, filter, fullEnc string, kvs ...kv.KeyValue) testCase {
|
|||||||
|
|
||||||
func TestSetDedup(t *testing.T) {
|
func TestSetDedup(t *testing.T) {
|
||||||
cases := []testCase{
|
cases := []testCase{
|
||||||
expect("A=B", kv.String("A", "2"), kv.String("A", "B")),
|
expect("A=B", label.String("A", "2"), label.String("A", "B")),
|
||||||
expect("A=B", kv.String("A", "2"), kv.Int("A", 1), kv.String("A", "B")),
|
expect("A=B", label.String("A", "2"), label.Int("A", 1), label.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", "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", label.String("A", "1"), label.String("C", "D"), label.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", label.String("A", "2"), label.String("A", "B"), label.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", label.Float64("C", 1.2), label.String("A", "2"), label.String("A", "B"), label.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", 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", 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", 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", 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", "B"), label.String("A", "C"), label.String("A", "D"), label.String("A", "B"), label.String("C", "D")),
|
||||||
}
|
}
|
||||||
enc := label.DefaultEncoder()
|
enc := label.DefaultEncoder()
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ func TestSetDedup(t *testing.T) {
|
|||||||
d2s := map[label.Distinct][]string{}
|
d2s := map[label.Distinct][]string{}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
cpy := make([]kv.KeyValue, len(tc.kvs))
|
cpy := make([]label.KeyValue, len(tc.kvs))
|
||||||
copy(cpy, tc.kvs)
|
copy(cpy, tc.kvs)
|
||||||
sl := label.NewSet(cpy...)
|
sl := label.NewSet(cpy...)
|
||||||
|
|
||||||
@ -130,19 +129,19 @@ func TestSetDedup(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUniqueness(t *testing.T) {
|
func TestUniqueness(t *testing.T) {
|
||||||
short := []kv.KeyValue{
|
short := []label.KeyValue{
|
||||||
kv.String("A", "0"),
|
label.String("A", "0"),
|
||||||
kv.String("B", "2"),
|
label.String("B", "2"),
|
||||||
kv.String("A", "1"),
|
label.String("A", "1"),
|
||||||
}
|
}
|
||||||
long := []kv.KeyValue{
|
long := []label.KeyValue{
|
||||||
kv.String("B", "2"),
|
label.String("B", "2"),
|
||||||
kv.String("C", "5"),
|
label.String("C", "5"),
|
||||||
kv.String("B", "2"),
|
label.String("B", "2"),
|
||||||
kv.String("C", "1"),
|
label.String("C", "1"),
|
||||||
kv.String("A", "4"),
|
label.String("A", "4"),
|
||||||
kv.String("C", "3"),
|
label.String("C", "3"),
|
||||||
kv.String("A", "1"),
|
label.String("A", "1"),
|
||||||
}
|
}
|
||||||
cases := []testCase{
|
cases := []testCase{
|
||||||
expectFiltered("A=1", "^A$", "B=2", short...),
|
expectFiltered("A=1", "^A$", "B=2", short...),
|
||||||
@ -158,9 +157,9 @@ func TestUniqueness(t *testing.T) {
|
|||||||
enc := label.DefaultEncoder()
|
enc := label.DefaultEncoder()
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
cpy := make([]kv.KeyValue, len(tc.kvs))
|
cpy := make([]label.KeyValue, len(tc.kvs))
|
||||||
copy(cpy, 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))
|
return tc.keyRe.MatchString(string(label.Key))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -172,7 +171,7 @@ func TestUniqueness(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLookup(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")
|
value, has := set.Value("C")
|
||||||
require.True(t, has)
|
require.True(t, has)
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by "stringer -type=Type"; DO NOT EDIT.
|
// Code generated by "stringer -type=Type"; DO NOT EDIT.
|
||||||
|
|
||||||
package kv
|
package label
|
||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv
|
package label
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -22,7 +22,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/internal"
|
"go.opentelemetry.io/otel/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate stringer -type=Type
|
//go:generate stringer -type=Type
|
@ -12,78 +12,78 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package kv_test
|
package label_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValue(t *testing.T) {
|
func TestValue(t *testing.T) {
|
||||||
k := kv.Key("test")
|
k := label.Key("test")
|
||||||
bli := getBitlessInfo(42)
|
bli := getBitlessInfo(42)
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name string
|
name string
|
||||||
value kv.Value
|
value label.Value
|
||||||
wantType kv.Type
|
wantType label.Type
|
||||||
wantValue interface{}
|
wantValue interface{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Key.Bool() correctly returns keys's internal bool value",
|
name: "Key.Bool() correctly returns keys's internal bool value",
|
||||||
value: k.Bool(true).Value,
|
value: k.Bool(true).Value,
|
||||||
wantType: kv.BOOL,
|
wantType: label.BOOL,
|
||||||
wantValue: true,
|
wantValue: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]bool) correctly return key's internal bool values",
|
name: "Key.Array([]bool) correctly return key's internal bool values",
|
||||||
value: k.Array([]bool{true, false}).Value,
|
value: k.Array([]bool{true, false}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []bool{true, false},
|
wantValue: []bool{true, false},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Int64() correctly returns keys's internal int64 value",
|
name: "Key.Int64() correctly returns keys's internal int64 value",
|
||||||
value: k.Int64(42).Value,
|
value: k.Int64(42).Value,
|
||||||
wantType: kv.INT64,
|
wantType: label.INT64,
|
||||||
wantValue: int64(42),
|
wantValue: int64(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Uint64() correctly returns keys's internal uint64 value",
|
name: "Key.Uint64() correctly returns keys's internal uint64 value",
|
||||||
value: k.Uint64(42).Value,
|
value: k.Uint64(42).Value,
|
||||||
wantType: kv.UINT64,
|
wantType: label.UINT64,
|
||||||
wantValue: uint64(42),
|
wantValue: uint64(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Float64() correctly returns keys's internal float64 value",
|
name: "Key.Float64() correctly returns keys's internal float64 value",
|
||||||
value: k.Float64(42.1).Value,
|
value: k.Float64(42.1).Value,
|
||||||
wantType: kv.FLOAT64,
|
wantType: label.FLOAT64,
|
||||||
wantValue: 42.1,
|
wantValue: 42.1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Int32() correctly returns keys's internal int32 value",
|
name: "Key.Int32() correctly returns keys's internal int32 value",
|
||||||
value: k.Int32(42).Value,
|
value: k.Int32(42).Value,
|
||||||
wantType: kv.INT32,
|
wantType: label.INT32,
|
||||||
wantValue: int32(42),
|
wantValue: int32(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Uint32() correctly returns keys's internal uint32 value",
|
name: "Key.Uint32() correctly returns keys's internal uint32 value",
|
||||||
value: k.Uint32(42).Value,
|
value: k.Uint32(42).Value,
|
||||||
wantType: kv.UINT32,
|
wantType: label.UINT32,
|
||||||
wantValue: uint32(42),
|
wantValue: uint32(42),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Float32() correctly returns keys's internal float32 value",
|
name: "Key.Float32() correctly returns keys's internal float32 value",
|
||||||
value: k.Float32(42.1).Value,
|
value: k.Float32(42.1).Value,
|
||||||
wantType: kv.FLOAT32,
|
wantType: label.FLOAT32,
|
||||||
wantValue: float32(42.1),
|
wantValue: float32(42.1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.String() correctly returns keys's internal string value",
|
name: "Key.String() correctly returns keys's internal string value",
|
||||||
value: k.String("foo").Value,
|
value: k.String("foo").Value,
|
||||||
wantType: kv.STRING,
|
wantType: label.STRING,
|
||||||
wantValue: "foo",
|
wantValue: "foo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -101,61 +101,61 @@ func TestValue(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Key.Array([]int64) correctly returns keys's internal int64 values",
|
name: "Key.Array([]int64) correctly returns keys's internal int64 values",
|
||||||
value: k.Array([]int64{42, 43}).Value,
|
value: k.Array([]int64{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []int64{42, 43},
|
wantValue: []int64{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "KeyArray([]uint64) correctly returns keys's internal uint64 values",
|
name: "KeyArray([]uint64) correctly returns keys's internal uint64 values",
|
||||||
value: k.Array([]uint64{42, 43}).Value,
|
value: k.Array([]uint64{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []uint64{42, 43},
|
wantValue: []uint64{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]float64) correctly returns keys's internal float64 values",
|
name: "Key.Array([]float64) correctly returns keys's internal float64 values",
|
||||||
value: k.Array([]float64{42, 43}).Value,
|
value: k.Array([]float64{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []float64{42, 43},
|
wantValue: []float64{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]int32) correctly returns keys's internal int32 values",
|
name: "Key.Array([]int32) correctly returns keys's internal int32 values",
|
||||||
value: k.Array([]int32{42, 43}).Value,
|
value: k.Array([]int32{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []int32{42, 43},
|
wantValue: []int32{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]uint32) correctly returns keys's internal uint32 values",
|
name: "Key.Array([]uint32) correctly returns keys's internal uint32 values",
|
||||||
value: k.Array([]uint32{42, 43}).Value,
|
value: k.Array([]uint32{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []uint32{42, 43},
|
wantValue: []uint32{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]float32) correctly returns keys's internal float32 values",
|
name: "Key.Array([]float32) correctly returns keys's internal float32 values",
|
||||||
value: k.Array([]float32{42, 43}).Value,
|
value: k.Array([]float32{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []float32{42, 43},
|
wantValue: []float32{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]string) correctly return key's internal string values",
|
name: "Key.Array([]string) correctly return key's internal string values",
|
||||||
value: k.Array([]string{"foo", "bar"}).Value,
|
value: k.Array([]string{"foo", "bar"}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []string{"foo", "bar"},
|
wantValue: []string{"foo", "bar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]int) correctly returns keys's internal signed integral values",
|
name: "Key.Array([]int) correctly returns keys's internal signed integral values",
|
||||||
value: k.Array([]int{42, 43}).Value,
|
value: k.Array([]int{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []int{42, 43},
|
wantValue: []int{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([]uint) correctly returns keys's internal unsigned integral values",
|
name: "Key.Array([]uint) correctly returns keys's internal unsigned integral values",
|
||||||
value: k.Array([]uint{42, 43}).Value,
|
value: k.Array([]uint{42, 43}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: []uint{42, 43},
|
wantValue: []uint{42, 43},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key.Array([][]int) correctly return key's multi dimensional array",
|
name: "Key.Array([][]int) correctly return key's multi dimensional array",
|
||||||
value: k.Array([][]int{{1, 2}, {3, 4}}).Value,
|
value: k.Array([][]int{{1, 2}, {3, 4}}).Value,
|
||||||
wantType: kv.ARRAY,
|
wantType: label.ARRAY,
|
||||||
wantValue: [][]int{{1, 2}, {3, 4}},
|
wantValue: [][]int{{1, 2}, {3, 4}},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
@ -173,8 +173,8 @@ func TestValue(t *testing.T) {
|
|||||||
type bitlessInfo struct {
|
type bitlessInfo struct {
|
||||||
intValue int
|
intValue int
|
||||||
uintValue uint
|
uintValue uint
|
||||||
signedType kv.Type
|
signedType label.Type
|
||||||
unsignedType kv.Type
|
unsignedType label.Type
|
||||||
signedValue interface{}
|
signedValue interface{}
|
||||||
unsignedValue interface{}
|
unsignedValue interface{}
|
||||||
}
|
}
|
||||||
@ -184,8 +184,8 @@ func getBitlessInfo(i int) bitlessInfo {
|
|||||||
return bitlessInfo{
|
return bitlessInfo{
|
||||||
intValue: i,
|
intValue: i,
|
||||||
uintValue: uint(i),
|
uintValue: uint(i),
|
||||||
signedType: kv.INT32,
|
signedType: label.INT32,
|
||||||
unsignedType: kv.UINT32,
|
unsignedType: label.UINT32,
|
||||||
signedValue: int32(i),
|
signedValue: int32(i),
|
||||||
unsignedValue: uint32(i),
|
unsignedValue: uint32(i),
|
||||||
}
|
}
|
||||||
@ -193,8 +193,8 @@ func getBitlessInfo(i int) bitlessInfo {
|
|||||||
return bitlessInfo{
|
return bitlessInfo{
|
||||||
intValue: i,
|
intValue: i,
|
||||||
uintValue: uint(i),
|
uintValue: uint(i),
|
||||||
signedType: kv.INT64,
|
signedType: label.INT64,
|
||||||
unsignedType: kv.UINT64,
|
unsignedType: label.UINT64,
|
||||||
signedValue: int64(i),
|
signedValue: int64(i),
|
||||||
unsignedValue: uint64(i),
|
unsignedValue: uint64(i),
|
||||||
}
|
}
|
@ -21,8 +21,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
|
@ -17,18 +17,17 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testSlice = []kv.KeyValue{
|
var testSlice = []label.KeyValue{
|
||||||
kv.String("bar", "baz"),
|
label.String("bar", "baz"),
|
||||||
kv.Int("foo", 42),
|
label.Int("foo", 42),
|
||||||
}
|
}
|
||||||
|
|
||||||
func newIter(slice []kv.KeyValue) label.Iterator {
|
func newIter(slice []label.KeyValue) label.Iterator {
|
||||||
labels := label.NewSet(slice...)
|
labels := label.NewSet(slice...)
|
||||||
return labels.Iter()
|
return labels.Iter()
|
||||||
}
|
}
|
||||||
@ -38,17 +37,17 @@ func TestLabelIterator(t *testing.T) {
|
|||||||
require.Equal(t, 2, iter.Len())
|
require.Equal(t, 2, iter.Len())
|
||||||
|
|
||||||
require.True(t, iter.Next())
|
require.True(t, iter.Next())
|
||||||
require.Equal(t, kv.String("bar", "baz"), iter.Label())
|
require.Equal(t, label.String("bar", "baz"), iter.Label())
|
||||||
idx, label := iter.IndexedLabel()
|
idx, kv := iter.IndexedLabel()
|
||||||
require.Equal(t, 0, idx)
|
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.Equal(t, 2, iter.Len())
|
||||||
|
|
||||||
require.True(t, iter.Next())
|
require.True(t, iter.Next())
|
||||||
require.Equal(t, kv.Int("foo", 42), iter.Label())
|
require.Equal(t, label.Int("foo", 42), iter.Label())
|
||||||
idx, label = iter.IndexedLabel()
|
idx, kv = iter.IndexedLabel()
|
||||||
require.Equal(t, 1, idx)
|
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.Equal(t, 2, iter.Len())
|
||||||
|
|
||||||
require.False(t, iter.Next())
|
require.False(t, iter.Next())
|
||||||
|
@ -21,9 +21,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"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,
|
// If there is an existing record with the same descriptor and labels,
|
||||||
// the stored aggregator will be returned and should be merged.
|
// the stored aggregator will be returned and should be merged.
|
||||||
func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...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...)
|
elabels := label.NewSet(labels...)
|
||||||
|
|
||||||
key := mapkey{
|
key := mapkey{
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
apitrace "go.opentelemetry.io/otel/api/trace"
|
apitrace "go.opentelemetry.io/otel/api/trace"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"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
|
// The wall clock time of EndTime will be adjusted to always be offset
|
||||||
// from StartTime by the duration of the span.
|
// from StartTime by the duration of the span.
|
||||||
EndTime time.Time
|
EndTime time.Time
|
||||||
Attributes []kv.KeyValue
|
Attributes []label.KeyValue
|
||||||
MessageEvents []Event
|
MessageEvents []Event
|
||||||
Links []apitrace.Link
|
Links []apitrace.Link
|
||||||
StatusCode codes.Code
|
StatusCode codes.Code
|
||||||
@ -84,8 +84,8 @@ type Event struct {
|
|||||||
// Name is the name of this event
|
// Name is the name of this event
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
// Attributes contains a list of kv pairs.
|
// Attributes contains a list of key-value pairs.
|
||||||
Attributes []kv.KeyValue
|
Attributes []label.KeyValue
|
||||||
|
|
||||||
// Time is the time at which this event was recorded.
|
// Time is the time at which this event was recorded.
|
||||||
Time time.Time
|
Time time.Time
|
||||||
|
@ -21,9 +21,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
sdk "go.opentelemetry.io/otel/sdk/metric"
|
sdk "go.opentelemetry.io/otel/sdk/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
"go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
||||||
@ -60,8 +59,8 @@ func (f *benchFixture) meterMust() metric.MeterMust {
|
|||||||
return metric.Must(f.meter)
|
return metric.Must(f.meter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeManyLabels(n int) [][]kv.KeyValue {
|
func makeManyLabels(n int) [][]label.KeyValue {
|
||||||
r := make([][]kv.KeyValue, n)
|
r := make([][]label.KeyValue, n)
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
r[i] = makeLabels(1)
|
r[i] = makeLabels(1)
|
||||||
@ -70,9 +69,9 @@ func makeManyLabels(n int) [][]kv.KeyValue {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeLabels(n int) []kv.KeyValue {
|
func makeLabels(n int) []label.KeyValue {
|
||||||
used := map[string]bool{}
|
used := map[string]bool{}
|
||||||
l := make([]kv.KeyValue, n)
|
l := make([]label.KeyValue, n)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
var k string
|
var k string
|
||||||
for {
|
for {
|
||||||
@ -82,7 +81,7 @@ func makeLabels(n int) []kv.KeyValue {
|
|||||||
break
|
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
|
return l
|
||||||
}
|
}
|
||||||
@ -169,7 +168,7 @@ func BenchmarkAcquireReleaseExistingHandle(b *testing.B) {
|
|||||||
|
|
||||||
// Iterators
|
// Iterators
|
||||||
|
|
||||||
var benchmarkIteratorVar kv.KeyValue
|
var benchmarkIteratorVar label.KeyValue
|
||||||
|
|
||||||
func benchmarkIterator(b *testing.B, n int) {
|
func benchmarkIterator(b *testing.B, n int) {
|
||||||
labels := label.NewSet(makeLabels(n)...)
|
labels := label.NewSet(makeLabels(n)...)
|
||||||
@ -218,7 +217,7 @@ func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) {
|
|||||||
sdk := global.Meter("test")
|
sdk := global.Meter("test")
|
||||||
global.SetMeterProvider(fix)
|
global.SetMeterProvider(fix)
|
||||||
|
|
||||||
labs := []kv.KeyValue{kv.String("A", "B")}
|
labs := []label.KeyValue{label.String("A", "B")}
|
||||||
cnt := Must(sdk).NewInt64Counter("int64.counter")
|
cnt := Must(sdk).NewInt64Counter("int64.counter")
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
@ -539,7 +538,7 @@ func BenchmarkRepeatedDirectCalls(b *testing.B) {
|
|||||||
fix := newFixture(b)
|
fix := newFixture(b)
|
||||||
|
|
||||||
c := fix.meterMust().NewInt64Counter("int64.counter")
|
c := fix.meterMust().NewInt64Counter("int64.counter")
|
||||||
k := kv.String("bench", "true")
|
k := label.String("bench", "true")
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
|
@ -22,9 +22,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||||
@ -47,7 +46,7 @@ func TestPullNoCache(t *testing.T) {
|
|||||||
meter := puller.Provider().Meter("nocache")
|
meter := puller.Provider().Meter("nocache")
|
||||||
counter := metric.Must(meter).NewInt64Counter("counter.sum")
|
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))
|
require.NoError(t, puller.Collect(ctx))
|
||||||
records := processortest.NewOutput(label.DefaultEncoder())
|
records := processortest.NewOutput(label.DefaultEncoder())
|
||||||
@ -57,7 +56,7 @@ func TestPullNoCache(t *testing.T) {
|
|||||||
"counter.sum/A=B/": 10,
|
"counter.sum/A=B/": 10,
|
||||||
}, records.Map())
|
}, records.Map())
|
||||||
|
|
||||||
counter.Add(ctx, 10, kv.String("A", "B"))
|
counter.Add(ctx, 10, label.String("A", "B"))
|
||||||
|
|
||||||
require.NoError(t, puller.Collect(ctx))
|
require.NoError(t, puller.Collect(ctx))
|
||||||
records = processortest.NewOutput(label.DefaultEncoder())
|
records = processortest.NewOutput(label.DefaultEncoder())
|
||||||
@ -84,7 +83,7 @@ func TestPullWithCache(t *testing.T) {
|
|||||||
meter := puller.Provider().Meter("nocache")
|
meter := puller.Provider().Meter("nocache")
|
||||||
counter := metric.Must(meter).NewInt64Counter("counter.sum")
|
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))
|
require.NoError(t, puller.Collect(ctx))
|
||||||
records := processortest.NewOutput(label.DefaultEncoder())
|
records := processortest.NewOutput(label.DefaultEncoder())
|
||||||
@ -94,7 +93,7 @@ func TestPullWithCache(t *testing.T) {
|
|||||||
"counter.sum/A=B/": 10,
|
"counter.sum/A=B/": 10,
|
||||||
}, records.Map())
|
}, records.Map())
|
||||||
|
|
||||||
counter.Add(ctx, 10, kv.String("A", "B"))
|
counter.Add(ctx, 10, label.String("A", "B"))
|
||||||
|
|
||||||
// Cached value!
|
// Cached value!
|
||||||
require.NoError(t, puller.Collect(ctx))
|
require.NoError(t, puller.Collect(ctx))
|
||||||
|
@ -17,15 +17,14 @@ package push
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWithResource(t *testing.T) {
|
func TestWithResource(t *testing.T) {
|
||||||
r := resource.New(kv.String("A", "a"))
|
r := resource.New(label.String("A", "a"))
|
||||||
|
|
||||||
c := &Config{}
|
c := &Config{}
|
||||||
WithResource(r).Apply(c)
|
WithResource(r).Apply(c)
|
||||||
|
@ -25,9 +25,8 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
||||||
@ -37,7 +36,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"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 {
|
type handler struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@ -201,7 +200,7 @@ func TestPushExportError(t *testing.T) {
|
|||||||
p.Start()
|
p.Start()
|
||||||
runtime.Gosched()
|
runtime.Gosched()
|
||||||
|
|
||||||
counter1.Add(ctx, 3, kv.String("X", "Y"))
|
counter1.Add(ctx, 3, label.String("X", "Y"))
|
||||||
counter2.Add(ctx, 5)
|
counter2.Add(ctx, 5)
|
||||||
|
|
||||||
require.Equal(t, 0, exporter.ExportCount())
|
require.Equal(t, 0, exporter.ExportCount())
|
||||||
|
@ -24,9 +24,8 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
||||||
@ -35,7 +34,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Must = metric.Must
|
var Must = metric.Must
|
||||||
var testResource = resource.New(kv.String("R", "V"))
|
var testResource = resource.New(label.String("R", "V"))
|
||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@ -209,19 +208,19 @@ func TestSDKLabelsDeduplication(t *testing.T) {
|
|||||||
keySets = 2
|
keySets = 2
|
||||||
repeats = 3
|
repeats = 3
|
||||||
)
|
)
|
||||||
var keysA []kv.Key
|
var keysA []label.Key
|
||||||
var keysB []kv.Key
|
var keysB []label.Key
|
||||||
|
|
||||||
for i := 0; i < maxKeys; i++ {
|
for i := 0; i < maxKeys; i++ {
|
||||||
keysA = append(keysA, kv.Key(fmt.Sprintf("A%03d", i)))
|
keysA = append(keysA, label.Key(fmt.Sprintf("A%03d", i)))
|
||||||
keysB = append(keysB, kv.Key(fmt.Sprintf("B%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++ {
|
for numKeys := 0; numKeys < maxKeys; numKeys++ {
|
||||||
|
|
||||||
var kvsA []kv.KeyValue
|
var kvsA []label.KeyValue
|
||||||
var kvsB []kv.KeyValue
|
var kvsB []label.KeyValue
|
||||||
for r := 0; r < repeats; r++ {
|
for r := 0; r < repeats; r++ {
|
||||||
for i := 0; i < numKeys; i++ {
|
for i := 0; i < numKeys; i++ {
|
||||||
kvsA = append(kvsA, keysA[i].Int(r))
|
kvsA = append(kvsA, keysA[i].Int(r))
|
||||||
@ -229,8 +228,8 @@ func TestSDKLabelsDeduplication(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectA []kv.KeyValue
|
var expectA []label.KeyValue
|
||||||
var expectB []kv.KeyValue
|
var expectB []label.KeyValue
|
||||||
for i := 0; i < numKeys; i++ {
|
for i := 0; i < numKeys; i++ {
|
||||||
expectA = append(expectA, keysA[i].Int(repeats-1))
|
expectA = append(expectA, keysA[i].Int(repeats-1))
|
||||||
expectB = append(expectB, keysB[i].Int(repeats-1))
|
expectB = append(expectB, keysB[i].Int(repeats-1))
|
||||||
@ -251,7 +250,7 @@ func TestSDKLabelsDeduplication(t *testing.T) {
|
|||||||
|
|
||||||
sdk.Collect(ctx)
|
sdk.Collect(ctx)
|
||||||
|
|
||||||
var actual [][]kv.KeyValue
|
var actual [][]label.KeyValue
|
||||||
for _, rec := range processor.accumulations {
|
for _, rec := range processor.accumulations {
|
||||||
sum, _ := rec.Aggregator().(aggregation.Sum).Sum()
|
sum, _ := rec.Aggregator().(aggregation.Sum).Sum()
|
||||||
require.Equal(t, sum, metric.NewInt64Number(2))
|
require.Equal(t, sum, metric.NewInt64Number(2))
|
||||||
@ -263,7 +262,7 @@ func TestSDKLabelsDeduplication(t *testing.T) {
|
|||||||
require.ElementsMatch(t, allExpect, actual)
|
require.ElementsMatch(t, allExpect, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSetIter(kvs ...kv.KeyValue) label.Iterator {
|
func newSetIter(kvs ...label.KeyValue) label.Iterator {
|
||||||
labels := label.NewSet(kvs...)
|
labels := label.NewSet(kvs...)
|
||||||
return labels.Iter()
|
return labels.Iter()
|
||||||
}
|
}
|
||||||
@ -271,28 +270,28 @@ func newSetIter(kvs ...kv.KeyValue) label.Iterator {
|
|||||||
func TestDefaultLabelEncoder(t *testing.T) {
|
func TestDefaultLabelEncoder(t *testing.T) {
|
||||||
encoder := label.DefaultEncoder()
|
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)
|
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)
|
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)
|
require.Equal(t, `\,=\\,\\=\=`, encoded)
|
||||||
|
|
||||||
// Note: the label encoder does not sort or de-dup values,
|
// Note: the label encoder does not sort or de-dup values,
|
||||||
// that is done in Labels(...).
|
// that is done in Labels(...).
|
||||||
encoded = encoder.Encode(newSetIter(
|
encoded = encoder.Encode(newSetIter(
|
||||||
kv.Int("I", 1),
|
label.Int("I", 1),
|
||||||
kv.Uint("U", 1),
|
label.Uint("U", 1),
|
||||||
kv.Int32("I32", 1),
|
label.Int32("I32", 1),
|
||||||
kv.Uint32("U32", 1),
|
label.Uint32("U32", 1),
|
||||||
kv.Int64("I64", 1),
|
label.Int64("I64", 1),
|
||||||
kv.Uint64("U64", 1),
|
label.Uint64("U64", 1),
|
||||||
kv.Float64("F64", 1),
|
label.Float64("F64", 1),
|
||||||
kv.Float64("F64", 1),
|
label.Float64("F64", 1),
|
||||||
kv.String("S", "1"),
|
label.String("S", "1"),
|
||||||
kv.Bool("B", true),
|
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)
|
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)
|
meter, sdk, processor := newSDK(t)
|
||||||
|
|
||||||
_ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) {
|
_ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(1, kv.String("A", "B"))
|
result.Observe(1, label.String("A", "B"))
|
||||||
// last value wins
|
// last value wins
|
||||||
result.Observe(-1, kv.String("A", "B"))
|
result.Observe(-1, label.String("A", "B"))
|
||||||
result.Observe(-1, kv.String("C", "D"))
|
result.Observe(-1, label.String("C", "D"))
|
||||||
})
|
})
|
||||||
_ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) {
|
_ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(-1, kv.String("A", "B"))
|
result.Observe(-1, label.String("A", "B"))
|
||||||
result.Observe(1)
|
result.Observe(1)
|
||||||
// last value wins
|
// last value wins
|
||||||
result.Observe(1, kv.String("A", "B"))
|
result.Observe(1, label.String("A", "B"))
|
||||||
result.Observe(1)
|
result.Observe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(1, kv.String("A", "B"))
|
result.Observe(1, label.String("A", "B"))
|
||||||
result.Observe(2, kv.String("A", "B"))
|
result.Observe(2, label.String("A", "B"))
|
||||||
result.Observe(1, kv.String("C", "D"))
|
result.Observe(1, label.String("C", "D"))
|
||||||
})
|
})
|
||||||
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(2, kv.String("A", "B"))
|
result.Observe(2, label.String("A", "B"))
|
||||||
result.Observe(1)
|
result.Observe(1)
|
||||||
// last value wins
|
// last value wins
|
||||||
result.Observe(1, kv.String("A", "B"))
|
result.Observe(1, label.String("A", "B"))
|
||||||
result.Observe(1)
|
result.Observe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
_ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
_ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(1, kv.String("A", "B"))
|
result.Observe(1, label.String("A", "B"))
|
||||||
result.Observe(-2, kv.String("A", "B"))
|
result.Observe(-2, label.String("A", "B"))
|
||||||
result.Observe(1, kv.String("C", "D"))
|
result.Observe(1, label.String("C", "D"))
|
||||||
})
|
})
|
||||||
_ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
_ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(2, kv.String("A", "B"))
|
result.Observe(2, label.String("A", "B"))
|
||||||
result.Observe(1)
|
result.Observe(1)
|
||||||
// last value wins
|
// last value wins
|
||||||
result.Observe(1, kv.String("A", "B"))
|
result.Observe(1, label.String("A", "B"))
|
||||||
result.Observe(-1)
|
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.
|
// TODO: these tests are testing for negative values, not for _descending values_. Fix.
|
||||||
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||||
result.Observe(-2, kv.String("A", "B"))
|
result.Observe(-2, label.String("A", "B"))
|
||||||
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
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())
|
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
||||||
})
|
})
|
||||||
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(-1, kv.String("A", "B"))
|
result.Observe(-1, label.String("A", "B"))
|
||||||
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
||||||
result.Observe(-1)
|
result.Observe(-1)
|
||||||
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
||||||
@ -411,8 +410,8 @@ func TestObserverBatch(t *testing.T) {
|
|||||||
var batch = Must(meter).NewBatchObserver(
|
var batch = Must(meter).NewBatchObserver(
|
||||||
func(_ context.Context, result metric.BatchObserverResult) {
|
func(_ context.Context, result metric.BatchObserverResult) {
|
||||||
result.Observe(
|
result.Observe(
|
||||||
[]kv.KeyValue{
|
[]label.KeyValue{
|
||||||
kv.String("A", "B"),
|
label.String("A", "B"),
|
||||||
},
|
},
|
||||||
floatValueObs.Observation(1),
|
floatValueObs.Observation(1),
|
||||||
floatValueObs.Observation(-1),
|
floatValueObs.Observation(-1),
|
||||||
@ -424,8 +423,8 @@ func TestObserverBatch(t *testing.T) {
|
|||||||
intUpDownSumObs.Observation(-100),
|
intUpDownSumObs.Observation(-100),
|
||||||
)
|
)
|
||||||
result.Observe(
|
result.Observe(
|
||||||
[]kv.KeyValue{
|
[]label.KeyValue{
|
||||||
kv.String("C", "D"),
|
label.String("C", "D"),
|
||||||
},
|
},
|
||||||
floatValueObs.Observation(-1),
|
floatValueObs.Observation(-1),
|
||||||
floatSumObs.Observation(-1),
|
floatSumObs.Observation(-1),
|
||||||
@ -484,9 +483,9 @@ func TestRecordBatch(t *testing.T) {
|
|||||||
|
|
||||||
sdk.RecordBatch(
|
sdk.RecordBatch(
|
||||||
ctx,
|
ctx,
|
||||||
[]kv.KeyValue{
|
[]label.KeyValue{
|
||||||
kv.String("A", "B"),
|
label.String("A", "B"),
|
||||||
kv.String("C", "D"),
|
label.String("C", "D"),
|
||||||
},
|
},
|
||||||
counter1.Measurement(1),
|
counter1.Measurement(1),
|
||||||
counter2.Measurement(2),
|
counter2.Measurement(2),
|
||||||
@ -516,8 +515,8 @@ func TestRecordPersistence(t *testing.T) {
|
|||||||
meter, sdk, processor := newSDK(t)
|
meter, sdk, processor := newSDK(t)
|
||||||
|
|
||||||
c := Must(meter).NewFloat64Counter("name.sum")
|
c := Must(meter).NewFloat64Counter("name.sum")
|
||||||
b := c.Bind(kv.String("bound", "true"))
|
b := c.Bind(label.String("bound", "true"))
|
||||||
uk := kv.String("bound", "false")
|
uk := label.String("bound", "false")
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
c.Add(ctx, 1, uk)
|
c.Add(ctx, 1, uk)
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
|
@ -24,9 +24,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
"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))
|
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...)
|
ls := label.NewSet(labs...)
|
||||||
var agg export.Aggregator
|
var agg export.Aggregator
|
||||||
selector.AggregatorFor(desc, &agg)
|
selector.AggregatorFor(desc, &agg)
|
||||||
@ -122,10 +121,10 @@ func testProcessor(
|
|||||||
// Note: this selector uses the instrument name to dictate
|
// Note: this selector uses the instrument name to dictate
|
||||||
// aggregation kind.
|
// aggregation kind.
|
||||||
selector := processorTest.AggregatorSelector()
|
selector := processorTest.AggregatorSelector()
|
||||||
res := resource.New(kv.String("R", "V"))
|
res := resource.New(label.String("R", "V"))
|
||||||
|
|
||||||
labs1 := []kv.KeyValue{kv.String("L1", "V")}
|
labs1 := []label.KeyValue{label.String("L1", "V")}
|
||||||
labs2 := []kv.KeyValue{kv.String("L2", "V")}
|
labs2 := []label.KeyValue{label.String("L2", "V")}
|
||||||
|
|
||||||
testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) {
|
testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) {
|
||||||
processor := basic.New(selector, ekind, basic.WithMemory(hasMemory))
|
processor := basic.New(selector, ekind, basic.WithMemory(hasMemory))
|
||||||
@ -362,7 +361,7 @@ func TestBasicTimestamps(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStatefulNoMemoryCumulative(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
|
ekind := export.CumulativeExporter
|
||||||
|
|
||||||
desc := metric.NewDescriptor("inst.sum", metric.CounterKind, metric.Int64NumberKind)
|
desc := metric.NewDescriptor("inst.sum", metric.CounterKind, metric.Int64NumberKind)
|
||||||
@ -383,7 +382,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
|
|||||||
|
|
||||||
// Add 10
|
// Add 10
|
||||||
processor.StartCollection()
|
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())
|
require.NoError(t, processor.FinishCollection())
|
||||||
|
|
||||||
// Verify one element
|
// Verify one element
|
||||||
@ -396,7 +395,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStatefulNoMemoryDelta(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
|
ekind := export.DeltaExporter
|
||||||
|
|
||||||
desc := metric.NewDescriptor("inst.sum", metric.SumObserverKind, metric.Int64NumberKind)
|
desc := metric.NewDescriptor("inst.sum", metric.SumObserverKind, metric.Int64NumberKind)
|
||||||
@ -417,7 +416,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) {
|
|||||||
|
|
||||||
// Add 10
|
// Add 10
|
||||||
processor.StartCollection()
|
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())
|
require.NoError(t, processor.FinishCollection())
|
||||||
|
|
||||||
// Verify one element
|
// Verify one element
|
||||||
@ -436,7 +435,7 @@ func TestMultiObserverSum(t *testing.T) {
|
|||||||
export.DeltaExporter,
|
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)
|
desc := metric.NewDescriptor("observe.sum", metric.SumObserverKind, metric.Int64NumberKind)
|
||||||
selector := processorTest.AggregatorSelector()
|
selector := processorTest.AggregatorSelector()
|
||||||
|
|
||||||
@ -446,9 +445,9 @@ func TestMultiObserverSum(t *testing.T) {
|
|||||||
for i := 1; i < 3; i++ {
|
for i := 1; i < 3; i++ {
|
||||||
// Add i*10*3 times
|
// Add i*10*3 times
|
||||||
processor.StartCollection()
|
processor.StartCollection()
|
||||||
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), 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), 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), kv.String("A", "B")))
|
_ = processor.Process(updateFor(t, &desc, selector, res, int64(i*10), label.String("A", "B")))
|
||||||
require.NoError(t, processor.FinishCollection())
|
require.NoError(t, processor.FinishCollection())
|
||||||
|
|
||||||
// Multiplier is 1 for deltas, otherwise i.
|
// Multiplier is 1 for deltas, otherwise i.
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
||||||
|
@ -20,9 +20,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
||||||
processorTest "go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
processorTest "go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
||||||
@ -34,7 +33,7 @@ func generateTestData(proc export.Processor) {
|
|||||||
accum := metricsdk.NewAccumulator(
|
accum := metricsdk.NewAccumulator(
|
||||||
proc,
|
proc,
|
||||||
metricsdk.WithResource(
|
metricsdk.WithResource(
|
||||||
resource.New(kv.String("R", "V")),
|
resource.New(label.String("R", "V")),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
meter := metric.WrapMeterImpl(accum, "testing")
|
meter := metric.WrapMeterImpl(accum, "testing")
|
||||||
@ -43,13 +42,13 @@ func generateTestData(proc export.Processor) {
|
|||||||
|
|
||||||
_ = metric.Must(meter).NewInt64SumObserver("observer.sum",
|
_ = metric.Must(meter).NewInt64SumObserver("observer.sum",
|
||||||
func(_ context.Context, result metric.Int64ObserverResult) {
|
func(_ context.Context, result metric.Int64ObserverResult) {
|
||||||
result.Observe(10, kv.String("K1", "V1"))
|
result.Observe(10, label.String("K1", "V1"))
|
||||||
result.Observe(11, kv.String("K1", "V2"))
|
result.Observe(11, label.String("K1", "V2"))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
counter.Add(ctx, 100, kv.String("K1", "V1"))
|
counter.Add(ctx, 100, label.String("K1", "V1"))
|
||||||
counter.Add(ctx, 101, kv.String("K1", "V2"))
|
counter.Add(ctx, 101, label.String("K1", "V2"))
|
||||||
|
|
||||||
accum.Collect(ctx)
|
accum.Collect(ctx)
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer"
|
package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/label"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +20,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"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/api/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||||
@ -32,22 +31,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
kvs1 = []kv.KeyValue{
|
kvs1 = []label.KeyValue{
|
||||||
kv.Int("A", 1),
|
label.Int("A", 1),
|
||||||
kv.Int("B", 2),
|
label.Int("B", 2),
|
||||||
kv.Int("C", 3),
|
label.Int("C", 3),
|
||||||
}
|
}
|
||||||
kvs2 = []kv.KeyValue{
|
kvs2 = []label.KeyValue{
|
||||||
kv.Int("A", 1),
|
label.Int("A", 1),
|
||||||
kv.Int("B", 0),
|
label.Int("B", 0),
|
||||||
kv.Int("C", 3),
|
label.Int("C", 3),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type testFilter struct{}
|
type testFilter struct{}
|
||||||
|
|
||||||
func (testFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter {
|
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"
|
return label.Key == "A" || label.Key == "C"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +76,7 @@ func TestFilterProcessor(t *testing.T) {
|
|||||||
accum := metricsdk.NewAccumulator(
|
accum := metricsdk.NewAccumulator(
|
||||||
reducer.New(testFilter{}, processorTest.Checkpointer(testProc)),
|
reducer.New(testFilter{}, processorTest.Checkpointer(testProc)),
|
||||||
metricsdk.WithResource(
|
metricsdk.WithResource(
|
||||||
resource.New(kv.String("R", "V")),
|
resource.New(label.String("R", "V")),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
generateData(accum)
|
generateData(accum)
|
||||||
@ -96,7 +95,7 @@ func TestFilterBasicProcessor(t *testing.T) {
|
|||||||
accum := metricsdk.NewAccumulator(
|
accum := metricsdk.NewAccumulator(
|
||||||
reducer.New(testFilter{}, basicProc),
|
reducer.New(testFilter{}, basicProc),
|
||||||
metricsdk.WithResource(
|
metricsdk.WithResource(
|
||||||
resource.New(kv.String("R", "V")),
|
resource.New(label.String("R", "V")),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
exporter := processorTest.NewExporter(basicProc, label.DefaultEncoder())
|
exporter := processorTest.NewExporter(basicProc, label.DefaultEncoder())
|
||||||
|
@ -22,11 +22,10 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"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/api/metric"
|
||||||
api "go.opentelemetry.io/otel/api/metric"
|
api "go.opentelemetry.io/otel/api/metric"
|
||||||
internal "go.opentelemetry.io/otel/internal/metric"
|
internal "go.opentelemetry.io/otel/internal/metric"
|
||||||
|
"go.opentelemetry.io/otel/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"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
|
// support re-use of the orderedLabels computed by a previous
|
||||||
// measurement in the same batch. This performs two allocations
|
// measurement in the same batch. This performs two allocations
|
||||||
// in the common case.
|
// in the common case.
|
||||||
func (s *syncInstrument) acquireHandle(kvs []kv.KeyValue, labelPtr *label.Set) *record {
|
func (s *syncInstrument) acquireHandle(kvs []label.KeyValue, labelPtr *label.Set) *record {
|
||||||
var rec *record
|
var rec *record
|
||||||
var equiv label.Distinct
|
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)
|
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)
|
h := s.acquireHandle(kvs, nil)
|
||||||
defer h.Unbind()
|
defer h.Unbind()
|
||||||
h.RecordOne(ctx, number)
|
h.RecordOne(ctx, number)
|
||||||
@ -406,7 +405,7 @@ func (m *Accumulator) collectSyncInstruments() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CollectAsync implements internal.AsyncCollector.
|
// 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)
|
labels := label.NewSetWithSortable(kv, &m.asyncSortSlice)
|
||||||
|
|
||||||
for _, ob := range obs {
|
for _, ob := range obs {
|
||||||
@ -483,7 +482,7 @@ func (m *Accumulator) checkpointAsync(a *asyncInstrument) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RecordBatch enters a batch of metric events.
|
// RecordBatch enters a batch of metric events.
|
||||||
func (m *Accumulator) RecordBatch(ctx context.Context, kvs []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
|
// Labels will be computed the first time acquireHandle is
|
||||||
// called. Subsequent calls to acquireHandle will re-use the
|
// called. Subsequent calls to acquireHandle will re-use the
|
||||||
// previously computed value instead of recomputing the
|
// previously computed value instead of recomputing the
|
||||||
|
@ -31,9 +31,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
api "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"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
"go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
||||||
@ -75,7 +75,7 @@ type (
|
|||||||
testImpl struct {
|
testImpl struct {
|
||||||
newInstrument func(meter api.Meter, name string) SyncImpler
|
newInstrument func(meter api.Meter, name string) SyncImpler
|
||||||
getUpdateValue func() api.Number
|
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{}
|
newStore func() interface{}
|
||||||
|
|
||||||
// storeCollect and storeExpect are the same for
|
// storeCollect and storeExpect are the same for
|
||||||
@ -105,7 +105,7 @@ func concurrency() int {
|
|||||||
return concurrencyPerCPU * runtime.NumCPU()
|
return concurrencyPerCPU * runtime.NumCPU()
|
||||||
}
|
}
|
||||||
|
|
||||||
func canonicalizeLabels(ls []kv.KeyValue) string {
|
func canonicalizeLabels(ls []label.KeyValue) string {
|
||||||
copy := append(ls[0:0:0], ls...)
|
copy := append(ls[0:0:0], ls...)
|
||||||
sort.SliceStable(copy, func(i, j int) bool {
|
sort.SliceStable(copy, func(i, j int) bool {
|
||||||
return copy[i].Key < copy[j].Key
|
return copy[i].Key < copy[j].Key
|
||||||
@ -128,9 +128,9 @@ func getPeriod() time.Duration {
|
|||||||
return time.Duration(dur)
|
return time.Duration(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *testFixture) someLabels() []kv.KeyValue {
|
func (f *testFixture) someLabels() []label.KeyValue {
|
||||||
n := 1 + rand.Intn(3)
|
n := 1 + rand.Intn(3)
|
||||||
l := make([]kv.KeyValue, n)
|
l := make([]label.KeyValue, n)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
oused := map[string]bool{}
|
oused := map[string]bool{}
|
||||||
@ -143,7 +143,7 @@ func (f *testFixture) someLabels() []kv.KeyValue {
|
|||||||
break
|
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)
|
lc := canonicalizeLabels(l)
|
||||||
f.lock.Lock()
|
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 := inst.(api.Int64Counter)
|
||||||
counter.Add(ctx, value.AsInt64(), labels...)
|
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 := inst.(api.Float64Counter)
|
||||||
counter.Add(ctx, value.AsFloat64(), labels...)
|
counter.Add(ctx, value.AsFloat64(), labels...)
|
||||||
},
|
},
|
||||||
@ -424,7 +424,7 @@ func intLastValueTestImpl() testImpl {
|
|||||||
r1 := rand.Int63()
|
r1 := rand.Int63()
|
||||||
return api.NewInt64Number(rand.Int63() - r1)
|
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 := inst.(api.Int64ValueRecorder)
|
||||||
valuerecorder.Record(ctx, value.AsInt64(), labels...)
|
valuerecorder.Record(ctx, value.AsInt64(), labels...)
|
||||||
},
|
},
|
||||||
@ -465,7 +465,7 @@ func floatLastValueTestImpl() testImpl {
|
|||||||
getUpdateValue: func() api.Number {
|
getUpdateValue: func() api.Number {
|
||||||
return api.NewFloat64Number((-0.5 + rand.Float64()) * 100000)
|
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 := inst.(api.Float64ValueRecorder)
|
||||||
valuerecorder.Record(ctx, value.AsFloat64(), labels...)
|
valuerecorder.Record(ctx, value.AsFloat64(), labels...)
|
||||||
},
|
},
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/kv"
|
"go.opentelemetry.io/otel/label"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,8 +27,8 @@ const conflict = 0.5
|
|||||||
|
|
||||||
func makeLabels(n int) (_, _ *resource.Resource) {
|
func makeLabels(n int) (_, _ *resource.Resource) {
|
||||||
used := map[string]bool{}
|
used := map[string]bool{}
|
||||||
l1 := make([]kv.KeyValue, n)
|
l1 := make([]label.KeyValue, n)
|
||||||
l2 := make([]kv.KeyValue, n)
|
l2 := make([]label.KeyValue, n)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
var k string
|
var k string
|
||||||
for {
|
for {
|
||||||
@ -38,12 +38,12 @@ func makeLabels(n int) (_, _ *resource.Resource) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l1[i] = kv.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
|
l1[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
|
||||||
|
|
||||||
if rand.Float64() < conflict {
|
if rand.Float64() < conflict {
|
||||||
l2[i] = l1[i]
|
l2[i] = l1[i]
|
||||||
} else {
|
} else {
|
||||||
l2[i] = kv.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
|
l2[i] = label.String(k, fmt.Sprint("v", rand.Intn(1000000000)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"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.
|
// 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) {
|
func constructOTResources(s string) (*Resource, error) {
|
||||||
pairs := strings.Split(s, ",")
|
pairs := strings.Split(s, ",")
|
||||||
labels := []kv.KeyValue{}
|
labels := []label.KeyValue{}
|
||||||
var invalid []string
|
var invalid []string
|
||||||
for _, p := range pairs {
|
for _, p := range pairs {
|
||||||
field := strings.SplitN(p, "=", 2)
|
field := strings.SplitN(p, "=", 2)
|
||||||
@ -59,7 +59,7 @@ func constructOTResources(s string) (*Resource, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1])
|
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
|
var err error
|
||||||
if len(invalid) > 0 {
|
if len(invalid) > 0 {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user