Skip to content

Commit

Permalink
[service] add internal factory method for meter provider
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 open-telemetry#10414

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten committed Jun 17, 2024
1 parent 7a3c35c commit b0e100d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 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 CreateSettings, cfg component.Config) (trace.TracerProvider, error)

// TODO: Add CreateMeterProvider.
// CreateMeterProvider creates a MeterProvider.
CreateMeterProvider(ctx context.Context, set CreateSettings, 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,21 @@ func (f *factory) CreateTracerProvider(ctx context.Context, set CreateSettings,
return f.CreateTracerProviderFunc(ctx, set, cfg)
}

type CreateMeterProviderFunc func(context.Context, CreateSettings, component.Config) (metric.MeterProvider, error)

func WithMeterProvier(createMeterProvider CreateMeterProviderFunc) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.CreateMeterProviderFunc = createMeterProvider
})
}

func (f *factory) CreateMeterProvider(ctx context.Context, set CreateSettings, 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 b0e100d

Please sign in to comment.