Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

* Fixed an issue where the Base2 Exponential Bucket Histogram did not reset its
scale to 20 after each collection cycle when using delta aggregation temporality.
([#6557](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6557))

## 1.13.0

Released 2025-Oct-01
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,16 @@ public void Record(double value)
Debug.Assert(n == 0, "Increment should always succeed after scale down.");
}

internal void Reset()
internal void Reset(bool isMinMax)
{
// TODO: Determine if this is sufficient for delta temporality.
// I'm not sure we should be resetting the scale.
if (isMinMax)
{
this.RunningMin = double.PositiveInfinity;
this.RunningMax = double.NegativeInfinity;
}

this.Scale = Metric.DefaultExponentialHistogramMaxScale;
this.RunningSum = 0;
this.ZeroCount = 0;
this.PositiveBuckets.Reset();
this.NegativeBuckets.Reset();
Expand Down
8 changes: 2 additions & 6 deletions src/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ internal void TakeSnapshot(bool outputDelta)
if (outputDelta)
{
this.runningValue.AsLong = 0;
histogram.RunningSum = 0;
histogram.Reset();
histogram.Reset(false);
}

this.MetricPointStatus = MetricPointStatus.NoCollectPending;
Expand All @@ -848,10 +847,7 @@ internal void TakeSnapshot(bool outputDelta)
if (outputDelta)
{
this.runningValue.AsLong = 0;
histogram.RunningSum = 0;
histogram.Reset();
histogram.RunningMin = double.PositiveInfinity;
histogram.RunningMax = double.NegativeInfinity;
histogram.Reset(true);
}

this.MetricPointStatus = MetricPointStatus.NoCollectPending;
Expand Down
7 changes: 6 additions & 1 deletion test/OpenTelemetry.Tests/Metrics/AggregatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,12 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega
var count = metricPoint.GetHistogramCount();
var sum = metricPoint.GetHistogramSum();
var hasMinMax = metricPoint.TryGetHistogramMinMaxValues(out var min, out var max);
var firstScale = metricPoint.GetExponentialHistogramData().Scale;

AssertExponentialBucketsAreCorrect(expectedHistogram, metricPoint.GetExponentialHistogramData());
Assert.Equal(50, sum);
Assert.Equal(6, count);
Assert.True(firstScale <= Metric.DefaultExponentialHistogramMaxScale);

if (aggregationType == AggregationType.Base2ExponentialHistogramWithMinMax)
{
Expand All @@ -373,12 +375,14 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega
count = metricPoint.GetHistogramCount();
sum = metricPoint.GetHistogramSum();
hasMinMax = metricPoint.TryGetHistogramMinMaxValues(out min, out max);
var secondScale = metricPoint.GetExponentialHistogramData().Scale;

if (aggregationTemporality == AggregationTemporality.Cumulative)
{
AssertExponentialBucketsAreCorrect(expectedHistogram, metricPoint.GetExponentialHistogramData());
Assert.Equal(50, sum);
Assert.Equal(6, count);
Assert.Equal(firstScale, secondScale);

if (aggregationType == AggregationType.Base2ExponentialHistogramWithMinMax)
{
Expand All @@ -393,10 +397,11 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega
}
else
{
expectedHistogram.Reset();
expectedHistogram.Reset(aggregationType == AggregationType.HistogramWithMinMax);
AssertExponentialBucketsAreCorrect(expectedHistogram, metricPoint.GetExponentialHistogramData());
Assert.Equal(0, sum);
Assert.Equal(0, count);
Assert.Equal(Metric.DefaultExponentialHistogramMaxScale, secondScale);

if (aggregationType == AggregationType.Base2ExponentialHistogramWithMinMax)
{
Expand Down
Loading