mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-16 02:47:20 +02:00
Remove extra labels types (#1314)
* Remove extra labels types Remove the following labels types: INT32, UINT32, UINT64 and FLOAT32. Fix all extra labels types occurrences in the project. Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com> * Update CHANGELOG.md Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com> * Delete unused helpers Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com> * Convert passed values into remaining types Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com> * Clarify func description * Fix uint64 convertion Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com> * Fix uint conversion Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com> * Update OTLP exporter label types Co-authored-by: Tyler Yahn <codingalias@gmail.com>
This commit is contained in:
parent
73194e44db
commit
7de3b58ce9
@ -142,6 +142,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- The `MockSpan` and `MockTracer` types are removed from `go.opentelemetry.io/otel/oteltest`.
|
||||
`Tracer` and `Span` from the same module should be used in their place instead. (#1306)
|
||||
- `WorkerCount` option is removed from `go.opentelemetry.io/otel/exporters/otlp`. (#1350)
|
||||
- Remove the following labels types: INT32, UINT32, UINT64 and FLOAT32. (#1314)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -130,6 +130,15 @@ func (s *bridgeSpan) SetOperationName(operationName string) ot.Span {
|
||||
return s
|
||||
}
|
||||
|
||||
// SetTag method adds a tag to the span.
|
||||
//
|
||||
// Note about the following value conversions:
|
||||
// - int -> int64
|
||||
// - uint -> string
|
||||
// - int32 -> int64
|
||||
// - uint32 -> int64
|
||||
// - uint64 -> string
|
||||
// - float32 -> float64
|
||||
func (s *bridgeSpan) SetTag(key string, value interface{}) ot.Span {
|
||||
switch key {
|
||||
case string(otext.SpanKind):
|
||||
@ -495,6 +504,14 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]label.Ke
|
||||
return pairs, kind, err
|
||||
}
|
||||
|
||||
// otTagToOTelLabel converts given key-value into label.KeyValue.
|
||||
// Note that some conversions are not obvious:
|
||||
// - int -> int64
|
||||
// - uint -> string
|
||||
// - int32 -> int64
|
||||
// - uint32 -> int64
|
||||
// - uint64 -> string
|
||||
// - float32 -> float64
|
||||
func otTagToOTelLabel(k string, v interface{}) label.KeyValue {
|
||||
key := otTagToOTelLabelKey(k)
|
||||
switch val := v.(type) {
|
||||
@ -503,19 +520,19 @@ func otTagToOTelLabel(k string, v interface{}) label.KeyValue {
|
||||
case int64:
|
||||
return key.Int64(val)
|
||||
case uint64:
|
||||
return key.Uint64(val)
|
||||
return key.String(fmt.Sprintf("%d", val))
|
||||
case float64:
|
||||
return key.Float64(val)
|
||||
case int32:
|
||||
return key.Int32(val)
|
||||
return key.Int64(int64(val))
|
||||
case uint32:
|
||||
return key.Uint32(val)
|
||||
return key.Int64(int64(val))
|
||||
case float32:
|
||||
return key.Float32(val)
|
||||
return key.Float64(float64(val))
|
||||
case int:
|
||||
return key.Int(val)
|
||||
case uint:
|
||||
return key.Uint(val)
|
||||
return key.String(fmt.Sprintf("%d", val))
|
||||
case string:
|
||||
return key.String(val)
|
||||
default:
|
||||
|
@ -210,7 +210,7 @@ func (s *MockSpan) IsRecording() bool {
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetStatus(code codes.Code, msg string) {
|
||||
s.SetAttributes(StatusCodeKey.Uint32(uint32(code)), StatusMessageKey.String(msg))
|
||||
s.SetAttributes(StatusCodeKey.Int(int(code)), StatusMessageKey.String(msg))
|
||||
}
|
||||
|
||||
func (s *MockSpan) SetName(name string) {
|
||||
|
@ -716,3 +716,77 @@ func runOTOtelOT(t *testing.T, ctx context.Context, name string, callback func(*
|
||||
}(ctx2)
|
||||
}(ctx)
|
||||
}
|
||||
|
||||
func TestOtTagToOTelLabel_CheckTypeConversions(t *testing.T) {
|
||||
tableTest := []struct {
|
||||
key string
|
||||
value interface{}
|
||||
expectedValueType label.Type
|
||||
}{
|
||||
{
|
||||
key: "bool to bool",
|
||||
value: true,
|
||||
expectedValueType: label.BOOL,
|
||||
},
|
||||
{
|
||||
key: "int to int64",
|
||||
value: 123,
|
||||
expectedValueType: label.INT64,
|
||||
},
|
||||
{
|
||||
key: "uint to string",
|
||||
value: uint(1234),
|
||||
expectedValueType: label.STRING,
|
||||
},
|
||||
{
|
||||
key: "int32 to int64",
|
||||
value: int32(12345),
|
||||
expectedValueType: label.INT64,
|
||||
},
|
||||
{
|
||||
key: "uint32 to int64",
|
||||
value: uint32(123456),
|
||||
expectedValueType: label.INT64,
|
||||
},
|
||||
{
|
||||
key: "int64 to int64",
|
||||
value: int64(1234567),
|
||||
expectedValueType: label.INT64,
|
||||
},
|
||||
{
|
||||
key: "uint64 to string",
|
||||
value: uint64(12345678),
|
||||
expectedValueType: label.STRING,
|
||||
},
|
||||
{
|
||||
key: "float32 to float64",
|
||||
value: float32(3.14),
|
||||
expectedValueType: label.FLOAT64,
|
||||
},
|
||||
{
|
||||
key: "float64 to float64",
|
||||
value: float64(3.14),
|
||||
expectedValueType: label.FLOAT64,
|
||||
},
|
||||
{
|
||||
key: "string to string",
|
||||
value: "string_value",
|
||||
expectedValueType: label.STRING,
|
||||
},
|
||||
{
|
||||
key: "unexpected type to string",
|
||||
value: struct{}{},
|
||||
expectedValueType: label.STRING,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tableTest {
|
||||
got := otTagToOTelLabel(test.key, test.value)
|
||||
if test.expectedValueType != got.Value.Type() {
|
||||
t.Errorf("Expected type %s, but got %s after conversion '%v' value",
|
||||
test.expectedValueType,
|
||||
got.Value.Type(),
|
||||
test.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr
|
||||
tp2 := sdktrace.NewTracerProvider(append(pOpts,
|
||||
sdktrace.WithResource(resource.NewWithAttributes(
|
||||
label.String("rk1", "rv12)"),
|
||||
label.Float32("rk3", 6.5),
|
||||
label.Float64("rk3", 6.5),
|
||||
)))...)
|
||||
|
||||
tr1 := tp1.Tracer("test-tracer1")
|
||||
|
@ -60,14 +60,10 @@ func toAttribute(v label.KeyValue) *commonpb.KeyValue {
|
||||
result.Value.Value = &commonpb.AnyValue_BoolValue{
|
||||
BoolValue: v.Value.AsBool(),
|
||||
}
|
||||
case label.INT64, label.INT32, label.UINT32, label.UINT64:
|
||||
case label.INT64:
|
||||
result.Value.Value = &commonpb.AnyValue_IntValue{
|
||||
IntValue: v.Value.AsInt64(),
|
||||
}
|
||||
case label.FLOAT32:
|
||||
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
||||
DoubleValue: float64(v.Value.AsFloat32()),
|
||||
}
|
||||
case label.FLOAT64:
|
||||
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
||||
DoubleValue: v.Value.AsFloat64(),
|
||||
@ -103,7 +99,7 @@ func arrayValues(kv label.KeyValue) []*commonpb.AnyValue {
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
case reflect.Int, reflect.Int64:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
@ -111,7 +107,7 @@ func arrayValues(kv label.KeyValue) []*commonpb.AnyValue {
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
case reflect.Uintptr:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
@ -119,7 +115,7 @@ func arrayValues(kv label.KeyValue) []*commonpb.AnyValue {
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.Float32, reflect.Float64:
|
||||
case reflect.Float64:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_DoubleValue{
|
||||
|
@ -34,13 +34,8 @@ func TestAttributes(t *testing.T) {
|
||||
{
|
||||
[]label.KeyValue{
|
||||
label.Int("int to int", 123),
|
||||
label.Uint("uint to int", 1234),
|
||||
label.Int32("int32 to int", 12345),
|
||||
label.Uint32("uint32 to int", 123456),
|
||||
label.Int64("int64 to int64", 1234567),
|
||||
label.Uint64("uint64 to int64", 12345678),
|
||||
label.Float32("float32 to double", 3.14),
|
||||
label.Float32("float64 to double", 1.61),
|
||||
label.Float64("float64 to double", 1.61),
|
||||
label.String("string to string", "string"),
|
||||
label.Bool("bool to bool", true),
|
||||
},
|
||||
@ -53,30 +48,6 @@ func TestAttributes(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "uint to int",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: 1234,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "int32 to int",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: 12345,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "uint32 to int",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: 123456,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "int64 to int64",
|
||||
Value: &commonpb.AnyValue{
|
||||
@ -85,22 +56,6 @@ func TestAttributes(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "uint64 to int64",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: 12345678,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "float32 to double",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_DoubleValue{
|
||||
DoubleValue: 3.14,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "float64 to double",
|
||||
Value: &commonpb.AnyValue{
|
||||
@ -151,9 +106,8 @@ func TestAttributes(t *testing.T) {
|
||||
|
||||
func TestArrayAttributes(t *testing.T) {
|
||||
// Array KeyValue supports only arrays of primitive types:
|
||||
// "bool", "int", "int32", "int64",
|
||||
// "float32", "float64", "string",
|
||||
// "uint", "uint32", "uint64"
|
||||
// "bool", "int", "int64",
|
||||
// "float64", "string",
|
||||
for _, test := range []attributeTest{
|
||||
{nil, nil},
|
||||
{
|
||||
@ -175,24 +129,14 @@ func TestArrayAttributes(t *testing.T) {
|
||||
[]label.KeyValue{
|
||||
label.Array("bool array to bool array", []bool{true, false}),
|
||||
label.Array("int array to int64 array", []int{1, 2, 3}),
|
||||
label.Array("uint array to int64 array", []uint{1, 2, 3}),
|
||||
label.Array("int32 array to int64 array", []int32{1, 2, 3}),
|
||||
label.Array("uint32 array to int64 array", []uint32{1, 2, 3}),
|
||||
label.Array("int64 array to int64 array", []int64{1, 2, 3}),
|
||||
label.Array("uint64 array to int64 array", []uint64{1, 2, 3}),
|
||||
label.Array("float32 array to double array", []float32{1.11, 2.22, 3.33}),
|
||||
label.Array("float64 array to double array", []float64{1.11, 2.22, 3.33}),
|
||||
label.Array("string array to string array", []string{"foo", "bar", "baz"}),
|
||||
},
|
||||
[]*commonpb.KeyValue{
|
||||
newOTelBoolArray("bool array to bool array", []bool{true, false}),
|
||||
newOTelIntArray("int array to int64 array", []int64{1, 2, 3}),
|
||||
newOTelIntArray("uint array to int64 array", []int64{1, 2, 3}),
|
||||
newOTelIntArray("int32 array to int64 array", []int64{1, 2, 3}),
|
||||
newOTelIntArray("uint32 array to int64 array", []int64{1, 2, 3}),
|
||||
newOTelIntArray("int64 array to int64 array", []int64{1, 2, 3}),
|
||||
newOTelIntArray("uint64 array to int64 array", []int64{1, 2, 3}),
|
||||
newOTelDoubleArray("float32 array to double array", []float64{1.11, 2.22, 3.33}),
|
||||
newOTelDoubleArray("float64 array to double array", []float64{1.11, 2.22, 3.33}),
|
||||
newOTelStringArray("string array to string array", []string{"foo", "bar", "baz"}),
|
||||
},
|
||||
|
@ -70,13 +70,13 @@ func TestStringKeyValues(t *testing.T) {
|
||||
[]label.KeyValue{
|
||||
label.Bool("true", true),
|
||||
label.Int64("one", 1),
|
||||
label.Uint64("two", 2),
|
||||
label.Int64("two", 2),
|
||||
label.Float64("three", 3),
|
||||
label.Int32("four", 4),
|
||||
label.Uint32("five", 5),
|
||||
label.Float32("six", 6),
|
||||
label.Int("four", 4),
|
||||
label.Int("five", 5),
|
||||
label.Float64("six", 6),
|
||||
label.Int("seven", 7),
|
||||
label.Uint("eight", 8),
|
||||
label.Int("eight", 8),
|
||||
label.String("the", "final word"),
|
||||
},
|
||||
[]*commonpb.StringKeyValue{
|
||||
|
@ -214,7 +214,7 @@ func TestSpanData(t *testing.T) {
|
||||
MessageEvents: []trace.Event{
|
||||
{Time: startTime,
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("CompressedByteSize", 512),
|
||||
label.Int64("CompressedByteSize", 512),
|
||||
},
|
||||
},
|
||||
{Time: endTime,
|
||||
|
@ -280,9 +280,7 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
|
||||
tr := tp.Tracer("test-tracer")
|
||||
testKvs := []label.KeyValue{
|
||||
label.Int("Int", 1),
|
||||
label.Int32("Int32", int32(2)),
|
||||
label.Int64("Int64", int64(3)),
|
||||
label.Float32("Float32", float32(1.11)),
|
||||
label.Float64("Float64", 2.22),
|
||||
label.Bool("Bool", true),
|
||||
label.String("String", "test"),
|
||||
@ -329,14 +327,6 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "Int32",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "Int64",
|
||||
Value: &commonpb.AnyValue{
|
||||
@ -345,14 +335,6 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "Float32",
|
||||
Value: &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_DoubleValue{
|
||||
DoubleValue: 1.11,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "Float64",
|
||||
Value: &commonpb.AnyValue{
|
||||
|
@ -359,13 +359,6 @@ func keyValueToTag(keyValue label.KeyValue) *gen.Tag {
|
||||
VBool: &b,
|
||||
VType: gen.TagType_BOOL,
|
||||
}
|
||||
case label.INT32:
|
||||
i := int64(keyValue.Value.AsInt32())
|
||||
tag = &gen.Tag{
|
||||
Key: string(keyValue.Key),
|
||||
VLong: &i,
|
||||
VType: gen.TagType_LONG,
|
||||
}
|
||||
case label.INT64:
|
||||
i := keyValue.Value.AsInt64()
|
||||
tag = &gen.Tag{
|
||||
@ -373,29 +366,6 @@ func keyValueToTag(keyValue label.KeyValue) *gen.Tag {
|
||||
VLong: &i,
|
||||
VType: gen.TagType_LONG,
|
||||
}
|
||||
case label.UINT32:
|
||||
i := int64(keyValue.Value.AsUint32())
|
||||
tag = &gen.Tag{
|
||||
Key: string(keyValue.Key),
|
||||
VLong: &i,
|
||||
VType: gen.TagType_LONG,
|
||||
}
|
||||
case label.UINT64:
|
||||
// we'll ignore the value if it overflows
|
||||
if i := int64(keyValue.Value.AsUint64()); i >= 0 {
|
||||
tag = &gen.Tag{
|
||||
Key: string(keyValue.Key),
|
||||
VLong: &i,
|
||||
VType: gen.TagType_LONG,
|
||||
}
|
||||
}
|
||||
case label.FLOAT32:
|
||||
f := float64(keyValue.Value.AsFloat32())
|
||||
tag = &gen.Tag{
|
||||
Key: string(keyValue.Key),
|
||||
VDouble: &f,
|
||||
VType: gen.TagType_DOUBLE,
|
||||
}
|
||||
case label.FLOAT64:
|
||||
f := keyValue.Value.AsFloat64()
|
||||
tag = &gen.Tag{
|
||||
|
@ -17,7 +17,6 @@ package jaeger
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
@ -365,7 +364,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
||||
keyValue := "value"
|
||||
statusCodeValue := int64(1)
|
||||
doubleValue := 123.456
|
||||
uintValue := int64(123)
|
||||
intValue := int64(123)
|
||||
boolTrue := true
|
||||
statusMessage := "this is a problem"
|
||||
spanKind := "client"
|
||||
@ -400,8 +399,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
||||
Attributes: []label.KeyValue{
|
||||
label.String("key", keyValue),
|
||||
label.Float64("double", doubleValue),
|
||||
label.Uint64("uint", uint64(uintValue)),
|
||||
label.Uint64("overflows", math.MaxUint64),
|
||||
label.Int64("int", intValue),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
{Name: eventNameValue, Attributes: []label.KeyValue{label.String("k1", keyValue)}, Time: now},
|
||||
@ -425,7 +423,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
||||
Tags: []*gen.Tag{
|
||||
{Key: "double", VType: gen.TagType_DOUBLE, VDouble: &doubleValue},
|
||||
{Key: "key", VType: gen.TagType_STRING, VStr: &keyValue},
|
||||
{Key: "uint", VType: gen.TagType_LONG, VLong: &uintValue},
|
||||
{Key: "int", VType: gen.TagType_LONG, VLong: &intValue},
|
||||
{Key: "error", VType: gen.TagType_BOOL, VBool: &boolTrue},
|
||||
{Key: "otel.instrumentation_library.name", VType: gen.TagType_STRING, VStr: &instrLibName},
|
||||
{Key: "otel.instrumentation_library.version", VType: gen.TagType_STRING, VStr: &instrLibVersion},
|
||||
|
@ -45,7 +45,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -53,7 +53,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -78,7 +78,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -86,7 +86,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -110,7 +110,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -118,7 +118,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -142,7 +142,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -150,7 +150,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -174,7 +174,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -182,7 +182,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -206,7 +206,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -214,7 +214,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -238,7 +238,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: []trace.Event{
|
||||
@ -246,7 +246,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -270,7 +270,7 @@ func TestModelConversion(t *testing.T) {
|
||||
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("attr1", 42),
|
||||
label.Int64("attr1", 42),
|
||||
label.String("attr2", "bar"),
|
||||
},
|
||||
MessageEvents: nil,
|
||||
@ -296,7 +296,7 @@ func TestModelConversion(t *testing.T) {
|
||||
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
|
||||
Name: "ev1",
|
||||
Attributes: []label.KeyValue{
|
||||
label.Uint64("eventattr1", 123),
|
||||
label.Int64("eventattr1", 123),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -680,7 +680,7 @@ func Test_toZipkinTags(t *testing.T) {
|
||||
Attributes: []label.KeyValue{
|
||||
label.String("key", keyValue),
|
||||
label.Float64("double", doubleValue),
|
||||
label.Uint64("uint", uint64(uintValue)),
|
||||
label.Int64("uint", uintValue),
|
||||
label.Bool("ok", true),
|
||||
},
|
||||
},
|
||||
|
@ -38,14 +38,6 @@ func RawToInt64(r uint64) int64 {
|
||||
return int64(r)
|
||||
}
|
||||
|
||||
func Uint64ToRaw(u uint64) uint64 {
|
||||
return u
|
||||
}
|
||||
|
||||
func RawToUint64(r uint64) uint64 {
|
||||
return r
|
||||
}
|
||||
|
||||
func Float64ToRaw(f float64) uint64 {
|
||||
return math.Float64bits(f)
|
||||
}
|
||||
@ -54,30 +46,6 @@ func RawToFloat64(r uint64) float64 {
|
||||
return math.Float64frombits(r)
|
||||
}
|
||||
|
||||
func Int32ToRaw(i int32) uint64 {
|
||||
return uint64(i)
|
||||
}
|
||||
|
||||
func RawToInt32(r uint64) int32 {
|
||||
return int32(r)
|
||||
}
|
||||
|
||||
func Uint32ToRaw(u uint32) uint64 {
|
||||
return uint64(u)
|
||||
}
|
||||
|
||||
func RawToUint32(r uint64) uint32 {
|
||||
return uint32(r)
|
||||
}
|
||||
|
||||
func Float32ToRaw(f float32) uint64 {
|
||||
return Uint32ToRaw(math.Float32bits(f))
|
||||
}
|
||||
|
||||
func RawToFloat32(r uint64) float32 {
|
||||
return math.Float32frombits(RawToUint32(r))
|
||||
}
|
||||
|
||||
func RawPtrToFloat64Ptr(r *uint64) *float64 {
|
||||
return (*float64)(unsafe.Pointer(r))
|
||||
}
|
||||
@ -85,7 +53,3 @@ func RawPtrToFloat64Ptr(r *uint64) *float64 {
|
||||
func RawPtrToInt64Ptr(r *uint64) *int64 {
|
||||
return (*int64)(unsafe.Pointer(r))
|
||||
}
|
||||
|
||||
func RawPtrToUint64Ptr(r *uint64) *uint64 {
|
||||
return r
|
||||
}
|
||||
|
@ -38,30 +38,9 @@ var (
|
||||
int16Val = int16(1)
|
||||
int16KeyVal = label.Int("int16", int(int16Val))
|
||||
|
||||
int32Val = int32(1)
|
||||
int32KeyVal = label.Int32("int32", int32Val)
|
||||
|
||||
int64Val = int64(1)
|
||||
int64KeyVal = label.Int64("int64", int64Val)
|
||||
|
||||
uintVal = uint(1)
|
||||
uintKeyVal = label.Uint("uint", uintVal)
|
||||
|
||||
uint8Val = uint8(1)
|
||||
uint8KeyVal = label.Uint("uint8", uint(uint8Val))
|
||||
|
||||
uint16Val = uint16(1)
|
||||
uint16KeyVal = label.Uint("uint16", uint(uint16Val))
|
||||
|
||||
uint32Val = uint32(1)
|
||||
uint32KeyVal = label.Uint32("uint32", uint32Val)
|
||||
|
||||
uint64Val = uint64(1)
|
||||
uint64KeyVal = label.Uint64("uint64", uint64Val)
|
||||
|
||||
float32Val = float32(1.0)
|
||||
float32KeyVal = label.Float32("float32", float32Val)
|
||||
|
||||
float64Val = float64(1.0)
|
||||
float64KeyVal = label.Float64("float64", float64Val)
|
||||
|
||||
@ -128,20 +107,6 @@ func BenchmarkInt16KeyAny(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkInt32Key(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Int32("int32", int32Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkInt32KeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("int32", int32Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkInt64Key(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@ -156,76 +121,6 @@ func BenchmarkInt64KeyAny(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUintKey(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Uint("uint", uintVal)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUintKeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("uint", uintVal)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUint8KeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("uint8", uint8Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUint16KeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("uint16", uint16Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUint32Key(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Uint32("uint32", uint32Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUint32KeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("uint32", uint32Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUint64Key(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Uint64("uint64", uint64Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUint64KeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("uint64", uint64Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFloat32Key(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Float32("float32", float32Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFloat32KeyAny(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = label.Any("float32", float32Val)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFloat64Key(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@ -303,13 +198,6 @@ func BenchmarkEmitInt16(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitInt32(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = int32KeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitInt64(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@ -317,48 +205,6 @@ func BenchmarkEmitInt64(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitUint(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uintKeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitUint8(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uint8KeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitUint16(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uint16KeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitUint32(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uint32KeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitUint64(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uint64KeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitFloat32(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = float32KeyVal.Value.Emit()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitFloat64(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
69
label/key.go
69
label/key.go
@ -44,19 +44,6 @@ func (k Key) Int64(v int64) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Uint64 creates a KeyValue instance with a UINT64 Value.
|
||||
//
|
||||
// If creating both key and a uint64 value at the same time, then
|
||||
// instead of calling Key(name).Uint64(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Uint64(name, value).
|
||||
func (k Key) Uint64(v uint64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: Uint64Value(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Float64 creates a KeyValue instance with a FLOAT64 Value.
|
||||
//
|
||||
// If creating both key and a float64 value at the same time, then
|
||||
@ -70,45 +57,6 @@ func (k Key) Float64(v float64) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Int32 creates a KeyValue instance with an INT32 Value.
|
||||
//
|
||||
// If creating both key and an int32 value at the same time, then
|
||||
// instead of calling Key(name).Int32(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Int32(name, value).
|
||||
func (k Key) Int32(v int32) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: Int32Value(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Uint32 creates a KeyValue instance with a UINT32 Value.
|
||||
//
|
||||
// If creating both key and a uint32 value at the same time, then
|
||||
// instead of calling Key(name).Uint32(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Uint32(name, value).
|
||||
func (k Key) Uint32(v uint32) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: Uint32Value(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Float32 creates a KeyValue instance with a FLOAT32 Value.
|
||||
//
|
||||
// If creating both key and a float32 value at the same time, then
|
||||
// instead of calling Key(name).Float32(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Float32(name, value).
|
||||
func (k Key) Float32(v float32) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: Float32Value(v),
|
||||
}
|
||||
}
|
||||
|
||||
// String creates a KeyValue instance with a STRING Value.
|
||||
//
|
||||
// If creating both key and a string value at the same time, then
|
||||
@ -122,8 +70,7 @@ func (k Key) String(v string) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Int creates a KeyValue instance with either an INT32 or an INT64
|
||||
// Value, depending on whether the int type is 32 or 64 bits wide.
|
||||
// Int creates a KeyValue instance with an INT64 Value.
|
||||
//
|
||||
// If creating both key and an int value at the same time, then
|
||||
// instead of calling Key(name).Int(value) consider using a
|
||||
@ -136,20 +83,6 @@ func (k Key) Int(v int) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Uint creates a KeyValue instance with either a UINT32 or a UINT64
|
||||
// Value, depending on whether the uint type is 32 or 64 bits wide.
|
||||
//
|
||||
// If creating both key and a uint value at the same time, then
|
||||
// instead of calling Key(name).Uint(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Uint(name, value).
|
||||
func (k Key) Uint(v uint) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: UintValue(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Defined returns true for non-empty keys.
|
||||
func (k Key) Defined() bool {
|
||||
return len(k) != 0
|
||||
|
@ -74,31 +74,11 @@ func TestEmit(t *testing.T) {
|
||||
v: label.BoolValue(true),
|
||||
want: "true",
|
||||
},
|
||||
{
|
||||
name: `test Key.Emit() can emit a string representing self.INT32`,
|
||||
v: label.Int32Value(42),
|
||||
want: "42",
|
||||
},
|
||||
{
|
||||
name: `test Key.Emit() can emit a string representing self.INT64`,
|
||||
v: label.Int64Value(42),
|
||||
want: "42",
|
||||
},
|
||||
{
|
||||
name: `test Key.Emit() can emit a string representing self.UINT32`,
|
||||
v: label.Uint32Value(42),
|
||||
want: "42",
|
||||
},
|
||||
{
|
||||
name: `test Key.Emit() can emit a string representing self.UINT64`,
|
||||
v: label.Uint64Value(42),
|
||||
want: "42",
|
||||
},
|
||||
{
|
||||
name: `test Key.Emit() can emit a string representing self.FLOAT32`,
|
||||
v: label.Float32Value(42.1),
|
||||
want: "42.1",
|
||||
},
|
||||
{
|
||||
name: `test Key.Emit() can emit a string representing self.FLOAT64`,
|
||||
v: label.Float64Value(42.1),
|
||||
|
43
label/kv.go
43
label/kv.go
@ -38,36 +38,12 @@ func Int64(k string, v int64) KeyValue {
|
||||
return Key(k).Int64(v)
|
||||
}
|
||||
|
||||
// Uint64 creates a new key-value pair with a passed name and a uint64
|
||||
// value.
|
||||
func Uint64(k string, v uint64) KeyValue {
|
||||
return Key(k).Uint64(v)
|
||||
}
|
||||
|
||||
// Float64 creates a new key-value pair with a passed name and a float64
|
||||
// value.
|
||||
func Float64(k string, v float64) KeyValue {
|
||||
return Key(k).Float64(v)
|
||||
}
|
||||
|
||||
// Int32 creates a new key-value pair with a passed name and an int32
|
||||
// value.
|
||||
func Int32(k string, v int32) KeyValue {
|
||||
return Key(k).Int32(v)
|
||||
}
|
||||
|
||||
// Uint32 creates a new key-value pair with a passed name and a uint32
|
||||
// value.
|
||||
func Uint32(k string, v uint32) KeyValue {
|
||||
return Key(k).Uint32(v)
|
||||
}
|
||||
|
||||
// Float32 creates a new key-value pair with a passed name and a float32
|
||||
// value.
|
||||
func Float32(k string, v float32) KeyValue {
|
||||
return Key(k).Float32(v)
|
||||
}
|
||||
|
||||
// String creates a new key-value pair with a passed name and a string
|
||||
// value.
|
||||
func String(k, v string) KeyValue {
|
||||
@ -87,13 +63,6 @@ func Int(k string, v int) KeyValue {
|
||||
return Key(k).Int(v)
|
||||
}
|
||||
|
||||
// Uint creates a new key-value pair instance with a passed name and
|
||||
// either an uint32 or an uint64 value, depending on whether the uint
|
||||
// type is 32 or 64 bits wide.
|
||||
func Uint(k string, v uint) KeyValue {
|
||||
return Key(k).Uint(v)
|
||||
}
|
||||
|
||||
// Array creates a new key-value pair with a passed name and a array.
|
||||
// Only arrays of primitive type are supported.
|
||||
func Array(k string, v interface{}) KeyValue {
|
||||
@ -120,18 +89,8 @@ func Any(k string, value interface{}) KeyValue {
|
||||
return Bool(k, rv.Bool())
|
||||
case reflect.Int, reflect.Int8, reflect.Int16:
|
||||
return Int(k, int(rv.Int()))
|
||||
case reflect.Int32:
|
||||
return Int32(k, int32(rv.Int()))
|
||||
case reflect.Int64:
|
||||
return Int64(k, int64(rv.Int()))
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16:
|
||||
return Uint(k, uint(rv.Uint()))
|
||||
case reflect.Uint32:
|
||||
return Uint32(k, uint32(rv.Uint()))
|
||||
case reflect.Uint64, reflect.Uintptr:
|
||||
return Uint64(k, rv.Uint())
|
||||
case reflect.Float32:
|
||||
return Float32(k, float32(rv.Float()))
|
||||
return Int64(k, rv.Int())
|
||||
case reflect.Float64:
|
||||
return Float64(k, rv.Float())
|
||||
case reflect.String:
|
||||
|
@ -45,14 +45,6 @@ func TestKeyValueConstructors(t *testing.T) {
|
||||
Value: label.Int64Value(123),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Uint64",
|
||||
actual: label.Uint64("k1", 1),
|
||||
expected: label.KeyValue{
|
||||
Key: "k1",
|
||||
Value: label.Uint64Value(1),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Float64",
|
||||
actual: label.Float64("k1", 123.5),
|
||||
@ -61,30 +53,6 @@ func TestKeyValueConstructors(t *testing.T) {
|
||||
Value: label.Float64Value(123.5),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Int32",
|
||||
actual: label.Int32("k1", 123),
|
||||
expected: label.KeyValue{
|
||||
Key: "k1",
|
||||
Value: label.Int32Value(123),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Uint32",
|
||||
actual: label.Uint32("k1", 123),
|
||||
expected: label.KeyValue{
|
||||
Key: "k1",
|
||||
Value: label.Uint32Value(123),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Float32",
|
||||
actual: label.Float32("k1", 123.5),
|
||||
expected: label.KeyValue{
|
||||
Key: "k1",
|
||||
Value: label.Float32Value(123.5),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "String",
|
||||
actual: label.String("k1", "123.5"),
|
||||
@ -101,14 +69,6 @@ func TestKeyValueConstructors(t *testing.T) {
|
||||
Value: label.IntValue(123),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Uint",
|
||||
actual: label.Uint("k1", 123),
|
||||
expected: label.KeyValue{
|
||||
Key: "k1",
|
||||
Value: label.UintValue(123),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tt {
|
||||
@ -152,36 +112,12 @@ func TestAny(t *testing.T) {
|
||||
wantType: label.INT64,
|
||||
wantValue: int64(42),
|
||||
},
|
||||
{
|
||||
key: "uint64 type inferred",
|
||||
value: uint64(42),
|
||||
wantType: label.UINT64,
|
||||
wantValue: uint64(42),
|
||||
},
|
||||
{
|
||||
key: "float64 type inferred",
|
||||
value: float64(42.1),
|
||||
wantType: label.FLOAT64,
|
||||
wantValue: 42.1,
|
||||
},
|
||||
{
|
||||
key: "int32 type inferred",
|
||||
value: int32(42),
|
||||
wantType: label.INT32,
|
||||
wantValue: int32(42),
|
||||
},
|
||||
{
|
||||
key: "uint32 type inferred",
|
||||
value: uint32(42),
|
||||
wantType: label.UINT32,
|
||||
wantValue: uint32(42),
|
||||
},
|
||||
{
|
||||
key: "float32 type inferred",
|
||||
value: float32(42.1),
|
||||
wantType: label.FLOAT32,
|
||||
wantValue: float32(42.1),
|
||||
},
|
||||
{
|
||||
key: "string type inferred",
|
||||
value: "foo",
|
||||
|
@ -10,19 +10,15 @@ func _() {
|
||||
var x [1]struct{}
|
||||
_ = x[INVALID-0]
|
||||
_ = x[BOOL-1]
|
||||
_ = x[INT32-2]
|
||||
_ = x[INT64-3]
|
||||
_ = x[UINT32-4]
|
||||
_ = x[UINT64-5]
|
||||
_ = x[FLOAT32-6]
|
||||
_ = x[FLOAT64-7]
|
||||
_ = x[STRING-8]
|
||||
_ = x[ARRAY-9]
|
||||
_ = x[INT64-2]
|
||||
_ = x[FLOAT64-3]
|
||||
_ = x[STRING-4]
|
||||
_ = x[ARRAY-5]
|
||||
}
|
||||
|
||||
const _Type_name = "INVALIDBOOLINT32INT64UINT32UINT64FLOAT32FLOAT64STRINGARRAY"
|
||||
const _Type_name = "INVALIDBOOLINT64FLOAT64STRINGARRAY"
|
||||
|
||||
var _Type_index = [...]uint8{0, 7, 11, 16, 21, 27, 33, 40, 47, 53, 58}
|
||||
var _Type_index = [...]uint8{0, 7, 11, 16, 23, 29, 34}
|
||||
|
||||
func (i Type) String() string {
|
||||
if i < 0 || i >= Type(len(_Type_index)-1) {
|
||||
|
106
label/value.go
106
label/value.go
@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel/internal"
|
||||
)
|
||||
@ -44,17 +43,9 @@ const (
|
||||
INVALID Type = iota
|
||||
// BOOL is a boolean Type Value.
|
||||
BOOL
|
||||
// INT32 is a 32-bit signed integral Type Value.
|
||||
INT32
|
||||
// INT64 is a 64-bit signed integral Type Value.
|
||||
INT64
|
||||
// UINT32 is a 32-bit unsigned integral Type Value.
|
||||
UINT32
|
||||
// UINT64 is a 64-bit unsigned integral Type Value.
|
||||
UINT64
|
||||
// FLOAT32 is a 32-bit floating point Type Value.
|
||||
FLOAT32
|
||||
// FLOAT64 is a 64-bit floating point Type Value.
|
||||
FLOAT64
|
||||
// STRING is a string Type Value.
|
||||
STRING
|
||||
@ -80,14 +71,6 @@ func Int64Value(v int64) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// Uint64Value creates a UINT64 Value.
|
||||
func Uint64Value(v uint64) Value {
|
||||
return Value{
|
||||
vtype: UINT64,
|
||||
numeric: internal.Uint64ToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Float64Value creates a FLOAT64 Value.
|
||||
func Float64Value(v float64) Value {
|
||||
return Value{
|
||||
@ -96,30 +79,6 @@ func Float64Value(v float64) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// Int32Value creates an INT32 Value.
|
||||
func Int32Value(v int32) Value {
|
||||
return Value{
|
||||
vtype: INT32,
|
||||
numeric: internal.Int32ToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Uint32Value creates a UINT32 Value.
|
||||
func Uint32Value(v uint32) Value {
|
||||
return Value{
|
||||
vtype: UINT32,
|
||||
numeric: internal.Uint32ToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Float32Value creates a FLOAT32 Value.
|
||||
func Float32Value(v float32) Value {
|
||||
return Value{
|
||||
vtype: FLOAT32,
|
||||
numeric: internal.Float32ToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// StringValue creates a STRING Value.
|
||||
func StringValue(v string) Value {
|
||||
return Value{
|
||||
@ -128,28 +87,14 @@ func StringValue(v string) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// IntValue creates either an INT32 or an INT64 Value, depending on whether
|
||||
// the int type is 32 or 64 bits wide.
|
||||
// IntValue creates an INT64 Value.
|
||||
func IntValue(v int) Value {
|
||||
if unsafe.Sizeof(v) == 4 {
|
||||
return Int32Value(int32(v))
|
||||
}
|
||||
return Int64Value(int64(v))
|
||||
}
|
||||
|
||||
// UintValue creates either a UINT32 or a UINT64 Value, depending on whether
|
||||
// the uint type is 32 or 64 bits wide.
|
||||
func UintValue(v uint) Value {
|
||||
if unsafe.Sizeof(v) == 4 {
|
||||
return Uint32Value(uint32(v))
|
||||
}
|
||||
return Uint64Value(uint64(v))
|
||||
}
|
||||
|
||||
// ArrayValue creates an ARRAY value from an array or slice.
|
||||
// Only arrays or slices of bool, int, int32, int64, uint, uint32, uint64,
|
||||
// float, float32, float64, or string types are allowed. Specifically, arrays
|
||||
// and slices can not contain other arrays, slices, structs, or non-standard
|
||||
// Only arrays or slices of bool, int, int64, float, float64, or string types are allowed.
|
||||
// Specifically, arrays and slices can not contain other arrays, slices, structs, or non-standard
|
||||
// types. If the passed value is not an array or slice of these types an
|
||||
// INVALID value is returned.
|
||||
func ArrayValue(v interface{}) Value {
|
||||
@ -159,9 +104,8 @@ func ArrayValue(v interface{}) Value {
|
||||
typ := reflect.TypeOf(v).Elem()
|
||||
kind := typ.Kind()
|
||||
switch kind {
|
||||
case reflect.Bool, reflect.Int, reflect.Int32, reflect.Int64,
|
||||
reflect.Float32, reflect.Float64, reflect.String,
|
||||
reflect.Uint, reflect.Uint32, reflect.Uint64:
|
||||
case reflect.Bool, reflect.Int, reflect.Int64,
|
||||
reflect.Float64, reflect.String:
|
||||
val := reflect.ValueOf(v)
|
||||
length := val.Len()
|
||||
frozen := reflect.Indirect(reflect.New(reflect.ArrayOf(length, typ)))
|
||||
@ -188,36 +132,12 @@ func (v Value) AsBool() bool {
|
||||
return internal.RawToBool(v.numeric)
|
||||
}
|
||||
|
||||
// AsInt32 returns the int32 value. Make sure that the Value's type is
|
||||
// INT32.
|
||||
func (v Value) AsInt32() int32 {
|
||||
return internal.RawToInt32(v.numeric)
|
||||
}
|
||||
|
||||
// AsInt64 returns the int64 value. Make sure that the Value's type is
|
||||
// INT64.
|
||||
func (v Value) AsInt64() int64 {
|
||||
return internal.RawToInt64(v.numeric)
|
||||
}
|
||||
|
||||
// AsUint32 returns the uint32 value. Make sure that the Value's type
|
||||
// is UINT32.
|
||||
func (v Value) AsUint32() uint32 {
|
||||
return internal.RawToUint32(v.numeric)
|
||||
}
|
||||
|
||||
// AsUint64 returns the uint64 value. Make sure that the Value's type is
|
||||
// UINT64.
|
||||
func (v Value) AsUint64() uint64 {
|
||||
return internal.RawToUint64(v.numeric)
|
||||
}
|
||||
|
||||
// AsFloat32 returns the float32 value. Make sure that the Value's
|
||||
// type is FLOAT32.
|
||||
func (v Value) AsFloat32() float32 {
|
||||
return internal.RawToFloat32(v.numeric)
|
||||
}
|
||||
|
||||
// AsFloat64 returns the float64 value. Make sure that the Value's
|
||||
// type is FLOAT64.
|
||||
func (v Value) AsFloat64() float64 {
|
||||
@ -244,16 +164,8 @@ func (v Value) AsInterface() interface{} {
|
||||
return v.AsArray()
|
||||
case BOOL:
|
||||
return v.AsBool()
|
||||
case INT32:
|
||||
return v.AsInt32()
|
||||
case INT64:
|
||||
return v.AsInt64()
|
||||
case UINT32:
|
||||
return v.AsUint32()
|
||||
case UINT64:
|
||||
return v.AsUint64()
|
||||
case FLOAT32:
|
||||
return v.AsFloat32()
|
||||
case FLOAT64:
|
||||
return v.AsFloat64()
|
||||
case STRING:
|
||||
@ -269,16 +181,8 @@ func (v Value) Emit() string {
|
||||
return fmt.Sprint(v.array)
|
||||
case BOOL:
|
||||
return strconv.FormatBool(v.AsBool())
|
||||
case INT32:
|
||||
return strconv.FormatInt(int64(v.AsInt32()), 10)
|
||||
case INT64:
|
||||
return strconv.FormatInt(v.AsInt64(), 10)
|
||||
case UINT32:
|
||||
return strconv.FormatUint(uint64(v.AsUint32()), 10)
|
||||
case UINT64:
|
||||
return strconv.FormatUint(v.AsUint64(), 10)
|
||||
case FLOAT32:
|
||||
return fmt.Sprint(v.AsFloat32())
|
||||
case FLOAT64:
|
||||
return fmt.Sprint(v.AsFloat64())
|
||||
case STRING:
|
||||
|
@ -17,7 +17,6 @@ package label_test
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
@ -51,36 +50,12 @@ func TestValue(t *testing.T) {
|
||||
wantType: label.INT64,
|
||||
wantValue: int64(42),
|
||||
},
|
||||
{
|
||||
name: "Key.Uint64() correctly returns keys's internal uint64 value",
|
||||
value: k.Uint64(42).Value,
|
||||
wantType: label.UINT64,
|
||||
wantValue: uint64(42),
|
||||
},
|
||||
{
|
||||
name: "Key.Float64() correctly returns keys's internal float64 value",
|
||||
value: k.Float64(42.1).Value,
|
||||
wantType: label.FLOAT64,
|
||||
wantValue: 42.1,
|
||||
},
|
||||
{
|
||||
name: "Key.Int32() correctly returns keys's internal int32 value",
|
||||
value: k.Int32(42).Value,
|
||||
wantType: label.INT32,
|
||||
wantValue: int32(42),
|
||||
},
|
||||
{
|
||||
name: "Key.Uint32() correctly returns keys's internal uint32 value",
|
||||
value: k.Uint32(42).Value,
|
||||
wantType: label.UINT32,
|
||||
wantValue: uint32(42),
|
||||
},
|
||||
{
|
||||
name: "Key.Float32() correctly returns keys's internal float32 value",
|
||||
value: k.Float32(42.1).Value,
|
||||
wantType: label.FLOAT32,
|
||||
wantValue: float32(42.1),
|
||||
},
|
||||
{
|
||||
name: "Key.String() correctly returns keys's internal string value",
|
||||
value: k.String("foo").Value,
|
||||
@ -93,48 +68,18 @@ func TestValue(t *testing.T) {
|
||||
wantType: bli.signedType,
|
||||
wantValue: bli.signedValue,
|
||||
},
|
||||
{
|
||||
name: "Key.Uint() correctly returns keys's internal unsigned integral value",
|
||||
value: k.Uint(bli.uintValue).Value,
|
||||
wantType: bli.unsignedType,
|
||||
wantValue: bli.unsignedValue,
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]int64) correctly returns keys's internal int64 values",
|
||||
value: k.Array([]int64{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]int64{42, 43},
|
||||
},
|
||||
{
|
||||
name: "KeyArray([]uint64) correctly returns keys's internal uint64 values",
|
||||
value: k.Array([]uint64{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]uint64{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]float64) correctly returns keys's internal float64 values",
|
||||
value: k.Array([]float64{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]float64{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]int32) correctly returns keys's internal int32 values",
|
||||
value: k.Array([]int32{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]int32{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]uint32) correctly returns keys's internal uint32 values",
|
||||
value: k.Array([]uint32{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]uint32{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]float32) correctly returns keys's internal float32 values",
|
||||
value: k.Array([]float32{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]float32{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]string) correctly return key's internal string values",
|
||||
value: k.Array([]string{"foo", "bar"}).Value,
|
||||
@ -147,12 +92,6 @@ func TestValue(t *testing.T) {
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]int{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([]uint) correctly returns keys's internal unsigned integral values",
|
||||
value: k.Array([]uint{42, 43}).Value,
|
||||
wantType: label.ARRAY,
|
||||
wantValue: [2]uint{42, 43},
|
||||
},
|
||||
{
|
||||
name: "Key.Array([][]int) refuses to create multi-dimensional array",
|
||||
value: k.Array([][]int{{1, 2}, {3, 4}}).Value,
|
||||
@ -175,37 +114,23 @@ func TestValue(t *testing.T) {
|
||||
}
|
||||
|
||||
type bitlessInfo struct {
|
||||
intValue int
|
||||
uintValue uint
|
||||
signedType label.Type
|
||||
unsignedType label.Type
|
||||
signedValue interface{}
|
||||
unsignedValue interface{}
|
||||
intValue int
|
||||
uintValue uint
|
||||
signedType label.Type
|
||||
signedValue interface{}
|
||||
}
|
||||
|
||||
func getBitlessInfo(i int) bitlessInfo {
|
||||
if unsafe.Sizeof(i) == 4 {
|
||||
return bitlessInfo{
|
||||
intValue: i,
|
||||
uintValue: uint(i),
|
||||
signedType: label.INT32,
|
||||
unsignedType: label.UINT32,
|
||||
signedValue: int32(i),
|
||||
unsignedValue: uint32(i),
|
||||
}
|
||||
}
|
||||
return bitlessInfo{
|
||||
intValue: i,
|
||||
uintValue: uint(i),
|
||||
signedType: label.INT64,
|
||||
unsignedType: label.UINT64,
|
||||
signedValue: int64(i),
|
||||
unsignedValue: uint64(i),
|
||||
intValue: i,
|
||||
uintValue: uint(i),
|
||||
signedType: label.INT64,
|
||||
signedValue: int64(i),
|
||||
}
|
||||
}
|
||||
|
||||
func TestAsArrayValue(t *testing.T) {
|
||||
v := label.ArrayValue([]uint{1, 2, 3}).AsArray()
|
||||
v := label.ArrayValue([]int{1, 2, 3}).AsArray()
|
||||
// Ensure the returned dynamic type is stable.
|
||||
if got, want := reflect.TypeOf(v).Kind(), reflect.Array; got != want {
|
||||
t.Errorf("AsArray() returned %T, want %T", got, want)
|
||||
|
@ -204,23 +204,13 @@ func TestInjectBaggageToHTTPReq(t *testing.T) {
|
||||
label.Bool("key1", true),
|
||||
label.Int("key2", 123),
|
||||
label.Int64("key3", 123),
|
||||
label.Int32("key4", 123),
|
||||
label.Uint("key5", 123),
|
||||
label.Uint32("key6", 123),
|
||||
label.Uint64("key7", 123),
|
||||
label.Float64("key8", 123.567),
|
||||
label.Float32("key9", 123.567),
|
||||
label.Float64("key4", 123.567),
|
||||
},
|
||||
wantInHeader: []string{
|
||||
"key1=true",
|
||||
"key2=123",
|
||||
"key3=123",
|
||||
"key4=123",
|
||||
"key5=123",
|
||||
"key6=123",
|
||||
"key7=123",
|
||||
"key8=123.567",
|
||||
"key9=123.567",
|
||||
"key4=123.567",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -284,17 +284,13 @@ func TestDefaultLabelEncoder(t *testing.T) {
|
||||
// that is done in Labels(...).
|
||||
encoded = encoder.Encode(newSetIter(
|
||||
label.Int("I", 1),
|
||||
label.Uint("U", 1),
|
||||
label.Int32("I32", 1),
|
||||
label.Uint32("U32", 1),
|
||||
label.Int64("I64", 1),
|
||||
label.Uint64("U64", 1),
|
||||
label.Float64("F64", 1),
|
||||
label.Float64("F64", 1),
|
||||
label.String("S", "1"),
|
||||
label.Bool("B", true),
|
||||
))
|
||||
require.Equal(t, "B=true,F64=1,I=1,I32=1,I64=1,S=1,U=1,U32=1,U64=1", encoded)
|
||||
require.Equal(t, "B=true,F64=1,I=1,I64=1,S=1", encoded)
|
||||
}
|
||||
|
||||
func TestObserverCollection(t *testing.T) {
|
||||
|
@ -45,7 +45,6 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) {
|
||||
span.SetAttributes(
|
||||
label.Bool("key1", false),
|
||||
label.String("key2", "hello"),
|
||||
label.Uint64("key3", 123),
|
||||
label.Float64("key4", 123.456),
|
||||
)
|
||||
span.End()
|
||||
@ -63,11 +62,9 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) {
|
||||
span.SetAttributes(
|
||||
label.Bool("key1", false),
|
||||
label.String("key2", "hello"),
|
||||
label.Uint64("key3", 123),
|
||||
label.Float64("key4", 123.456),
|
||||
label.Bool("key21", false),
|
||||
label.String("key22", "hello"),
|
||||
label.Uint64("key23", 123),
|
||||
label.Float64("key24", 123.456),
|
||||
)
|
||||
span.End()
|
||||
@ -86,13 +83,8 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) {
|
||||
label.Bool("key1", false),
|
||||
label.String("key2", "hello"),
|
||||
label.Int64("key3", 123),
|
||||
label.Uint64("key4", 123),
|
||||
label.Int32("key5", 123),
|
||||
label.Uint32("key6", 123),
|
||||
label.Float64("key7", 123.456),
|
||||
label.Float32("key8", 123.456),
|
||||
label.Int("key9", 123),
|
||||
label.Uint("key10", 123),
|
||||
)
|
||||
span.End()
|
||||
}
|
||||
@ -110,23 +102,13 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) {
|
||||
label.Bool("key1", false),
|
||||
label.String("key2", "hello"),
|
||||
label.Int64("key3", 123),
|
||||
label.Uint64("key4", 123),
|
||||
label.Int32("key5", 123),
|
||||
label.Uint32("key6", 123),
|
||||
label.Float64("key7", 123.456),
|
||||
label.Float32("key8", 123.456),
|
||||
label.Int("key10", 123),
|
||||
label.Uint("key11", 123),
|
||||
label.Bool("key21", false),
|
||||
label.String("key22", "hello"),
|
||||
label.Int64("key23", 123),
|
||||
label.Uint64("key24", 123),
|
||||
label.Int32("key25", 123),
|
||||
label.Uint32("key26", 123),
|
||||
label.Float64("key27", 123.456),
|
||||
label.Float32("key28", 123.456),
|
||||
label.Int("key210", 123),
|
||||
label.Uint("key211", 123),
|
||||
)
|
||||
span.End()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user