diff --git a/sdk/metric/internal/aggregate/exponential_histogram.go b/sdk/metric/internal/aggregate/exponential_histogram.go index 857eddf30..cf4e86acf 100644 --- a/sdk/metric/internal/aggregate/exponential_histogram.go +++ b/sdk/metric/internal/aggregate/exponential_histogram.go @@ -338,13 +338,18 @@ func (e *expoHistogram[N]) measure( e.valuesMu.Lock() defer e.valuesMu.Unlock() - attr := e.limit.Attributes(fltrAttr, e.values) - v, ok := e.values[attr.Equivalent()] + v, ok := e.values[fltrAttr.Equivalent()] if !ok { - v = newExpoHistogramDataPoint[N](attr, e.maxSize, e.maxScale, e.noMinMax, e.noSum) - v.res = e.newRes(attr) + fltrAttr = e.limit.Attributes(fltrAttr, e.values) + // If we overflowed, make sure we add to the existing overflow series + // if it already exists. + v, ok = e.values[fltrAttr.Equivalent()] + if !ok { + v = newExpoHistogramDataPoint[N](fltrAttr, e.maxSize, e.maxScale, e.noMinMax, e.noSum) + v.res = e.newRes(fltrAttr) - e.values[attr.Equivalent()] = v + e.values[fltrAttr.Equivalent()] = v + } } v.record(value) v.res.Offer(ctx, value, droppedAttr) diff --git a/sdk/metric/internal/aggregate/histogram.go b/sdk/metric/internal/aggregate/histogram.go index 22d6c67d1..639c4d002 100644 --- a/sdk/metric/internal/aggregate/histogram.go +++ b/sdk/metric/internal/aggregate/histogram.go @@ -97,22 +97,27 @@ func (s *histValues[N]) measure( s.valuesMu.Lock() defer s.valuesMu.Unlock() - attr := s.limit.Attributes(fltrAttr, s.values) - b, ok := s.values[attr.Equivalent()] + b, ok := s.values[fltrAttr.Equivalent()] if !ok { - // N+1 buckets. For example: - // - // bounds = [0, 5, 10] - // - // Then, - // - // buckets = (-∞, 0], (0, 5.0], (5.0, 10.0], (10.0, +∞) - b = newBuckets[N](attr, len(s.bounds)+1) - b.res = s.newRes(attr) + fltrAttr = s.limit.Attributes(fltrAttr, s.values) + // If we overflowed, make sure we add to the existing overflow series + // if it already exists. + b, ok = s.values[fltrAttr.Equivalent()] + if !ok { + // N+1 buckets. For example: + // + // bounds = [0, 5, 10] + // + // Then, + // + // buckets = (-∞, 0], (0, 5.0], (5.0, 10.0], (10.0, +∞) + b = newBuckets[N](fltrAttr, len(s.bounds)+1) + b.res = s.newRes(fltrAttr) - // Ensure min and max are recorded values (not zero), for new buckets. - b.min, b.max = value, value - s.values[attr.Equivalent()] = b + // Ensure min and max are recorded values (not zero), for new buckets. + b.min, b.max = value, value + s.values[fltrAttr.Equivalent()] = b + } } b.bin(idx) if !s.noMinMax { diff --git a/sdk/metric/internal/aggregate/lastvalue.go b/sdk/metric/internal/aggregate/lastvalue.go index 4bbe624c7..6faf4920c 100644 --- a/sdk/metric/internal/aggregate/lastvalue.go +++ b/sdk/metric/internal/aggregate/lastvalue.go @@ -42,17 +42,18 @@ func (s *lastValue[N]) measure(ctx context.Context, value N, fltrAttr attribute. s.Lock() defer s.Unlock() - attr := s.limit.Attributes(fltrAttr, s.values) - d, ok := s.values[attr.Equivalent()] + d, ok := s.values[fltrAttr.Equivalent()] if !ok { - d.res = s.newRes(attr) + fltrAttr = s.limit.Attributes(fltrAttr, s.values) + d = s.values[fltrAttr.Equivalent()] + d.res = s.newRes(fltrAttr) + d.attrs = fltrAttr } - d.attrs = attr d.value = value d.res.Offer(ctx, value, droppedAttr) - s.values[attr.Equivalent()] = d + s.values[fltrAttr.Equivalent()] = d } func (s *lastValue[N]) delta( diff --git a/sdk/metric/internal/aggregate/sum.go b/sdk/metric/internal/aggregate/sum.go index 1b4b2304c..164feb867 100644 --- a/sdk/metric/internal/aggregate/sum.go +++ b/sdk/metric/internal/aggregate/sum.go @@ -38,17 +38,18 @@ func (s *valueMap[N]) measure(ctx context.Context, value N, fltrAttr attribute.S s.Lock() defer s.Unlock() - attr := s.limit.Attributes(fltrAttr, s.values) - v, ok := s.values[attr.Equivalent()] + v, ok := s.values[fltrAttr.Equivalent()] if !ok { - v.res = s.newRes(attr) + fltrAttr = s.limit.Attributes(fltrAttr, s.values) + v = s.values[fltrAttr.Equivalent()] + v.res = s.newRes(fltrAttr) + v.attrs = fltrAttr } - v.attrs = attr v.n += value v.res.Offer(ctx, value, droppedAttr) - s.values[attr.Equivalent()] = v + s.values[fltrAttr.Equivalent()] = v } // newSum returns an aggregator that summarizes a set of measurements as their