Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NewKey and update doc comment #721

Merged
merged 3 commits into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/correlation/correlation_context_propagator.go
Expand Up @@ -97,7 +97,7 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP
trimmedValueWithProps.WriteString(prop)
}

keyValues = append(keyValues, kv.NewKey(trimmedName).String(trimmedValueWithProps.String()))
keyValues = append(keyValues, kv.Key(trimmedName).String(trimmedValueWithProps.String()))
}
return ContextWithMap(ctx, NewMap(MapUpdate{
MultiKV: keyValues,
Expand Down
50 changes: 25 additions & 25 deletions api/correlation/correlation_context_propagator_test.go
Expand Up @@ -40,48 +40,48 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
name: "valid w3cHeader",
header: "key1=val1,key2=val2",
wantKVs: []kv.KeyValue{
kv.NewKey("key1").String("val1"),
kv.NewKey("key2").String("val2"),
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
},
},
{
name: "valid w3cHeader with spaces",
header: "key1 = val1, key2 =val2 ",
wantKVs: []kv.KeyValue{
kv.NewKey("key1").String("val1"),
kv.NewKey("key2").String("val2"),
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
},
},
{
name: "valid w3cHeader with properties",
header: "key1=val1,key2=val2;prop=1",
wantKVs: []kv.KeyValue{
kv.NewKey("key1").String("val1"),
kv.NewKey("key2").String("val2;prop=1"),
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2;prop=1"),
},
},
{
name: "valid header with url-escaped comma",
header: "key1=val1,key2=val2%2Cval3",
wantKVs: []kv.KeyValue{
kv.NewKey("key1").String("val1"),
kv.NewKey("key2").String("val2,val3"),
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2,val3"),
},
},
{
name: "valid header with an invalid header",
header: "key1=val1,key2=val2,a,val3",
wantKVs: []kv.KeyValue{
kv.NewKey("key1").String("val1"),
kv.NewKey("key2").String("val2"),
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
},
},
{
name: "valid header with no value",
header: "key1=,key2=val2",
wantKVs: []kv.KeyValue{
kv.NewKey("key1").String(""),
kv.NewKey("key2").String("val2"),
kv.Key("key1").String(""),
kv.Key("key2").String("val2"),
},
},
}
Expand Down Expand Up @@ -157,31 +157,31 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
{
name: "two simple values",
kvs: []kv.KeyValue{
kv.NewKey("key1").String("val1"),
kv.NewKey("key2").String("val2"),
kv.Key("key1").String("val1"),
kv.Key("key2").String("val2"),
},
wantInHeader: []string{"key1=val1", "key2=val2"},
},
{
name: "two values with escaped chars",
kvs: []kv.KeyValue{
kv.NewKey("key1").String("val1,val2"),
kv.NewKey("key2").String("val3=4"),
kv.Key("key1").String("val1,val2"),
kv.Key("key2").String("val3=4"),
},
wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"},
},
{
name: "values of non-string types",
kvs: []kv.KeyValue{
kv.NewKey("key1").Bool(true),
kv.NewKey("key2").Int(123),
kv.NewKey("key3").Int64(123),
kv.NewKey("key4").Int32(123),
kv.NewKey("key5").Uint(123),
kv.NewKey("key6").Uint32(123),
kv.NewKey("key7").Uint64(123),
kv.NewKey("key8").Float64(123.567),
kv.NewKey("key9").Float32(123.567),
kv.Key("key1").Bool(true),
kv.Key("key2").Int(123),
kv.Key("key3").Int64(123),
kv.Key("key4").Int32(123),
kv.Key("key5").Uint(123),
kv.Key("key6").Uint32(123),
kv.Key("key7").Uint64(123),
kv.Key("key8").Float64(123.567),
kv.Key("key9").Float32(123.567),
},
wantInHeader: []string{
"key1=true",
Expand Down
16 changes: 8 additions & 8 deletions api/correlation/map_test.go
Expand Up @@ -86,7 +86,7 @@ func TestSizeComputation(t *testing.T) {
func getTestCases() []testCase {
return []testCase{
{
name: "NewKey map with MultiKV",
name: "map with MultiKV",
value: MapUpdate{MultiKV: []kv.KeyValue{
kv.Int64("key1", 1),
kv.String("key2", "val2")},
Expand All @@ -98,15 +98,15 @@ func getTestCases() []testCase {
},
},
{
name: "NewKey map with SingleKV",
name: "map with SingleKV",
value: MapUpdate{SingleKV: kv.String("key1", "val1")},
init: []int{},
wantKVs: []kv.KeyValue{
kv.String("key1", "val1"),
},
},
{
name: "NewKey map with both add fields",
name: "map with both add fields",
value: MapUpdate{SingleKV: kv.Int64("key1", 3),
MultiKV: []kv.KeyValue{
kv.String("key1", ""),
Expand All @@ -119,27 +119,27 @@ func getTestCases() []testCase {
},
},
{
name: "NewKey map with empty MapUpdate",
name: "map with empty MapUpdate",
value: MapUpdate{},
init: []int{},
wantKVs: []kv.KeyValue{},
},
{
name: "NewKey map with DropSingleK",
name: "map with DropSingleK",
value: MapUpdate{DropSingleK: kv.Key("key1")},
init: []int{},
wantKVs: []kv.KeyValue{},
},
{
name: "NewKey map with DropMultiK",
name: "map with DropMultiK",
value: MapUpdate{DropMultiK: []kv.Key{
kv.Key("key1"), kv.Key("key2"),
}},
init: []int{},
wantKVs: []kv.KeyValue{},
},
{
name: "NewKey map with both drop fields",
name: "map with both drop fields",
value: MapUpdate{
DropSingleK: kv.Key("key1"),
DropMultiK: []kv.Key{
Expand All @@ -151,7 +151,7 @@ func getTestCases() []testCase {
wantKVs: []kv.KeyValue{},
},
{
name: "NewKey map with all fields",
name: "map with all fields",
value: MapUpdate{
DropSingleK: kv.Key("key1"),
DropMultiK: []kv.Key{
Expand Down
6 changes: 1 addition & 5 deletions api/kv/doc.go
Expand Up @@ -12,9 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// This package provides basic types used in OpenTelemetry - keys,
// values, numbers and span contexts.
//
// See the api/key package for convenience functions for creating keys
// and key-value pairs.
// package kv provides basic key and value types.
package kv // import "go.opentelemetry.io/otel/api/kv"
5 changes: 0 additions & 5 deletions api/kv/key.go
Expand Up @@ -22,11 +22,6 @@ import (
// allowed character set in the key depends on the use of the key.
type Key string

// NewKey creates a new key with a passed name.
func NewKey(name string) Key {
return Key(name)
}

// Bool creates a KeyValue instance with a BOOL Value.
//
// If creating both key and a bool value at the same time, then
Expand Down
22 changes: 11 additions & 11 deletions api/kv/kv.go
Expand Up @@ -30,69 +30,69 @@ type KeyValue struct {
// Bool creates a new key-value pair with a passed name and a bool
// value.
func Bool(k string, v bool) KeyValue {
return NewKey(k).Bool(v)
return Key(k).Bool(v)
}

// Int64 creates a new key-value pair with a passed name and an int64
// value.
func Int64(k string, v int64) KeyValue {
return NewKey(k).Int64(v)
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 NewKey(k).Uint64(v)
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 NewKey(k).Float64(v)
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 NewKey(k).Int32(v)
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 NewKey(k).Uint32(v)
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 NewKey(k).Float32(v)
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 {
return NewKey(k).String(v)
return Key(k).String(v)
}

// Stringer creates a new key-value pair with a passed name and a string
// value generated by the passed Stringer interface.
func Stringer(k string, v fmt.Stringer) KeyValue {
return NewKey(k).String(v.String())
return Key(k).String(v.String())
}

// Int creates a new key-value pair instance with a passed name and
// either an int32 or an int64 value, depending on whether the int
// type is 32 or 64 bits wide.
func Int(k string, v int) KeyValue {
return NewKey(k).Int(v)
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 NewKey(k).Uint(v)
return Key(k).Uint(v)
}

// Infer creates a new key-value pair instance with a passed name and
Expand Down
4 changes: 2 additions & 2 deletions bridge/opentracing/bridge.go
Expand Up @@ -66,12 +66,12 @@ func (c *bridgeSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {

func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
crk := http.CanonicalHeaderKey(restrictedKey)
c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: otelcore.NewKey(crk).String(value)})
c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: otelcore.Key(crk).String(value)})
}

func (c *bridgeSpanContext) baggageItem(restrictedKey string) string {
crk := http.CanonicalHeaderKey(restrictedKey)
val, _ := c.baggageItems.Value(otelcore.NewKey(crk))
val, _ := c.baggageItems.Value(otelcore.Key(crk))
return val.Emit()
}

Expand Down
12 changes: 6 additions & 6 deletions bridge/opentracing/internal/mock.go
Expand Up @@ -32,12 +32,12 @@ import (
)

var (
ComponentKey = otelcore.NewKey("component")
ServiceKey = otelcore.NewKey("service")
StatusCodeKey = otelcore.NewKey("status.code")
StatusMessageKey = otelcore.NewKey("status.message")
ErrorKey = otelcore.NewKey("error")
NameKey = otelcore.NewKey("name")
ComponentKey = otelcore.Key("component")
ServiceKey = otelcore.Key("service")
StatusCodeKey = otelcore.Key("status.code")
StatusMessageKey = otelcore.Key("status.message")
ErrorKey = otelcore.Key("error")
NameKey = otelcore.Key("name")
)

type MockContextKeyValue struct {
Expand Down
10 changes: 5 additions & 5 deletions example/basic/main.go
Expand Up @@ -30,10 +30,10 @@ import (
)

var (
fooKey = kv.NewKey("ex.com/foo")
barKey = kv.NewKey("ex.com/bar")
lemonsKey = kv.NewKey("ex.com/lemons")
anotherKey = kv.NewKey("ex.com/another")
fooKey = kv.Key("ex.com/foo")
barKey = kv.Key("ex.com/bar")
lemonsKey = kv.Key("ex.com/lemons")
anotherKey = kv.Key("ex.com/another")
)

// initTracer creates and registers trace provider instance.
Expand Down Expand Up @@ -94,7 +94,7 @@ func main() {

err := tracer.WithSpan(ctx, "operation", func(ctx context.Context) error {

trace.SpanFromContext(ctx).AddEvent(ctx, "Nice operation!", kv.NewKey("bogons").Int(100))
trace.SpanFromContext(ctx).AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100))

trace.SpanFromContext(ctx).SetAttributes(anotherKey.String("yes"))

Expand Down
2 changes: 1 addition & 1 deletion example/namedtracer/foo/foo.go
Expand Up @@ -23,7 +23,7 @@ import (
)

var (
lemonsKey = kv.NewKey("ex.com/lemons")
lemonsKey = kv.Key("ex.com/lemons")
)

// SubOperation is an example to demonstrate the use of named tracer.
Expand Down
8 changes: 4 additions & 4 deletions example/namedtracer/main.go
Expand Up @@ -29,9 +29,9 @@ import (
)

var (
fooKey = kv.NewKey("ex.com/foo")
barKey = kv.NewKey("ex.com/bar")
anotherKey = kv.NewKey("ex.com/another")
fooKey = kv.Key("ex.com/foo")
barKey = kv.Key("ex.com/bar")
anotherKey = kv.Key("ex.com/another")
)

var tp *sdktrace.Provider
Expand Down Expand Up @@ -67,7 +67,7 @@ func main() {

err := tracer.WithSpan(ctx, "operation", func(ctx context.Context) error {

trace.SpanFromContext(ctx).AddEvent(ctx, "Nice operation!", kv.NewKey("bogons").Int(100))
trace.SpanFromContext(ctx).AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100))

trace.SpanFromContext(ctx).SetAttributes(anotherKey.String("yes"))

Expand Down
2 changes: 1 addition & 1 deletion example/prometheus/main.go
Expand Up @@ -29,7 +29,7 @@ import (
)

var (
lemonsKey = kv.NewKey("ex.com/lemons")
lemonsKey = kv.Key("ex.com/lemons")
)

func initMeter() *push.Controller {
Expand Down