Skip to content

Commit

Permalink
[service] add internal factory method for meter provider (#10415)
Browse files Browse the repository at this point in the history
This will be used when moving the meter provider configuration to use
the otel-go config package.

Part of #10414

Skipping changelog as there's no usage of this method yet. It will be
done in a separate PR

---------

Signed-off-by: Alex Boten <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
codeboten and mx-psi authored Jul 5, 2024
1 parent e014c1e commit 6fca9ee
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion service/telemetry/internal/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package internal // import "go.opentelemetry.io/collector/service/telemetry/inte
import (
"context"

"go.opentelemetry.io/otel/metric"
metricnoop "go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/trace"
tracenoop "go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"
Expand Down Expand Up @@ -34,7 +36,8 @@ type Factory interface {
// CreateTracerProvider creates a TracerProvider.
CreateTracerProvider(ctx context.Context, set Settings, cfg component.Config) (trace.TracerProvider, error)

// TODO: Add CreateMeterProvider.
// CreateMeterProvider creates a MeterProvider.
CreateMeterProvider(ctx context.Context, set Settings, cfg component.Config) (metric.MeterProvider, error)

// unexportedFactoryFunc is used to prevent external implementations of Factory.
unexportedFactoryFunc()
Expand Down Expand Up @@ -62,6 +65,7 @@ type factory struct {
createDefaultConfig component.CreateDefaultConfigFunc
CreateLoggerFunc
CreateTracerProviderFunc
CreateMeterProviderFunc
}

func (f *factory) CreateDefaultConfig() component.Config {
Expand Down Expand Up @@ -102,6 +106,23 @@ func (f *factory) CreateTracerProvider(ctx context.Context, set Settings, cfg co
return f.CreateTracerProviderFunc(ctx, set, cfg)
}

// CreateMeterProviderFunc is the equivalent of Factory.CreateMeterProvider.
type CreateMeterProviderFunc func(context.Context, Settings, component.Config) (metric.MeterProvider, error)

// WithMeterProvider overrides the default no-op meter provider.
func WithMeterProvider(createMeterProvider CreateMeterProviderFunc) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.CreateMeterProviderFunc = createMeterProvider
})
}

func (f *factory) CreateMeterProvider(ctx context.Context, set Settings, cfg component.Config) (metric.MeterProvider, error) {
if f.CreateMeterProviderFunc == nil {
return metricnoop.NewMeterProvider(), nil
}
return f.CreateMeterProviderFunc(ctx, set, cfg)
}

func (f *factory) unexportedFactoryFunc() {}

// NewFactory returns a new Factory.
Expand Down

0 comments on commit 6fca9ee

Please sign in to comment.