You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	Increase the visibility of the api/key package (#650)
				
					
				
			* Point to the convenience functions in api/key package This is to increase the visibility of the api/key package through the api/core package, otherwise developers often tend to miss the api/key package altogether and write `core.Key(name).TYPE(value)` and complain at the verbosity of such a construction. The api/key package would allow them to write `key.TYPE(name, value)`. * Use the api/key package where applicable This transforms all the uses of `core.Key(name).TYPE(value)` to `key.TYPE(name, value)`. This also should help increasing the visibility of the api/key package for developers reading the otel-go code. Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
This commit is contained in:
		| @@ -21,6 +21,7 @@ import ( | ||||
| 	"github.com/stretchr/testify/assert" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/api/core" | ||||
| 	"go.opentelemetry.io/otel/api/key" | ||||
| ) | ||||
|  | ||||
| func TestAttributes(t *testing.T) { | ||||
| @@ -31,16 +32,16 @@ func TestAttributes(t *testing.T) { | ||||
| 		{nil, nil}, | ||||
| 		{ | ||||
| 			[]core.KeyValue{ | ||||
| 				core.Key("int to int").Int(123), | ||||
| 				core.Key("uint to int").Uint(1234), | ||||
| 				core.Key("int32 to int").Int32(12345), | ||||
| 				core.Key("uint32 to int").Uint32(123456), | ||||
| 				core.Key("int64 to int64").Int64(1234567), | ||||
| 				core.Key("uint64 to int64").Uint64(12345678), | ||||
| 				core.Key("float32 to double").Float32(3.14), | ||||
| 				core.Key("float64 to double").Float32(1.61), | ||||
| 				core.Key("string to string").String("string"), | ||||
| 				core.Key("bool to bool").Bool(true), | ||||
| 				key.Int("int to int", 123), | ||||
| 				key.Uint("uint to int", 1234), | ||||
| 				key.Int32("int32 to int", 12345), | ||||
| 				key.Uint32("uint32 to int", 123456), | ||||
| 				key.Int64("int64 to int64", 1234567), | ||||
| 				key.Uint64("uint64 to int64", 12345678), | ||||
| 				key.Float32("float32 to double", 3.14), | ||||
| 				key.Float32("float64 to double", 1.61), | ||||
| 				key.String("string to string", "string"), | ||||
| 				key.Bool("bool to bool", true), | ||||
| 			}, | ||||
| 			[]*commonpb.AttributeKeyValue{ | ||||
| 				{ | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import ( | ||||
| 	"github.com/stretchr/testify/assert" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/api/core" | ||||
| 	"go.opentelemetry.io/otel/api/key" | ||||
| 	"go.opentelemetry.io/otel/api/metric" | ||||
| 	"go.opentelemetry.io/otel/api/unit" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| @@ -47,16 +48,16 @@ func TestStringKeyValues(t *testing.T) { | ||||
| 		}, | ||||
| 		{ | ||||
| 			[]core.KeyValue{ | ||||
| 				core.Key("true").Bool(true), | ||||
| 				core.Key("one").Int64(1), | ||||
| 				core.Key("two").Uint64(2), | ||||
| 				core.Key("three").Float64(3), | ||||
| 				core.Key("four").Int32(4), | ||||
| 				core.Key("five").Uint32(5), | ||||
| 				core.Key("six").Float32(6), | ||||
| 				core.Key("seven").Int(7), | ||||
| 				core.Key("eight").Uint(8), | ||||
| 				core.Key("the").String("final word"), | ||||
| 				key.Bool("true", true), | ||||
| 				key.Int64("one", 1), | ||||
| 				key.Uint64("two", 2), | ||||
| 				key.Float64("three", 3), | ||||
| 				key.Int32("four", 4), | ||||
| 				key.Uint32("five", 5), | ||||
| 				key.Float32("six", 6), | ||||
| 				key.Int("seven", 7), | ||||
| 				key.Uint("eight", 8), | ||||
| 				key.String("the", "final word"), | ||||
| 			}, | ||||
| 			[]*commonpb.StringKeyValue{ | ||||
| 				{Key: "true", Value: "true"}, | ||||
| @@ -130,7 +131,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) { | ||||
| 			"test-b-description", | ||||
| 			unit.Bytes, | ||||
| 			core.Float64NumberKind, // This shouldn't change anything. | ||||
| 			[]core.KeyValue{core.Key("A").String("1")}, | ||||
| 			[]core.KeyValue{key.String("A", "1")}, | ||||
| 			&metricpb.MetricDescriptor{ | ||||
| 				Name:        "mmsc-test-b", | ||||
| 				Description: "test-b-description", | ||||
| @@ -232,7 +233,7 @@ func TestSumMetricDescriptor(t *testing.T) { | ||||
| 			"test-b-description", | ||||
| 			unit.Milliseconds, | ||||
| 			core.Float64NumberKind, | ||||
| 			[]core.KeyValue{core.Key("A").String("1")}, | ||||
| 			[]core.KeyValue{key.String("A", "1")}, | ||||
| 			&metricpb.MetricDescriptor{ | ||||
| 				Name:        "sum-test-b", | ||||
| 				Description: "test-b-description", | ||||
|   | ||||
| @@ -20,6 +20,7 @@ import ( | ||||
| 	"github.com/stretchr/testify/assert" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/api/core" | ||||
| 	"go.opentelemetry.io/otel/api/key" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| ) | ||||
|  | ||||
| @@ -38,7 +39,7 @@ func TestEmptyResource(t *testing.T) { | ||||
|  */ | ||||
|  | ||||
| func TestResourceAttributes(t *testing.T) { | ||||
| 	attrs := []core.KeyValue{core.Key("one").Int(1), core.Key("two").Int(2)} | ||||
| 	attrs := []core.KeyValue{key.Int("one", 1), key.Int("two", 2)} | ||||
|  | ||||
| 	got := Resource(resource.New(attrs...)).GetAttributes() | ||||
| 	if !assert.Len(t, attrs, 2) { | ||||
|   | ||||
| @@ -26,6 +26,7 @@ import ( | ||||
| 	"google.golang.org/grpc/codes" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/api/core" | ||||
| 	"go.opentelemetry.io/otel/api/key" | ||||
| 	apitrace "go.opentelemetry.io/otel/api/trace" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| @@ -74,7 +75,7 @@ func TestEmptySpanEvent(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestSpanEvent(t *testing.T) { | ||||
| 	attrs := []core.KeyValue{core.Key("one").Int(1), core.Key("two").Int(2)} | ||||
| 	attrs := []core.KeyValue{key.Int("one", 1), key.Int("two", 2)} | ||||
| 	now := time.Now() | ||||
| 	got := spanEvents([]export.Event{ | ||||
| 		{ | ||||
| @@ -118,7 +119,7 @@ func TestEmptyLinks(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestLinks(t *testing.T) { | ||||
| 	attrs := []core.KeyValue{core.Key("one").Int(1), core.Key("two").Int(2)} | ||||
| 	attrs := []core.KeyValue{key.Int("one", 1), key.Int("two", 2)} | ||||
| 	l := []apitrace.Link{ | ||||
| 		{}, | ||||
| 		{ | ||||
| @@ -281,12 +282,12 @@ func TestSpanData(t *testing.T) { | ||||
| 		MessageEvents: []export.Event{ | ||||
| 			{Time: startTime, | ||||
| 				Attributes: []core.KeyValue{ | ||||
| 					core.Key("CompressedByteSize").Uint64(512), | ||||
| 					key.Uint64("CompressedByteSize", 512), | ||||
| 				}, | ||||
| 			}, | ||||
| 			{Time: endTime, | ||||
| 				Attributes: []core.KeyValue{ | ||||
| 					core.Key("MessageEventType").String("Recv"), | ||||
| 					key.String("MessageEventType", "Recv"), | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -298,7 +299,7 @@ func TestSpanData(t *testing.T) { | ||||
| 					TraceFlags: 0, | ||||
| 				}, | ||||
| 				Attributes: []core.KeyValue{ | ||||
| 					core.Key("LinkType").String("Parent"), | ||||
| 					key.String("LinkType", "Parent"), | ||||
| 				}, | ||||
| 			}, | ||||
| 			{ | ||||
| @@ -308,7 +309,7 @@ func TestSpanData(t *testing.T) { | ||||
| 					TraceFlags: 0, | ||||
| 				}, | ||||
| 				Attributes: []core.KeyValue{ | ||||
| 					core.Key("LinkType").String("Child"), | ||||
| 					key.String("LinkType", "Child"), | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -316,12 +317,12 @@ func TestSpanData(t *testing.T) { | ||||
| 		StatusMessage:   "utterly unrecognized", | ||||
| 		HasRemoteParent: true, | ||||
| 		Attributes: []core.KeyValue{ | ||||
| 			core.Key("timeout_ns").Int64(12e9), | ||||
| 			key.Int64("timeout_ns", 12e9), | ||||
| 		}, | ||||
| 		DroppedAttributeCount:    1, | ||||
| 		DroppedMessageEventCount: 2, | ||||
| 		DroppedLinkCount:         3, | ||||
| 		Resource:                 resource.New(core.Key("rk1").String("rv1"), core.Key("rk2").Int64(5)), | ||||
| 		Resource:                 resource.New(key.String("rk1", "rv1"), key.Int64("rk2", 5)), | ||||
| 	} | ||||
|  | ||||
| 	// Not checking resource as the underlying map of our Resource makes | ||||
|   | ||||
| @@ -88,13 +88,13 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) | ||||
| 		), | ||||
| 	} | ||||
| 	tp1, err := sdktrace.NewProvider(append(pOpts, | ||||
| 		sdktrace.WithResourceAttributes(core.Key("rk1").String("rv11)"), | ||||
| 			core.Key("rk2").Int64(5)))...) | ||||
| 		sdktrace.WithResourceAttributes(key.String("rk1", "rv11)"), | ||||
| 			key.Int64("rk2", 5)))...) | ||||
| 	assert.NoError(t, err) | ||||
|  | ||||
| 	tp2, err := sdktrace.NewProvider(append(pOpts, | ||||
| 		sdktrace.WithResourceAttributes(core.Key("rk1").String("rv12)"), | ||||
| 			core.Key("rk3").Float32(6.5)))...) | ||||
| 		sdktrace.WithResourceAttributes(key.String("rk1", "rv12)"), | ||||
| 			key.Float32("rk3", 6.5)))...) | ||||
| 	assert.NoError(t, err) | ||||
|  | ||||
| 	tr1 := tp1.Tracer("test-tracer1") | ||||
| @@ -103,11 +103,11 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) | ||||
| 	m := 4 | ||||
| 	for i := 0; i < m; i++ { | ||||
| 		_, span := tr1.Start(context.Background(), "AlwaysSample") | ||||
| 		span.SetAttributes(core.Key("i").Int64(int64(i))) | ||||
| 		span.SetAttributes(key.Int64("i", int64(i))) | ||||
| 		span.End() | ||||
|  | ||||
| 		_, span = tr2.Start(context.Background(), "AlwaysSample") | ||||
| 		span.SetAttributes(core.Key("i").Int64(int64(i))) | ||||
| 		span.SetAttributes(key.Int64("i", int64(i))) | ||||
| 		span.End() | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -28,6 +28,7 @@ import ( | ||||
| 	"google.golang.org/grpc/codes" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/api/core" | ||||
| 	"go.opentelemetry.io/otel/api/key" | ||||
| 	apitrace "go.opentelemetry.io/otel/api/trace" | ||||
| 	tracesdk "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| @@ -90,12 +91,12 @@ func TestExportSpans(t *testing.T) { | ||||
| 					StartTime: startTime, | ||||
| 					EndTime:   endTime, | ||||
| 					Attributes: []core.KeyValue{ | ||||
| 						core.Key("user").String("alice"), | ||||
| 						core.Key("authenticated").Bool(true), | ||||
| 						key.String("user", "alice"), | ||||
| 						key.Bool("authenticated", true), | ||||
| 					}, | ||||
| 					StatusCode:    codes.OK, | ||||
| 					StatusMessage: "Ok", | ||||
| 					Resource:      resource.New(core.Key("instance").String("tester-a")), | ||||
| 					Resource:      resource.New(key.String("instance", "tester-a")), | ||||
| 				}, | ||||
| 				{ | ||||
| 					SpanContext: core.SpanContext{ | ||||
| @@ -109,12 +110,12 @@ func TestExportSpans(t *testing.T) { | ||||
| 					StartTime:    startTime, | ||||
| 					EndTime:      endTime, | ||||
| 					Attributes: []core.KeyValue{ | ||||
| 						core.Key("user").String("alice"), | ||||
| 						core.Key("authenticated").Bool(true), | ||||
| 						key.String("user", "alice"), | ||||
| 						key.Bool("authenticated", true), | ||||
| 					}, | ||||
| 					StatusCode:    codes.OK, | ||||
| 					StatusMessage: "Ok", | ||||
| 					Resource:      resource.New(core.Key("instance").String("tester-a")), | ||||
| 					Resource:      resource.New(key.String("instance", "tester-a")), | ||||
| 				}, | ||||
| 				{ | ||||
| 					SpanContext: core.SpanContext{ | ||||
| @@ -127,12 +128,12 @@ func TestExportSpans(t *testing.T) { | ||||
| 					StartTime: startTime, | ||||
| 					EndTime:   endTime, | ||||
| 					Attributes: []core.KeyValue{ | ||||
| 						core.Key("user").String("bob"), | ||||
| 						core.Key("authenticated").Bool(false), | ||||
| 						key.String("user", "bob"), | ||||
| 						key.Bool("authenticated", false), | ||||
| 					}, | ||||
| 					StatusCode:    codes.Unauthenticated, | ||||
| 					StatusMessage: "Unauthenticated", | ||||
| 					Resource:      resource.New(core.Key("instance").String("tester-b")), | ||||
| 					Resource:      resource.New(key.String("instance", "tester-b")), | ||||
| 				}, | ||||
| 			}, | ||||
| 			[]tracepb.ResourceSpans{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user