From 01ee503919045b4660650675d91a4fc237eba2d8 Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Sun, 2 Jul 2023 10:47:00 +0000 Subject: [PATCH] refactors otel grpc intrumn --- examples/hotrod/pkg/tracing/init.go | 4 ++-- examples/hotrod/services/driver/redis.go | 3 ++- examples/hotrod/services/driver/server.go | 11 ++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/hotrod/pkg/tracing/init.go b/examples/hotrod/pkg/tracing/init.go index 367d328b30dc..823335402738 100644 --- a/examples/hotrod/pkg/tracing/init.go +++ b/examples/hotrod/pkg/tracing/init.go @@ -45,11 +45,11 @@ import ( var once sync.Once // InitOTEL initializes OpenTelemetry SDK. -func InitOTEL(serviceName string, exporterType string, metricsFactory metrics.Factory, logger log.Factory) trace.Tracer { +func InitOTEL(serviceName string, exporterType string, metricsFactory metrics.Factory, logger log.Factory) trace.TracerProvider { _, oteltp := initBOTH(serviceName, exporterType, metricsFactory, logger) logger.Bg().Debug("Created OTEL tracer", zap.String("service-name", serviceName)) - return oteltp.Tracer(serviceName) + return oteltp } // Init returns OTel-OpenTracing Bridge. diff --git a/examples/hotrod/services/driver/redis.go b/examples/hotrod/services/driver/redis.go index 1199017dfb0a..004d4c189962 100644 --- a/examples/hotrod/services/driver/redis.go +++ b/examples/hotrod/services/driver/redis.go @@ -42,8 +42,9 @@ type Redis struct { } func newRedis(otelExporter string, metricsFactory metrics.Factory, logger log.Factory) *Redis { + tp := tracing.InitOTEL("redis-manual", otelExporter, metricsFactory, logger) return &Redis{ - tracer: tracing.InitOTEL("redis-manual", otelExporter, metricsFactory, logger), + tracer: tp.Tracer("redis-manual"), logger: logger, } } diff --git a/examples/hotrod/services/driver/server.go b/examples/hotrod/services/driver/server.go index e1d1aa3975b8..4c112daf718b 100644 --- a/examples/hotrod/services/driver/server.go +++ b/examples/hotrod/services/driver/server.go @@ -19,8 +19,7 @@ import ( "context" "net" - otgrpc "github.com/opentracing-contrib/go-grpc" - "github.com/opentracing/opentracing-go" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "go.uber.org/zap" "google.golang.org/grpc" @@ -32,7 +31,6 @@ import ( // Server implements jaeger-demo-frontend service type Server struct { hostPort string - tracer opentracing.Tracer logger log.Factory redis *Redis server *grpc.Server @@ -42,14 +40,13 @@ var _ DriverServiceServer = (*Server)(nil) // NewServer creates a new driver.Server func NewServer(hostPort string, otelExporter string, metricsFactory metrics.Factory, logger log.Factory) *Server { - tracer := tracing.Init("driver", otelExporter, metricsFactory, logger) + tracerProvider := tracing.InitOTEL("driver", otelExporter, metricsFactory, logger) server := grpc.NewServer( - grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)), - grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer)), + grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), + grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), ) return &Server{ hostPort: hostPort, - tracer: tracer, logger: logger, server: server, redis: newRedis(otelExporter, metricsFactory, logger),