diff --git a/exporter/exporterhelper/factory.go b/exporter/exporterhelper/factory.go new file mode 100644 index 000000000000..bf5a33d899ff --- /dev/null +++ b/exporter/exporterhelper/factory.go @@ -0,0 +1,129 @@ +// Copyright OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package exporterhelper + +import ( + "context" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config/configerror" + "go.opentelemetry.io/collector/config/configmodels" +) + +// FactoryOption apply changes to ExporterOptions. +type FactoryOption func(o *factory) + +// CreateDefaultConfig is the equivalent of component.ExporterFactory.CreateDefaultConfig() +type CreateDefaultConfig func() configmodels.Exporter + +// CreateTraceExporter is the equivalent of component.ExporterFactory.CreateTraceExporter() +type CreateTraceExporter func(context.Context, component.ExporterCreateParams, configmodels.Exporter) (component.TraceExporter, error) + +// CreateMetricsExporter is the equivalent of component.ExporterFactory.CreateMetricsExporter() +type CreateMetricsExporter func(context.Context, component.ExporterCreateParams, configmodels.Exporter) (component.MetricsExporter, error) + +// CreateMetricsExporter is the equivalent of component.ExporterFactory.CreateLogExporter() +type CreateLogExporter func(context.Context, component.ExporterCreateParams, configmodels.Exporter) (component.LogExporter, error) + +// factory is the factory for Jaeger gRPC exporter. +type factory struct { + cfgType configmodels.Type + createDefaultConfig CreateDefaultConfig + createTraceExporter CreateTraceExporter + createMetricsExporter CreateMetricsExporter + createLogExporter CreateLogExporter +} + +var _ component.LogExporterFactory = new(factory) + +// WithTraces overrides the default "error not supported" implementation for CreateTraceReceiver. +func WithTraces(createTraceExporter CreateTraceExporter) FactoryOption { + return func(o *factory) { + o.createTraceExporter = createTraceExporter + } +} + +// WithMetrics overrides the default "error not supported" implementation for CreateMetricsReceiver. +func WithMetrics(createMetricsExporter CreateMetricsExporter) FactoryOption { + return func(o *factory) { + o.createMetricsExporter = createMetricsExporter + } +} + +// WithLogs overrides the default "error not supported" implementation for CreateLogReceiver. +func WithLogs(createLogExporter CreateLogExporter) FactoryOption { + return func(o *factory) { + o.createLogExporter = createLogExporter + } +} + +// NewFactory returns a component.ExporterFactory that only supports all types. +func NewFactory( + cfgType configmodels.Type, + createDefaultConfig CreateDefaultConfig, + options ...FactoryOption) component.ExporterFactory { + f := &factory{ + cfgType: cfgType, + createDefaultConfig: createDefaultConfig, + } + for _, opt := range options { + opt(f) + } + return f +} + +// Type gets the type of the Exporter config created by this factory. +func (f *factory) Type() configmodels.Type { + return f.cfgType +} + +// CreateDefaultConfig creates the default configuration for processor. +func (f *factory) CreateDefaultConfig() configmodels.Exporter { + return f.createDefaultConfig() +} + +// CreateTraceExporter creates a component.TraceExporter based on this config. +func (f *factory) CreateTraceExporter( + ctx context.Context, + params component.ExporterCreateParams, + cfg configmodels.Exporter) (component.TraceExporter, error) { + if f.createTraceExporter != nil { + return f.createTraceExporter(ctx, params, cfg) + } + return nil, configerror.ErrDataTypeIsNotSupported +} + +// CreateMetricsExporter creates a consumer.MetricsConsumer based on this config. +func (f *factory) CreateMetricsExporter( + ctx context.Context, + params component.ExporterCreateParams, + cfg configmodels.Exporter) (component.MetricsExporter, error) { + if f.createMetricsExporter != nil { + return f.createMetricsExporter(ctx, params, cfg) + } + return nil, configerror.ErrDataTypeIsNotSupported +} + +// CreateLogExporter creates a metrics processor based on this config. +func (f *factory) CreateLogExporter( + ctx context.Context, + params component.ExporterCreateParams, + cfg configmodels.Exporter, +) (component.LogExporter, error) { + if f.createLogExporter != nil { + return f.createLogExporter(ctx, params, cfg) + } + return nil, configerror.ErrDataTypeIsNotSupported +} diff --git a/exporter/exporterhelper/factory_test.go b/exporter/exporterhelper/factory_test.go new file mode 100644 index 000000000000..01ecf877dc8e --- /dev/null +++ b/exporter/exporterhelper/factory_test.go @@ -0,0 +1,94 @@ +// Copyright OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package exporterhelper + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config/configerror" + "go.opentelemetry.io/collector/config/configmodels" + "go.opentelemetry.io/collector/exporter/exportertest" +) + +const typeStr = "test" + +var ( + defaultCfg = &configmodels.ExporterSettings{ + TypeVal: typeStr, + NameVal: typeStr, + } + nopTracesExporter = exportertest.NewNopTraceExporter() + nopMetricsExporter = exportertest.NewNopMetricsExporter() + nopLogsExporter = exportertest.NewNopLogsExporter() +) + +func TestNewFactory(t *testing.T) { + factory := NewFactory( + typeStr, + defaultConfig) + assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, defaultCfg, factory.CreateDefaultConfig()) + _, err := factory.CreateTraceExporter(context.Background(), component.ExporterCreateParams{}, defaultCfg) + assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err) + _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, defaultCfg) + assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err) + lfactory := factory.(component.LogExporterFactory) + _, err = lfactory.CreateLogExporter(context.Background(), component.ExporterCreateParams{}, defaultCfg) + assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err) +} + +func TestNewFactory_WithConstructors(t *testing.T) { + factory := NewFactory( + typeStr, + defaultConfig, + WithTraces(createTraceExporter), + WithMetrics(createMetricsExporter), + WithLogs(createLogExporter)) + assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, defaultCfg, factory.CreateDefaultConfig()) + + te, err := factory.CreateTraceExporter(context.Background(), component.ExporterCreateParams{}, defaultCfg) + assert.NoError(t, err) + assert.Same(t, nopTracesExporter, te) + + me, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, defaultCfg) + assert.NoError(t, err) + assert.Same(t, nopMetricsExporter, me) + + lfactory := factory.(component.LogExporterFactory) + le, err := lfactory.CreateLogExporter(context.Background(), component.ExporterCreateParams{}, defaultCfg) + assert.NoError(t, err) + assert.Same(t, nopLogsExporter, le) +} + +func defaultConfig() configmodels.Exporter { + return defaultCfg +} + +func createTraceExporter(context.Context, component.ExporterCreateParams, configmodels.Exporter) (component.TraceExporter, error) { + return nopTracesExporter, nil +} + +func createMetricsExporter(context.Context, component.ExporterCreateParams, configmodels.Exporter) (component.MetricsExporter, error) { + return nopMetricsExporter, nil +} + +func createLogExporter(context.Context, component.ExporterCreateParams, configmodels.Exporter) (component.LogExporter, error) { + return nopLogsExporter, nil +} diff --git a/exporter/jaegerexporter/config_test.go b/exporter/jaegerexporter/config_test.go index c9060f4a59fd..8e7c532c0b2a 100644 --- a/exporter/jaegerexporter/config_test.go +++ b/exporter/jaegerexporter/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factories, err := config.ExampleComponents() assert.NoError(t, err) - factory := &Factory{} + factory := NewFactory() factories.Exporters[typeStr] = factory cfg, err := config.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) diff --git a/exporter/jaegerexporter/exporter_test.go b/exporter/jaegerexporter/exporter_test.go index 9ac435311e0a..0860bb15ac9b 100644 --- a/exporter/jaegerexporter/exporter_test.go +++ b/exporter/jaegerexporter/exporter_test.go @@ -206,7 +206,7 @@ func TestMutualTLS(t *testing.T) { defer server.GracefulStop() // Create gRPC trace exporter - factory := &Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) cfg.GRPCClientSettings = configgrpc.GRPCClientSettings{ Endpoint: serverAddr.String(), diff --git a/exporter/jaegerexporter/factory.go b/exporter/jaegerexporter/factory.go index 145fda5d4052..95a33d229065 100644 --- a/exporter/jaegerexporter/factory.go +++ b/exporter/jaegerexporter/factory.go @@ -19,9 +19,9 @@ import ( "fmt" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config/configerror" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configmodels" + "go.opentelemetry.io/collector/exporter/exporterhelper" ) const ( @@ -29,17 +29,15 @@ const ( typeStr = "jaeger" ) -// Factory is the factory for Jaeger gRPC exporter. -type Factory struct { +// NewFactory creates a factory for Jaeger exporter +func NewFactory() component.ExporterFactory { + return exporterhelper.NewFactory( + typeStr, + createDefaultConfig, + exporterhelper.WithTraces(createTraceExporter)) } -// Type gets the type of the Exporter config created by this factory. -func (f *Factory) Type() configmodels.Type { - return typeStr -} - -// CreateDefaultConfig creates the default configuration for exporter. -func (f *Factory) CreateDefaultConfig() configmodels.Exporter { +func createDefaultConfig() configmodels.Exporter { return &Config{ ExporterSettings: configmodels.ExporterSettings{ TypeVal: typeStr, @@ -52,8 +50,7 @@ func (f *Factory) CreateDefaultConfig() configmodels.Exporter { } } -// CreateTraceExporter creates a trace exporter based on this config. -func (f *Factory) CreateTraceExporter( +func createTraceExporter( _ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter, @@ -75,12 +72,3 @@ func (f *Factory) CreateTraceExporter( return exp, nil } - -// CreateMetricsExporter creates a metrics exporter based on this config. -func (f *Factory) CreateMetricsExporter( - _ context.Context, - _ component.ExporterCreateParams, - _ configmodels.Exporter, -) (component.MetricsExporter, error) { - return nil, configerror.ErrDataTypeIsNotSupported -} diff --git a/exporter/jaegerexporter/factory_test.go b/exporter/jaegerexporter/factory_test.go index a37dac5d1614..42646dceaa28 100644 --- a/exporter/jaegerexporter/factory_test.go +++ b/exporter/jaegerexporter/factory_test.go @@ -27,14 +27,14 @@ import ( ) func TestCreateDefaultConfig(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, configcheck.ValidateConfig(cfg)) } func TestCreateMetricsExporter(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() params := component.ExporterCreateParams{Logger: zap.NewNop()} @@ -43,7 +43,7 @@ func TestCreateMetricsExporter(t *testing.T) { } func TestCreateInstanceViaFactory(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() diff --git a/exporter/loggingexporter/config_test.go b/exporter/loggingexporter/config_test.go index f9a708b410e5..34bb25a8e5a8 100644 --- a/exporter/loggingexporter/config_test.go +++ b/exporter/loggingexporter/config_test.go @@ -29,7 +29,7 @@ func TestLoadConfig(t *testing.T) { factories, err := config.ExampleComponents() assert.NoError(t, err) - factory := &Factory{} + factory := NewFactory() factories.Exporters[typeStr] = factory cfg, err := config.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) diff --git a/exporter/loggingexporter/factory.go b/exporter/loggingexporter/factory.go index ff339368041c..601703cab2da 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configmodels" + "go.opentelemetry.io/collector/exporter/exporterhelper" ) const ( @@ -31,17 +32,17 @@ const ( defaultSamplingThereafter = 500 ) -// Factory is the factory for logging exporter. -type Factory struct { +// NewFactory creates a factory for Logging exporter +func NewFactory() component.ExporterFactory { + return exporterhelper.NewFactory( + typeStr, + createDefaultConfig, + exporterhelper.WithTraces(createTraceExporter), + exporterhelper.WithMetrics(createMetricsExporter), + exporterhelper.WithLogs(createLogExporter)) } -// Type gets the type of the Exporter config created by this factory. -func (f *Factory) Type() configmodels.Type { - return typeStr -} - -// CreateDefaultConfig creates the default configuration for exporter. -func (f *Factory) CreateDefaultConfig() configmodels.Exporter { +func createDefaultConfig() configmodels.Exporter { return &Config{ ExporterSettings: configmodels.ExporterSettings{ TypeVal: typeStr, @@ -53,11 +54,10 @@ func (f *Factory) CreateDefaultConfig() configmodels.Exporter { } } -// CreateTraceExporter creates a trace exporter based on this config. -func (f *Factory) CreateTraceExporter(_ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter) (component.TraceExporter, error) { +func createTraceExporter(_ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter) (component.TraceExporter, error) { cfg := config.(*Config) - exporterLogger, err := f.createLogger(cfg) + exporterLogger, err := createLogger(cfg) if err != nil { return nil, err } @@ -69,59 +69,55 @@ func (f *Factory) CreateTraceExporter(_ context.Context, _ component.ExporterCre return lexp, nil } -func (f *Factory) createLogger(cfg *Config) (*zap.Logger, error) { - var level zapcore.Level - err := (&level).UnmarshalText([]byte(cfg.LogLevel)) +func createMetricsExporter(_ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter) (component.MetricsExporter, error) { + cfg := config.(*Config) + + exporterLogger, err := createLogger(cfg) if err != nil { return nil, err } - // We take development config as the base since it matches the purpose - // of logging exporter being used for debugging reasons (so e.g. console encoder) - conf := zap.NewDevelopmentConfig() - conf.Level = zap.NewAtomicLevelAt(level) - conf.Sampling = &zap.SamplingConfig{ - Initial: cfg.SamplingInitial, - Thereafter: cfg.SamplingThereafter, - } - - logginglogger, err := conf.Build() + lexp, err := NewMetricsExporter(config, cfg.LogLevel, exporterLogger) if err != nil { return nil, err } - return logginglogger, nil + return lexp, nil } -// CreateMetricsExporter creates a metrics exporter based on this config. -func (f *Factory) CreateMetricsExporter(_ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter) (component.MetricsExporter, error) { +func createLogExporter(_ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter) (component.LogExporter, error) { cfg := config.(*Config) - exporterLogger, err := f.createLogger(cfg) + exporterLogger, err := createLogger(cfg) if err != nil { return nil, err } - lexp, err := NewMetricsExporter(config, cfg.LogLevel, exporterLogger) + lexp, err := NewLogExporter(config, cfg.LogLevel, exporterLogger) if err != nil { return nil, err } return lexp, nil } -// CreateLogExporter creates a log exporter based on this config. -func (f *Factory) CreateLogExporter(_ context.Context, _ component.ExporterCreateParams, config configmodels.Exporter) (component.LogExporter, error) { - cfg := config.(*Config) - - exporterLogger, err := f.createLogger(cfg) +func createLogger(cfg *Config) (*zap.Logger, error) { + var level zapcore.Level + err := (&level).UnmarshalText([]byte(cfg.LogLevel)) if err != nil { return nil, err } - lexp, err := NewLogExporter(config, cfg.LogLevel, exporterLogger) + // We take development config as the base since it matches the purpose + // of logging exporter being used for debugging reasons (so e.g. console encoder) + conf := zap.NewDevelopmentConfig() + conf.Level = zap.NewAtomicLevelAt(level) + conf.Sampling = &zap.SamplingConfig{ + Initial: cfg.SamplingInitial, + Thereafter: cfg.SamplingThereafter, + } + + logginglogger, err := conf.Build() if err != nil { return nil, err } - return lexp, nil + return logginglogger, nil } - -var _ component.LogExporterFactory = (*Factory)(nil) diff --git a/exporter/loggingexporter/factory_test.go b/exporter/loggingexporter/factory_test.go index 071b83759bce..2db2797ea736 100644 --- a/exporter/loggingexporter/factory_test.go +++ b/exporter/loggingexporter/factory_test.go @@ -26,14 +26,14 @@ import ( ) func TestCreateDefaultConfig(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, configcheck.ValidateConfig(cfg)) } func TestCreateMetricsExporter(t *testing.T) { - factory := &Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() me, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, cfg) @@ -42,7 +42,7 @@ func TestCreateMetricsExporter(t *testing.T) { } func TestCreateTraceExporter(t *testing.T) { - factory := &Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() te, err := factory.CreateTraceExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, cfg) @@ -51,7 +51,7 @@ func TestCreateTraceExporter(t *testing.T) { } func TestCreateLogExporter(t *testing.T) { - factory := &Factory{} + factory := NewFactory().(component.LogExporterFactory) cfg := factory.CreateDefaultConfig() te, err := factory.CreateLogExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, cfg) diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index 9c5c3afbad72..5433e59ea05b 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factories, err := config.ExampleComponents() assert.NoError(t, err) - factory := &Factory{} + factory := NewFactory() factories.Exporters[typeStr] = factory cfg, err := config.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 3d1ea2d0f218..6134d0662974 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -28,17 +28,17 @@ const ( typeStr = "otlp" ) -// Factory is the factory for OpenCensus exporter. -type Factory struct { +// NewFactory creates a factory for OTLP exporter. +func NewFactory() component.ExporterFactory { + return exporterhelper.NewFactory( + typeStr, + createDefaultConfig, + exporterhelper.WithTraces(createTraceExporter), + exporterhelper.WithMetrics(createMetricsExporter), + exporterhelper.WithLogs(createLogExporter)) } -// Type gets the type of the Exporter config created by this factory. -func (f *Factory) Type() configmodels.Type { - return typeStr -} - -// CreateDefaultConfig creates the default configuration for exporter. -func (f *Factory) CreateDefaultConfig() configmodels.Exporter { +func createDefaultConfig() configmodels.Exporter { return &Config{ ExporterSettings: configmodels.ExporterSettings{ TypeVal: typeStr, @@ -52,10 +52,9 @@ func (f *Factory) CreateDefaultConfig() configmodels.Exporter { } } -// CreateTraceExporter creates a trace exporter based on this config. -func (f *Factory) CreateTraceExporter( - ctx context.Context, - params component.ExporterCreateParams, +func createTraceExporter( + _ context.Context, + _ component.ExporterCreateParams, cfg configmodels.Exporter, ) (component.TraceExporter, error) { oce, err := newExporter(cfg) @@ -73,8 +72,7 @@ func (f *Factory) CreateTraceExporter( return oexp, nil } -// CreateMetricsExporter creates a metrics exporter based on this config. -func (f *Factory) CreateMetricsExporter( +func createMetricsExporter( _ context.Context, _ component.ExporterCreateParams, cfg configmodels.Exporter, @@ -95,8 +93,7 @@ func (f *Factory) CreateMetricsExporter( return oexp, nil } -// CreateLogExporter creates a log exporter based on this config. -func (f *Factory) CreateLogExporter( +func createLogExporter( _ context.Context, _ component.ExporterCreateParams, cfg configmodels.Exporter, diff --git a/exporter/otlpexporter/factory_test.go b/exporter/otlpexporter/factory_test.go index 7ff72307ab91..c554592748f4 100644 --- a/exporter/otlpexporter/factory_test.go +++ b/exporter/otlpexporter/factory_test.go @@ -31,14 +31,14 @@ import ( ) func TestCreateDefaultConfig(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, configcheck.ValidateConfig(cfg)) } func TestCreateMetricsExporter(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) cfg.GRPCClientSettings.Endpoint = testutil.GetAvailableLocalAddress(t) @@ -159,7 +159,7 @@ func TestCreateTraceExporter(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - factory := &Factory{} + factory := NewFactory() creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} consumer, err := factory.CreateTraceExporter(context.Background(), creationParams, &tt.config) @@ -181,12 +181,12 @@ func TestCreateTraceExporter(t *testing.T) { } func TestCreateLogsExporter(t *testing.T) { - factory := Factory{} + factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) cfg.GRPCClientSettings.Endpoint = testutil.GetAvailableLocalAddress(t) creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} - oexp, err := factory.CreateLogExporter(context.Background(), creationParams, cfg) + oexp, err := factory.(component.LogExporterFactory).CreateLogExporter(context.Background(), creationParams, cfg) require.Nil(t, err) require.NotNil(t, oexp) } diff --git a/exporter/otlpexporter/otlp_test.go b/exporter/otlpexporter/otlp_test.go index b32d03a885df..9c76518b6817 100644 --- a/exporter/otlpexporter/otlp_test.go +++ b/exporter/otlpexporter/otlp_test.go @@ -131,7 +131,7 @@ func TestSendTraceData(t *testing.T) { }, } - factory := &Factory{} + factory := NewFactory() creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} exp, err := factory.CreateTraceExporter(context.Background(), creationParams, &config) require.NoError(t, err) @@ -198,7 +198,7 @@ func TestSendTraceDataServerDownAndUp(t *testing.T) { }, } - factory := &Factory{} + factory := NewFactory() creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} exp, err := factory.CreateTraceExporter(context.Background(), creationParams, &config) require.NoError(t, err) @@ -257,7 +257,7 @@ func TestSendTraceDataServerStartWhileRequest(t *testing.T) { }, } - factory := &Factory{} + factory := NewFactory() creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} exp, err := factory.CreateTraceExporter(context.Background(), creationParams, &config) require.NoError(t, err) @@ -336,7 +336,7 @@ func TestSendLogData(t *testing.T) { }, } - factory := &Factory{} + factory := NewFactory().(component.LogExporterFactory) creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} exp, err := factory.CreateLogExporter(context.Background(), creationParams, &config) require.NoError(t, err) diff --git a/service/defaultcomponents/defaults.go b/service/defaultcomponents/defaults.go index 11581b69d573..83f915c068c2 100644 --- a/service/defaultcomponents/defaults.go +++ b/service/defaultcomponents/defaults.go @@ -78,11 +78,11 @@ func Components() ( exporters, err := component.MakeExporterFactoryMap( &opencensusexporter.Factory{}, &prometheusexporter.Factory{}, - &loggingexporter.Factory{}, + loggingexporter.NewFactory(), &zipkinexporter.Factory{}, - &jaegerexporter.Factory{}, + jaegerexporter.NewFactory(), &fileexporter.Factory{}, - &otlpexporter.Factory{}, + otlpexporter.NewFactory(), ) if err != nil { errs = append(errs, err) diff --git a/testbed/testbed/senders.go b/testbed/testbed/senders.go index 33b5818231f5..85b88d90ed32 100644 --- a/testbed/testbed/senders.go +++ b/testbed/testbed/senders.go @@ -139,7 +139,7 @@ func NewJaegerGRPCDataSender(host string, port int) *JaegerGRPCDataSender { } func (je *JaegerGRPCDataSender) Start() error { - factory := jaegerexporter.Factory{} + factory := jaegerexporter.NewFactory() cfg := factory.CreateDefaultConfig().(*jaegerexporter.Config) cfg.Endpoint = fmt.Sprintf("%s:%d", je.Host, je.Port) cfg.TLSSetting = configtls.TLSClientSetting{ @@ -289,7 +289,7 @@ func NewOTLPTraceDataSender(host string, port int) *OTLPTraceDataSender { } func (ote *OTLPTraceDataSender) Start() error { - factory := otlpexporter.Factory{} + factory := otlpexporter.NewFactory() cfg := factory.CreateDefaultConfig().(*otlpexporter.Config) cfg.Endpoint = fmt.Sprintf("%s:%d", ote.Host, ote.Port) cfg.TLSSetting = configtls.TLSClientSetting{ @@ -339,7 +339,7 @@ func NewOTLPMetricDataSender(host string, port int) *OTLPMetricsDataSender { } func (ome *OTLPMetricsDataSender) Start() error { - factory := otlpexporter.Factory{} + factory := otlpexporter.NewFactory() cfg := factory.CreateDefaultConfig().(*otlpexporter.Config) cfg.Endpoint = fmt.Sprintf("%s:%d", ome.host, ome.port) cfg.TLSSetting = configtls.TLSClientSetting{