diff --git a/.chloggen/deprecatecompexp.yaml b/.chloggen/deprecatecompexp.yaml new file mode 100755 index 00000000000..4e4e099243e --- /dev/null +++ b/.chloggen/deprecatecompexp.yaml @@ -0,0 +1,25 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: component + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate Exporter related types/funcs from component package in favor of exporter package. + +# One or more tracking issues or pull requests related to the change +issues: [6578] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: |- + - `component.ExporterCreateSettings` -> `exporter.CreateSettings` + - `component.CreateTracesExporterFunc` -> `exporter.CreateTracesFunc` + - `component.CreateMetricsExporterFunc` -> `exporter.CreateMetricsFunc` + - `component.CreateLogsExporterFunc` -> `exporter.CreateLogsFunc` + - `component.ExporterFactory` -> `exporter.Factory` + - `component.NewExporterFactory` -> `exporter.NewFactory` + - `component.MakeExporterFactoryMap` -> `exporter.MakeFactoryMap` + - `componenttest.NewNopExporterCreateSettings` -> `exportertest.NewNopCreateSettings` + - `componenttest.NewNopExporterFactory` -> `exportertest.NewNopFactory` \ No newline at end of file diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index c1f54017047..ac038d4130f 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -20,11 +20,12 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/exporter" ) // NewNopExporterCreateSettings returns a new nop settings for Create*Exporter functions. -func NewNopExporterCreateSettings() component.ExporterCreateSettings { - return component.ExporterCreateSettings{ +func NewNopExporterCreateSettings() exporter.CreateSettings { + return exporter.CreateSettings{ TelemetrySettings: NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -34,30 +35,30 @@ type nopExporterConfig struct { config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } -// NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters. -func NewNopExporterFactory() component.ExporterFactory { - return component.NewExporterFactory( +// NewNopExporterFactory returns an exporter.Factory that constructs nop exporters. +func NewNopExporterFactory() exporter.Factory { + return exporter.NewFactory( "nop", func() component.Config { return &nopExporterConfig{ ExporterSettings: config.NewExporterSettings(component.NewID("nop")), } }, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelStable), + exporter.WithTraces(createTracesExporter, component.StabilityLevelStable), + exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable), + exporter.WithLogs(createLogsExporter, component.StabilityLevelStable), ) } -func createTracesExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) { +func createTracesExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Traces, error) { return nopExporterInstance, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Metrics, error) { return nopExporterInstance, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) { +func createLogsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Logs, error) { return nopExporterInstance, nil } diff --git a/component/componenttest/nop_factories.go b/component/componenttest/nop_factories.go index fc32472a05c..ae1f92831e5 100644 --- a/component/componenttest/nop_factories.go +++ b/component/componenttest/nop_factories.go @@ -32,6 +32,7 @@ func NopFactories() (component.Factories, error) { return component.Factories{}, err } + //nolint:staticcheck if factories.Exporters, err = component.MakeExporterFactoryMap(NewNopExporterFactory()); err != nil { return component.Factories{}, err } diff --git a/component/exporter.go b/component/exporter.go index 3f2044cc5ea..88c2102f416 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -26,25 +26,25 @@ type ExporterConfig = Config // Deprecated: [v0.67.0] use UnmarshalConfig. var UnmarshalExporterConfig = UnmarshalConfig -// TracesExporter is an Exporter that can consume traces. +// Deprecated: [v0.67.0] use exporter.Traces. type TracesExporter interface { Component consumer.Traces } -// MetricsExporter is an Exporter that can consume metrics. +// Deprecated: [v0.67.0] use exporter.Metrics. type MetricsExporter interface { Component consumer.Metrics } -// LogsExporter is an Exporter that can consume logs. +// Deprecated: [v0.67.0] use exporter.Logs. type LogsExporter interface { Component consumer.Logs } -// ExporterCreateSettings configures Exporter creators. +// Deprecated: [v0.67.0] use exporter.CreateSettings. type ExporterCreateSettings struct { // ID returns the ID of the component that will be created. ID ID @@ -55,10 +55,7 @@ type ExporterCreateSettings struct { BuildInfo BuildInfo } -// ExporterFactory is factory interface for exporters. -// -// This interface cannot be directly implemented. Implementations must -// use the NewExporterFactory to implement it. +// Deprecated: [v0.67.0] use exporter.Factory. type ExporterFactory interface { Factory @@ -87,7 +84,7 @@ type ExporterFactory interface { LogsExporterStability() StabilityLevel } -// ExporterFactoryOption apply changes to ExporterOptions. +// Deprecated: [v0.67.0] use exporter.FactoryOption. type ExporterFactoryOption interface { // applyExporterFactoryOption applies the option. applyExporterFactoryOption(o *exporterFactory) @@ -105,7 +102,7 @@ func (f exporterFactoryOptionFunc) applyExporterFactoryOption(o *exporterFactory // Deprecated: [v0.67.0] use CreateDefaultConfigFunc. type ExporterCreateDefaultConfigFunc = CreateDefaultConfigFunc -// CreateTracesExporterFunc is the equivalent of ExporterFactory.CreateTracesExporter(). +// Deprecated: [v0.67.0] use exporter.CreateTracesFunc. type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, Config) (TracesExporter, error) // CreateTracesExporter implements ExporterFactory.CreateTracesExporter(). @@ -116,7 +113,7 @@ func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set return f(ctx, set, cfg) } -// CreateMetricsExporterFunc is the equivalent of ExporterFactory.CreateMetricsExporter(). +// Deprecated: [v0.67.0] use exporter.CreateMetricsFunc. type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, Config) (MetricsExporter, error) // CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter(). @@ -127,7 +124,7 @@ func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, se return f(ctx, set, cfg) } -// CreateLogsExporterFunc is the equivalent of ExporterFactory.CreateLogsExporter(). +// Deprecated: [v0.67.0] use exporter.CreateLogsFunc. type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, Config) (LogsExporter, error) // CreateLogsExporter implements ExporterFactory.CreateLogsExporter(). @@ -160,7 +157,7 @@ func (e exporterFactory) LogsExporterStability() StabilityLevel { return e.logsStabilityLevel } -// WithTracesExporter overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level. +// Deprecated: [v0.67.0] use exporter.WithTraces. func WithTracesExporter(createTracesExporter CreateTracesExporterFunc, sl StabilityLevel) ExporterFactoryOption { return exporterFactoryOptionFunc(func(o *exporterFactory) { o.tracesStabilityLevel = sl @@ -168,7 +165,7 @@ func WithTracesExporter(createTracesExporter CreateTracesExporterFunc, sl Stabil }) } -// WithMetricsExporter overrides the default "error not supported" implementation for CreateMetricsExporter and the default "undefined" stability level. +// Deprecated: [v0.67.0] use exporter.WithMetrics. func WithMetricsExporter(createMetricsExporter CreateMetricsExporterFunc, sl StabilityLevel) ExporterFactoryOption { return exporterFactoryOptionFunc(func(o *exporterFactory) { o.metricsStabilityLevel = sl @@ -176,7 +173,7 @@ func WithMetricsExporter(createMetricsExporter CreateMetricsExporterFunc, sl Sta }) } -// WithLogsExporter overrides the default "error not supported" implementation for CreateLogsExporter and the default "undefined" stability level. +// Deprecated: [v0.67.0] use exporter.WithLogs. func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLevel) ExporterFactoryOption { return exporterFactoryOptionFunc(func(o *exporterFactory) { o.logsStabilityLevel = sl @@ -184,7 +181,7 @@ func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLev }) } -// NewExporterFactory returns a ExporterFactory. +// Deprecated: [v0.67.0] use exporter.NewFactory. func NewExporterFactory(cfgType Type, createDefaultConfig CreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory { f := &exporterFactory{ baseFactory: baseFactory{ diff --git a/component/exporter_test.go b/component/exporter_test.go deleted file mode 100644 index 5bc6a002754..00000000000 --- a/component/exporter_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright The 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. - -// TODO: Move tests back to component package after config.*Settings are removed. - -package component_test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" -) - -func TestNewExporterFactory(t *testing.T) { - const typeStr = "test" - defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) - factory := component.NewExporterFactory( - typeStr, - func() component.Config { return &defaultCfg }) - assert.EqualValues(t, typeStr, factory.Type()) - assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - _, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) - assert.Error(t, err) - _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) - assert.Error(t, err) - _, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) - assert.Error(t, err) -} - -func TestNewExporterFactory_WithOptions(t *testing.T) { - const typeStr = "test" - defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) - factory := component.NewExporterFactory( - typeStr, - func() component.Config { return &defaultCfg }, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelDevelopment), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelAlpha), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelDeprecated)) - assert.EqualValues(t, typeStr, factory.Type()) - assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - - assert.Equal(t, component.StabilityLevelDevelopment, factory.TracesExporterStability()) - _, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) - assert.NoError(t, err) - - assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsExporterStability()) - _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) - assert.NoError(t, err) - - assert.Equal(t, component.StabilityLevelDeprecated, factory.LogsExporterStability()) - _, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) - assert.NoError(t, err) -} - -func createTracesExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) { - return nil, nil -} - -func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) { - return nil, nil -} - -func createLogsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) { - return nil, nil -} diff --git a/component/factories.go b/component/factories.go index fd1902b572d..21b031e602a 100644 --- a/component/factories.go +++ b/component/factories.go @@ -62,9 +62,7 @@ func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[Type]ProcessorF return fMap, nil } -// MakeExporterFactoryMap takes a list of exporter factories and returns a map -// with factory type as keys. It returns a non-nil error when more than one factories -// have the same type. +// Deprecated: [v0.67.0] use exporter.MakeFactoryMap func MakeExporterFactoryMap(factories ...ExporterFactory) (map[Type]ExporterFactory, error) { fMap := map[Type]ExporterFactory{} for _, f := range factories { diff --git a/component/factories_test.go b/component/factories_test.go index 40ecdb3cba0..c3a6d8f5f33 100644 --- a/component/factories_test.go +++ b/component/factories_test.go @@ -95,41 +95,3 @@ func TestMakeProcessorFactoryMap(t *testing.T) { }) } } - -func TestMakeExporterFactoryMap(t *testing.T) { - type testCase struct { - name string - in []ExporterFactory - out map[Type]ExporterFactory - } - - p1 := NewExporterFactory("p1", nil) - p2 := NewExporterFactory("p2", nil) - testCases := []testCase{ - { - name: "different names", - in: []ExporterFactory{p1, p2}, - out: map[Type]ExporterFactory{ - p1.Type(): p1, - p2.Type(): p2, - }, - }, - { - name: "same name", - in: []ExporterFactory{p1, p2, NewExporterFactory("p1", nil)}, - }, - } - - for i := range testCases { - tt := testCases[i] - t.Run(tt.name, func(t *testing.T) { - out, err := MakeExporterFactoryMap(tt.in...) - if tt.out == nil { - assert.Error(t, err) - return - } - assert.NoError(t, err) - assert.Equal(t, tt.out, out) - }) - } -} diff --git a/exporter/exporter.go b/exporter/exporter.go new file mode 100644 index 00000000000..7267c45ad35 --- /dev/null +++ b/exporter/exporter.go @@ -0,0 +1,66 @@ +// Copyright The 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 exporter // import "go.opentelemetry.io/collector/exporter" + +import ( + "go.opentelemetry.io/collector/component" +) + +// Traces is an exporter that can consume traces. +type Traces = component.TracesExporter //nolint:staticcheck + +// Metrics is an exporter that can consume metrics. +type Metrics = component.MetricsExporter //nolint:staticcheck + +// Logs is an exporter that can consume logs. +type Logs = component.LogsExporter //nolint:staticcheck + +// CreateSettings configures exporter creators. +type CreateSettings = component.ExporterCreateSettings //nolint:staticcheck + +// Factory is factory interface for exporters. +// +// This interface cannot be directly implemented. Implementations must +// use the NewFactory to implement it. +type Factory = component.ExporterFactory //nolint:staticcheck + +// FactoryOption apply changes to Factory. +type FactoryOption = component.ExporterFactoryOption //nolint:staticcheck + +// CreateTracesFunc is the equivalent of Factory.CreateTraces. +type CreateTracesFunc = component.CreateTracesExporterFunc //nolint:staticcheck + +// CreateMetricsFunc is the equivalent of Factory.CreateMetrics. +type CreateMetricsFunc = component.CreateMetricsExporterFunc //nolint:staticcheck + +// CreateLogsFunc is the equivalent of Factory.CreateLogs. +type CreateLogsFunc = component.CreateLogsExporterFunc //nolint:staticcheck + +// WithTraces overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level. +var WithTraces = component.WithTracesExporter //nolint:staticcheck + +// WithMetrics overrides the default "error not supported" implementation for CreateMetricsExporter and the default "undefined" stability level. +var WithMetrics = component.WithMetricsExporter //nolint:staticcheck + +// WithLogs overrides the default "error not supported" implementation for CreateLogsExporter and the default "undefined" stability level. +var WithLogs = component.WithLogsExporter //nolint:staticcheck + +// NewFactory returns a Factory. +var NewFactory = component.NewExporterFactory //nolint:staticcheck + +// MakeFactoryMap takes a list of exporter factories and returns a map +// with factory type as keys. It returns a non-nil error when more than one factories +// have the same type. +var MakeFactoryMap = component.MakeExporterFactoryMap //nolint:staticcheck diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go new file mode 100644 index 00000000000..8890943cf11 --- /dev/null +++ b/exporter/exporter_test.go @@ -0,0 +1,118 @@ +// Copyright The 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. + +// TODO: Move tests back to component package after config.*Settings are removed. + +package exporter + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" +) + +func TestNewFactory(t *testing.T) { + const typeStr = "test" + defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) + factory := NewFactory( + typeStr, + func() component.Config { return &defaultCfg }) + assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) + _, err := factory.CreateTracesExporter(context.Background(), CreateSettings{}, &defaultCfg) + assert.Error(t, err) + _, err = factory.CreateMetricsExporter(context.Background(), CreateSettings{}, &defaultCfg) + assert.Error(t, err) + _, err = factory.CreateLogsExporter(context.Background(), CreateSettings{}, &defaultCfg) + assert.Error(t, err) +} + +func TestNewFactoryWithOptions(t *testing.T) { + const typeStr = "test" + defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) + factory := NewFactory( + typeStr, + func() component.Config { return &defaultCfg }, + WithTraces(createTracesExporter, component.StabilityLevelDevelopment), + WithMetrics(createMetricsExporter, component.StabilityLevelAlpha), + WithLogs(createLogsExporter, component.StabilityLevelDeprecated)) + assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) + + assert.Equal(t, component.StabilityLevelDevelopment, factory.TracesExporterStability()) + _, err := factory.CreateTracesExporter(context.Background(), CreateSettings{}, &defaultCfg) + assert.NoError(t, err) + + assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsExporterStability()) + _, err = factory.CreateMetricsExporter(context.Background(), CreateSettings{}, &defaultCfg) + assert.NoError(t, err) + + assert.Equal(t, component.StabilityLevelDeprecated, factory.LogsExporterStability()) + _, err = factory.CreateLogsExporter(context.Background(), CreateSettings{}, &defaultCfg) + assert.NoError(t, err) +} + +func TestMakeFactoryMap(t *testing.T) { + type testCase struct { + name string + in []Factory + out map[component.Type]Factory + } + + p1 := NewFactory("p1", nil) + p2 := NewFactory("p2", nil) + testCases := []testCase{ + { + name: "different names", + in: []Factory{p1, p2}, + out: map[component.Type]Factory{ + p1.Type(): p1, + p2.Type(): p2, + }, + }, + { + name: "same name", + in: []Factory{p1, p2, NewFactory("p1", nil)}, + }, + } + + for i := range testCases { + tt := testCases[i] + t.Run(tt.name, func(t *testing.T) { + out, err := MakeFactoryMap(tt.in...) + if tt.out == nil { + assert.Error(t, err) + return + } + assert.NoError(t, err) + assert.Equal(t, tt.out, out) + }) + } +} + +func createTracesExporter(context.Context, CreateSettings, component.Config) (Traces, error) { + return nil, nil +} + +func createMetricsExporter(context.Context, CreateSettings, component.Config) (Metrics, error) { + return nil, nil +} + +func createLogsExporter(context.Context, CreateSettings, component.Config) (Logs, error) { + return nil, nil +} diff --git a/exporter/exporterhelper/common.go b/exporter/exporterhelper/common.go index 62db09f9927..aae998d0d32 100644 --- a/exporter/exporterhelper/common.go +++ b/exporter/exporterhelper/common.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/obsreport" ) @@ -155,7 +156,7 @@ type baseExporter struct { qrSender *queuedRetrySender } -func newBaseExporter(set component.ExporterCreateSettings, bs *baseSettings, signal component.DataType, reqUnmarshaler internal.RequestUnmarshaler) (*baseExporter, error) { +func newBaseExporter(set exporter.CreateSettings, bs *baseSettings, signal component.DataType, reqUnmarshaler internal.RequestUnmarshaler) (*baseExporter, error) { be := &baseExporter{} var err error diff --git a/exporter/exporterhelper/common_test.go b/exporter/exporterhelper/common_test.go index c719ed6b0bd..0937bf34815 100644 --- a/exporter/exporterhelper/common_test.go +++ b/exporter/exporterhelper/common_test.go @@ -26,13 +26,14 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/ptrace" ) var ( defaultID = component.NewID("test") - defaultSettings = func() component.ExporterCreateSettings { + defaultSettings = func() exporter.CreateSettings { set := componenttest.NewNopExporterCreateSettings() set.ID = defaultID return set diff --git a/exporter/exporterhelper/logs.go b/exporter/exporterhelper/logs.go index 7cb6287a72c..60770aab477 100644 --- a/exporter/exporterhelper/logs.go +++ b/exporter/exporterhelper/logs.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/plog" ) @@ -77,14 +78,14 @@ type logsExporter struct { consumer.Logs } -// NewLogsExporter creates a component.LogsExporter that records observability metrics and wraps every request with a Span. +// NewLogsExporter creates a exporter.Logs that records observability metrics and wraps every request with a Span. func NewLogsExporter( _ context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, pusher consumer.ConsumeLogsFunc, options ...Option, -) (component.LogsExporter, error) { +) (exporter.Logs, error) { if cfg == nil { return nil, errNilConfig } diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index f85e8307336..44148860fba 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -65,7 +66,7 @@ func TestLogsExporter_InvalidName(t *testing.T) { } func TestLogsExporter_NilLogger(t *testing.T) { - le, err := NewLogsExporter(context.Background(), component.ExporterCreateSettings{}, &fakeLogsExporterConfig, newPushLogsData(nil)) + le, err := NewLogsExporter(context.Background(), exporter.CreateSettings{}, &fakeLogsExporterConfig, newPushLogsData(nil)) require.Nil(t, le) require.Equal(t, errNilLogger, err) } @@ -212,7 +213,7 @@ func newPushLogsData(retError error) consumer.ConsumeLogsFunc { } } -func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTelemetry, le component.LogsExporter, wantError error) { +func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTelemetry, le exporter.Logs, wantError error) { ld := testdata.GenerateLogs(2) const numBatches = 7 for i := 0; i < numBatches; i++ { @@ -227,7 +228,7 @@ func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTele } } -func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le component.LogsExporter, numRequests int, wantError error) { +func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le exporter.Logs, numRequests int, wantError error) { ld := testdata.GenerateLogs(1) ctx, span := tracer.Start(context.Background(), fakeLogsParentSpanName) defer span.End() @@ -236,7 +237,7 @@ func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le component.LogsExp } } -func checkWrapSpanForLogsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le component.LogsExporter, wantError error, numLogRecords int64) { +func checkWrapSpanForLogsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.Logs, wantError error, numLogRecords int64) { const numRequests = 5 generateLogsTraffic(t, tracer, le, numRequests, wantError) diff --git a/exporter/exporterhelper/metrics.go b/exporter/exporterhelper/metrics.go index 4c1154ce524..aefa6586fce 100644 --- a/exporter/exporterhelper/metrics.go +++ b/exporter/exporterhelper/metrics.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -78,14 +79,14 @@ type metricsExporter struct { consumer.Metrics } -// NewMetricsExporter creates a component.MetricsExporter that records observability metrics and wraps every request with a Span. +// NewMetricsExporter creates a exporter.Metrics that records observability metrics and wraps every request with a Span. func NewMetricsExporter( _ context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, pusher consumer.ConsumeMetricsFunc, options ...Option, -) (component.MetricsExporter, error) { +) (exporter.Metrics, error) { if cfg == nil { return nil, errNilConfig } diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index 831ace6a150..83d091c32c2 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -64,7 +65,7 @@ func TestMetricsExporter_InvalidName(t *testing.T) { } func TestMetricsExporter_NilLogger(t *testing.T) { - me, err := NewMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &fakeMetricsExporterConfig, newPushMetricsData(nil)) + me, err := NewMetricsExporter(context.Background(), exporter.CreateSettings{}, &fakeMetricsExporterConfig, newPushMetricsData(nil)) require.Nil(t, me) require.Equal(t, errNilLogger, err) } @@ -213,7 +214,7 @@ func newPushMetricsData(retError error) consumer.ConsumeMetricsFunc { } } -func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestTelemetry, me component.MetricsExporter, wantError error) { +func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestTelemetry, me exporter.Metrics, wantError error) { md := testdata.GenerateMetrics(2) const numBatches = 7 for i := 0; i < numBatches; i++ { @@ -229,7 +230,7 @@ func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestT } } -func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me component.MetricsExporter, numRequests int, wantError error) { +func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me exporter.Metrics, numRequests int, wantError error) { md := testdata.GenerateMetrics(1) ctx, span := tracer.Start(context.Background(), fakeMetricsParentSpanName) defer span.End() @@ -238,7 +239,7 @@ func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me component.Metr } } -func checkWrapSpanForMetricsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, me component.MetricsExporter, wantError error, numMetricPoints int64) { +func checkWrapSpanForMetricsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, me exporter.Metrics, wantError error, numMetricPoints int64) { const numRequests = 5 generateMetricsTraffic(t, tracer, me, numRequests, wantError) diff --git a/exporter/exporterhelper/traces.go b/exporter/exporterhelper/traces.go index ea336d586f5..013787d2a94 100644 --- a/exporter/exporterhelper/traces.go +++ b/exporter/exporterhelper/traces.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/ptrace" ) @@ -78,14 +79,14 @@ type traceExporter struct { consumer.Traces } -// NewTracesExporter creates a component.TracesExporter that records observability metrics and wraps every request with a Span. +// NewTracesExporter creates a exporter.Traces that records observability metrics and wraps every request with a Span. func NewTracesExporter( _ context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, pusher consumer.ConsumeTracesFunc, options ...Option, -) (component.TracesExporter, error) { +) (exporter.Traces, error) { if cfg == nil { return nil, errNilConfig } diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index 8c3e3ecb4a9..46cad9ff7ca 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -60,7 +61,7 @@ func TestTracesExporter_InvalidName(t *testing.T) { } func TestTracesExporter_NilLogger(t *testing.T) { - te, err := NewTracesExporter(context.Background(), component.ExporterCreateSettings{}, &fakeTracesExporterConfig, newTraceDataPusher(nil)) + te, err := NewTracesExporter(context.Background(), exporter.CreateSettings{}, &fakeTracesExporterConfig, newTraceDataPusher(nil)) require.Nil(t, te) require.Equal(t, errNilLogger, err) } @@ -213,7 +214,7 @@ func newTraceDataPusher(retError error) consumer.ConsumeTracesFunc { } } -func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTelemetry, te component.TracesExporter, wantError error) { +func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTelemetry, te exporter.Traces, wantError error) { td := testdata.GenerateTraces(2) const numBatches = 7 for i := 0; i < numBatches; i++ { @@ -228,7 +229,7 @@ func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTe } } -func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te component.TracesExporter, numRequests int, wantError error) { +func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te exporter.Traces, numRequests int, wantError error) { td := ptrace.NewTraces() td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty() ctx, span := tracer.Start(context.Background(), fakeTraceParentSpanName) @@ -238,7 +239,7 @@ func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te component.Traces } } -func checkWrapSpanForTracesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, te component.TracesExporter, wantError error, numSpans int64) { +func checkWrapSpanForTracesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, te exporter.Traces, wantError error, numSpans int64) { const numRequests = 5 generateTraceTraffic(t, tracer, te, numRequests, wantError) diff --git a/exporter/exportertest/nop_exporter.go b/exporter/exportertest/nop_exporter.go new file mode 100644 index 00000000000..3a256b653bf --- /dev/null +++ b/exporter/exportertest/nop_exporter.go @@ -0,0 +1,25 @@ +// Copyright The 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 exportertest // import "go.opentelemetry.io/collector/exporter/exportertest" + +import ( + "go.opentelemetry.io/collector/component/componenttest" +) + +// NewNopCreateSettings returns a new nop settings for Create*Exporter functions. +var NewNopCreateSettings = componenttest.NewNopExporterCreateSettings + +// NewNopFactory returns an exporter.Factory that constructs nop exporters. +var NewNopFactory = componenttest.NewNopExporterFactory diff --git a/component/componenttest/nop_exporter_test.go b/exporter/exportertest/nop_exporter_test.go similarity index 69% rename from component/componenttest/nop_exporter_test.go rename to exporter/exportertest/nop_exporter_test.go index 19694f3dd4e..d0fa7aa4213 100644 --- a/component/componenttest/nop_exporter_test.go +++ b/exporter/exportertest/nop_exporter_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package componenttest +package exportertest import ( "context" @@ -22,34 +22,34 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" ) -func TestNewNopExporterFactory(t *testing.T) { - factory := NewNopExporterFactory() +func TestNewNopFactory(t *testing.T) { + factory := NewNopFactory() require.NotNil(t, factory) assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(component.NewID("nop"))}, cfg) + // assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(component.NewID("nop"))}, cfg) - traces, err := factory.CreateTracesExporter(context.Background(), NewNopExporterCreateSettings(), cfg) + traces, err := factory.CreateTracesExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), cfg) require.NoError(t, err) - assert.NoError(t, traces.Start(context.Background(), NewNopHost())) + assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, traces.ConsumeTraces(context.Background(), ptrace.NewTraces())) assert.NoError(t, traces.Shutdown(context.Background())) - metrics, err := factory.CreateMetricsExporter(context.Background(), NewNopExporterCreateSettings(), cfg) + metrics, err := factory.CreateMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), cfg) require.NoError(t, err) - assert.NoError(t, metrics.Start(context.Background(), NewNopHost())) + assert.NoError(t, metrics.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, metrics.ConsumeMetrics(context.Background(), pmetric.NewMetrics())) assert.NoError(t, metrics.Shutdown(context.Background())) - logs, err := factory.CreateLogsExporter(context.Background(), NewNopExporterCreateSettings(), cfg) + logs, err := factory.CreateLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), cfg) require.NoError(t, err) - assert.NoError(t, logs.Start(context.Background(), NewNopHost())) + assert.NoError(t, logs.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, logs.ConsumeLogs(context.Background(), plog.NewLogs())) assert.NoError(t, logs.Shutdown(context.Background())) } diff --git a/exporter/loggingexporter/factory.go b/exporter/loggingexporter/factory.go index 3941138cc4f..76e7601a47b 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -26,6 +26,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -39,13 +40,13 @@ const ( var onceWarnLogLevel sync.Once // NewFactory creates a factory for Logging exporter -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewFactory() exporter.Factory { + return exporter.NewFactory( typeStr, createDefaultConfig, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelDevelopment), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelDevelopment), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelDevelopment), + exporter.WithTraces(createTracesExporter, component.StabilityLevelDevelopment), + exporter.WithMetrics(createMetricsExporter, component.StabilityLevelDevelopment), + exporter.WithLogs(createLogsExporter, component.StabilityLevelDevelopment), ) } @@ -59,7 +60,7 @@ func createDefaultConfig() component.Config { } } -func createTracesExporter(ctx context.Context, set component.ExporterCreateSettings, config component.Config) (component.TracesExporter, error) { +func createTracesExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Traces, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) @@ -74,7 +75,7 @@ func createTracesExporter(ctx context.Context, set component.ExporterCreateSetti ) } -func createMetricsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.Config) (component.MetricsExporter, error) { +func createMetricsExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Metrics, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) @@ -89,7 +90,7 @@ func createMetricsExporter(ctx context.Context, set component.ExporterCreateSett ) } -func createLogsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.Config) (component.LogsExporter, error) { +func createLogsExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Logs, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 39b450fd206..9c83e53432e 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -31,13 +32,13 @@ const ( ) // NewFactory creates a factory for OTLP exporter. -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewFactory() exporter.Factory { + return exporter.NewFactory( typeStr, createDefaultConfig, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta), + exporter.WithTraces(createTracesExporter, component.StabilityLevelStable), + exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable), + exporter.WithLogs(createLogsExporter, component.StabilityLevelBeta), ) } @@ -59,9 +60,9 @@ func createDefaultConfig() component.Config { func createTracesExporter( ctx context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, -) (component.TracesExporter, error) { +) (exporter.Traces, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -79,9 +80,9 @@ func createTracesExporter( func createMetricsExporter( ctx context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, -) (component.MetricsExporter, error) { +) (exporter.Metrics, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -100,9 +101,9 @@ func createMetricsExporter( func createLogsExporter( ctx context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, -) (component.LogsExporter, error) { +) (exporter.Logs, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err diff --git a/exporter/otlpexporter/otlp.go b/exporter/otlpexporter/otlp.go index 3694f8fb9bc..d8eb12d1d56 100644 --- a/exporter/otlpexporter/otlp.go +++ b/exporter/otlpexporter/otlp.go @@ -29,6 +29,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/plog/plogotlp" @@ -38,7 +39,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" ) -type exporter struct { +type baseExporter struct { // Input configuration. config *Config @@ -58,7 +59,7 @@ type exporter struct { // Crete new exporter and start it. The exporter will begin connecting but // this function may return before the connection is established. -func newExporter(cfg component.Config, set component.ExporterCreateSettings) (*exporter, error) { +func newExporter(cfg component.Config, set exporter.CreateSettings) (*baseExporter, error) { oCfg := cfg.(*Config) if oCfg.Endpoint == "" { @@ -68,12 +69,12 @@ func newExporter(cfg component.Config, set component.ExporterCreateSettings) (*e userAgent := fmt.Sprintf("%s/%s (%s/%s)", set.BuildInfo.Description, set.BuildInfo.Version, runtime.GOOS, runtime.GOARCH) - return &exporter{config: oCfg, settings: set.TelemetrySettings, userAgent: userAgent}, nil + return &baseExporter{config: oCfg, settings: set.TelemetrySettings, userAgent: userAgent}, nil } // start actually creates the gRPC connection. The client construction is deferred till this point as this // is the only place we get hold of Extensions which are required to construct auth round tripper. -func (e *exporter) start(ctx context.Context, host component.Host) (err error) { +func (e *baseExporter) start(ctx context.Context, host component.Host) (err error) { if e.clientConn, err = e.config.GRPCClientSettings.ToClientConn(ctx, host, e.settings, grpc.WithUserAgent(e.userAgent)); err != nil { return err } @@ -88,32 +89,32 @@ func (e *exporter) start(ctx context.Context, host component.Host) (err error) { return } -func (e *exporter) shutdown(context.Context) error { +func (e *baseExporter) shutdown(context.Context) error { if e.clientConn != nil { return e.clientConn.Close() } return nil } -func (e *exporter) pushTraces(ctx context.Context, td ptrace.Traces) error { +func (e *baseExporter) pushTraces(ctx context.Context, td ptrace.Traces) error { req := ptraceotlp.NewExportRequestFromTraces(td) _, err := e.traceExporter.Export(e.enhanceContext(ctx), req, e.callOptions...) return processError(err) } -func (e *exporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error { +func (e *baseExporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error { req := pmetricotlp.NewExportRequestFromMetrics(md) _, err := e.metricExporter.Export(e.enhanceContext(ctx), req, e.callOptions...) return processError(err) } -func (e *exporter) pushLogs(ctx context.Context, ld plog.Logs) error { +func (e *baseExporter) pushLogs(ctx context.Context, ld plog.Logs) error { req := plogotlp.NewExportRequestFromLogs(ld) _, err := e.logExporter.Export(e.enhanceContext(ctx), req, e.callOptions...) return processError(err) } -func (e *exporter) enhanceContext(ctx context.Context) context.Context { +func (e *baseExporter) enhanceContext(ctx context.Context) context.Context { if e.metadata.Len() > 0 { return metadata.NewOutgoingContext(ctx, e.metadata) } diff --git a/exporter/otlpexporter/otlp_test.go b/exporter/otlpexporter/otlp_test.go index e5899e63b7b..706591c3d26 100644 --- a/exporter/otlpexporter/otlp_test.go +++ b/exporter/otlpexporter/otlp_test.go @@ -34,10 +34,10 @@ import ( "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/durationpb" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/plog/plogotlp" @@ -586,7 +586,7 @@ func TestSendTracesOnResourceExhaustion(t *testing.T) { }, 10*time.Second, 5*time.Millisecond, "Should retry if RetryInfo is included into status details by the server.") } -func startServerAndMakeRequest(t *testing.T, exp component.TracesExporter, td ptrace.Traces, ln net.Listener) { +func startServerAndMakeRequest(t *testing.T, exp exporter.Traces, td ptrace.Traces, ln net.Listener) { rcv, _ := otlpTracesReceiverOnGRPCServer(ln, false) defer rcv.srv.GracefulStop() // Ensure that initially there is no data in the receiver. diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index b720e442af8..e32576080c4 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -34,13 +35,13 @@ const ( ) // NewFactory creates a factory for OTLP exporter. -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewFactory() exporter.Factory { + return exporter.NewFactory( typeStr, createDefaultConfig, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta), + exporter.WithTraces(createTracesExporter, component.StabilityLevelStable), + exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable), + exporter.WithLogs(createLogsExporter, component.StabilityLevelBeta), ) } @@ -78,9 +79,9 @@ func composeSignalURL(oCfg *Config, signalOverrideURL string, signalName string) func createTracesExporter( ctx context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, -) (component.TracesExporter, error) { +) (exporter.Traces, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -104,9 +105,9 @@ func createTracesExporter( func createMetricsExporter( ctx context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, -) (component.MetricsExporter, error) { +) (exporter.Metrics, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -130,9 +131,9 @@ func createMetricsExporter( func createLogsExporter( ctx context.Context, - set component.ExporterCreateSettings, + set exporter.CreateSettings, cfg component.Config, -) (component.LogsExporter, error) { +) (exporter.Logs, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index e98767dcff9..b9853de44a9 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -32,6 +32,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/plog/plogotlp" @@ -41,7 +42,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" ) -type exporter struct { +type baseExporter struct { // Input configuration. config *Config client *http.Client @@ -60,7 +61,7 @@ const ( ) // Create new exporter. -func newExporter(cfg component.Config, set component.ExporterCreateSettings) (*exporter, error) { +func newExporter(cfg component.Config, set exporter.CreateSettings) (*baseExporter, error) { oCfg := cfg.(*Config) if oCfg.Endpoint != "" { @@ -74,7 +75,7 @@ func newExporter(cfg component.Config, set component.ExporterCreateSettings) (*e set.BuildInfo.Description, set.BuildInfo.Version, runtime.GOOS, runtime.GOARCH) // client construction is deferred to start - return &exporter{ + return &baseExporter{ config: oCfg, logger: set.Logger, userAgent: userAgent, @@ -84,7 +85,7 @@ func newExporter(cfg component.Config, set component.ExporterCreateSettings) (*e // start actually creates the HTTP client. The client construction is deferred till this point as this // is the only place we get hold of Extensions which are required to construct auth round tripper. -func (e *exporter) start(_ context.Context, host component.Host) error { +func (e *baseExporter) start(_ context.Context, host component.Host) error { client, err := e.config.HTTPClientSettings.ToClient(host, e.settings) if err != nil { return err @@ -93,7 +94,7 @@ func (e *exporter) start(_ context.Context, host component.Host) error { return nil } -func (e *exporter) pushTraces(ctx context.Context, td ptrace.Traces) error { +func (e *baseExporter) pushTraces(ctx context.Context, td ptrace.Traces) error { tr := ptraceotlp.NewExportRequestFromTraces(td) request, err := tr.MarshalProto() if err != nil { @@ -103,7 +104,7 @@ func (e *exporter) pushTraces(ctx context.Context, td ptrace.Traces) error { return e.export(ctx, e.tracesURL, request) } -func (e *exporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error { +func (e *baseExporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error { tr := pmetricotlp.NewExportRequestFromMetrics(md) request, err := tr.MarshalProto() if err != nil { @@ -112,7 +113,7 @@ func (e *exporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error { return e.export(ctx, e.metricsURL, request) } -func (e *exporter) pushLogs(ctx context.Context, ld plog.Logs) error { +func (e *baseExporter) pushLogs(ctx context.Context, ld plog.Logs) error { tr := plogotlp.NewExportRequestFromLogs(ld) request, err := tr.MarshalProto() if err != nil { @@ -122,7 +123,7 @@ func (e *exporter) pushLogs(ctx context.Context, ld plog.Logs) error { return e.export(ctx, e.logsURL, request) } -func (e *exporter) export(ctx context.Context, url string, request []byte) error { +func (e *baseExporter) export(ctx context.Context, url string, request []byte) error { e.logger.Debug("Preparing to make HTTP request", zap.String("url", url)) req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(request)) if err != nil { diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index 7036b1370f7..3f566bf46f0 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -42,6 +42,7 @@ import ( "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/internal/testutil" @@ -302,7 +303,7 @@ func TestIssue_4221(t *testing.T) { assert.NoError(t, exp.ConsumeTraces(context.Background(), md)) } -func startTracesExporter(t *testing.T, baseURL string, overrideURL string) component.TracesExporter { +func startTracesExporter(t *testing.T, baseURL string, overrideURL string) exporter.Traces { factory := NewFactory() cfg := createExporterConfig(baseURL, factory.CreateDefaultConfig()) cfg.TracesEndpoint = overrideURL @@ -312,7 +313,7 @@ func startTracesExporter(t *testing.T, baseURL string, overrideURL string) compo return exp } -func startMetricsExporter(t *testing.T, baseURL string, overrideURL string) component.MetricsExporter { +func startMetricsExporter(t *testing.T, baseURL string, overrideURL string) exporter.Metrics { factory := NewFactory() cfg := createExporterConfig(baseURL, factory.CreateDefaultConfig()) cfg.MetricsEndpoint = overrideURL @@ -322,7 +323,7 @@ func startMetricsExporter(t *testing.T, baseURL string, overrideURL string) comp return exp } -func startLogsExporter(t *testing.T, baseURL string, overrideURL string) component.LogsExporter { +func startLogsExporter(t *testing.T, baseURL string, overrideURL string) exporter.Logs { factory := NewFactory() cfg := createExporterConfig(baseURL, factory.CreateDefaultConfig()) cfg.LogsEndpoint = overrideURL diff --git a/obsreport/obsreport_exporter.go b/obsreport/obsreport_exporter.go index 46c8cd4da4d..5ddb2fcc475 100644 --- a/obsreport/obsreport_exporter.go +++ b/obsreport/obsreport_exporter.go @@ -29,6 +29,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/internal/obsreportconfig" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -61,7 +62,7 @@ type Exporter struct { // ExporterSettings are settings for creating an Exporter. type ExporterSettings struct { ExporterID component.ID - ExporterCreateSettings component.ExporterCreateSettings + ExporterCreateSettings exporter.CreateSettings } // NewExporter creates a new Exporter. diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index 1c62b73c7ee..dec6588be58 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -38,10 +38,10 @@ const ( ) var ( - receiver = component.NewID("fakeReceiver") - scraper = component.NewID("fakeScraper") - processor = component.NewID("fakeProcessor") - exporter = component.NewID("fakeExporter") + receiverID = component.NewID("fakeReceiver") + scraperID = component.NewID("fakeScraper") + processorID = component.NewID("fakeProcessor") + exporterID = component.NewID("fakeExporter") errFake = errors.New("errFake") partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1) @@ -75,7 +75,7 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt } func TestReceiveTraceDataOp(t *testing.T) { - testTelemetry(t, receiver, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { + testTelemetry(t, receiverID, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { parentCtx, parentSpan := tt.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() @@ -85,7 +85,7 @@ func TestReceiveTraceDataOp(t *testing.T) { } for i, param := range params { rec, err := newReceiver(ReceiverSettings{ - ReceiverID: receiver, + ReceiverID: receiverID, Transport: transport, ReceiverCreateSettings: tt.ToReceiverCreateSettings(), }, registry) @@ -100,7 +100,7 @@ func TestReceiveTraceDataOp(t *testing.T) { var acceptedSpans, refusedSpans int for i, span := range spans { - assert.Equal(t, "receiver/"+receiver.String()+"/TraceDataReceived", span.Name()) + assert.Equal(t, "receiver/"+receiverID.String()+"/TraceDataReceived", span.Name()) switch { case params[i].err == nil: acceptedSpans += params[i].items @@ -122,7 +122,7 @@ func TestReceiveTraceDataOp(t *testing.T) { } func TestReceiveLogsOp(t *testing.T) { - testTelemetry(t, receiver, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { + testTelemetry(t, receiverID, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { parentCtx, parentSpan := tt.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() @@ -132,7 +132,7 @@ func TestReceiveLogsOp(t *testing.T) { } for i, param := range params { rec, err := newReceiver(ReceiverSettings{ - ReceiverID: receiver, + ReceiverID: receiverID, Transport: transport, ReceiverCreateSettings: tt.ToReceiverCreateSettings(), }, registry) @@ -148,7 +148,7 @@ func TestReceiveLogsOp(t *testing.T) { var acceptedLogRecords, refusedLogRecords int for i, span := range spans { - assert.Equal(t, "receiver/"+receiver.String()+"/LogsReceived", span.Name()) + assert.Equal(t, "receiver/"+receiverID.String()+"/LogsReceived", span.Name()) switch { case params[i].err == nil: acceptedLogRecords += params[i].items @@ -170,7 +170,7 @@ func TestReceiveLogsOp(t *testing.T) { } func TestReceiveMetricsOp(t *testing.T) { - testTelemetry(t, receiver, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { + testTelemetry(t, receiverID, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { parentCtx, parentSpan := tt.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() @@ -180,7 +180,7 @@ func TestReceiveMetricsOp(t *testing.T) { } for i, param := range params { rec, err := newReceiver(ReceiverSettings{ - ReceiverID: receiver, + ReceiverID: receiverID, Transport: transport, ReceiverCreateSettings: tt.ToReceiverCreateSettings(), }, registry) @@ -196,7 +196,7 @@ func TestReceiveMetricsOp(t *testing.T) { var acceptedMetricPoints, refusedMetricPoints int for i, span := range spans { - assert.Equal(t, "receiver/"+receiver.String()+"/MetricsReceived", span.Name()) + assert.Equal(t, "receiver/"+receiverID.String()+"/MetricsReceived", span.Name()) switch { case params[i].err == nil: acceptedMetricPoints += params[i].items @@ -219,7 +219,7 @@ func TestReceiveMetricsOp(t *testing.T) { } func TestScrapeMetricsDataOp(t *testing.T) { - testTelemetry(t, receiver, testScrapeMetricsDataOp) + testTelemetry(t, receiverID, testScrapeMetricsDataOp) } func testScrapeMetricsDataOp(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { @@ -233,8 +233,8 @@ func testScrapeMetricsDataOp(t *testing.T, tt obsreporttest.TestTelemetry, regis } for i := range params { scrp, err := newScraper(ScraperSettings{ - ReceiverID: receiver, - Scraper: scraper, + ReceiverID: receiverID, + Scraper: scraperID, ReceiverCreateSettings: tt.ToReceiverCreateSettings(), }, registry) require.NoError(t, err) @@ -248,7 +248,7 @@ func testScrapeMetricsDataOp(t *testing.T, tt obsreporttest.TestTelemetry, regis var scrapedMetricPoints, erroredMetricPoints int for i, span := range spans { - assert.Equal(t, "scraper/"+receiver.String()+"/"+scraper.String()+"/MetricsScraped", span.Name()) + assert.Equal(t, "scraper/"+receiverID.String()+"/"+scraperID.String()+"/MetricsScraped", span.Name()) switch { case params[i].err == nil: scrapedMetricPoints += params[i].items @@ -274,16 +274,16 @@ func testScrapeMetricsDataOp(t *testing.T, tt obsreporttest.TestTelemetry, regis } } - require.NoError(t, obsreporttest.CheckScraperMetrics(tt, receiver, scraper, int64(scrapedMetricPoints), int64(erroredMetricPoints))) + require.NoError(t, obsreporttest.CheckScraperMetrics(tt, receiverID, scraperID, int64(scrapedMetricPoints), int64(erroredMetricPoints))) } func TestExportTraceDataOp(t *testing.T) { - testTelemetry(t, exporter, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { + testTelemetry(t, exporterID, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { parentCtx, parentSpan := tt.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() obsrep, err := newExporter(ExporterSettings{ - ExporterID: exporter, + ExporterID: exporterID, ExporterCreateSettings: tt.ToExporterCreateSettings(), }, registry) require.NoError(t, err) @@ -303,7 +303,7 @@ func TestExportTraceDataOp(t *testing.T) { var sentSpans, failedToSendSpans int for i, span := range spans { - assert.Equal(t, "exporter/"+exporter.String()+"/traces", span.Name()) + assert.Equal(t, "exporter/"+exporterID.String()+"/traces", span.Name()) switch { case params[i].err == nil: sentSpans += params[i].items @@ -327,12 +327,12 @@ func TestExportTraceDataOp(t *testing.T) { } func TestExportMetricsOp(t *testing.T) { - testTelemetry(t, exporter, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { + testTelemetry(t, exporterID, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { parentCtx, parentSpan := tt.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() obsrep, err := newExporter(ExporterSettings{ - ExporterID: exporter, + ExporterID: exporterID, ExporterCreateSettings: tt.ToExporterCreateSettings(), }, registry) require.NoError(t, err) @@ -353,7 +353,7 @@ func TestExportMetricsOp(t *testing.T) { var sentMetricPoints, failedToSendMetricPoints int for i, span := range spans { - assert.Equal(t, "exporter/"+exporter.String()+"/metrics", span.Name()) + assert.Equal(t, "exporter/"+exporterID.String()+"/metrics", span.Name()) switch { case params[i].err == nil: sentMetricPoints += params[i].items @@ -376,12 +376,12 @@ func TestExportMetricsOp(t *testing.T) { } func TestExportLogsOp(t *testing.T) { - testTelemetry(t, exporter, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { + testTelemetry(t, exporterID, func(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { parentCtx, parentSpan := tt.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() obsrep, err := newExporter(ExporterSettings{ - ExporterID: exporter, + ExporterID: exporterID, ExporterCreateSettings: tt.ToExporterCreateSettings(), }, registry) require.NoError(t, err) @@ -402,7 +402,7 @@ func TestExportLogsOp(t *testing.T) { var sentLogRecords, failedToSendLogRecords int for i, span := range spans { - assert.Equal(t, "exporter/"+exporter.String()+"/logs", span.Name()) + assert.Equal(t, "exporter/"+exporterID.String()+"/logs", span.Name()) switch { case params[i].err == nil: sentLogRecords += params[i].items @@ -425,7 +425,7 @@ func TestExportLogsOp(t *testing.T) { } func TestReceiveWithLongLivedCtx(t *testing.T) { - tt, err := obsreporttest.SetupTelemetryWithID(receiver) + tt, err := obsreporttest.SetupTelemetryWithID(receiverID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -440,7 +440,7 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { // Use a new context on each operation to simulate distinct operations // under the same long lived context. rec, rerr := NewReceiver(ReceiverSettings{ - ReceiverID: receiver, + ReceiverID: receiverID, Transport: transport, LongLivedCtx: true, ReceiverCreateSettings: tt.ToReceiverCreateSettings(), @@ -460,7 +460,7 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { link := span.Links()[0] assert.Equal(t, parentSpan.SpanContext().TraceID(), link.SpanContext.TraceID()) assert.Equal(t, parentSpan.SpanContext().SpanID(), link.SpanContext.SpanID()) - assert.Equal(t, "receiver/"+receiver.String()+"/TraceDataReceived", span.Name()) + assert.Equal(t, "receiver/"+receiverID.String()+"/TraceDataReceived", span.Name()) require.Contains(t, span.Attributes(), attribute.KeyValue{Key: obsmetrics.TransportKey, Value: attribute.StringValue(transport)}) switch { case params[i].err == nil: @@ -479,7 +479,7 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { } func TestProcessorTraceData(t *testing.T) { - testTelemetry(t, processor, testProcessorTraceData) + testTelemetry(t, processorID, testProcessorTraceData) } func testProcessorTraceData(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { @@ -487,7 +487,7 @@ func testProcessorTraceData(t *testing.T, tt obsreporttest.TestTelemetry, regist const refusedSpans = 19 const droppedSpans = 13 obsrep, err := newProcessor(ProcessorSettings{ - ProcessorID: processor, + ProcessorID: processorID, ProcessorCreateSettings: tt.ToProcessorCreateSettings(), }, registry) require.NoError(t, err) @@ -499,7 +499,7 @@ func testProcessorTraceData(t *testing.T, tt obsreporttest.TestTelemetry, regist } func TestProcessorMetricsData(t *testing.T) { - testTelemetry(t, processor, testProcessorMetricsData) + testTelemetry(t, processorID, testProcessorMetricsData) } func testProcessorMetricsData(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { @@ -508,7 +508,7 @@ func testProcessorMetricsData(t *testing.T, tt obsreporttest.TestTelemetry, regi const droppedPoints = 17 obsrep, err := newProcessor(ProcessorSettings{ - ProcessorID: processor, + ProcessorID: processorID, ProcessorCreateSettings: tt.ToProcessorCreateSettings(), }, registry) require.NoError(t, err) @@ -542,7 +542,7 @@ func TestBuildProcessorCustomMetricName(t *testing.T) { } func TestProcessorLogRecords(t *testing.T) { - testTelemetry(t, processor, testProcessorLogRecords) + testTelemetry(t, processorID, testProcessorLogRecords) } func testProcessorLogRecords(t *testing.T, tt obsreporttest.TestTelemetry, registry *featuregate.Registry) { @@ -551,7 +551,7 @@ func testProcessorLogRecords(t *testing.T, tt obsreporttest.TestTelemetry, regis const droppedRecords = 17 obsrep, err := newProcessor(ProcessorSettings{ - ProcessorID: processor, + ProcessorID: processorID, ProcessorCreateSettings: tt.ToProcessorCreateSettings(), }, registry) require.NoError(t, err) diff --git a/obsreport/obsreporttest/obsreporttest.go b/obsreport/obsreporttest/obsreporttest.go index 8146756c1a1..ef04537e6bd 100644 --- a/obsreport/obsreporttest/obsreporttest.go +++ b/obsreport/obsreporttest/obsreporttest.go @@ -30,6 +30,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configtelemetry" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig" ) @@ -59,7 +60,7 @@ type TestTelemetry struct { } // ToExporterCreateSettings returns ExporterCreateSettings with configured TelemetrySettings -func (tts *TestTelemetry) ToExporterCreateSettings() component.ExporterCreateSettings { +func (tts *TestTelemetry) ToExporterCreateSettings() exporter.CreateSettings { set := componenttest.NewNopExporterCreateSettings() set.TelemetrySettings = tts.TelemetrySettings set.ID = tts.id diff --git a/service/internal/configunmarshaler/exporters.go b/service/internal/configunmarshaler/exporters.go index 53f29501072..cd68761caa7 100644 --- a/service/internal/configunmarshaler/exporters.go +++ b/service/internal/configunmarshaler/exporters.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/exporter" ) // exportersKeyName is the configuration key name for exporters section. @@ -27,10 +28,10 @@ const exportersKeyName = "exporters" type Exporters struct { exps map[component.ID]component.Config - factories map[component.Type]component.ExporterFactory + factories map[component.Type]exporter.Factory } -func NewExporters(factories map[component.Type]component.ExporterFactory) *Exporters { +func NewExporters(factories map[component.Type]exporter.Factory) *Exporters { return &Exporters{factories: factories} } diff --git a/service/internal/configunmarshaler/exporters_test.go b/service/internal/configunmarshaler/exporters_test.go index e1f171636d1..0b0223f1daf 100644 --- a/service/internal/configunmarshaler/exporters_test.go +++ b/service/internal/configunmarshaler/exporters_test.go @@ -23,10 +23,11 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/exporter" ) func TestExportersUnmarshal(t *testing.T) { - factories, err := component.MakeExporterFactoryMap(componenttest.NewNopExporterFactory()) + factories, err := exporter.MakeFactoryMap(componenttest.NewNopExporterFactory()) require.NoError(t, err) exps := NewExporters(factories) @@ -100,7 +101,7 @@ func TestExportersUnmarshalError(t *testing.T) { }, } - factories, err := component.MakeExporterFactoryMap(componenttest.NewNopExporterFactory()) + factories, err := exporter.MakeFactoryMap(componenttest.NewNopExporterFactory()) assert.NoError(t, err) for _, tt := range testCases { diff --git a/service/internal/testcomponents/example_exporter.go b/service/internal/testcomponents/example_exporter.go index fe91a5e2fdb..df353991034 100644 --- a/service/internal/testcomponents/example_exporter.go +++ b/service/internal/testcomponents/example_exporter.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" @@ -36,12 +37,12 @@ type ExampleExporterConfig struct { } // ExampleExporterFactory is factory for ExampleExporter. -var ExampleExporterFactory = component.NewExporterFactory( +var ExampleExporterFactory = exporter.NewFactory( typeStr, createExporterDefaultConfig, - component.WithTracesExporter(createTracesExporter, stability), - component.WithMetricsExporter(createMetricsExporter, stability), - component.WithLogsExporter(createLogsExporter, stability), + exporter.WithTraces(createTracesExporter, stability), + exporter.WithMetrics(createMetricsExporter, stability), + exporter.WithLogs(createLogsExporter, stability), ) func createExporterDefaultConfig() component.Config { @@ -50,15 +51,15 @@ func createExporterDefaultConfig() component.Config { } } -func createTracesExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) { +func createTracesExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Traces, error) { return &ExampleExporter{}, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Metrics, error) { return &ExampleExporter{}, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) { +func createLogsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Logs, error) { return &ExampleExporter{}, nil } diff --git a/service/pipelines.go b/service/pipelines.go index df793f5e958..76d7285d704 100644 --- a/service/pipelines.go +++ b/service/pipelines.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/service/internal/capabilityconsumer" "go.opentelemetry.io/collector/service/internal/components" "go.opentelemetry.io/collector/service/internal/fanoutconsumer" @@ -194,8 +195,8 @@ type Settings struct { // ProcessorConfigs is a map of component.ID to component.Config. ProcessorConfigs map[component.ID]component.Config - // ExporterFactories maps exporter type names in the config to the respective component.ExporterFactory. - ExporterFactories map[component.Type]component.ExporterFactory + // ExporterFactories maps exporter type names in the config to the respective exporter.Factory. + ExporterFactories map[component.Type]exporter.Factory // ExporterConfigs is a map of component.ID to component.Config. ExporterConfigs map[component.ID]component.Config @@ -336,7 +337,7 @@ func buildExporter( settings component.TelemetrySettings, buildInfo component.BuildInfo, cfgs map[component.ID]component.Config, - factories map[component.Type]component.ExporterFactory, + factories map[component.Type]exporter.Factory, id component.ID, pipelineID component.ID, ) (component.Component, error) { @@ -350,7 +351,7 @@ func buildExporter( return nil, fmt.Errorf("exporter factory not available for: %q", id) } - set := component.ExporterCreateSettings{ + set := exporter.CreateSettings{ ID: id, TelemetrySettings: settings, BuildInfo: buildInfo, @@ -366,7 +367,7 @@ func buildExporter( return exp, nil } -func createExporter(ctx context.Context, set component.ExporterCreateSettings, cfg component.Config, id component.ID, pipelineID component.ID, factory component.ExporterFactory) (component.Component, error) { +func createExporter(ctx context.Context, set exporter.CreateSettings, cfg component.Config, id component.ID, pipelineID component.ID, factory exporter.Factory) (component.Component, error) { switch pipelineID.Type() { case component.DataTypeTraces: return factory.CreateTracesExporter(ctx, set, cfg) @@ -414,7 +415,7 @@ func exporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) zap.String(components.ZapNameKey, id.String())) } -func getExporterStabilityLevel(factory component.ExporterFactory, dt component.DataType) component.StabilityLevel { +func getExporterStabilityLevel(factory exporter.Factory, dt component.DataType) component.StabilityLevel { switch dt { case component.DataTypeTraces: return factory.TracesExporterStability() diff --git a/service/pipelines_test.go b/service/pipelines_test.go index f1b6341c885..ef6ba6cf240 100644 --- a/service/pipelines_test.go +++ b/service/pipelines_test.go @@ -27,6 +27,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/service/internal/testcomponents" ) @@ -193,7 +194,7 @@ func TestBuildPipelines(t *testing.T) { component.NewID("exampleprocessor"): testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), component.NewIDWithName("exampleprocessor", "1"): testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), }, - ExporterFactories: map[component.Type]component.ExporterFactory{ + ExporterFactories: map[component.Type]exporter.Factory{ testcomponents.ExampleExporterFactory.Type(): testcomponents.ExampleExporterFactory, }, ExporterConfigs: map[component.ID]component.Config{ @@ -209,15 +210,15 @@ func TestBuildPipelines(t *testing.T) { for dt, pipeline := range test.pipelineConfigs { // Verify exporters created, started and empty. for _, expID := range pipeline.Exporters { - exporter := pipelines.GetExporters()[dt.Type()][expID].(*testcomponents.ExampleExporter) - assert.True(t, exporter.Started) + exp := pipelines.GetExporters()[dt.Type()][expID].(*testcomponents.ExampleExporter) + assert.True(t, exp.Started) switch dt.Type() { case component.DataTypeTraces: - assert.Len(t, exporter.Traces, 0) + assert.Len(t, exp.Traces, 0) case component.DataTypeMetrics: - assert.Len(t, exporter.Metrics, 0) + assert.Len(t, exp.Metrics, 0) case component.DataTypeLogs: - assert.Len(t, exporter.Logs, 0) + assert.Len(t, exp.Logs, 0) } } @@ -267,19 +268,19 @@ func TestBuildPipelines(t *testing.T) { // Now verify that exporters received data, and are shutdown. for _, expID := range pipeline.Exporters { - exporter := pipelines.GetExporters()[dt.Type()][expID].(*testcomponents.ExampleExporter) + exp := pipelines.GetExporters()[dt.Type()][expID].(*testcomponents.ExampleExporter) switch dt.Type() { case component.DataTypeTraces: - require.Len(t, exporter.Traces, test.expectedRequests) - assert.EqualValues(t, testdata.GenerateTraces(1), exporter.Traces[0]) + require.Len(t, exp.Traces, test.expectedRequests) + assert.EqualValues(t, testdata.GenerateTraces(1), exp.Traces[0]) case component.DataTypeMetrics: - require.Len(t, exporter.Metrics, test.expectedRequests) - assert.EqualValues(t, testdata.GenerateMetrics(1), exporter.Metrics[0]) + require.Len(t, exp.Metrics, test.expectedRequests) + assert.EqualValues(t, testdata.GenerateMetrics(1), exp.Metrics[0]) case component.DataTypeLogs: - require.Len(t, exporter.Logs, test.expectedRequests) - assert.EqualValues(t, testdata.GenerateLogs(1), exporter.Logs[0]) + require.Len(t, exp.Logs, test.expectedRequests) + assert.EqualValues(t, testdata.GenerateLogs(1), exp.Logs[0]) } - assert.True(t, exporter.Stopped) + assert.True(t, exp.Stopped) } } }) @@ -588,7 +589,7 @@ func TestBuildErrors(t *testing.T) { nopProcessorFactory.Type(): nopProcessorFactory, badProcessorFactory.Type(): badProcessorFactory, } - set.ExporterFactories = map[component.Type]component.ExporterFactory{ + set.ExporterFactories = map[component.Type]exporter.Factory{ nopExporterFactory.Type(): nopExporterFactory, badExporterFactory.Type(): badExporterFactory, } @@ -626,7 +627,7 @@ func TestFailToStartAndShutdown(t *testing.T) { component.NewID(nopProcessorFactory.Type()): nopProcessorFactory.CreateDefaultConfig(), component.NewID(errProcessorFactory.Type()): errProcessorFactory.CreateDefaultConfig(), }, - ExporterFactories: map[component.Type]component.ExporterFactory{ + ExporterFactories: map[component.Type]exporter.Factory{ nopExporterFactory.Type(): nopExporterFactory, errExporterFactory.Type(): errExporterFactory, }, @@ -701,8 +702,8 @@ func newBadProcessorFactory() component.ProcessorFactory { }) } -func newBadExporterFactory() component.ExporterFactory { - return component.NewExporterFactory("bf", func() component.Config { +func newBadExporterFactory() exporter.Factory { + return exporter.NewFactory("bf", func() component.Config { return &struct { config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ @@ -751,21 +752,21 @@ func newErrProcessorFactory() component.ProcessorFactory { ) } -func newErrExporterFactory() component.ExporterFactory { - return component.NewExporterFactory("err", func() component.Config { +func newErrExporterFactory() exporter.Factory { + return exporter.NewFactory("err", func() component.Config { return &struct { config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ ExporterSettings: config.NewExporterSettings(component.NewID("bf")), } }, - component.WithTracesExporter(func(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) { + exporter.WithTraces(func(context.Context, exporter.CreateSettings, component.Config) (exporter.Traces, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithLogsExporter(func(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) { + exporter.WithLogs(func(context.Context, exporter.CreateSettings, component.Config) (exporter.Logs, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithMetricsExporter(func(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) { + exporter.WithMetrics(func(context.Context, exporter.CreateSettings, component.Config) (exporter.Metrics, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), )