From 57d2e1f319148218482f6bd099311b98bf64713c Mon Sep 17 00:00:00 2001 From: Yang Hu Date: Thu, 27 Aug 2020 12:18:55 -0500 Subject: [PATCH] add check for nil --- exporter/prometheusremotewriteexporter/exporter.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index 2eaa3509ca8..ea1362ca965 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -90,10 +90,19 @@ func (prwe *prwExporter) pushMetrics(ctx context.Context, md pdata.Metrics) (int errs := []string{} resourceMetrics := data.MetricDataToOtlp(pdatautil.MetricsToInternalMetrics(md)) - for _, r := range resourceMetrics { - for _, instMetrics := range r.InstrumentationLibraryMetrics { + for _, resourceMetric := range resourceMetrics { + if resourceMetric == nil { + continue + } + for _, instMetrics := range resourceMetric.InstrumentationLibraryMetrics { + if instMetrics == nil { + continue + } // TODO: decide if instrumentation library information should be exported as labels for _, metric := range instMetrics.Metrics { + if metric == nil { + continue + } // check for valid type and temporality combination if ok := validateMetrics(metric.MetricDescriptor); !ok { dropped++