Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate New*ExporterWithContext, update New*Exporter to the new API #5914

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

### 🛑 Breaking changes 🛑

- Replace `exporterhelper.New[Traces|Metrics|Logs]Exporter` with `exporterhelper.New[Traces|Metrics|Logs]ExporterWithContext` definition (#5914)

### 🚩 Deprecations 🚩

- 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)

### 💡 Enhancements 💡

Expand Down
13 changes: 7 additions & 6 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@ type logsExporter struct {
consumer.Logs
}

// Deprecated: [v0.58.0] use NewLogsExporterWithContext.
func NewLogsExporter(
cfg config.Exporter,
// Deprecated: [v0.58.0] use NewLogsExporter.
func NewLogsExporterWithContext(
ctx context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
pusher consumer.ConsumeLogsFunc,
options ...Option,
) (component.LogsExporter, error) {
return NewLogsExporterWithContext(context.Background(), set, cfg, pusher, options...)
return NewLogsExporter(ctx, set, cfg, pusher, options...)
}

// NewLogsExporterWithContext creates an LogsExporter that records observability metrics and wraps every request with a Span.
func NewLogsExporterWithContext(
// NewLogsExporter creates a component.LogsExporter that records observability metrics and wraps every request with a Span.
func NewLogsExporter(
_ context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
Expand Down
26 changes: 13 additions & 13 deletions exporter/exporterhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ func TestLogsRequest(t *testing.T) {
}

func TestLogsExporter_InvalidName(t *testing.T) {
le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), nil, newPushLogsData(nil))
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), nil, newPushLogsData(nil))
require.Nil(t, le)
require.Equal(t, errNilConfig, err)
}

func TestLogsExporter_NilLogger(t *testing.T) {
le, err := NewLogsExporterWithContext(context.Background(), component.ExporterCreateSettings{}, &fakeLogsExporterConfig, newPushLogsData(nil))
le, err := NewLogsExporter(context.Background(), component.ExporterCreateSettings{}, &fakeLogsExporterConfig, newPushLogsData(nil))
require.Nil(t, le)
require.Equal(t, errNilLogger, err)
}

func TestLogsExporter_NilPushLogsData(t *testing.T) {
le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, nil)
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, nil)
require.Nil(t, le)
require.Equal(t, errNilPushLogsData, err)
}

func TestLogsExporter_Default(t *testing.T) {
ld := plog.NewLogs()
le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil))
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil))
assert.NotNil(t, le)
assert.NoError(t, err)

Expand All @@ -90,7 +90,7 @@ func TestLogsExporter_Default(t *testing.T) {

func TestLogsExporter_WithCapabilities(t *testing.T) {
capabilities := consumer.Capabilities{MutatesData: true}
le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil), WithCapabilities(capabilities))
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil), WithCapabilities(capabilities))
require.NoError(t, err)
require.NotNil(t, le)

Expand All @@ -100,7 +100,7 @@ func TestLogsExporter_WithCapabilities(t *testing.T) {
func TestLogsExporter_Default_ReturnError(t *testing.T) {
ld := plog.NewLogs()
want := errors.New("my_error")
le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(want))
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(want))
require.NoError(t, err)
require.NotNil(t, le)
require.Equal(t, want, le.ConsumeLogs(context.Background(), ld))
Expand All @@ -111,7 +111,7 @@ func TestLogsExporter_WithRecordLogs(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

le, err := NewLogsExporterWithContext(context.Background(), tt.ToExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil))
le, err := NewLogsExporter(context.Background(), tt.ToExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil))
require.NoError(t, err)
require.NotNil(t, le)

Expand All @@ -124,7 +124,7 @@ func TestLogsExporter_WithRecordLogs_ReturnError(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

le, err := NewLogsExporterWithContext(context.Background(), tt.ToExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(want))
le, err := NewLogsExporter(context.Background(), tt.ToExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(want))
require.Nil(t, err)
require.NotNil(t, le)

Expand All @@ -141,7 +141,7 @@ func TestLogsExporter_WithRecordEnqueueFailedMetrics(t *testing.T) {
qCfg.NumConsumers = 1
qCfg.QueueSize = 2
wantErr := errors.New("some-error")
te, err := NewLogsExporterWithContext(context.Background(), tt.ToExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
te, err := NewLogsExporter(context.Background(), tt.ToExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)
require.NotNil(t, te)

Expand All @@ -163,7 +163,7 @@ func TestLogsExporter_WithSpan(t *testing.T) {
otel.SetTracerProvider(set.TracerProvider)
defer otel.SetTracerProvider(trace.NewNoopTracerProvider())

le, err := NewLogsExporterWithContext(context.Background(), set, &fakeLogsExporterConfig, newPushLogsData(nil))
le, err := NewLogsExporter(context.Background(), set, &fakeLogsExporterConfig, newPushLogsData(nil))
require.Nil(t, err)
require.NotNil(t, le)
checkWrapSpanForLogsExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1)
Expand All @@ -177,7 +177,7 @@ func TestLogsExporter_WithSpan_ReturnError(t *testing.T) {
defer otel.SetTracerProvider(trace.NewNoopTracerProvider())

want := errors.New("my_error")
le, err := NewLogsExporterWithContext(context.Background(), set, &fakeLogsExporterConfig, newPushLogsData(want))
le, err := NewLogsExporter(context.Background(), set, &fakeLogsExporterConfig, newPushLogsData(want))
require.Nil(t, err)
require.NotNil(t, le)
checkWrapSpanForLogsExporter(t, sr, set.TracerProvider.Tracer("test"), le, want, 1)
Expand All @@ -187,7 +187,7 @@ func TestLogsExporter_WithShutdown(t *testing.T) {
shutdownCalled := false
shutdown := func(context.Context) error { shutdownCalled = true; return nil }

le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil), WithShutdown(shutdown))
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil), WithShutdown(shutdown))
assert.NotNil(t, le)
assert.NoError(t, err)

Expand All @@ -199,7 +199,7 @@ func TestLogsExporter_WithShutdown_ReturnError(t *testing.T) {
want := errors.New("my_error")
shutdownErr := func(context.Context) error { return want }

le, err := NewLogsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil), WithShutdown(shutdownErr))
le, err := NewLogsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeLogsExporterConfig, newPushLogsData(nil), WithShutdown(shutdownErr))
assert.NotNil(t, le)
assert.NoError(t, err)

Expand Down
13 changes: 7 additions & 6 deletions exporter/exporterhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,19 @@ type metricsExporter struct {
consumer.Metrics
}

// Deprecated: [v0.58.0] use NewMetricsExporterWithContext.
func NewMetricsExporter(
cfg config.Exporter,
// Deprecated: [v0.58.0] use NewMetricsExporter.
func NewMetricsExporterWithContext(
ctx context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
pusher consumer.ConsumeMetricsFunc,
options ...Option,
) (component.MetricsExporter, error) {
return NewMetricsExporterWithContext(context.Background(), set, cfg, pusher, options...)
return NewMetricsExporter(ctx, set, cfg, pusher, options...)
}

// NewMetricsExporterWithContext creates an MetricsExporter that records observability metrics and wraps every request with a Span.
func NewMetricsExporterWithContext(
// NewMetricsExporter creates a component.MetricsExporter that records observability metrics and wraps every request with a Span.
func NewMetricsExporter(
_ context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
Expand Down
26 changes: 13 additions & 13 deletions exporter/exporterhelper/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ func TestMetricsRequest(t *testing.T) {
}

func TestMetricsExporter_InvalidName(t *testing.T) {
me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), nil, newPushMetricsData(nil))
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), nil, newPushMetricsData(nil))
require.Nil(t, me)
require.Equal(t, errNilConfig, err)
}

func TestMetricsExporter_NilLogger(t *testing.T) {
me, err := NewMetricsExporterWithContext(context.Background(), component.ExporterCreateSettings{}, &fakeMetricsExporterConfig, newPushMetricsData(nil))
me, err := NewMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &fakeMetricsExporterConfig, newPushMetricsData(nil))
require.Nil(t, me)
require.Equal(t, errNilLogger, err)
}

func TestMetricsExporter_NilPushMetricsData(t *testing.T) {
me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, nil)
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, nil)
require.Nil(t, me)
require.Equal(t, errNilPushMetricsData, err)
}

func TestMetricsExporter_Default(t *testing.T) {
md := pmetric.NewMetrics()
me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil))
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil))
assert.NoError(t, err)
assert.NotNil(t, me)

Expand All @@ -89,7 +89,7 @@ func TestMetricsExporter_Default(t *testing.T) {

func TestMetricsExporter_WithCapabilities(t *testing.T) {
capabilities := consumer.Capabilities{MutatesData: true}
me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil), WithCapabilities(capabilities))
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil), WithCapabilities(capabilities))
assert.NoError(t, err)
assert.NotNil(t, me)

Expand All @@ -99,7 +99,7 @@ func TestMetricsExporter_WithCapabilities(t *testing.T) {
func TestMetricsExporter_Default_ReturnError(t *testing.T) {
md := pmetric.NewMetrics()
want := errors.New("my_error")
me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(want))
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(want))
require.NoError(t, err)
require.NotNil(t, me)
require.Equal(t, want, me.ConsumeMetrics(context.Background(), md))
Expand All @@ -110,7 +110,7 @@ func TestMetricsExporter_WithRecordMetrics(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

me, err := NewMetricsExporterWithContext(context.Background(), tt.ToExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil))
me, err := NewMetricsExporter(context.Background(), tt.ToExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil))
require.NoError(t, err)
require.NotNil(t, me)

Expand All @@ -123,7 +123,7 @@ func TestMetricsExporter_WithRecordMetrics_ReturnError(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

me, err := NewMetricsExporterWithContext(context.Background(), tt.ToExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(want))
me, err := NewMetricsExporter(context.Background(), tt.ToExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(want))
require.NoError(t, err)
require.NotNil(t, me)

Expand All @@ -140,7 +140,7 @@ func TestMetricsExporter_WithRecordEnqueueFailedMetrics(t *testing.T) {
qCfg.NumConsumers = 1
qCfg.QueueSize = 2
wantErr := errors.New("some-error")
te, err := NewMetricsExporterWithContext(context.Background(), tt.ToExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
te, err := NewMetricsExporter(context.Background(), tt.ToExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)
require.NotNil(t, te)

Expand All @@ -162,7 +162,7 @@ func TestMetricsExporter_WithSpan(t *testing.T) {
otel.SetTracerProvider(set.TracerProvider)
defer otel.SetTracerProvider(trace.NewNoopTracerProvider())

me, err := NewMetricsExporterWithContext(context.Background(), set, &fakeMetricsExporterConfig, newPushMetricsData(nil))
me, err := NewMetricsExporter(context.Background(), set, &fakeMetricsExporterConfig, newPushMetricsData(nil))
require.NoError(t, err)
require.NotNil(t, me)
checkWrapSpanForMetricsExporter(t, sr, set.TracerProvider.Tracer("test"), me, nil, 2)
Expand All @@ -176,7 +176,7 @@ func TestMetricsExporter_WithSpan_ReturnError(t *testing.T) {
defer otel.SetTracerProvider(trace.NewNoopTracerProvider())

want := errors.New("my_error")
me, err := NewMetricsExporterWithContext(context.Background(), set, &fakeMetricsExporterConfig, newPushMetricsData(want))
me, err := NewMetricsExporter(context.Background(), set, &fakeMetricsExporterConfig, newPushMetricsData(want))
require.NoError(t, err)
require.NotNil(t, me)
checkWrapSpanForMetricsExporter(t, sr, set.TracerProvider.Tracer("test"), me, want, 2)
Expand All @@ -186,7 +186,7 @@ func TestMetricsExporter_WithShutdown(t *testing.T) {
shutdownCalled := false
shutdown := func(context.Context) error { shutdownCalled = true; return nil }

me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil), WithShutdown(shutdown))
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil), WithShutdown(shutdown))
assert.NotNil(t, me)
assert.NoError(t, err)

Expand All @@ -199,7 +199,7 @@ func TestMetricsExporter_WithShutdown_ReturnError(t *testing.T) {
want := errors.New("my_error")
shutdownErr := func(context.Context) error { return want }

me, err := NewMetricsExporterWithContext(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil), WithShutdown(shutdownErr))
me, err := NewMetricsExporter(context.Background(), componenttest.NewNopExporterCreateSettings(), &fakeMetricsExporterConfig, newPushMetricsData(nil), WithShutdown(shutdownErr))
assert.NotNil(t, me)
assert.NoError(t, err)

Expand Down
13 changes: 7 additions & 6 deletions exporter/exporterhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,19 @@ type traceExporter struct {
consumer.Traces
}

// Deprecated: [v0.58.0] use NewTracesExporterWithContext.
func NewTracesExporter(
cfg config.Exporter,
// Deprecated: [v0.58.0] use NewTracesExporter.
func NewTracesExporterWithContext(
ctx context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
pusher consumer.ConsumeTracesFunc,
options ...Option,
) (component.TracesExporter, error) {
return NewTracesExporterWithContext(context.Background(), set, cfg, pusher, options...)
return NewTracesExporter(ctx, set, cfg, pusher, options...)
}

// NewTracesExporterWithContext creates an TracesExporter that records observability metrics and wraps every request with a Span.
func NewTracesExporterWithContext(
// NewTracesExporter creates a component.TracesExporter that records observability metrics and wraps every request with a Span.
func NewTracesExporter(
_ context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
Expand Down
Loading