From 1533288fd63fec9c98f11ed7d8a87c31f30dd529 Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Mon, 31 Jul 2023 07:55:08 +0000 Subject: [PATCH 1/3] repaces otgrpc with otel Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- plugin/storage/grpc/README.md | 6 +++--- plugin/storage/grpc/config/config.go | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/plugin/storage/grpc/README.md b/plugin/storage/grpc/README.md index ec0dcbf113e..dcca8ee8e9e 100644 --- a/plugin/storage/grpc/README.md +++ b/plugin/storage/grpc/README.md @@ -200,13 +200,13 @@ grpc.ServeWithGRPCServer(&shared.PluginServices{ ArchiveStore: memStorePlugin, }, func(options []googleGRPC.ServerOption) *googleGRPC.Server { return plugin.DefaultGRPCServer([]googleGRPC.ServerOption{ - googleGRPC.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)), - googleGRPC.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer)), + grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), + grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), }) }) ``` -Refer to `example/memstore-plugin` for more details. +Refer to `example/hotrod` for more details. Bearer token propagation from the UI ------------------------------------ diff --git a/plugin/storage/grpc/config/config.go b/plugin/storage/grpc/config/config.go index c5cc8154a4f..3d241c216f8 100644 --- a/plugin/storage/grpc/config/config.go +++ b/plugin/storage/grpc/config/config.go @@ -21,10 +21,10 @@ import ( "runtime" "time" - "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" - "github.com/opentracing/opentracing-go" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "go.opentelemetry.io/otel" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -84,8 +84,10 @@ func (c *Configuration) Close() error { func (c *Configuration) buildRemote(logger *zap.Logger) (*ClientPluginServices, error) { opts := []grpc.DialOption{ - grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer())), - grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer())), + grpc.WithUnaryInterceptor( + otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), + grpc.WithStreamInterceptor( + otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), grpc.WithBlock(), } if c.RemoteTLS.Enabled { @@ -125,8 +127,10 @@ func (c *Configuration) buildRemote(logger *zap.Logger) (*ClientPluginServices, func (c *Configuration) buildPlugin(logger *zap.Logger) (*ClientPluginServices, error) { opts := []grpc.DialOption{ - grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer())), - grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer())), + grpc.WithUnaryInterceptor( + otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), + grpc.WithStreamInterceptor( + otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), } tenancyMgr := tenancy.NewManager(&c.TenancyOpts) From b77914f1571f581b8a1c560560519223963e61a1 Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Fri, 4 Aug 2023 02:25:01 +0000 Subject: [PATCH 2/3] adds otel tracerprovider to main call Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- plugin/storage/grpc/config/config.go | 22 +++++++++++----------- plugin/storage/grpc/factory.go | 6 +++++- plugin/storage/grpc/factory_test.go | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/plugin/storage/grpc/config/config.go b/plugin/storage/grpc/config/config.go index 3d241c216f8..b81647916fa 100644 --- a/plugin/storage/grpc/config/config.go +++ b/plugin/storage/grpc/config/config.go @@ -24,7 +24,7 @@ import ( "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" - "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -60,16 +60,16 @@ type ClientPluginServices struct { // PluginBuilder is used to create storage plugins. Implemented by Configuration. type PluginBuilder interface { - Build(logger *zap.Logger) (*ClientPluginServices, error) + Build(logger *zap.Logger, tracerProvider trace.TracerProvider) (*ClientPluginServices, error) Close() error } // Build instantiates a PluginServices -func (c *Configuration) Build(logger *zap.Logger) (*ClientPluginServices, error) { +func (c *Configuration) Build(logger *zap.Logger, tracerProvider trace.TracerProvider) (*ClientPluginServices, error) { if c.PluginBinary != "" { - return c.buildPlugin(logger) + return c.buildPlugin(logger, tracerProvider) } else { - return c.buildRemote(logger) + return c.buildRemote(logger, tracerProvider) } } @@ -82,12 +82,12 @@ func (c *Configuration) Close() error { return c.RemoteTLS.Close() } -func (c *Configuration) buildRemote(logger *zap.Logger) (*ClientPluginServices, error) { +func (c *Configuration) buildRemote(logger *zap.Logger, tracerProvider trace.TracerProvider) (*ClientPluginServices, error) { opts := []grpc.DialOption{ grpc.WithUnaryInterceptor( - otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), + otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), grpc.WithStreamInterceptor( - otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), + otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), grpc.WithBlock(), } if c.RemoteTLS.Enabled { @@ -125,12 +125,12 @@ func (c *Configuration) buildRemote(logger *zap.Logger) (*ClientPluginServices, }, nil } -func (c *Configuration) buildPlugin(logger *zap.Logger) (*ClientPluginServices, error) { +func (c *Configuration) buildPlugin(logger *zap.Logger, tracerProvider trace.TracerProvider) (*ClientPluginServices, error) { opts := []grpc.DialOption{ grpc.WithUnaryInterceptor( - otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), + otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), grpc.WithStreamInterceptor( - otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))), + otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(tracerProvider))), } tenancyMgr := tenancy.NewManager(&c.TenancyOpts) diff --git a/plugin/storage/grpc/factory.go b/plugin/storage/grpc/factory.go index 32c7f24dbbc..cf44df3283b 100644 --- a/plugin/storage/grpc/factory.go +++ b/plugin/storage/grpc/factory.go @@ -20,6 +20,8 @@ import ( "io" "github.com/spf13/viper" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/metrics" @@ -41,6 +43,7 @@ type Factory struct { options Options metricsFactory metrics.Factory logger *zap.Logger + tracerProvider trace.TracerProvider builder config.PluginBuilder @@ -77,8 +80,9 @@ func (f *Factory) InitFromOptions(opts Options) { // Initialize implements storage.Factory func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { f.metricsFactory, f.logger = metricsFactory, logger + f.tracerProvider = otel.GetTracerProvider() - services, err := f.builder.Build(logger) + services, err := f.builder.Build(logger, f.tracerProvider) if err != nil { return fmt.Errorf("grpc-plugin builder failed to create a store: %w", err) } diff --git a/plugin/storage/grpc/factory_test.go b/plugin/storage/grpc/factory_test.go index d157fac1f31..9525a4735aa 100644 --- a/plugin/storage/grpc/factory_test.go +++ b/plugin/storage/grpc/factory_test.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/config" @@ -43,7 +44,7 @@ type mockPluginBuilder struct { err error } -func (b *mockPluginBuilder) Build(logger *zap.Logger) (*grpcConfig.ClientPluginServices, error) { +func (b *mockPluginBuilder) Build(logger *zap.Logger, tracer trace.TracerProvider) (*grpcConfig.ClientPluginServices, error) { if b.err != nil { return nil, b.err } From c18927f9eca1718dd64968ce774d0909ca733937 Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Fri, 4 Aug 2023 02:27:29 +0000 Subject: [PATCH 3/3] revert the referrence Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- plugin/storage/grpc/README.md | 2 +- plugin/storage/grpc/factory.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/storage/grpc/README.md b/plugin/storage/grpc/README.md index dcca8ee8e9e..1fee18db23a 100644 --- a/plugin/storage/grpc/README.md +++ b/plugin/storage/grpc/README.md @@ -206,7 +206,7 @@ grpc.ServeWithGRPCServer(&shared.PluginServices{ }) ``` -Refer to `example/hotrod` for more details. +Refer to `example/memstore-plugin` for more details. Bearer token propagation from the UI ------------------------------------ diff --git a/plugin/storage/grpc/factory.go b/plugin/storage/grpc/factory.go index cf44df3283b..24a4712ff8d 100644 --- a/plugin/storage/grpc/factory.go +++ b/plugin/storage/grpc/factory.go @@ -43,7 +43,7 @@ type Factory struct { options Options metricsFactory metrics.Factory logger *zap.Logger - tracerProvider trace.TracerProvider + tracerProvider trace.TracerProvider builder config.PluginBuilder