diff --git a/CHANGELOG.md b/CHANGELOG.md index dd0fab0c105..0b92503eda5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed +- Rename the `Typ` field of `"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc".InterceptorInfo` to `Type`. (#2688) - Use Go 1.19 as the default version for CI testing/linting. (#2675) ## [1.9.0/0.34.0/0.4.0] - 2022-08-02 diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters.go b/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters.go index 90290234f5d..61dc9420da0 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters.go @@ -32,7 +32,7 @@ type gRPCPath struct { // If name is not FullMethod, returned gRPCPath has empty service field. func splitFullMethod(i *otelgrpc.InterceptorInfo) gRPCPath { var name string - switch i.Typ { + switch i.Type { case otelgrpc.UnaryServer: name = i.UnaryServerInfo.FullMethod case otelgrpc.StreamServer: @@ -118,7 +118,7 @@ func MethodPrefix(pre string) otelgrpc.Filter { func FullMethodName(n string) otelgrpc.Filter { return func(i *otelgrpc.InterceptorInfo) bool { var fm string - switch i.Typ { + switch i.Type { case otelgrpc.UnaryClient, otelgrpc.StreamClient: fm = i.Method case otelgrpc.UnaryServer: diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters_test.go index 0d07bf64263..5ba88c56fd4 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/filters/filters_test.go @@ -46,31 +46,31 @@ func TestMethodName(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: MethodName("Hello"), want: true, }, { name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, f: MethodName("Hello"), want: true, }, { name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, f: MethodName("Hello"), want: true, }, { name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, f: MethodName("Hello"), want: true, }, { name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: MethodName("Goodbye"), want: false, }, @@ -89,31 +89,31 @@ func TestMethodPrefix(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: MethodPrefix("Foobar"), want: true, }, { name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, f: MethodPrefix("Foobar"), want: true, }, { name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, f: MethodPrefix("Foobar"), want: true, }, { name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, f: MethodPrefix("Foobar"), want: true, }, { name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: MethodPrefix("Barfoo"), want: false, }, @@ -131,31 +131,31 @@ func TestFullMethodName(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: FullMethodName(dummyFullMethodName), want: true, }, { name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, f: FullMethodName(dummyFullMethodName), want: true, }, { name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, f: FullMethodName(dummyFullMethodName), want: true, }, { name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, f: FullMethodName(dummyFullMethodName), want: true, }, { name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: FullMethodName("/example.HelloService/Goodbye"), want: false, }, @@ -175,31 +175,31 @@ func TestServiceName(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: ServiceName("example.HelloService"), want: true, }, { name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, f: ServiceName("example.HelloService"), want: true, }, { name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, f: ServiceName("example.HelloService"), want: true, }, { name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, f: ServiceName("example.HelloService"), want: true, }, { name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: ServiceName("opentelemetry.HelloService"), want: false, }, @@ -218,31 +218,31 @@ func TestServicePrefix(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: ServicePrefix("example"), want: true, }, { name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, f: ServicePrefix("example"), want: true, }, { name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, f: ServicePrefix("example"), want: true, }, { name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, f: ServicePrefix("example"), want: true, }, { name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: ServicePrefix("opentelemetry"), want: false, }, @@ -260,19 +260,19 @@ func TestAny(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor true && true", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: Any(MethodName("FoobarHello"), MethodPrefix("Foobar")), want: true, }, { name: "unary client interceptor false && true", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: Any(MethodName("Hello"), MethodPrefix("Foobar")), want: true, }, { name: "unary client interceptor false && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: Any(MethodName("Goodbye"), MethodPrefix("Barfoo")), want: false, }, @@ -290,19 +290,19 @@ func TestAll(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor true && true", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: All(MethodName("FoobarHello"), MethodPrefix("Foobar")), want: true, }, { name: "unary client interceptor true && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: All(MethodName("FoobarHello"), MethodPrefix("Barfoo")), want: false, }, { name: "unary client interceptor false && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: All(MethodName("FoobarGoodbye"), MethodPrefix("Barfoo")), want: false, }, @@ -320,19 +320,19 @@ func TestNone(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor true && true", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: None(MethodName("FoobarHello"), MethodPrefix("Foobar")), want: false, }, { name: "unary client interceptor true && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: None(MethodName("FoobarHello"), MethodPrefix("Barfoo")), want: false, }, { name: "unary client interceptor false && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: None(MethodName("FoobarGoodbye"), MethodPrefix("Barfoo")), want: true, }, @@ -350,19 +350,19 @@ func TestNot(t *testing.T) { tcs := []testCase{ { name: "methodname not", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: Not(MethodName("FoobarHello")), want: false, }, { name: "method prefix not", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, f: Not(MethodPrefix("FoobarHello")), want: false, }, { name: "unary client interceptor not all(true && true)", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, f: Not(All(MethodName("FoobarHello"), MethodPrefix("Foobar"))), want: false, }, @@ -384,49 +384,49 @@ func TestHealthCheck(t *testing.T) { tcs := []testCase{ { name: "unary client interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{Method: healthCheck, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: healthCheck, Type: otelgrpc.UnaryClient}, f: HealthCheck(), want: true, }, { name: "stream client interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{Method: healthCheck, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: healthCheck, Type: otelgrpc.StreamClient}, f: HealthCheck(), want: true, }, { name: "unary server interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(healthCheck), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(healthCheck), Type: otelgrpc.UnaryServer}, f: HealthCheck(), want: true, }, { name: "stream server interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(healthCheck), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(healthCheck), Type: otelgrpc.StreamServer}, f: HealthCheck(), want: true, }, { name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Typ: otelgrpc.UnaryClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Type: otelgrpc.UnaryClient}, f: HealthCheck(), want: false, }, { name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Typ: otelgrpc.StreamClient}, + i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Type: otelgrpc.StreamClient}, f: HealthCheck(), want: false, }, { name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethod), Typ: otelgrpc.UnaryServer}, + i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethod), Type: otelgrpc.UnaryServer}, f: HealthCheck(), want: false, }, { name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethod), Typ: otelgrpc.StreamServer}, + i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethod), Type: otelgrpc.StreamServer}, f: HealthCheck(), want: false, }, diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go index a3d2b77226f..26343dfc16e 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go @@ -76,7 +76,7 @@ func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor { ) error { i := &InterceptorInfo{ Method: method, - Typ: UnaryClient, + Type: UnaryClient, } if cfg.Filter != nil && !cfg.Filter(i) { return invoker(ctx, method, req, reply, cc, callOpts...) @@ -255,7 +255,7 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { ) (grpc.ClientStream, error) { i := &InterceptorInfo{ Method: method, - Typ: StreamClient, + Type: StreamClient, } if cfg.Filter != nil && !cfg.Filter(i) { return streamer(ctx, desc, cc, method, callOpts...) @@ -321,7 +321,7 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor { ) (interface{}, error) { i := &InterceptorInfo{ UnaryServerInfo: info, - Typ: UnaryServer, + Type: UnaryServer, } if cfg.Filter != nil && !cfg.Filter(i) { return handler(ctx, req) @@ -418,7 +418,7 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor { ctx := ss.Context() i := &InterceptorInfo{ StreamServerInfo: info, - Typ: StreamServer, + Type: StreamServer, } if cfg.Filter != nil && !cfg.Filter(i) { return handler(srv, wrapServerStream(ctx, ss)) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go b/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go index 0d9c4d3452d..f6116946bfd 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go @@ -45,6 +45,6 @@ type InterceptorInfo struct { UnaryServerInfo *grpc.UnaryServerInfo // StreamServerInfo if the metadata for StreamServer StreamServerInfo *grpc.StreamServerInfo - // Typ is the type for interceptor - Typ InterceptorType + // Type is the type for interceptor + Type InterceptorType }