From b4e5f8d562bd23794f4ec1a597cd08f06597dfa3 Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Wed, 17 Mar 2021 16:23:11 +0000 Subject: [PATCH] Address punya's comment, log deprecation warning --- exporter/stackdriverexporter/factory.go | 36 ++++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/exporter/stackdriverexporter/factory.go b/exporter/stackdriverexporter/factory.go index e2f058a23494..eda92044b785 100644 --- a/exporter/stackdriverexporter/factory.go +++ b/exporter/stackdriverexporter/factory.go @@ -16,33 +16,43 @@ package stackdriverexporter import ( "context" + "sync" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configmodels" + "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter" ) type factory struct { - delegate component.ExporterFactory + component.ExporterFactory } const ( // The value of "type" key in configuration. - typeStr = "stackdriver" + typeVal = configmodels.Type("stackdriver") ) +var once sync.Once + // NewFactory creates a factory for the stackdriver exporter func NewFactory() component.ExporterFactory { - return &factory{delegate: googlecloudexporter.NewFactory()} + return &factory{ExporterFactory: googlecloudexporter.NewFactory()} +} + +func logDeprecation(logger *zap.Logger) { + once.Do(func() { + logger.Warn("stackdriver exporter is deprecated. Use googlecloudexporter instead.") + }) } -func (*factory) Type() configmodels.Type { - return configmodels.Type(typeStr) +func (f *factory) Type() configmodels.Type { + return typeVal } func (f *factory) CreateDefaultConfig() configmodels.Exporter { - cfg := f.delegate.CreateDefaultConfig() + cfg := f.ExporterFactory.CreateDefaultConfig() cfg.(*googlecloudexporter.Config).TypeVal = f.Type() return cfg } @@ -52,7 +62,8 @@ func (f *factory) CreateTracesExporter( params component.ExporterCreateParams, cfg configmodels.Exporter, ) (component.TracesExporter, error) { - return f.delegate.CreateTracesExporter(ctx, params, cfg) + logDeprecation(params.Logger) + return f.ExporterFactory.CreateTracesExporter(ctx, params, cfg) } func (f *factory) CreateMetricsExporter( @@ -60,13 +71,6 @@ func (f *factory) CreateMetricsExporter( params component.ExporterCreateParams, cfg configmodels.Exporter, ) (component.MetricsExporter, error) { - return f.delegate.CreateMetricsExporter(ctx, params, cfg) -} - -func (f *factory) CreateLogsExporter( - ctx context.Context, - params component.ExporterCreateParams, - cfg configmodels.Exporter, -) (component.LogsExporter, error) { - return f.delegate.CreateLogsExporter(ctx, params, cfg) + logDeprecation(params.Logger) + return f.ExporterFactory.CreateMetricsExporter(ctx, params, cfg) }