diff --git a/exporter/stackdriverexporter/factory.go b/exporter/stackdriverexporter/factory.go index 0ffed84e67a8..51d154f490f5 100644 --- a/exporter/stackdriverexporter/factory.go +++ b/exporter/stackdriverexporter/factory.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config/configerror" "go.opentelemetry.io/collector/config/configmodels" //"go.uber.org/zap" ) @@ -61,7 +60,6 @@ func (f *Factory) CreateMetricsExporter( _ context.Context, _ component.ExporterCreateParams, cfg configmodels.Exporter) (component.MetricsExporter, error) { - // eCfg := cfg.(*Config) - // return newStackdriverMetricsExporter(eCfg) - return nil, configerror.ErrDataTypeIsNotSupported + eCfg := cfg.(*Config) + return newStackdriverMetricsExporter(eCfg) } diff --git a/exporter/stackdriverexporter/stackdriver.go b/exporter/stackdriverexporter/stackdriver.go index c9af7c452a10..cccb667b7c13 100644 --- a/exporter/stackdriverexporter/stackdriver.go +++ b/exporter/stackdriverexporter/stackdriver.go @@ -27,6 +27,7 @@ import ( "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/consumer/consumerdata" "go.opentelemetry.io/collector/consumer/pdata" + "go.opentelemetry.io/collector/consumer/pdatautil" "go.opentelemetry.io/collector/exporter/exporterhelper" export "go.opentelemetry.io/otel/sdk/export/trace" "google.golang.org/api/option" @@ -86,16 +87,16 @@ func newStackdriverTraceExporter(cfg *Config) (component.TraceExporter, error) { exporterhelper.WithShutdown(tExp.Shutdown)) } -func newStackdriverMetricsExporter(cfg *Config) (component.MetricsExporterOld, error) { +func newStackdriverMetricsExporter(cfg *Config) (component.MetricsExporter, error) { sde, serr := newStackdriverExporter(cfg) if serr != nil { return nil, fmt.Errorf("cannot configure Stackdriver metric exporter: %v", serr) } mExp := &stackdriverExporter{exporter: sde} - return exporterhelper.NewMetricsExporterOld( + return exporterhelper.NewMetricsExporter( cfg, - mExp.pushMetricsData, + mExp.pushMetrics, exporterhelper.WithShutdown(mExp.Shutdown)) } @@ -145,6 +146,19 @@ func (se *stackdriverExporter) pushMetricsData(ctx context.Context, md consumerd return se.exporter.PushMetricsProto(ctx, md.Node, md.Resource, md.Metrics) } +func (se *stackdriverExporter) pushMetrics(ctx context.Context, m pdata.Metrics) (int, error) { + mds := pdatautil.MetricsToMetricsData(m) + dropped := 0 + for _, md := range mds { + d, err := se.pushMetricsData(ctx, md) + dropped += d + if err != nil { + return dropped, err + } + } + return dropped, nil +} + // pushTraceData is a wrapper method on StackdriverExporter.PushTraceSpans func (se *stackdriverExporter) pushTraceData(ctx context.Context, td consumerdata.TraceData) (int, error) { var errs []error