From 90bb3996cffc7c4a4c3540f38b2382306a41ab61 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 31 Jul 2020 12:49:14 -0700 Subject: [PATCH 1/4] Rename api/standard package to semconv --- {api/standard => semconv}/doc.go | 12 +++++------- {api/standard => semconv}/http.go | 2 +- {api/standard => semconv}/http_test.go | 2 +- {api/standard => semconv}/resource.go | 20 ++++++++++---------- {api/standard => semconv}/trace.go | 20 +++++++++++--------- 5 files changed, 28 insertions(+), 28 deletions(-) rename {api/standard => semconv}/doc.go (51%) rename {api/standard => semconv}/http.go (99%) rename {api/standard => semconv}/http_test.go (99%) rename {api/standard => semconv}/resource.go (90%) rename {api/standard => semconv}/trace.go (95%) diff --git a/api/standard/doc.go b/semconv/doc.go similarity index 51% rename from api/standard/doc.go rename to semconv/doc.go index b20d2f2469b..ec562543a8e 100644 --- a/api/standard/doc.go +++ b/semconv/doc.go @@ -12,11 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package standard contains keys and values that have been standardized for -// use in OpenTelemetry. These standardizations are specified in the -// OpenTelemetry specification: +// Package semconv implements OpenTelemetry semantic conventions. // -// - https://github.com/open-telemetry/opentelemetry-specification/tree/v0.6.0/specification/resource/semantic_conventions -// - https://github.com/open-telemetry/opentelemetry-specification/tree/v0.6.0/specification/trace/semantic_conventions -// - https://github.com/open-telemetry/opentelemetry-specification/tree/v0.6.0/specification/metrics/semantic_conventions -package standard +// OpenTelemetry semantic conventions are agreed standardized naming +// patterns for OpenTelemetry things. This package aims to be the +// centralized place to interact with these conventions. +package semconv // import "go.opentelemetry.io/otel/semconv" diff --git a/api/standard/http.go b/semconv/http.go similarity index 99% rename from api/standard/http.go rename to semconv/http.go index 040d0a19bbb..785581c6234 100644 --- a/api/standard/http.go +++ b/semconv/http.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package standard +package semconv import ( "fmt" diff --git a/api/standard/http_test.go b/semconv/http_test.go similarity index 99% rename from api/standard/http_test.go rename to semconv/http_test.go index 31d384a4643..700ca1db05e 100644 --- a/api/standard/http_test.go +++ b/semconv/http_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package standard +package semconv import ( "crypto/tls" diff --git a/api/standard/resource.go b/semconv/resource.go similarity index 90% rename from api/standard/resource.go rename to semconv/resource.go index 9d12750d532..fc1e11edfbe 100644 --- a/api/standard/resource.go +++ b/semconv/resource.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package standard // import "go.opentelemetry.io/otel/api/standard" +package semconv import "go.opentelemetry.io/otel/api/kv" -// Standard service resource attribute keys. +// Semantic conventions for service resource attribute keys. const ( // Name of the service. ServiceNameKey = kv.Key("service.name") @@ -35,7 +35,7 @@ const ( ServiceVersionKey = kv.Key("service.version") ) -// Standard telemetry SDK resource attribute keys. +// Semantic conventions for telemetry SDK resource attribute keys. const ( // The name of the telemetry SDK. // @@ -56,12 +56,12 @@ const ( TelemetrySDKVersionKey = kv.Key("telemetry.sdk.version") ) -// Standard telemetry SDK resource attributes. +// Semantic conventions for telemetry SDK resource attributes. var ( TelemetrySDKLanguageGo = TelemetrySDKLanguageKey.String("go") ) -// Standard container resource attribute keys. +// Semantic conventions for container resource attribute keys. const ( // A uniquely identifying name for the Container. ContainerNameKey = kv.Key("container.name") @@ -77,7 +77,7 @@ const ( ContainerImageTagKey = kv.Key("container.image.tag") ) -// Standard Function-as-a-Service resource attribute keys. +// Semantic conventions for Function-as-a-Service resource attribute keys. const ( // A uniquely identifying name for the FaaS. FaaSNameKey = kv.Key("faas.name") @@ -92,7 +92,7 @@ const ( FaaSInstanceKey = kv.Key("faas.instance") ) -// Standard operating system process resource attribute keys. +// Semantic conventions for operating system process resource attribute keys. const ( // Process identifier (PID). ProcessPIDKey = kv.Key("process.pid") @@ -120,7 +120,7 @@ const ( ProcessOwnerKey = kv.Key("process.owner") ) -// Standard Kubernetes resource attribute keys. +// Semantic conventions for Kubernetes resource attribute keys. const ( // A uniquely identifying name for the Kubernetes cluster. Kubernetes // does not have cluster names as an internal concept so this may be @@ -138,7 +138,7 @@ const ( K8SDeploymentNameKey = kv.Key("k8s.deployment.name") ) -// Standard host resource attribute keys. +// Semantic conventions for host resource attribute keys. const ( // A uniquely identifying name for the host. HostNameKey = kv.Key("host.name") @@ -162,7 +162,7 @@ const ( HostImageVersionKey = kv.Key("host.image.version") ) -// Standard cloud environment resource attribute keys. +// Semantic conventions for cloud environment resource attribute keys. const ( // Name of the cloud provider. CloudProviderKey = kv.Key("cloud.provider") diff --git a/api/standard/trace.go b/semconv/trace.go similarity index 95% rename from api/standard/trace.go rename to semconv/trace.go index 4c25cd24f8d..991ab9a4397 100644 --- a/api/standard/trace.go +++ b/semconv/trace.go @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package standard +package semconv import "go.opentelemetry.io/otel/api/kv" -// Standard attribute keys used for network related operations. +// Semantic conventions for attribute keys used for network related +// operations. const ( // Transport protocol used. NetTransportKey = kv.Key("net.transport") @@ -57,7 +58,8 @@ const ( PeerServiceKey = kv.Key("peer.service") ) -// Standard attribute keys used to identify an authorized enduser. +// Semantic conventions for attribute keys used to identify an authorized +// user. const ( // Username or the client identifier extracted from the access token or // authorization header in the inbound request from outside the system. @@ -70,7 +72,7 @@ const ( EnduserScopeKey = kv.Key("enduser.scope") ) -// Standard attribute keys for HTTP. +// Semantic conventions for attribute keys for HTTP. const ( // HTTP request method. HTTPMethodKey = kv.Key("http.method") @@ -138,7 +140,7 @@ var ( HTTPFlavorQUIC = HTTPFlavorKey.String("QUIC") ) -// Standard attribute keys for database connections. +// Semantic conventions for attribute keys for database connections. const ( // Identifier for the database system (DBMS) being used. DBSystemKey = kv.Key("db.system") @@ -173,7 +175,7 @@ var ( DBSystemRedis = DBSystemKey.String("redis") // Redis ) -// Standard attribute keys for database calls. +// Semantic conventions for attribute keys for database calls. const ( // Database instance name. DBNameKey = kv.Key("db.name") @@ -200,7 +202,7 @@ const ( DBMongoDBCollectionKey = kv.Key("db.mongodb.collection") ) -// Standard attribute keys for RPC. +// Semantic conventions for attribute keys for RPC. const ( // A string identifying the remoting system. RPCSystemKey = kv.Key("rpc.system") @@ -237,7 +239,7 @@ var ( RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED") ) -// Standard attribute keys for messaging systems. +// Semantic conventions for attribute keys for messaging systems. const ( // A unique identifier describing the messaging system. For example, // kafka, rabbitmq or activemq. @@ -291,7 +293,7 @@ var ( MessagingOperationProcess = MessagingOperationKey.String("process") ) -// Standard attribute keys for FaaS systems. +// Semantic conventions for attribute keys for FaaS systems. const ( // Type of the trigger on which the function is executed. From fdc7889a8e948c5c0ef38a823857ebaa805643d3 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 31 Jul 2020 12:51:46 -0700 Subject: [PATCH 2/4] Update `api/standard` package dependencies to `semconv` --- example/http/client/client.go | 4 +- example/http/server/server.go | 4 +- example/otel-collector/main.go | 4 +- instrumentation/grpctrace/interceptor.go | 22 +-- instrumentation/grpctrace/interceptor_test.go | 144 +++++++++--------- instrumentation/httptrace/clienttrace.go | 6 +- instrumentation/httptrace/httptrace.go | 6 +- instrumentation/httptrace/httptrace_test.go | 26 ++-- instrumentation/othttp/handler.go | 16 +- instrumentation/othttp/handler_test.go | 12 +- instrumentation/othttp/transport.go | 8 +- 11 files changed, 126 insertions(+), 126 deletions(-) diff --git a/example/http/client/client.go b/example/http/client/client.go index 2a4529bb38a..3cb4773cf10 100644 --- a/example/http/client/client.go +++ b/example/http/client/client.go @@ -22,8 +22,8 @@ import ( "log" "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/semconv" "net/http" "time" @@ -83,7 +83,7 @@ func main() { return err }, - trace.WithAttributes(standard.PeerServiceKey.String("ExampleService"))) + trace.WithAttributes(semconv.PeerServiceKey.String("ExampleService"))) if err != nil { panic(err) diff --git a/example/http/server/server.go b/example/http/server/server.go index d3543818881..bacfd32c023 100644 --- a/example/http/server/server.go +++ b/example/http/server/server.go @@ -21,12 +21,12 @@ import ( "go.opentelemetry.io/otel/api/correlation" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/exporters/stdout" "go.opentelemetry.io/otel/instrumentation/httptrace" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/semconv" ) func initTracer() { @@ -41,7 +41,7 @@ func initTracer() { // In a production application, use sdktrace.ProbabilitySampler with a desired probability. tp, err := sdktrace.NewProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithSyncer(exporter), - sdktrace.WithResource(resource.New(standard.ServiceNameKey.String("ExampleService")))) + sdktrace.WithResource(resource.New(semconv.ServiceNameKey.String("ExampleService")))) if err != nil { log.Fatal(err) } diff --git a/example/otel-collector/main.go b/example/otel-collector/main.go index 81b1e724045..23065e5df2c 100644 --- a/example/otel-collector/main.go +++ b/example/otel-collector/main.go @@ -28,13 +28,13 @@ import ( "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" - "go.opentelemetry.io/otel/api/standard" apitrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/exporters/otlp" "go.opentelemetry.io/otel/sdk/metric/controller/push" "go.opentelemetry.io/otel/sdk/metric/selector/simple" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/semconv" ) // Initializes an OTLP exporter, and configures the corresponding trace and @@ -57,7 +57,7 @@ func initProvider() (*otlp.Exporter, *push.Controller) { sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithResource(resource.New( // the service name used to display traces in backends - kv.Key(standard.ServiceNameKey).String("test-service"), + kv.Key(semconv.ServiceNameKey).String("test-service"), )), sdktrace.WithSyncer(exp), ) diff --git a/instrumentation/grpctrace/interceptor.go b/instrumentation/grpctrace/interceptor.go index b35208a65c6..7e6df7fbd01 100644 --- a/instrumentation/grpctrace/interceptor.go +++ b/instrumentation/grpctrace/interceptor.go @@ -22,7 +22,7 @@ import ( "net" "strings" - "go.opentelemetry.io/otel/api/standard" + "go.opentelemetry.io/otel/semconv" "github.com/golang/protobuf/proto" //nolint:staticcheck @@ -45,20 +45,20 @@ func (m messageType) Event(ctx context.Context, id int, message interface{}) { if p, ok := message.(proto.Message); ok { span.AddEvent(ctx, "message", kv.KeyValue(m), - standard.RPCMessageIDKey.Int(id), - standard.RPCMessageUncompressedSizeKey.Int(proto.Size(p)), + semconv.RPCMessageIDKey.Int(id), + semconv.RPCMessageUncompressedSizeKey.Int(proto.Size(p)), ) } else { span.AddEvent(ctx, "message", kv.KeyValue(m), - standard.RPCMessageIDKey.Int(id), + semconv.RPCMessageIDKey.Int(id), ) } } var ( - messageSent = messageType(standard.RPCMessageTypeSent) - messageReceived = messageType(standard.RPCMessageTypeReceived) + messageSent = messageType(semconv.RPCMessageTypeSent) + messageReceived = messageType(semconv.RPCMessageTypeReceived) ) // UnaryClientInterceptor returns a grpc.UnaryClientInterceptor suitable @@ -404,7 +404,7 @@ func StreamServerInterceptor(tracer trace.Tracer, opts ...Option) grpc.StreamSer // spanInfo returns a span name and all appropriate attributes from the gRPC // method and peer address. func spanInfo(fullMethod, peerAddress string) (string, []kv.KeyValue) { - attrs := []kv.KeyValue{standard.RPCSystemGRPC} + attrs := []kv.KeyValue{semconv.RPCSystemGRPC} name, mAttrs := parseFullMethod(fullMethod) attrs = append(attrs, mAttrs...) attrs = append(attrs, peerAttr(peerAddress)...) @@ -423,8 +423,8 @@ func peerAttr(addr string) []kv.KeyValue { } return []kv.KeyValue{ - standard.NetPeerIPKey.String(host), - standard.NetPeerPortKey.String(port), + semconv.NetPeerIPKey.String(host), + semconv.NetPeerPortKey.String(port), } } @@ -450,10 +450,10 @@ func parseFullMethod(fullMethod string) (string, []kv.KeyValue) { var attrs []kv.KeyValue if service := parts[0]; service != "" { - attrs = append(attrs, standard.RPCServiceKey.String(service)) + attrs = append(attrs, semconv.RPCServiceKey.String(service)) } if method := parts[1]; method != "" { - attrs = append(attrs, standard.RPCMethodKey.String(method)) + attrs = append(attrs, semconv.RPCMethodKey.String(method)) } return name, attrs } diff --git a/instrumentation/grpctrace/interceptor_test.go b/instrumentation/grpctrace/interceptor_test.go index d900e926e70..3b5d29fb603 100644 --- a/instrumentation/grpctrace/interceptor_test.go +++ b/instrumentation/grpctrace/interceptor_test.go @@ -19,8 +19,8 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace/testtrace" + "go.opentelemetry.io/otel/semconv" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -105,22 +105,22 @@ func TestUnaryClientInterceptor(t *testing.T) { method: "/github.com.serviceName/bar", name: "github.com.serviceName/bar", expectedAttr: map[kv.Key]kv.Value{ - standard.RPCSystemKey: kv.StringValue("grpc"), - standard.RPCServiceKey: kv.StringValue("github.com.serviceName"), - standard.RPCMethodKey: kv.StringValue("bar"), - standard.NetPeerIPKey: kv.StringValue("fake"), - standard.NetPeerPortKey: kv.StringValue("connection"), + semconv.RPCSystemKey: kv.StringValue("grpc"), + semconv.RPCServiceKey: kv.StringValue("github.com.serviceName"), + semconv.RPCMethodKey: kv.StringValue("bar"), + semconv.NetPeerIPKey: kv.StringValue("fake"), + semconv.NetPeerPortKey: kv.StringValue("connection"), }, eventsAttr: []map[kv.Key]kv.Value{ { - standard.RPCMessageTypeKey: kv.StringValue("SENT"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), + semconv.RPCMessageTypeKey: kv.StringValue("SENT"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), }, { - standard.RPCMessageTypeKey: kv.StringValue("RECEIVED"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), + semconv.RPCMessageTypeKey: kv.StringValue("RECEIVED"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), }, }, }, @@ -128,22 +128,22 @@ func TestUnaryClientInterceptor(t *testing.T) { method: "/serviceName/bar", name: "serviceName/bar", expectedAttr: map[kv.Key]kv.Value{ - standard.RPCSystemKey: kv.StringValue("grpc"), - standard.RPCServiceKey: kv.StringValue("serviceName"), - standard.RPCMethodKey: kv.StringValue("bar"), - standard.NetPeerIPKey: kv.StringValue("fake"), - standard.NetPeerPortKey: kv.StringValue("connection"), + semconv.RPCSystemKey: kv.StringValue("grpc"), + semconv.RPCServiceKey: kv.StringValue("serviceName"), + semconv.RPCMethodKey: kv.StringValue("bar"), + semconv.NetPeerIPKey: kv.StringValue("fake"), + semconv.NetPeerPortKey: kv.StringValue("connection"), }, eventsAttr: []map[kv.Key]kv.Value{ { - standard.RPCMessageTypeKey: kv.StringValue("SENT"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), + semconv.RPCMessageTypeKey: kv.StringValue("SENT"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), }, { - standard.RPCMessageTypeKey: kv.StringValue("RECEIVED"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), + semconv.RPCMessageTypeKey: kv.StringValue("RECEIVED"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), }, }, }, @@ -151,22 +151,22 @@ func TestUnaryClientInterceptor(t *testing.T) { method: "serviceName/bar", name: "serviceName/bar", expectedAttr: map[kv.Key]kv.Value{ - standard.RPCSystemKey: kv.StringValue("grpc"), - standard.RPCServiceKey: kv.StringValue("serviceName"), - standard.RPCMethodKey: kv.StringValue("bar"), - standard.NetPeerIPKey: kv.StringValue("fake"), - standard.NetPeerPortKey: kv.StringValue("connection"), + semconv.RPCSystemKey: kv.StringValue("grpc"), + semconv.RPCServiceKey: kv.StringValue("serviceName"), + semconv.RPCMethodKey: kv.StringValue("bar"), + semconv.NetPeerIPKey: kv.StringValue("fake"), + semconv.NetPeerPortKey: kv.StringValue("connection"), }, eventsAttr: []map[kv.Key]kv.Value{ { - standard.RPCMessageTypeKey: kv.StringValue("SENT"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), + semconv.RPCMessageTypeKey: kv.StringValue("SENT"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), }, { - standard.RPCMessageTypeKey: kv.StringValue("RECEIVED"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), + semconv.RPCMessageTypeKey: kv.StringValue("RECEIVED"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), }, }, }, @@ -174,20 +174,20 @@ func TestUnaryClientInterceptor(t *testing.T) { method: "invalidName", name: "invalidName", expectedAttr: map[kv.Key]kv.Value{ - standard.RPCSystemKey: kv.StringValue("grpc"), - standard.NetPeerIPKey: kv.StringValue("fake"), - standard.NetPeerPortKey: kv.StringValue("connection"), + semconv.RPCSystemKey: kv.StringValue("grpc"), + semconv.NetPeerIPKey: kv.StringValue("fake"), + semconv.NetPeerPortKey: kv.StringValue("connection"), }, eventsAttr: []map[kv.Key]kv.Value{ { - standard.RPCMessageTypeKey: kv.StringValue("SENT"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), + semconv.RPCMessageTypeKey: kv.StringValue("SENT"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), }, { - standard.RPCMessageTypeKey: kv.StringValue("RECEIVED"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), + semconv.RPCMessageTypeKey: kv.StringValue("RECEIVED"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), }, }, }, @@ -195,22 +195,22 @@ func TestUnaryClientInterceptor(t *testing.T) { method: "/github.com.foo.serviceName_123/method", name: "github.com.foo.serviceName_123/method", expectedAttr: map[kv.Key]kv.Value{ - standard.RPCSystemKey: kv.StringValue("grpc"), - standard.RPCServiceKey: kv.StringValue("github.com.foo.serviceName_123"), - standard.RPCMethodKey: kv.StringValue("method"), - standard.NetPeerIPKey: kv.StringValue("fake"), - standard.NetPeerPortKey: kv.StringValue("connection"), + semconv.RPCSystemKey: kv.StringValue("grpc"), + semconv.RPCServiceKey: kv.StringValue("github.com.foo.serviceName_123"), + semconv.RPCMethodKey: kv.StringValue("method"), + semconv.NetPeerIPKey: kv.StringValue("fake"), + semconv.NetPeerPortKey: kv.StringValue("connection"), }, eventsAttr: []map[kv.Key]kv.Value{ { - standard.RPCMessageTypeKey: kv.StringValue("SENT"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), + semconv.RPCMessageTypeKey: kv.StringValue("SENT"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(req))), }, { - standard.RPCMessageTypeKey: kv.StringValue("RECEIVED"), - standard.RPCMessageIDKey: kv.IntValue(1), - standard.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), + semconv.RPCMessageTypeKey: kv.StringValue("RECEIVED"), + semconv.RPCMessageIDKey: kv.IntValue(1), + semconv.RPCMessageUncompressedSizeKey: kv.IntValue(proto.Size(proto.Message(reply))), }, }, }, @@ -309,11 +309,11 @@ func TestStreamClientInterceptor(t *testing.T) { require.True(t, ok, "missing span %s", name) expectedAttr := map[kv.Key]kv.Value{ - standard.RPCSystemKey: kv.StringValue("grpc"), - standard.RPCServiceKey: kv.StringValue("github.com.serviceName"), - standard.RPCMethodKey: kv.StringValue("bar"), - standard.NetPeerIPKey: kv.StringValue("fake"), - standard.NetPeerPortKey: kv.StringValue("connection"), + semconv.RPCSystemKey: kv.StringValue("grpc"), + semconv.RPCServiceKey: kv.StringValue("github.com.serviceName"), + semconv.RPCMethodKey: kv.StringValue("bar"), + semconv.NetPeerIPKey: kv.StringValue("fake"), + semconv.NetPeerPortKey: kv.StringValue("connection"), } assert.Equal(t, expectedAttr, span.Attributes()) @@ -323,10 +323,10 @@ func TestStreamClientInterceptor(t *testing.T) { msgID := i/2 + 1 validate := func(eventName string, attrs map[kv.Key]kv.Value) { for k, v := range attrs { - if k == standard.RPCMessageTypeKey && v.AsString() != eventName { + if k == semconv.RPCMessageTypeKey && v.AsString() != eventName { t.Errorf("invalid event on index: %d expecting %s event, receive %s event", i, eventName, v.AsString()) } - if k == standard.RPCMessageIDKey && v != kv.IntValue(msgID) { + if k == semconv.RPCMessageIDKey && v != kv.IntValue(msgID) { t.Errorf("invalid id for message event expected %d received %d", msgID, v.AsInt32()) } } @@ -376,36 +376,36 @@ func TestParseFullMethod(t *testing.T) { fullMethod: "/grpc.test.EchoService/Echo", name: "grpc.test.EchoService/Echo", attr: []kv.KeyValue{ - standard.RPCServiceKey.String("grpc.test.EchoService"), - standard.RPCMethodKey.String("Echo"), + semconv.RPCServiceKey.String("grpc.test.EchoService"), + semconv.RPCMethodKey.String("Echo"), }, }, { fullMethod: "/com.example.ExampleRmiService/exampleMethod", name: "com.example.ExampleRmiService/exampleMethod", attr: []kv.KeyValue{ - standard.RPCServiceKey.String("com.example.ExampleRmiService"), - standard.RPCMethodKey.String("exampleMethod"), + semconv.RPCServiceKey.String("com.example.ExampleRmiService"), + semconv.RPCMethodKey.String("exampleMethod"), }, }, { fullMethod: "/MyCalcService.Calculator/Add", name: "MyCalcService.Calculator/Add", attr: []kv.KeyValue{ - standard.RPCServiceKey.String("MyCalcService.Calculator"), - standard.RPCMethodKey.String("Add"), + semconv.RPCServiceKey.String("MyCalcService.Calculator"), + semconv.RPCMethodKey.String("Add"), }, }, { fullMethod: "/MyServiceReference.ICalculator/Add", name: "MyServiceReference.ICalculator/Add", attr: []kv.KeyValue{ - standard.RPCServiceKey.String("MyServiceReference.ICalculator"), - standard.RPCMethodKey.String("Add"), + semconv.RPCServiceKey.String("MyServiceReference.ICalculator"), + semconv.RPCMethodKey.String("Add"), }, }, { fullMethod: "/MyServiceWithNoPackage/theMethod", name: "MyServiceWithNoPackage/theMethod", attr: []kv.KeyValue{ - standard.RPCServiceKey.String("MyServiceWithNoPackage"), - standard.RPCMethodKey.String("theMethod"), + semconv.RPCServiceKey.String("MyServiceWithNoPackage"), + semconv.RPCMethodKey.String("theMethod"), }, }, { fullMethod: "/pkg.srv", @@ -415,7 +415,7 @@ func TestParseFullMethod(t *testing.T) { fullMethod: "/pkg.srv/", name: "pkg.srv/", attr: []kv.KeyValue{ - standard.RPCServiceKey.String("pkg.srv"), + semconv.RPCServiceKey.String("pkg.srv"), }, }, } diff --git a/instrumentation/httptrace/clienttrace.go b/instrumentation/httptrace/clienttrace.go index 454a3c0b1b7..e77e77c762b 100644 --- a/instrumentation/httptrace/clienttrace.go +++ b/instrumentation/httptrace/clienttrace.go @@ -22,7 +22,7 @@ import ( "strings" "sync" - "go.opentelemetry.io/otel/api/standard" + "go.opentelemetry.io/otel/semconv" "google.golang.org/grpc/codes" @@ -152,7 +152,7 @@ func (ct *clientTracer) span(hook string) trace.Span { } func (ct *clientTracer) getConn(host string) { - ct.start("http.getconn", "http.getconn", standard.HTTPHostKey.String(host)) + ct.start("http.getconn", "http.getconn", semconv.HTTPHostKey.String(host)) } func (ct *clientTracer) gotConn(info httptrace.GotConnInfo) { @@ -172,7 +172,7 @@ func (ct *clientTracer) gotFirstResponseByte() { } func (ct *clientTracer) dnsStart(info httptrace.DNSStartInfo) { - ct.start("http.dns", "http.dns", standard.HTTPHostKey.String(info.Host)) + ct.start("http.dns", "http.dns", semconv.HTTPHostKey.String(info.Host)) } func (ct *clientTracer) dnsDone(info httptrace.DNSDoneInfo) { diff --git a/instrumentation/httptrace/httptrace.go b/instrumentation/httptrace/httptrace.go index 4f382217dc6..ccea090ef86 100644 --- a/instrumentation/httptrace/httptrace.go +++ b/instrumentation/httptrace/httptrace.go @@ -22,8 +22,8 @@ import ( "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/propagation" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/semconv" ) // Option is a function that allows configuration of the httptrace Extract() @@ -55,8 +55,8 @@ func Extract(ctx context.Context, req *http.Request, opts ...Option) ([]kv.KeyVa ctx = propagation.ExtractHTTP(ctx, c.propagators, req.Header) attrs := append( - standard.HTTPServerAttributesFromHTTPRequest("", "", req), - standard.NetAttributesFromHTTPRequest("tcp", req)..., + semconv.HTTPServerAttributesFromHTTPRequest("", "", req), + semconv.NetAttributesFromHTTPRequest("tcp", req)..., ) var correlationCtxKVs []kv.KeyValue diff --git a/instrumentation/httptrace/httptrace_test.go b/instrumentation/httptrace/httptrace_test.go index 06aa9782d2f..3b704b0baee 100644 --- a/instrumentation/httptrace/httptrace_test.go +++ b/instrumentation/httptrace/httptrace_test.go @@ -26,9 +26,9 @@ import ( "go.opentelemetry.io/otel/api/correlation" "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/propagation" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace/testtrace" "go.opentelemetry.io/otel/instrumentation/httptrace" + "go.opentelemetry.io/otel/semconv" ) func TestRoundtrip(t *testing.T) { @@ -44,7 +44,7 @@ func TestRoundtrip(t *testing.T) { actualAttrs := make(map[kv.Key]string) for _, attr := range attrs { - if attr.Key == standard.NetPeerPortKey { + if attr.Key == semconv.NetPeerPortKey { // Peer port will be non-deterministic continue } @@ -79,17 +79,17 @@ func TestRoundtrip(t *testing.T) { address := ts.Listener.Addr() hp := strings.Split(address.String(), ":") expectedAttrs = map[kv.Key]string{ - standard.HTTPFlavorKey: "1.1", - standard.HTTPHostKey: address.String(), - standard.HTTPMethodKey: "GET", - standard.HTTPSchemeKey: "http", - standard.HTTPTargetKey: "/", - standard.HTTPUserAgentKey: "Go-http-client/1.1", - standard.HTTPRequestContentLengthKey: "3", - standard.NetHostIPKey: hp[0], - standard.NetHostPortKey: hp[1], - standard.NetPeerIPKey: "127.0.0.1", - standard.NetTransportKey: "IP.TCP", + semconv.HTTPFlavorKey: "1.1", + semconv.HTTPHostKey: address.String(), + semconv.HTTPMethodKey: "GET", + semconv.HTTPSchemeKey: "http", + semconv.HTTPTargetKey: "/", + semconv.HTTPUserAgentKey: "Go-http-client/1.1", + semconv.HTTPRequestContentLengthKey: "3", + semconv.NetHostIPKey: hp[0], + semconv.NetHostPortKey: hp[1], + semconv.NetPeerIPKey: "127.0.0.1", + semconv.NetTransportKey: "IP.TCP", } client := ts.Client() diff --git a/instrumentation/othttp/handler.go b/instrumentation/othttp/handler.go index 87463f3d064..20471ffd791 100644 --- a/instrumentation/othttp/handler.go +++ b/instrumentation/othttp/handler.go @@ -25,8 +25,8 @@ import ( "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/propagation" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/semconv" ) var _ http.Handler = &Handler{} @@ -127,9 +127,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } opts := append([]trace.StartOption{ - trace.WithAttributes(standard.NetAttributesFromHTTPRequest("tcp", r)...), - trace.WithAttributes(standard.EndUserAttributesFromHTTPRequest(r)...), - trace.WithAttributes(standard.HTTPServerAttributesFromHTTPRequest(h.operation, "", r)...), + trace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...), + trace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...), + trace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(h.operation, "", r)...), }, h.spanStartOptions...) // start with the configured options ctx := propagation.ExtractHTTP(r.Context(), h.propagators, r.Header) @@ -176,7 +176,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Add request metrics - labels := standard.HTTPServerMetricAttributesFromHTTPRequest(h.operation, r) + labels := semconv.HTTPServerMetricAttributesFromHTTPRequest(h.operation, r) h.counters[RequestContentLength].Add(ctx, bw.read, labels...) h.counters[ResponseContentLength].Add(ctx, rww.written, labels...) @@ -201,8 +201,8 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, kv = append(kv, WroteBytesKey.Int64(wrote)) } if statusCode > 0 { - kv = append(kv, standard.HTTPAttributesFromHTTPStatusCode(statusCode)...) - span.SetStatus(standard.SpanStatusFromHTTPStatusCode(statusCode)) + kv = append(kv, semconv.HTTPAttributesFromHTTPStatusCode(statusCode)...) + span.SetStatus(semconv.SpanStatusFromHTTPStatusCode(statusCode)) } if werr != nil && werr != io.EOF { kv = append(kv, WriteErrorKey.String(werr.Error())) @@ -215,7 +215,7 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, func WithRouteTag(route string, h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { span := trace.SpanFromContext(r.Context()) - span.SetAttributes(standard.HTTPRouteKey.String(route)) + span.SetAttributes(semconv.HTTPRouteKey.String(route)) h.ServeHTTP(w, r) }) } diff --git a/instrumentation/othttp/handler_test.go b/instrumentation/othttp/handler_test.go index 89d0f111c44..3d98481c29a 100644 --- a/instrumentation/othttp/handler_test.go +++ b/instrumentation/othttp/handler_test.go @@ -26,10 +26,10 @@ import ( "google.golang.org/grpc/codes" "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace" mockmeter "go.opentelemetry.io/otel/internal/metric" mocktrace "go.opentelemetry.io/otel/internal/trace" + "go.opentelemetry.io/otel/semconv" ) func assertMetricLabels(t *testing.T, expectedLabels []kv.KeyValue, measurementBatches []mockmeter.Batch) { @@ -68,11 +68,11 @@ func TestHandlerBasics(t *testing.T) { } labelsToVerify := []kv.KeyValue{ - standard.HTTPServerNameKey.String(operation), - standard.HTTPSchemeHTTP, - standard.HTTPHostKey.String(r.Host), - standard.HTTPFlavorKey.String(fmt.Sprintf("1.%d", r.ProtoMinor)), - standard.HTTPRequestContentLengthKey.Int64(3), + semconv.HTTPServerNameKey.String(operation), + semconv.HTTPSchemeHTTP, + semconv.HTTPHostKey.String(r.Host), + semconv.HTTPFlavorKey.String(fmt.Sprintf("1.%d", r.ProtoMinor)), + semconv.HTTPRequestContentLengthKey.Int64(3), } assertMetricLabels(t, labelsToVerify, meterimpl.MeasurementBatches) diff --git a/instrumentation/othttp/transport.go b/instrumentation/othttp/transport.go index e61e3a42ca8..aa619ea62a5 100644 --- a/instrumentation/othttp/transport.go +++ b/instrumentation/othttp/transport.go @@ -21,8 +21,8 @@ import ( "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/propagation" - "go.opentelemetry.io/otel/api/standard" "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/semconv" "google.golang.org/grpc/codes" ) @@ -89,7 +89,7 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) { ctx, span := t.tracer.Start(r.Context(), t.spanNameFormatter("", r), opts...) r = r.WithContext(ctx) - span.SetAttributes(standard.HTTPClientAttributesFromHTTPRequest(r)...) + span.SetAttributes(semconv.HTTPClientAttributesFromHTTPRequest(r)...) propagation.InjectHTTP(ctx, t.propagators, r.Header) res, err := t.rt.RoundTrip(r) @@ -99,8 +99,8 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) { return res, err } - span.SetAttributes(standard.HTTPAttributesFromHTTPStatusCode(res.StatusCode)...) - span.SetStatus(standard.SpanStatusFromHTTPStatusCode(res.StatusCode)) + span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(res.StatusCode)...) + span.SetStatus(semconv.SpanStatusFromHTTPStatusCode(res.StatusCode)) res.Body = &wrappedBody{ctx: ctx, span: span, body: res.Body} return res, err From 77be5cde2ffcf74e4bd0c7956f772e5270f8b1a7 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 31 Jul 2020 12:54:32 -0700 Subject: [PATCH 3/4] Update Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70259acbd91..fae9d068d91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Changed + +- Renamed `go.opentelemetry.io/otel/api/standard` package to `go.opentelemetry.io/otel/semconv` to avoid the ambiguous and generic name `standard` and better describe the package as containing OpenTelemetry semantic conventions. + ## [0.10.0] - 2020-07-29 This release migrates the default OpenTelemetry SDK into its own Go module, decoupling the SDK from the API and reducing dependencies for instrumentation packages. From bf5c5d169aa07cac739d229cb6b59fe68ccb525b Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 31 Jul 2020 12:55:45 -0700 Subject: [PATCH 4/4] Add PR number to Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fae9d068d91..2316885b77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed -- Renamed `go.opentelemetry.io/otel/api/standard` package to `go.opentelemetry.io/otel/semconv` to avoid the ambiguous and generic name `standard` and better describe the package as containing OpenTelemetry semantic conventions. +- Renamed `go.opentelemetry.io/otel/api/standard` package to `go.opentelemetry.io/otel/semconv` to avoid the ambiguous and generic name `standard` and better describe the package as containing OpenTelemetry semantic conventions. (#1016) ## [0.10.0] - 2020-07-29