diff --git a/sdk/metric/internal/aggregate/exponential_histogram.go b/sdk/metric/internal/aggregate/exponential_histogram.go index 2aeba437894..51f31a227b6 100644 --- a/sdk/metric/internal/aggregate/exponential_histogram.go +++ b/sdk/metric/internal/aggregate/exponential_histogram.go @@ -45,6 +45,7 @@ type expoHistogramDataPoint[N int64 | float64] struct { posBuckets expoBuckets negBuckets expoBuckets zeroCount uint64 + start time.Time } func newExpoHistogramDataPoint[N int64 | float64]( @@ -68,6 +69,7 @@ func newExpoHistogramDataPoint[N int64 | float64]( noMinMax: noMinMax, noSum: noSum, scale: maxScale, + start: now(), } } @@ -446,7 +448,7 @@ func (e *expoHistogram[N]) cumulative( var i int for _, val := range e.values { hDPts[i].Attributes = val.attrs - hDPts[i].StartTime = e.start + hDPts[i].StartTime = val.start hDPts[i].Time = t hDPts[i].Count = val.count() hDPts[i].Scale = val.scale diff --git a/sdk/metric/internal/aggregate/histogram.go b/sdk/metric/internal/aggregate/histogram.go index 421325fb728..73d0a248f03 100644 --- a/sdk/metric/internal/aggregate/histogram.go +++ b/sdk/metric/internal/aggregate/histogram.go @@ -29,6 +29,7 @@ type hotColdHistogramPoint[N int64 | float64] struct { attrs attribute.Set res FilteredExemplarReservoir[N] + start time.Time } // histogramPointCounters contains only the atomic counter data, and is used by @@ -242,7 +243,6 @@ func (s *deltaHistogram[N]) collect( type cumulativeHistogram[N int64 | float64] struct { values limitedSyncMap - start time.Time noMinMax bool noSum bool bounds []float64 @@ -264,7 +264,6 @@ func newCumulativeHistogram[N int64 | float64]( b := slices.Clone(boundaries) slices.Sort(b) return &cumulativeHistogram[N]{ - start: now(), noMinMax: noMinMax, noSum: noSum, bounds: b, @@ -298,6 +297,7 @@ func (s *cumulativeHistogram[N]) measure( counts: make([]atomic.Uint64, len(s.bounds)+1), }, }, + start: now(), } return hPt }).(*hotColdHistogramPoint[N]) @@ -348,7 +348,7 @@ func (s *cumulativeHistogram[N]) collect( count := val.hotColdPoint[readIdx].loadCountsInto(&bucketCounts) newPt := metricdata.HistogramDataPoint[N]{ Attributes: val.attrs, - StartTime: s.start, + StartTime: val.start, Time: t, Count: count, Bounds: bounds, diff --git a/sdk/metric/internal/aggregate/lastvalue.go b/sdk/metric/internal/aggregate/lastvalue.go index 494864a91ef..26959402c03 100644 --- a/sdk/metric/internal/aggregate/lastvalue.go +++ b/sdk/metric/internal/aggregate/lastvalue.go @@ -16,6 +16,7 @@ type lastValuePoint[N int64 | float64] struct { attrs attribute.Set value atomicN[N] res FilteredExemplarReservoir[N] + start time.Time } // lastValue summarizes a set of measurements as the last one made. @@ -34,6 +35,7 @@ func (s *lastValueMap[N]) measure( return &lastValuePoint[N]{ res: s.newRes(attr), attrs: attr, + start: now(), } }).(*lastValuePoint[N]) @@ -128,7 +130,6 @@ func (s *deltaLastValue[N]) copyAndClearDpts( // cumulativeLastValue summarizes a set of measurements as the last one made. type cumulativeLastValue[N int64 | float64] struct { lastValueMap[N] - start time.Time } func newCumulativeLastValue[N int64 | float64]( @@ -140,7 +141,6 @@ func newCumulativeLastValue[N int64 | float64]( values: limitedSyncMap{aggLimit: limit}, newRes: r, }, - start: now(), } } @@ -161,7 +161,7 @@ func (s *cumulativeLastValue[N]) collect( v := value.(*lastValuePoint[N]) newPt := metricdata.DataPoint[N]{ Attributes: v.attrs, - StartTime: s.start, + StartTime: v.start, Time: t, Value: v.value.Load(), } diff --git a/sdk/metric/internal/aggregate/sum.go b/sdk/metric/internal/aggregate/sum.go index 66cb68085fd..18806f3eb0b 100644 --- a/sdk/metric/internal/aggregate/sum.go +++ b/sdk/metric/internal/aggregate/sum.go @@ -15,6 +15,7 @@ type sumValue[N int64 | float64] struct { n atomicCounter[N] res FilteredExemplarReservoir[N] attrs attribute.Set + start time.Time } type sumValueMap[N int64 | float64] struct { @@ -32,6 +33,7 @@ func (s *sumValueMap[N]) measure( return &sumValue[N]{ res: s.newRes(attr), attrs: attr, + start: now(), } }).(*sumValue[N]) sv.n.add(value) @@ -129,7 +131,6 @@ func newCumulativeSum[N int64 | float64]( ) *cumulativeSum[N] { return &cumulativeSum[N]{ monotonic: monotonic, - start: now(), sumValueMap: sumValueMap[N]{ values: limitedSyncMap{aggLimit: limit}, newRes: r, @@ -140,7 +141,6 @@ func newCumulativeSum[N int64 | float64]( // deltaSum is the storage for sums which never reset. type cumulativeSum[N int64 | float64] struct { monotonic bool - start time.Time sumValueMap[N] } @@ -165,7 +165,7 @@ func (s *cumulativeSum[N]) collect( val := value.(*sumValue[N]) newPt := metricdata.DataPoint[N]{ Attributes: val.attrs, - StartTime: s.start, + StartTime: val.start, Time: t, Value: val.n.load(), }