diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index e5edd978864a..06da382970e3 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -70,7 +70,7 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pdata.Metric } fallbackHost := metadata.GetHost(exp.params.Logger, exp.cfg) - ms, _ := mapMetrics(exp.cfg.Metrics, exp.prevPts, fallbackHost, md) + ms, _ := mapMetrics(exp.params.Logger, exp.cfg.Metrics, exp.prevPts, fallbackHost, md) metrics.ProcessMetrics(ms, exp.cfg) err := exp.client.PostMetrics(ms) diff --git a/exporter/datadogexporter/metrics_translator.go b/exporter/datadogexporter/metrics_translator.go index d50c9fa946f5..f760ac562bc1 100644 --- a/exporter/datadogexporter/metrics_translator.go +++ b/exporter/datadogexporter/metrics_translator.go @@ -21,6 +21,7 @@ import ( "time" "go.opentelemetry.io/collector/consumer/pdata" + "go.uber.org/zap" "gopkg.in/zorkian/go-datadog-api.v2" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/attributes" @@ -250,7 +251,7 @@ func mapHistogramMetrics(name string, slice pdata.HistogramDataPointSlice, bucke } // mapMetrics maps OTLP metrics into the DataDog format -func mapMetrics(cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost string, md pdata.Metrics) (series []datadog.Metric, droppedTimeSeries int) { +func mapMetrics(logger *zap.Logger, cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost string, md pdata.Metrics) (series []datadog.Metric, droppedTimeSeries int) { pushTime := uint64(time.Now().UTC().UnixNano()) rms := md.ResourceMetrics() for i := 0; i < rms.Len(); i++ { @@ -282,8 +283,6 @@ func mapMetrics(cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost s md := metricsArray.At(k) var datapoints []datadog.Metric switch md.DataType() { - case pdata.MetricDataTypeNone: - continue case pdata.MetricDataTypeIntGauge: datapoints = mapIntMetrics(md.Name(), md.IntGauge().DataPoints(), attributeTags) case pdata.MetricDataTypeDoubleGauge: @@ -304,6 +303,9 @@ func mapMetrics(cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost s datapoints = mapIntHistogramMetrics(md.Name(), md.IntHistogram().DataPoints(), cfg.Buckets, attributeTags) case pdata.MetricDataTypeHistogram: datapoints = mapHistogramMetrics(md.Name(), md.Histogram().DataPoints(), cfg.Buckets, attributeTags) + default: // pdata.MetricDataTypeNone or any other not supported type + logger.Debug("Unknown or unsupported metric type", zap.String("metric name", md.Name()), zap.Any("data type", md.DataType())) + continue } for i := range datapoints { diff --git a/exporter/datadogexporter/metrics_translator_test.go b/exporter/datadogexporter/metrics_translator_test.go index add1526ae914..38885f3656d6 100644 --- a/exporter/datadogexporter/metrics_translator_test.go +++ b/exporter/datadogexporter/metrics_translator_test.go @@ -21,6 +21,9 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/consumer/pdata" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" "gopkg.in/zorkian/go-datadog-api.v2" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config" @@ -534,7 +537,7 @@ func TestRunningMetrics(t *testing.T) { cfg := config.MetricsConfig{} prevPts := newTTLMap() - series, _ := mapMetrics(cfg, prevPts, "fallbackHostname", ms) + series, _ := mapMetrics(zap.NewNop(), cfg, prevPts, "fallbackHostname", ms) runningHostnames := []string{} @@ -685,7 +688,9 @@ func testCount(name string, val float64) datadog.Metric { func TestMapMetrics(t *testing.T) { md := createTestMetrics() cfg := config.MetricsConfig{SendMonotonic: true} - series, dropped := mapMetrics(cfg, newTTLMap(), "", md) + core, observed := observer.New(zapcore.DebugLevel) + testLogger := zap.New(core) + series, dropped := mapMetrics(testLogger, cfg, newTTLMap(), "", md) assert.Equal(t, dropped, 0) filtered := removeRunningMetrics(series) assert.ElementsMatch(t, filtered, []datadog.Metric{ @@ -700,4 +705,7 @@ func TestMapMetrics(t *testing.T) { testCount("int.cumulative.sum", 3), testCount("double.cumulative.sum", math.Pi), }) + + // One metric was unknown or unsupported + assert.Equal(t, observed.FilterMessage("Unknown or unsupported metric type").Len(), 1) }