diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ef3285dd46..a1225dc05d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,14 @@ ## Unreleased ### 🛑 Breaking changes 🛑 + +- Replace `processorhelper.New[Traces|Metrics|Logs]Exporter` with `processorhelper.New[Traces|Metrics|Logs]ProcessorWithCreateSettings` definition (#5915) - Replace `exporterhelper.New[Traces|Metrics|Logs]Exporter` with `exporterhelper.New[Traces|Metrics|Logs]ExporterWithContext` definition (#5914) ### 🚩 Deprecations 🚩 +- Deprecate `processorhelper.New[Traces|Metrics|Logs]ProcessorWithCreateSettings` in favor of `processorhelper.New[Traces|Metrics|Logs]Exporter` (#5915) - Deprecates `LogRecord.Flags()` and `LogRecord.SetFlags()` in favor of `LogRecord.FlagsStruct()`. (#5866) - Deprecate `exporterhelper.New[Traces|Metrics|Logs]ExporterWithContext` in favor of `exporterhelper.New[Traces|Metrics|Logs]Exporter` (#5914) diff --git a/processor/memorylimiterprocessor/factory.go b/processor/memorylimiterprocessor/factory.go index ec8c95f4792b..31de08cd094e 100644 --- a/processor/memorylimiterprocessor/factory.go +++ b/processor/memorylimiterprocessor/factory.go @@ -69,7 +69,7 @@ func (f *factory) createTracesProcessor( if err != nil { return nil, err } - return processorhelper.NewTracesProcessorWithCreateSettings(ctx, set, cfg, nextConsumer, + return processorhelper.NewTracesProcessor(ctx, set, cfg, nextConsumer, memLimiter.processTraces, processorhelper.WithCapabilities(processorCapabilities), processorhelper.WithStart(memLimiter.start), @@ -86,7 +86,7 @@ func (f *factory) createMetricsProcessor( if err != nil { return nil, err } - return processorhelper.NewMetricsProcessorWithCreateSettings(ctx, set, cfg, nextConsumer, + return processorhelper.NewMetricsProcessor(ctx, set, cfg, nextConsumer, memLimiter.processMetrics, processorhelper.WithCapabilities(processorCapabilities), processorhelper.WithStart(memLimiter.start), @@ -103,7 +103,7 @@ func (f *factory) createLogsProcessor( if err != nil { return nil, err } - return processorhelper.NewLogsProcessorWithCreateSettings(ctx, set, cfg, nextConsumer, + return processorhelper.NewLogsProcessor(ctx, set, cfg, nextConsumer, memLimiter.processLogs, processorhelper.WithCapabilities(processorCapabilities), processorhelper.WithStart(memLimiter.start), diff --git a/processor/memorylimiterprocessor/memorylimiter_test.go b/processor/memorylimiterprocessor/memorylimiter_test.go index b23d1e9b9ac4..181193c02f5e 100644 --- a/processor/memorylimiterprocessor/memorylimiter_test.go +++ b/processor/memorylimiterprocessor/memorylimiter_test.go @@ -119,7 +119,7 @@ func TestMetricsMemoryPressureResponse(t *testing.T) { obsrep: newObsReport(), logger: zap.NewNop(), } - mp, err := processorhelper.NewMetricsProcessorWithCreateSettings( + mp, err := processorhelper.NewMetricsProcessor( context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ @@ -190,7 +190,7 @@ func TestTraceMemoryPressureResponse(t *testing.T) { obsrep: newObsReport(), logger: zap.NewNop(), } - tp, err := processorhelper.NewTracesProcessorWithCreateSettings( + tp, err := processorhelper.NewTracesProcessor( context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ @@ -261,7 +261,7 @@ func TestLogMemoryPressureResponse(t *testing.T) { obsrep: newObsReport(), logger: zap.NewNop(), } - lp, err := processorhelper.NewLogsProcessorWithCreateSettings( + lp, err := processorhelper.NewLogsProcessor( context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ diff --git a/processor/processorhelper/logs.go b/processor/processorhelper/logs.go index 1f2040177791..6e8f3834890a 100644 --- a/processor/processorhelper/logs.go +++ b/processor/processorhelper/logs.go @@ -36,18 +36,20 @@ type logProcessor struct { consumer.Logs } -// Deprecated: [v0.58.0] use version with NewLogsProcessorWithCreateSettings. -func NewLogsProcessor( +// Deprecated: [v0.58.0] use version with NewLogsProcessor. +func NewLogsProcessorWithCreateSettings( + ctx context.Context, + set component.ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Logs, logsFunc ProcessLogsFunc, options ...Option, ) (component.LogsProcessor, error) { - return NewLogsProcessorWithCreateSettings(context.Background(), component.ProcessorCreateSettings{}, cfg, nextConsumer, logsFunc, options...) + return NewLogsProcessor(ctx, set, cfg, nextConsumer, logsFunc, options...) } -// NewLogsProcessorWithCreateSettings creates a LogsProcessor that ensure context propagation and the right tags are set. -func NewLogsProcessorWithCreateSettings( +// NewLogsProcessor creates a component.LogsProcessor that ensure context propagation and the right tags are set. +func NewLogsProcessor( _ context.Context, _ component.ProcessorCreateSettings, cfg config.Processor, diff --git a/processor/processorhelper/logs_test.go b/processor/processorhelper/logs_test.go index fb6a45655c0b..e68431e14f4f 100644 --- a/processor/processorhelper/logs_test.go +++ b/processor/processorhelper/logs_test.go @@ -33,7 +33,7 @@ import ( var testLogsCfg = config.NewProcessorSettings(config.NewComponentID("test")) func TestNewLogsProcessor(t *testing.T) { - lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil)) + lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil)) require.NoError(t, err) assert.True(t, lp.Capabilities().MutatesData) @@ -44,7 +44,7 @@ func TestNewLogsProcessor(t *testing.T) { func TestNewLogsProcessor_WithOptions(t *testing.T) { want := errors.New("my_error") - lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil), + lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil), WithStart(func(context.Context, component.Host) error { return want }), WithShutdown(func(context.Context) error { return want }), WithCapabilities(consumer.Capabilities{MutatesData: false})) @@ -56,22 +56,22 @@ func TestNewLogsProcessor_WithOptions(t *testing.T) { } func TestNewLogsProcessor_NilRequiredFields(t *testing.T) { - _, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), nil) + _, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), nil) assert.Error(t, err) - _, err = NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, nil, newTestLProcessor(nil)) + _, err = NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, nil, newTestLProcessor(nil)) assert.Equal(t, component.ErrNilNextConsumer, err) } func TestNewLogsProcessor_ProcessLogError(t *testing.T) { want := errors.New("my_error") - lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(want)) + lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(want)) require.NoError(t, err) assert.Equal(t, want, lp.ConsumeLogs(context.Background(), plog.NewLogs())) } func TestNewLogsProcessor_ProcessLogsErrSkipProcessingData(t *testing.T) { - lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(ErrSkipProcessingData)) + lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(ErrSkipProcessingData)) require.NoError(t, err) assert.Equal(t, nil, lp.ConsumeLogs(context.Background(), plog.NewLogs())) } diff --git a/processor/processorhelper/metrics.go b/processor/processorhelper/metrics.go index 24f493f6c0b3..26d663844801 100644 --- a/processor/processorhelper/metrics.go +++ b/processor/processorhelper/metrics.go @@ -36,18 +36,20 @@ type metricsProcessor struct { consumer.Metrics } -// Deprecated: [v0.58.0] use version with NewMetricsProcessorWithCreateSettings. -func NewMetricsProcessor( +// Deprecated: [v0.58.0] use version with NewMetricsProcessor. +func NewMetricsProcessorWithCreateSettings( + ctx context.Context, + set component.ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Metrics, metricsFunc ProcessMetricsFunc, options ...Option, ) (component.MetricsProcessor, error) { - return NewMetricsProcessorWithCreateSettings(context.Background(), component.ProcessorCreateSettings{}, cfg, nextConsumer, metricsFunc, options...) + return NewMetricsProcessor(ctx, set, cfg, nextConsumer, metricsFunc, options...) } -// NewMetricsProcessorWithCreateSettings creates a MetricsProcessor that ensure context propagation and the right tags are set. -func NewMetricsProcessorWithCreateSettings( +// NewMetricsProcessor creates a component.MetricsProcessor that ensure context propagation and the right tags are set. +func NewMetricsProcessor( _ context.Context, _ component.ProcessorCreateSettings, cfg config.Processor, diff --git a/processor/processorhelper/metrics_test.go b/processor/processorhelper/metrics_test.go index 4c274434dfeb..363ce273414c 100644 --- a/processor/processorhelper/metrics_test.go +++ b/processor/processorhelper/metrics_test.go @@ -33,7 +33,7 @@ import ( var testMetricsCfg = config.NewProcessorSettings(config.NewComponentID("test")) func TestNewMetricsProcessor(t *testing.T) { - mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil)) + mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil)) require.NoError(t, err) assert.True(t, mp.Capabilities().MutatesData) @@ -44,7 +44,7 @@ func TestNewMetricsProcessor(t *testing.T) { func TestNewMetricsProcessor_WithOptions(t *testing.T) { want := errors.New("my_error") - mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil), + mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil), WithStart(func(context.Context, component.Host) error { return want }), WithShutdown(func(context.Context) error { return want }), WithCapabilities(consumer.Capabilities{MutatesData: false})) @@ -56,22 +56,22 @@ func TestNewMetricsProcessor_WithOptions(t *testing.T) { } func TestNewMetricsProcessor_NilRequiredFields(t *testing.T) { - _, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), nil) + _, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), nil) assert.Error(t, err) - _, err = NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, nil, newTestMProcessor(nil)) + _, err = NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, nil, newTestMProcessor(nil)) assert.Equal(t, component.ErrNilNextConsumer, err) } func TestNewMetricsProcessor_ProcessMetricsError(t *testing.T) { want := errors.New("my_error") - mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(want)) + mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(want)) require.NoError(t, err) assert.Equal(t, want, mp.ConsumeMetrics(context.Background(), pmetric.NewMetrics())) } func TestNewMetricsProcessor_ProcessMetricsErrSkipProcessingData(t *testing.T) { - mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(ErrSkipProcessingData)) + mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(ErrSkipProcessingData)) require.NoError(t, err) assert.Equal(t, nil, mp.ConsumeMetrics(context.Background(), pmetric.NewMetrics())) } diff --git a/processor/processorhelper/traces.go b/processor/processorhelper/traces.go index 55f80a15d66f..578b13211bf9 100644 --- a/processor/processorhelper/traces.go +++ b/processor/processorhelper/traces.go @@ -36,18 +36,20 @@ type tracesProcessor struct { consumer.Traces } -// Deprecated: [v0.58.0] use version with NewTracesProcessorWithCreateSettings. -func NewTracesProcessor( +// Deprecated: [v0.58.0] use version with NewTracesProcessor. +func NewTracesProcessorWithCreateSettings( + ctx context.Context, + set component.ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Traces, tracesFunc ProcessTracesFunc, options ...Option, ) (component.TracesProcessor, error) { - return NewTracesProcessorWithCreateSettings(context.Background(), component.ProcessorCreateSettings{}, cfg, nextConsumer, tracesFunc, options...) + return NewTracesProcessor(ctx, set, cfg, nextConsumer, tracesFunc, options...) } -// NewTracesProcessorWithCreateSettings creates a TracesProcessor that ensure context propagation and the right tags are set. -func NewTracesProcessorWithCreateSettings( +// NewTracesProcessor creates a component.TracesProcessor that ensure context propagation and the right tags are set. +func NewTracesProcessor( _ context.Context, _ component.ProcessorCreateSettings, cfg config.Processor, diff --git a/processor/processorhelper/traces_test.go b/processor/processorhelper/traces_test.go index 54adcfcab08a..df5808c13a10 100644 --- a/processor/processorhelper/traces_test.go +++ b/processor/processorhelper/traces_test.go @@ -33,7 +33,7 @@ import ( var testTracesCfg = config.NewProcessorSettings(config.NewComponentID("test")) func TestNewTracesProcessor(t *testing.T) { - tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil)) + tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil)) require.NoError(t, err) assert.True(t, tp.Capabilities().MutatesData) @@ -44,7 +44,7 @@ func TestNewTracesProcessor(t *testing.T) { func TestNewTracesProcessor_WithOptions(t *testing.T) { want := errors.New("my_error") - tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil), + tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil), WithStart(func(context.Context, component.Host) error { return want }), WithShutdown(func(context.Context) error { return want }), WithCapabilities(consumer.Capabilities{MutatesData: false})) @@ -56,22 +56,22 @@ func TestNewTracesProcessor_WithOptions(t *testing.T) { } func TestNewTracesProcessor_NilRequiredFields(t *testing.T) { - _, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), nil) + _, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), nil) assert.Error(t, err) - _, err = NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, nil, newTestTProcessor(nil)) + _, err = NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, nil, newTestTProcessor(nil)) assert.Equal(t, component.ErrNilNextConsumer, err) } func TestNewTracesProcessor_ProcessTraceError(t *testing.T) { want := errors.New("my_error") - tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(want)) + tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(want)) require.NoError(t, err) assert.Equal(t, want, tp.ConsumeTraces(context.Background(), ptrace.NewTraces())) } func TestNewTracesProcessor_ProcessTracesErrSkipProcessingData(t *testing.T) { - tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(ErrSkipProcessingData)) + tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(ErrSkipProcessingData)) require.NoError(t, err) assert.Equal(t, nil, tp.ConsumeTraces(context.Background(), ptrace.NewTraces())) }