diff --git a/plugin/storage/grpc/factory.go b/plugin/storage/grpc/factory.go index 07daea2e569..80626330b3c 100644 --- a/plugin/storage/grpc/factory.go +++ b/plugin/storage/grpc/factory.go @@ -18,7 +18,6 @@ import ( "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/metric" - noopmetric "go.opentelemetry.io/otel/metric/noop" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/noop" "go.uber.org/zap" @@ -51,6 +50,7 @@ type Factory struct { tracedRemoteConn *grpc.ClientConn untracedRemoteConn *grpc.ClientConn host component.Host + meterProvider metric.MeterProvider } // NewFactory creates a new Factory. @@ -66,10 +66,12 @@ func NewFactoryWithConfig( metricsFactory metrics.Factory, logger *zap.Logger, host component.Host, + meterProvider metric.MeterProvider, ) (*Factory, error) { f := NewFactory() f.config = cfg f.host = host + f.meterProvider = meterProvider if err := f.Initialize(metricsFactory, logger); err != nil { return nil, err } @@ -93,8 +95,8 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) f.metricsFactory, f.logger = metricsFactory, logger f.tracerProvider = otel.GetTracerProvider() - tracedTelset := getTelset(logger, f.tracerProvider) - untracedTelset := getTelset(logger, noop.NewTracerProvider()) + tracedTelset := getTelset(logger, f.tracerProvider, f.meterProvider) + untracedTelset := getTelset(logger, noop.NewTracerProvider(), f.meterProvider) newClientFn := func(telset component.TelemetrySettings, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error) { clientOpts := make([]configgrpc.ToClientConnOption, 0) for _, opt := range opts { @@ -232,13 +234,13 @@ func (f *Factory) Close() error { return errors.Join(errs...) } -func getTelset(logger *zap.Logger, tracerProvider trace.TracerProvider) component.TelemetrySettings { +func getTelset(logger *zap.Logger, tracerProvider trace.TracerProvider, meterProvider metric.MeterProvider) component.TelemetrySettings { return component.TelemetrySettings{ Logger: logger, TracerProvider: tracerProvider, // TODO needs to be joined with the metricsFactory LeveledMeterProvider: func(_ configtelemetry.Level) metric.MeterProvider { - return noopmetric.NewMeterProvider() + return meterProvider }, } } diff --git a/plugin/storage/grpc/factory_test.go b/plugin/storage/grpc/factory_test.go index 60e78958794..7d08fa5807e 100644 --- a/plugin/storage/grpc/factory_test.go +++ b/plugin/storage/grpc/factory_test.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/exporter/exporterhelper" + "go.opentelemetry.io/otel/metric/noop" "go.uber.org/zap" "google.golang.org/grpc" @@ -106,7 +107,7 @@ func TestNewFactoryError(t *testing.T) { }, } t.Run("with_config", func(t *testing.T) { - _, err := NewFactoryWithConfig(*cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost()) + _, err := NewFactoryWithConfig(*cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost(), noop.NewMeterProvider()) assert.ErrorContains(t, err, "authenticator") }) @@ -120,7 +121,7 @@ func TestNewFactoryError(t *testing.T) { t.Run("client", func(t *testing.T) { // this is a silly test to verify handling of error from grpc.NewClient, which cannot be induced via params. - f, err := NewFactoryWithConfig(Config{}, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost()) + f, err := NewFactoryWithConfig(Config{}, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost(), noop.NewMeterProvider()) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, f.Close()) }) newClientFn := func(_ component.TelemetrySettings, _ ...grpc.DialOption) (conn *grpc.ClientConn, err error) { @@ -171,7 +172,7 @@ func TestGRPCStorageFactoryWithConfig(t *testing.T) { Enabled: true, }, } - f, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost()) + f, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost(), noop.NewMeterProvider()) require.NoError(t, err) require.NoError(t, f.Close()) }