diff --git a/api/correlation/correlation_context_propagator.go b/api/correlation/correlation_context_propagator.go index 8cee24208bc..20e1cd6af78 100644 --- a/api/correlation/correlation_context_propagator.go +++ b/api/correlation/correlation_context_propagator.go @@ -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, diff --git a/api/correlation/correlation_context_propagator_test.go b/api/correlation/correlation_context_propagator_test.go index d422653c51e..3fe832fa661 100644 --- a/api/correlation/correlation_context_propagator_test.go +++ b/api/correlation/correlation_context_propagator_test.go @@ -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"), }, }, } @@ -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", diff --git a/api/correlation/map_test.go b/api/correlation/map_test.go index cc8e24e11aa..c886b842dbd 100644 --- a/api/correlation/map_test.go +++ b/api/correlation/map_test.go @@ -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")}, @@ -98,7 +98,7 @@ func getTestCases() []testCase { }, }, { - name: "NewKey map with SingleKV", + name: "map with SingleKV", value: MapUpdate{SingleKV: kv.String("key1", "val1")}, init: []int{}, wantKVs: []kv.KeyValue{ @@ -106,7 +106,7 @@ func getTestCases() []testCase { }, }, { - 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", ""), @@ -119,19 +119,19 @@ 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"), }}, @@ -139,7 +139,7 @@ func getTestCases() []testCase { 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{ @@ -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{ diff --git a/api/kv/doc.go b/api/kv/doc.go index 5261ec99f3f..3e635cdc3bd 100644 --- a/api/kv/doc.go +++ b/api/kv/doc.go @@ -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" diff --git a/api/kv/key.go b/api/kv/key.go index 202851879ea..b1e04c447da 100644 --- a/api/kv/key.go +++ b/api/kv/key.go @@ -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 diff --git a/api/kv/kv.go b/api/kv/kv.go index f159b553f19..e10b9134965 100644 --- a/api/kv/kv.go +++ b/api/kv/kv.go @@ -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 diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index b4c6748bd3b..dd8ee6190db 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -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() } diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index 132b081563e..718a1f044eb 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -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 { diff --git a/example/basic/main.go b/example/basic/main.go index 718899b7f9d..9a5b05983f1 100644 --- a/example/basic/main.go +++ b/example/basic/main.go @@ -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. @@ -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")) diff --git a/example/namedtracer/foo/foo.go b/example/namedtracer/foo/foo.go index 40e64b28067..160aa274030 100644 --- a/example/namedtracer/foo/foo.go +++ b/example/namedtracer/foo/foo.go @@ -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. diff --git a/example/namedtracer/main.go b/example/namedtracer/main.go index c3786ae3199..f0aae45ad75 100644 --- a/example/namedtracer/main.go +++ b/example/namedtracer/main.go @@ -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 @@ -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")) diff --git a/example/prometheus/main.go b/example/prometheus/main.go index 6e9ba622227..6c0282801e6 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -29,7 +29,7 @@ import ( ) var ( - lemonsKey = kv.NewKey("ex.com/lemons") + lemonsKey = kv.Key("ex.com/lemons") ) func initMeter() *push.Controller { diff --git a/exporters/metric/prometheus/prometheus_test.go b/exporters/metric/prometheus/prometheus_test.go index 3a0b8adde5b..362df65a6fb 100644 --- a/exporters/metric/prometheus/prometheus_test.go +++ b/exporters/metric/prometheus/prometheus_test.go @@ -51,8 +51,8 @@ func TestPrometheusExporter(t *testing.T) { "histogram_measure", metric.MeasureKind, metric.Float64NumberKind) labels := []kv.KeyValue{ - kv.NewKey("A").String("B"), - kv.NewKey("C").String("D"), + kv.Key("A").String("B"), + kv.Key("C").String("D"), } checkpointSet.AddCounter(&counter, 15.3, labels...) @@ -83,8 +83,8 @@ func TestPrometheusExporter(t *testing.T) { expected = append(expected, `histogram_measure_sum{A="B",C="D"} 19.6`) missingLabels := []kv.KeyValue{ - kv.NewKey("A").String("E"), - kv.NewKey("C").String(""), + kv.Key("A").String("E"), + kv.Key("C").String(""), } checkpointSet.AddCounter(&counter, 12, missingLabels...) diff --git a/exporters/metric/stdout/example_test.go b/exporters/metric/stdout/example_test.go index f86d175e842..9cb3b45ad2f 100644 --- a/exporters/metric/stdout/example_test.go +++ b/exporters/metric/stdout/example_test.go @@ -37,7 +37,7 @@ func ExampleNewExportPipeline() { ctx := context.Background() - key := kv.NewKey("key") + key := kv.Key("key") meter := pusher.Meter("example") // Create and update a single counter: diff --git a/plugin/grpctrace/interceptor.go b/plugin/grpctrace/interceptor.go index 9dbdcf136b4..a84aec9e12d 100644 --- a/plugin/grpctrace/interceptor.go +++ b/plugin/grpctrace/interceptor.go @@ -34,13 +34,13 @@ import ( ) var ( - rpcServiceKey = kv.NewKey("rpc.service") - netPeerIPKey = kv.NewKey("net.peer.ip") - netPeerPortKey = kv.NewKey("net.peer.port") + rpcServiceKey = kv.Key("rpc.service") + netPeerIPKey = kv.Key("net.peer.ip") + netPeerPortKey = kv.Key("net.peer.port") - messageTypeKey = kv.NewKey("message.type") - messageIDKey = kv.NewKey("message.id") - messageUncompressedSizeKey = kv.NewKey("message.uncompressed_size") + messageTypeKey = kv.Key("message.type") + messageIDKey = kv.Key("message.id") + messageUncompressedSizeKey = kv.Key("message.uncompressed_size") ) const ( diff --git a/plugin/httptrace/clienttrace.go b/plugin/httptrace/clienttrace.go index 2f48519583d..66df26260d1 100644 --- a/plugin/httptrace/clienttrace.go +++ b/plugin/httptrace/clienttrace.go @@ -30,10 +30,10 @@ import ( ) var ( - HTTPStatus = kv.NewKey("http.status") - HTTPHeaderMIME = kv.NewKey("http.mime") - HTTPRemoteAddr = kv.NewKey("http.remote") - HTTPLocalAddr = kv.NewKey("http.local") + HTTPStatus = kv.Key("http.status") + HTTPHeaderMIME = kv.Key("http.mime") + HTTPRemoteAddr = kv.Key("http.remote") + HTTPLocalAddr = kv.Key("http.local") ) var ( diff --git a/plugin/httptrace/clienttrace_test.go b/plugin/httptrace/clienttrace_test.go index adbe22bd390..072313be564 100644 --- a/plugin/httptrace/clienttrace_test.go +++ b/plugin/httptrace/clienttrace_test.go @@ -151,7 +151,7 @@ func TestHTTPRequestWithClientTrace(t *testing.T) { } if tl.name == "http.getconn" { - local := kv.NewKey("http.local") + local := kv.Key("http.local") // http.local attribute is not deterministic, just make sure it exists for `getconn`. if _, ok := actualAttrs[local]; ok { delete(actualAttrs, local) diff --git a/plugin/httptrace/httptrace.go b/plugin/httptrace/httptrace.go index 2955a301049..87746574d5e 100644 --- a/plugin/httptrace/httptrace.go +++ b/plugin/httptrace/httptrace.go @@ -26,8 +26,8 @@ import ( ) var ( - HostKey = kv.NewKey("http.host") - URLKey = kv.NewKey("http.url") + HostKey = kv.Key("http.host") + URLKey = kv.Key("http.url") ) // Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject. diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index aa0cb1c1fb5..9cbc1a5780e 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -111,7 +111,7 @@ func makeLabels(n int) []kv.KeyValue { break } } - l[i] = kv.NewKey(k).String(fmt.Sprint("v", rand.Intn(1000000000))) + l[i] = kv.Key(k).String(fmt.Sprint("v", rand.Intn(1000000000))) } return l } diff --git a/sdk/metric/example_test.go b/sdk/metric/example_test.go index b960b83f135..4f39441b53e 100644 --- a/sdk/metric/example_test.go +++ b/sdk/metric/example_test.go @@ -37,7 +37,7 @@ func ExampleNew() { ctx := context.Background() - key := kv.NewKey("key") + key := kv.Key("key") meter := pusher.Meter("example") counter := metric.Must(meter).NewInt64Counter("a.counter") diff --git a/sdk/metric/integrator/test/test.go b/sdk/metric/integrator/test/test.go index 8d6fe0cd262..383c77645de 100644 --- a/sdk/metric/integrator/test/test.go +++ b/sdk/metric/integrator/test/test.go @@ -82,8 +82,8 @@ func NewOutput(labelEncoder label.Encoder) Output { } // NewAggregationSelector returns a policy that is consistent with the -// test descriptors above. I.e., it returns sum.NewKey() for counter -// instruments and lastvalue.NewKey for lastValue instruments. +// test descriptors above. I.e., it returns sum.New() for counter +// instruments and lastvalue.New() for lastValue instruments. func NewAggregationSelector() export.AggregationSelector { return &testAggregationSelector{} } diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index bdda93fa4af..7e15e1594c7 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -142,7 +142,7 @@ func (f *testFixture) someLabels() []kv.KeyValue { break } } - l[i] = kv.NewKey(k).String(fmt.Sprint("v", rand.Intn(1000000000))) + l[i] = kv.Key(k).String(fmt.Sprint("v", rand.Intn(1000000000))) } lc := canonicalizeLabels(l) f.lock.Lock() diff --git a/sdk/resource/resource.go b/sdk/resource/resource.go index 4f107e03b09..8599f04bdfe 100644 --- a/sdk/resource/resource.go +++ b/sdk/resource/resource.go @@ -34,7 +34,7 @@ type Resource struct { var emptyResource Resource -// NewKey creates a resource from a set of attributes. If there are +// Key creates a resource from a set of attributes. If there are // duplicate keys present in the list of attributes, then the last // value found for the key is preserved. func New(kvs ...kv.KeyValue) *Resource { @@ -96,7 +96,7 @@ func Merge(a, b *Resource) *Resource { b = Empty() } // Note: 'b' is listed first so that 'a' will overwrite with - // last-value-wins in label.NewKey() + // last-value-wins in label.Key() combine := append(b.Attributes(), a.Attributes()...) return New(combine...) } diff --git a/sdk/resource/resource_test.go b/sdk/resource/resource_test.go index 1bb717b41a5..e9b560f1ae2 100644 --- a/sdk/resource/resource_test.go +++ b/sdk/resource/resource_test.go @@ -43,17 +43,17 @@ func TestNew(t *testing.T) { want []kv.KeyValue }{ { - name: "NewKey with common key order1", + name: "Key with common key order1", in: []kv.KeyValue{kv12, kv11, kv21}, want: []kv.KeyValue{kv11, kv21}, }, { - name: "NewKey with common key order2", + name: "Key with common key order2", in: []kv.KeyValue{kv11, kv12, kv21}, want: []kv.KeyValue{kv12, kv21}, }, { - name: "NewKey with nil", + name: "Key with nil", in: nil, want: nil, }, diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index f9bbbfa4b4a..70dd374f982 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -43,10 +43,10 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.NewKey("key1").Bool(false), - kv.NewKey("key2").String("hello"), - kv.NewKey("key3").Uint64(123), - kv.NewKey("key4").Float64(123.456), + kv.Key("key1").Bool(false), + kv.Key("key2").String("hello"), + kv.Key("key3").Uint64(123), + kv.Key("key4").Float64(123.456), ) span.End() } @@ -61,14 +61,14 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.NewKey("key1").Bool(false), - kv.NewKey("key2").String("hello"), - kv.NewKey("key3").Uint64(123), - kv.NewKey("key4").Float64(123.456), - kv.NewKey("key21").Bool(false), - kv.NewKey("key22").String("hello"), - kv.NewKey("key23").Uint64(123), - kv.NewKey("key24").Float64(123.456), + kv.Key("key1").Bool(false), + kv.Key("key2").String("hello"), + kv.Key("key3").Uint64(123), + kv.Key("key4").Float64(123.456), + kv.Key("key21").Bool(false), + kv.Key("key22").String("hello"), + kv.Key("key23").Uint64(123), + kv.Key("key24").Float64(123.456), ) span.End() } @@ -83,16 +83,16 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.NewKey("key1").Bool(false), - kv.NewKey("key2").String("hello"), - kv.NewKey("key3").Int64(123), - kv.NewKey("key4").Uint64(123), - kv.NewKey("key5").Int32(123), - kv.NewKey("key6").Uint32(123), - kv.NewKey("key7").Float64(123.456), - kv.NewKey("key8").Float32(123.456), - kv.NewKey("key9").Int(123), - kv.NewKey("key10").Uint(123), + kv.Key("key1").Bool(false), + kv.Key("key2").String("hello"), + kv.Key("key3").Int64(123), + kv.Key("key4").Uint64(123), + kv.Key("key5").Int32(123), + kv.Key("key6").Uint32(123), + kv.Key("key7").Float64(123.456), + kv.Key("key8").Float32(123.456), + kv.Key("key9").Int(123), + kv.Key("key10").Uint(123), ) span.End() } @@ -107,26 +107,26 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) { for i := 0; i < b.N; i++ { _, span := t.Start(ctx, "/foo") span.SetAttributes( - kv.NewKey("key1").Bool(false), - kv.NewKey("key2").String("hello"), - kv.NewKey("key3").Int64(123), - kv.NewKey("key4").Uint64(123), - kv.NewKey("key5").Int32(123), - kv.NewKey("key6").Uint32(123), - kv.NewKey("key7").Float64(123.456), - kv.NewKey("key8").Float32(123.456), - kv.NewKey("key10").Int(123), - kv.NewKey("key11").Uint(123), - kv.NewKey("key21").Bool(false), - kv.NewKey("key22").String("hello"), - kv.NewKey("key23").Int64(123), - kv.NewKey("key24").Uint64(123), - kv.NewKey("key25").Int32(123), - kv.NewKey("key26").Uint32(123), - kv.NewKey("key27").Float64(123.456), - kv.NewKey("key28").Float32(123.456), - kv.NewKey("key210").Int(123), - kv.NewKey("key211").Uint(123), + kv.Key("key1").Bool(false), + kv.Key("key2").String("hello"), + kv.Key("key3").Int64(123), + kv.Key("key4").Uint64(123), + kv.Key("key5").Int32(123), + kv.Key("key6").Uint32(123), + kv.Key("key7").Float64(123.456), + kv.Key("key8").Float32(123.456), + kv.Key("key10").Int(123), + kv.Key("key11").Uint(123), + kv.Key("key21").Bool(false), + kv.Key("key22").String("hello"), + kv.Key("key23").Int64(123), + kv.Key("key24").Uint64(123), + kv.Key("key25").Int32(123), + kv.Key("key26").Uint32(123), + kv.Key("key27").Float64(123.456), + kv.Key("key28").Float32(123.456), + kv.Key("key210").Int(123), + kv.Key("key211").Uint(123), ) span.End() } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 19e7f20a650..a2dc2af547a 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -306,7 +306,7 @@ func TestSetSpanAttributes(t *testing.T) { te := &testExporter{} tp, _ := NewProvider(WithSyncer(te)) span := startSpan(tp, "SpanAttribute") - span.SetAttributes(kv.NewKey("key1").String("value1")) + span.SetAttributes(kv.Key("key1").String("value1")) got, err := endSpan(te, span) if err != nil { t.Fatal(err) @@ -372,11 +372,11 @@ func TestEvents(t *testing.T) { tp, _ := NewProvider(WithSyncer(te)) span := startSpan(tp, "Events") - k1v1 := kv.NewKey("key1").String("value1") + k1v1 := kv.Key("key1").String("value1") k2v2 := kv.Bool("key2", true) k3v3 := kv.Int64("key3", 3) - span.AddEvent(context.Background(), "foo", kv.NewKey("key1").String("value1")) + span.AddEvent(context.Background(), "foo", kv.Key("key1").String("value1")) span.AddEvent(context.Background(), "bar", kv.Bool("key2", true), kv.Int64("key3", 3), @@ -417,19 +417,19 @@ func TestEventsOverLimit(t *testing.T) { tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) span := startSpan(tp, "EventsOverLimit") - k1v1 := kv.NewKey("key1").String("value1") + k1v1 := kv.Key("key1").String("value1") k2v2 := kv.Bool("key2", false) - k3v3 := kv.NewKey("key3").String("value3") + k3v3 := kv.Key("key3").String("value3") - span.AddEvent(context.Background(), "fooDrop", kv.NewKey("key1").String("value1")) + span.AddEvent(context.Background(), "fooDrop", kv.Key("key1").String("value1")) span.AddEvent(context.Background(), "barDrop", kv.Bool("key2", true), - kv.NewKey("key3").String("value3"), + kv.Key("key3").String("value3"), ) - span.AddEvent(context.Background(), "foo", kv.NewKey("key1").String("value1")) + span.AddEvent(context.Background(), "foo", kv.Key("key1").String("value1")) span.AddEvent(context.Background(), "bar", kv.Bool("key2", false), - kv.NewKey("key3").String("value3"), + kv.Key("key3").String("value3"), ) got, err := endSpan(te, span) if err != nil { @@ -466,18 +466,18 @@ func TestLinks(t *testing.T) { te := &testExporter{} tp, _ := NewProvider(WithSyncer(te)) - k1v1 := kv.NewKey("key1").String("value1") - k2v2 := kv.NewKey("key2").String("value2") - k3v3 := kv.NewKey("key3").String("value3") + k1v1 := kv.Key("key1").String("value1") + k2v2 := kv.Key("key2").String("value2") + k3v3 := kv.Key("key3").String("value3") sc1 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} span := startSpan(tp, "Links", - apitrace.LinkedTo(sc1, kv.NewKey("key1").String("value1")), + apitrace.LinkedTo(sc1, kv.Key("key1").String("value1")), apitrace.LinkedTo(sc2, - kv.NewKey("key2").String("value2"), - kv.NewKey("key3").String("value3"), + kv.Key("key2").String("value2"), + kv.Key("key3").String("value3"), ), ) @@ -516,13 +516,13 @@ func TestLinksOverLimit(t *testing.T) { tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) span := startSpan(tp, "LinksOverLimit", - apitrace.LinkedTo(sc1, kv.NewKey("key1").String("value1")), - apitrace.LinkedTo(sc2, kv.NewKey("key2").String("value2")), - apitrace.LinkedTo(sc3, kv.NewKey("key3").String("value3")), + apitrace.LinkedTo(sc1, kv.Key("key1").String("value1")), + apitrace.LinkedTo(sc2, kv.Key("key2").String("value2")), + apitrace.LinkedTo(sc3, kv.Key("key3").String("value3")), ) - k2v2 := kv.NewKey("key2").String("value2") - k3v3 := kv.NewKey("key3").String("value3") + k2v2 := kv.Key("key2").String("value2") + k3v3 := kv.Key("key3").String("value3") got, err := endSpan(te, span) if err != nil {