From b56efb06a763e7da174f8bfd896d37e244754ccc Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 29 Sep 2022 08:28:20 -0700 Subject: [PATCH] Do not return agg if adding err-ed --- sdk/metric/pipeline.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sdk/metric/pipeline.go b/sdk/metric/pipeline.go index 9eb86f593ac..0dbdccd6291 100644 --- a/sdk/metric/pipeline.go +++ b/sdk/metric/pipeline.go @@ -216,14 +216,17 @@ func (i *inserter[N]) Instrument(inst view.Instrument, instUnit unit.Unit) ([]in if agg == nil { // Drop aggregator. continue } - // TODO (#3011): If filtering is done at the instrument level add here. - // This is where the aggregator and the view are both in scope. - aggs = append(aggs, agg) - seen[id] = struct{}{} err = i.pipeline.addAggregator(inst.Scope, inst.Name, inst.Description, instUnit, agg) if err != nil { errs.append(err) + // Do not return the aggregator to be updated if the pipeline will + // never produce from it. + continue } + // TODO (#3011): If filtering is done at the instrument level add here. + // This is where the aggregator and the view are both in scope. + aggs = append(aggs, agg) + seen[id] = struct{}{} } if !matched { // Apply implicit default view if no explicit matched. @@ -232,10 +235,13 @@ func (i *inserter[N]) Instrument(inst view.Instrument, instUnit unit.Unit) ([]in errs.append(err) } if a != nil { - aggs = append(aggs, a) err = i.pipeline.addAggregator(inst.Scope, inst.Name, inst.Description, instUnit, a) if err != nil { + // Do not return the aggregator to be updated if the pipeline + // will never produce from it. errs.append(err) + } else { + aggs = append(aggs, a) } } }