diff --git a/CHANGELOG.md b/CHANGELOG.md index 352ca2dd4d2..01a03282006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### 🚩 Deprecations 🚩 - Deprecate `config.Config` and `config.Service`, use `service.Config*` (#4608) +- Deprecate `componenterror` package, move everything to `component` (#5383) ### 💡 Enhancements 💡 diff --git a/component/component.go b/component/component.go index 210becf4b74..b8b206089eb 100644 --- a/component/component.go +++ b/component/component.go @@ -16,10 +16,21 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" + "errors" "go.opentelemetry.io/collector/config" ) +var ( + // ErrNilNextConsumer can be returned by receiver, or processor Start factory funcs that create the Component if the + // expected next Consumer is nil. + ErrNilNextConsumer = errors.New("nil next Consumer") + + // ErrDataTypeIsNotSupported can be returned by receiver, exporter or processor factory funcs that create the + // Component if the particular telemetry data type is not supported by the receiver, exporter or processor. + ErrDataTypeIsNotSupported = errors.New("telemetry type is not supported") +) + // Component is either a receiver, exporter, processor, or an extension. // // A component's lifecycle has the following phases: diff --git a/component/componenterror/errors.go b/component/componenterror/errors.go index 07d0c3bc398..a017ba8b0d7 100644 --- a/component/componenterror/errors.go +++ b/component/componenterror/errors.go @@ -15,15 +15,13 @@ package componenterror // import "go.opentelemetry.io/collector/component/componenterror" import ( - "errors" + "go.opentelemetry.io/collector/component" ) var ( - // ErrNilNextConsumer indicates an error on nil next consumer. - ErrNilNextConsumer = errors.New("nil nextConsumer") + // Deprecated: use component.ErrNilNextConsumer + ErrNilNextConsumer = component.ErrNilNextConsumer - // ErrDataTypeIsNotSupported can be returned by receiver, exporter or processor - // factory methods that create the entity if the particular telemetry - // data type is not supported by the receiver, exporter or processor. - ErrDataTypeIsNotSupported = errors.New("telemetry type is not supported") + // Deprecated: use component.ErrDataTypeIsNotSupported + ErrDataTypeIsNotSupported = component.ErrDataTypeIsNotSupported ) diff --git a/component/componenttest/shutdown_verifier.go b/component/componenttest/shutdown_verifier.go index fd55a51ee5b..51eaa63d706 100644 --- a/component/componenttest/shutdown_verifier.go +++ b/component/componenttest/shutdown_verifier.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/internal/testdata" @@ -39,7 +38,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo nextSink, ) if err != nil { - if errors.Is(err, componenterror.ErrDataTypeIsNotSupported) { + if errors.Is(err, component.ErrDataTypeIsNotSupported) { return } require.NoError(t, err) diff --git a/component/exporter.go b/component/exporter.go index 61c118bc9bb..86836804080 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -102,7 +101,7 @@ type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, conf // CreateTracesExporter implements ExporterFactory.CreateTracesExporter(). func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg) } @@ -113,7 +112,7 @@ type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, con // CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter(). func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (MetricsExporter, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg) } @@ -124,7 +123,7 @@ type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, config // CreateLogsExporter implements ExporterFactory.CreateLogsExporter(). func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (LogsExporter, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg) } diff --git a/component/processor.go b/component/processor.go index f31d1b2ebcf..d3f9cd1a365 100644 --- a/component/processor.go +++ b/component/processor.go @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -122,7 +121,7 @@ func (f CreateTracesProcessorFunc) CreateTracesProcessor( cfg config.Processor, nextConsumer consumer.Traces) (TracesProcessor, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg, nextConsumer) } @@ -138,7 +137,7 @@ func (f CreateMetricsProcessorFunc) CreateMetricsProcessor( nextConsumer consumer.Metrics, ) (MetricsProcessor, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg, nextConsumer) } @@ -154,7 +153,7 @@ func (f CreateLogsProcessorFunc) CreateLogsProcessor( nextConsumer consumer.Logs, ) (LogsProcessor, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg, nextConsumer) } diff --git a/component/receiver.go b/component/receiver.go index 58f47ce4a08..825c7b2a6eb 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -154,7 +153,7 @@ func (f CreateTracesReceiverFunc) CreateTracesReceiver( cfg config.Receiver, nextConsumer consumer.Traces) (TracesReceiver, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg, nextConsumer) } @@ -170,7 +169,7 @@ func (f CreateMetricsReceiverFunc) CreateMetricsReceiver( nextConsumer consumer.Metrics, ) (MetricsReceiver, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg, nextConsumer) } @@ -186,7 +185,7 @@ func (f CreateLogsReceiverFunc) CreateLogsReceiver( nextConsumer consumer.Logs, ) (LogsReceiver, error) { if f == nil { - return nil, componenterror.ErrDataTypeIsNotSupported + return nil, ErrDataTypeIsNotSupported } return f(ctx, set, cfg, nextConsumer) } diff --git a/processor/processorhelper/logs.go b/processor/processorhelper/logs.go index 8520df99820..fd1c8d82229 100644 --- a/processor/processorhelper/logs.go +++ b/processor/processorhelper/logs.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/plog" @@ -50,7 +49,7 @@ func NewLogsProcessor( } if nextConsumer == nil { - return nil, componenterror.ErrNilNextConsumer + return nil, component.ErrNilNextConsumer } eventOptions := spanAttributes(cfg.ID()) diff --git a/processor/processorhelper/logs_test.go b/processor/processorhelper/logs_test.go index 7a8d56786ca..2214c1c115e 100644 --- a/processor/processorhelper/logs_test.go +++ b/processor/processorhelper/logs_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" @@ -61,7 +60,7 @@ func TestNewLogsProcessor_NilRequiredFields(t *testing.T) { assert.Error(t, err) _, err = NewLogsProcessor(&testLogsCfg, nil, newTestLProcessor(nil)) - assert.Equal(t, componenterror.ErrNilNextConsumer, err) + assert.Equal(t, component.ErrNilNextConsumer, err) } func TestNewLogsProcessor_ProcessLogError(t *testing.T) { diff --git a/processor/processorhelper/metrics.go b/processor/processorhelper/metrics.go index 30316debbe2..56e85a8188f 100644 --- a/processor/processorhelper/metrics.go +++ b/processor/processorhelper/metrics.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/pmetric" @@ -50,7 +49,7 @@ func NewMetricsProcessor( } if nextConsumer == nil { - return nil, componenterror.ErrNilNextConsumer + return nil, component.ErrNilNextConsumer } eventOptions := spanAttributes(cfg.ID()) diff --git a/processor/processorhelper/metrics_test.go b/processor/processorhelper/metrics_test.go index a95c8015832..e86beb5d3e4 100644 --- a/processor/processorhelper/metrics_test.go +++ b/processor/processorhelper/metrics_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" @@ -61,7 +60,7 @@ func TestNewMetricsProcessor_NilRequiredFields(t *testing.T) { assert.Error(t, err) _, err = NewMetricsProcessor(&testMetricsCfg, nil, newTestMProcessor(nil)) - assert.Equal(t, componenterror.ErrNilNextConsumer, err) + assert.Equal(t, component.ErrNilNextConsumer, err) } func TestNewMetricsProcessor_ProcessMetricsError(t *testing.T) { diff --git a/processor/processorhelper/traces.go b/processor/processorhelper/traces.go index 2d7c2e953aa..43e0d4faaa0 100644 --- a/processor/processorhelper/traces.go +++ b/processor/processorhelper/traces.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/ptrace" @@ -50,7 +49,7 @@ func NewTracesProcessor( } if nextConsumer == nil { - return nil, componenterror.ErrNilNextConsumer + return nil, component.ErrNilNextConsumer } eventOptions := spanAttributes(cfg.ID()) diff --git a/processor/processorhelper/traces_test.go b/processor/processorhelper/traces_test.go index 3ece81ffe91..ff5e3bd8d1c 100644 --- a/processor/processorhelper/traces_test.go +++ b/processor/processorhelper/traces_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" @@ -61,7 +60,7 @@ func TestNewTracesProcessor_NilRequiredFields(t *testing.T) { assert.Error(t, err) _, err = NewTracesProcessor(&testTracesCfg, nil, newTestTProcessor(nil)) - assert.Equal(t, componenterror.ErrNilNextConsumer, err) + assert.Equal(t, component.ErrNilNextConsumer, err) } func TestNewTracesProcessor_ProcessTraceError(t *testing.T) { diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 905d1ab1d6b..0156cb2e106 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -25,7 +25,6 @@ import ( "google.golang.org/grpc" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/consumer" @@ -174,7 +173,7 @@ func (r *otlpReceiver) Shutdown(ctx context.Context) error { func (r *otlpReceiver) registerTraceConsumer(tc consumer.Traces) error { if tc == nil { - return componenterror.ErrNilNextConsumer + return component.ErrNilNextConsumer } r.traceReceiver = trace.New(r.cfg.ID(), tc, r.settings) if r.httpMux != nil { @@ -198,7 +197,7 @@ func (r *otlpReceiver) registerTraceConsumer(tc consumer.Traces) error { func (r *otlpReceiver) registerMetricsConsumer(mc consumer.Metrics) error { if mc == nil { - return componenterror.ErrNilNextConsumer + return component.ErrNilNextConsumer } r.metricsReceiver = metrics.New(r.cfg.ID(), mc, r.settings) if r.httpMux != nil { @@ -222,7 +221,7 @@ func (r *otlpReceiver) registerMetricsConsumer(mc consumer.Metrics) error { func (r *otlpReceiver) registerLogsConsumer(lc consumer.Logs) error { if lc == nil { - return componenterror.ErrNilNextConsumer + return component.ErrNilNextConsumer } r.logReceiver = logs.New(r.cfg.ID(), lc, r.settings) if r.httpMux != nil { diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index 5a5596f4605..c2c63a329df 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -23,7 +23,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/obsreport" @@ -97,7 +96,7 @@ func NewScraperControllerReceiver( options ...ScraperControllerOption, ) (component.Receiver, error) { if nextConsumer == nil { - return nil, componenterror.ErrNilNextConsumer + return nil, component.ErrNilNextConsumer } if cfg.CollectionInterval <= 0 { diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index fc5ee174e60..ef88029ca0c 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -107,7 +107,7 @@ func TestScrapeController(t *testing.T) { name: "AddMetricsScrapers_NilNextConsumerError", scrapers: 2, nilNextConsumer: true, - expectedNewErr: "nil nextConsumer", + expectedNewErr: "nil next Consumer", }, { name: "AddMetricsScrapersWithCollectionInterval_InvalidCollectionIntervalError", diff --git a/service/internal/builder/exporters_builder.go b/service/internal/builder/exporters_builder.go index cbfcd1663f6..9de7b4437a9 100644 --- a/service/internal/builder/exporters_builder.go +++ b/service/internal/builder/exporters_builder.go @@ -23,7 +23,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/service/internal/components" ) @@ -238,7 +237,7 @@ func buildExporter( } if err != nil { - if errors.Is(err, componenterror.ErrDataTypeIsNotSupported) { + if errors.Is(err, component.ErrDataTypeIsNotSupported) { // Could not create because this exporter does not support this data type. return nil, exporterTypeMismatchErr(cfg, pipelineID, dataType) } diff --git a/service/internal/builder/receivers_builder.go b/service/internal/builder/receivers_builder.go index f987a11e738..f73d2be3e48 100644 --- a/service/internal/builder/receivers_builder.go +++ b/service/internal/builder/receivers_builder.go @@ -23,7 +23,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/service/internal/components" @@ -191,11 +190,11 @@ func attachReceiverToPipelines( createdReceiver, err = factory.CreateLogsReceiver(ctx, set, cfg, junction) default: - err = componenterror.ErrDataTypeIsNotSupported + err = component.ErrDataTypeIsNotSupported } if err != nil { - if errors.Is(err, componenterror.ErrDataTypeIsNotSupported) { + if errors.Is(err, component.ErrDataTypeIsNotSupported) { return fmt.Errorf( "receiver %v does not support %s but it was used in a %s pipeline", id, dataType, dataType)