Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Notes](../../RELEASENOTES.md).
exception is thrown by their constructor after resource creation.
([#7615](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7615))

* Restored configured `MaxScale` after delta exponential histogram collection.
([#7671](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7671))

## 1.17.0

Released 2026-Jul-16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal sealed partial class Base2ExponentialBucketHistogram

internal ExponentialHistogramData SnapshotExponentialHistogramData = new();

private readonly int maxScale;
private int scale;
private double scalingFactor; // 2 ^ scale / log(2)

Expand Down Expand Up @@ -90,6 +91,7 @@ The following table is calculated based on [ MapToIndex(double.Epsilon), MapToIn
*/
Guard.ThrowIfOutOfRange(maxBuckets, min: 2);

this.maxScale = scale;
this.Scale = scale;
this.PositiveBuckets = new CircularBufferBuckets(maxBuckets);
this.NegativeBuckets = new CircularBufferBuckets(maxBuckets);
Expand Down Expand Up @@ -213,7 +215,7 @@ internal void Reset(bool isMinMax)
this.RunningMax = double.NegativeInfinity;
}

this.Scale = Metric.DefaultExponentialHistogramMaxScale;
this.Scale = this.maxScale;
this.RunningSum = 0;
this.ZeroCount = 0;
this.PositiveBuckets.Reset();
Expand All @@ -235,8 +237,9 @@ internal Base2ExponentialBucketHistogram Copy()
{
Debug.Assert(this.PositiveBuckets.Capacity == this.NegativeBuckets.Capacity, "Capacity of positive and negative buckets are not equal.");

return new Base2ExponentialBucketHistogram(this.PositiveBuckets.Capacity, this.SnapshotExponentialHistogramData.Scale)
return new Base2ExponentialBucketHistogram(this.PositiveBuckets.Capacity, this.maxScale)
{
Scale = this.SnapshotExponentialHistogramData.Scale,
SnapshotSum = this.SnapshotSum,
SnapshotMin = this.SnapshotMin,
SnapshotMax = this.SnapshotMax,
Expand Down
33 changes: 33 additions & 0 deletions test/OpenTelemetry.Tests/Metrics/AggregatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,39 @@ internal void ExponentialMaxScaleConfigWorks(int? maxScale)
Assert.Equal(expectedScale, metricPoint.GetExponentialHistogramData().Scale);
}

[Theory]
[InlineData(-5)]
[InlineData(5)]
internal void ExponentialMaxScaleConfigPersistsAfterDeltaSnapshot(int maxScale)
{
var streamConfiguration = new Base2ExponentialBucketHistogramConfiguration { MaxScale = maxScale };
var metricStreamIdentity = new MetricStreamIdentity(Instrument, streamConfiguration);

var aggregatorStore = new AggregatorStore(
metricStreamIdentity,
AggregationType.Base2ExponentialHistogram,
AggregationTemporality.Delta,
cardinalityLimit: 1024);

aggregatorStore.Update(10, []);
aggregatorStore.Snapshot();

var metricPoints = new List<MetricPoint>();
foreach (ref readonly var mp in aggregatorStore.GetMetricPoints())
{
metricPoints.Add(mp);
}

Assert.Single(metricPoints);
var metricPoint = metricPoints[0];
Comment thread
martincostello marked this conversation as resolved.
Resolved
Assert.Equal(maxScale, metricPoint.GetExponentialHistogramData().Scale);

// A subsequent delta snapshot should retain the configured maximum scale.
metricPoint.TakeSnapshot(outputDelta: true);

Assert.Equal(maxScale, metricPoint.GetExponentialHistogramData().Scale);
}

[Theory]
#pragma warning disable xUnit1045 // Avoid using TheoryData type arguments that might not be serializable
[MemberData(nameof(HistogramBoundaryTestCase.HistogramInfinityBoundariesTestCases))]
Expand Down