Skip to content

Commit 66d2621

Browse files
authored
Rename histogram configuration bucketbounds to boundaries (#2638)
1 parent 1be29c8 commit 66d2621

11 files changed

Lines changed: 57 additions & 51 deletions

File tree

docs/metrics/customizing-the-sdk/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public static void Main(string[] args)
3333
// Rename an instrument to new name.
3434
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")
3535

36-
// Change Histogram bounds
37-
.AddView(instrumentName: "MyHistogram", new HistogramConfiguration() { BucketBounds = new double[] { 10, 20 } })
36+
// Change Histogram boundaries
37+
.AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } })
3838

3939
// For the instrument "MyCounterCustomTags", aggregate with only the keys "tag1", "tag2".
4040
.AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = new string[] { "tag1", "tag2" } })
@@ -48,7 +48,7 @@ public static void Main(string[] args)
4848
if (instrument.Meter.Name.Equals("CompanyA.ProductB.Library2") &&
4949
instrument.GetType().Name.Contains("Histogram"))
5050
{
51-
return new HistogramConfiguration() { BucketBounds = new double[] { 10, 20 } };
51+
return new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } };
5252
}
5353

5454
return null;

docs/metrics/customizing-the-sdk/README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,30 +218,31 @@ with the metric are of interest to you.
218218
})
219219
```
220220

221-
#### Specify custom bounds for Histogram
221+
#### Specify custom boundaries for Histogram
222222

223-
By default, the bounds used for a Histogram are [`{ 0, 5, 10, 25, 50, 75, 100,
223+
By default, the boundaries used for a Histogram are [`{ 0, 5, 10, 25, 50, 75, 100,
224224
250, 500,
225225
1000}`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation).
226-
Views can be used to provide custom bounds for a Histogram. The measurements are
227-
then aggregated using the custom bounds provided instead of the the default
228-
bounds. This requires the use of `HistogramConfiguration`.
226+
Views can be used to provide custom boundaries for a Histogram. The measurements
227+
are then aggregated using the custom boundaries provided instead of the the
228+
default boundaries. This requires the use of `ExplicitBucketHistogramConfiguration`.
229229

230230
```csharp
231-
// Change Histogram bounds to count measurements under the following buckets:
231+
// Change Histogram boundaries to count measurements under the following buckets:
232232
// (-inf, 10]
233233
// (10, 20]
234234
// (20, +inf)
235235
.AddView(
236236
instrumentName: "MyHistogram",
237-
new HistogramConfiguration{ BucketBounds = new double[] { 10, 20 } })
237+
new ExplicitBucketHistogramConfiguration
238+
{ Boundaries = new double[] { 10, 20 } })
238239

239-
// If you provide an empty `double` array as `BucketBounds` to the `HistogramConfiguration`,
240+
// If you provide an empty `double` array as `Boundaries` to the `ExplicitBucketHistogramConfiguration`,
240241
// the SDK will only export the sum and count for the measurements.
241242
// There are no buckets exported in this case.
242243
.AddView(
243244
instrumentName: "MyHistogram",
244-
new HistogramConfiguration { BucketBounds = new double[] { } })
245+
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { } })
245246
```
246247

247248
```csharp
@@ -251,10 +252,10 @@ bounds. This requires the use of `HistogramConfiguration`.
251252
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
252253
instrument.Name == "MyHistogram")
253254
{
254-
// `HistogramConfiguration` is a child class of `MetricStreamConfiguration`
255-
return new HistogramConfiguration
255+
// `ExplicitBucketHistogramConfiguration` is a child class of `MetricStreamConfiguration`
256+
return new ExplicitBucketHistogramConfiguration
256257
{
257-
BucketBounds = new double[] { 10, 20 },
258+
Boundaries = new double[] { 10, 20 },
258259
};
259260
}
260261

src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ OpenTelemetry.Metrics.ExportModes.Push = 1 -> OpenTelemetry.Metrics.ExportModes
3535
OpenTelemetry.Metrics.ExportModesAttribute
3636
OpenTelemetry.Metrics.ExportModesAttribute.ExportModesAttribute(OpenTelemetry.Metrics.ExportModes supported) -> void
3737
OpenTelemetry.Metrics.ExportModesAttribute.Supported.get -> OpenTelemetry.Metrics.ExportModes
38-
OpenTelemetry.Metrics.HistogramConfiguration
39-
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.get -> double[]
40-
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.set -> void
41-
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
38+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
39+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
40+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
41+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
4242
OpenTelemetry.Metrics.IPullMetricExporter
4343
OpenTelemetry.Metrics.IPullMetricExporter.Collect.get -> System.Func<int, bool>
4444
OpenTelemetry.Metrics.IPullMetricExporter.Collect.set -> void
@@ -100,8 +100,8 @@ override OpenTelemetry.Metrics.BaseExportingMetricReader.Dispose(bool disposing)
100100
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnCollect(int timeoutMilliseconds) -> bool
101101
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnShutdown(int timeoutMilliseconds) -> bool
102102
override OpenTelemetry.Metrics.BaseExportingMetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
103-
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
104-
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.set -> void
103+
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
104+
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.set -> void
105105
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Metrics.MeterProviderBuilder
106106
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddMeter(params string[] names) -> OpenTelemetry.Metrics.MeterProviderBuilder
107107
override OpenTelemetry.Metrics.PeriodicExportingMetricReader.Dispose(bool disposing) -> void

src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ OpenTelemetry.Metrics.ExportModes.Push = 1 -> OpenTelemetry.Metrics.ExportModes
3535
OpenTelemetry.Metrics.ExportModesAttribute
3636
OpenTelemetry.Metrics.ExportModesAttribute.ExportModesAttribute(OpenTelemetry.Metrics.ExportModes supported) -> void
3737
OpenTelemetry.Metrics.ExportModesAttribute.Supported.get -> OpenTelemetry.Metrics.ExportModes
38-
OpenTelemetry.Metrics.HistogramConfiguration
39-
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.get -> double[]
40-
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.set -> void
41-
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
38+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
39+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
40+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
41+
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
4242
OpenTelemetry.Metrics.IPullMetricExporter
4343
OpenTelemetry.Metrics.IPullMetricExporter.Collect.get -> System.Func<int, bool>
4444
OpenTelemetry.Metrics.IPullMetricExporter.Collect.set -> void
@@ -100,8 +100,8 @@ override OpenTelemetry.Metrics.BaseExportingMetricReader.Dispose(bool disposing)
100100
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnCollect(int timeoutMilliseconds) -> bool
101101
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnShutdown(int timeoutMilliseconds) -> bool
102102
override OpenTelemetry.Metrics.BaseExportingMetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
103-
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
104-
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.set -> void
103+
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
104+
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.set -> void
105105
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Metrics.MeterProviderBuilder
106106
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddMeter(params string[] names) -> OpenTelemetry.Metrics.MeterProviderBuilder
107107
override OpenTelemetry.Metrics.PeriodicExportingMetricReader.Dispose(bool disposing) -> void

src/OpenTelemetry/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
* Renamed `HistogramConfiguration` to `ExplicitBucketHistogramConfiguration`
6+
and changed its member `BucketBounds` to `Boundaries`.
7+
([#2638](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2638))
8+
59
* Metrics with the same name but from different meters are allowed.
610
([#2634](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2634))
711

src/OpenTelemetry/Metrics/HistogramConfiguration.cs renamed to src/OpenTelemetry/Metrics/ExplicitBucketHistogramConfiguration.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="HistogramConfiguration.cs" company="OpenTelemetry Authors">
1+
// <copyright file="ExplicitBucketHistogramConfiguration.cs" company="OpenTelemetry Authors">
22
// Copyright The OpenTelemetry Authors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,17 +18,18 @@
1818

1919
namespace OpenTelemetry.Metrics
2020
{
21-
public class HistogramConfiguration : MetricStreamConfiguration
21+
public class ExplicitBucketHistogramConfiguration : MetricStreamConfiguration
2222
{
2323
private Aggregation aggregation = Aggregation.Histogram;
2424

2525
/// <summary>
26-
/// Gets or sets the custom histogram bounds.
26+
/// Gets or sets the values representing explicit histogram bucket
27+
/// boundary values.
2728
/// </summary>
2829
/// <remarks>
2930
/// The array must be in ascending order with distinct values.
3031
/// </remarks>
31-
public double[] BucketBounds { get; set; }
32+
public double[] Boundaries { get; set; }
3233

3334
public override Aggregation Aggregation
3435
{

src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ public static MeterProviderBuilder AddView(this MeterProviderBuilder meterProvid
8686
throw new ArgumentException($"Custom view name {metricStreamConfiguration.Name} is invalid.", nameof(metricStreamConfiguration.Name));
8787
}
8888

89-
if (metricStreamConfiguration is HistogramConfiguration histogramConfiguration)
89+
if (metricStreamConfiguration is ExplicitBucketHistogramConfiguration histogramConfiguration)
9090
{
91-
// Validate histogram bounds
92-
if (histogramConfiguration.BucketBounds != null && !IsSortedAndDistinct(histogramConfiguration.BucketBounds))
91+
// Validate histogram boundaries
92+
if (histogramConfiguration.Boundaries != null && !IsSortedAndDistinct(histogramConfiguration.Boundaries))
9393
{
94-
throw new ArgumentException($"Histogram bounds must be in ascending order with distinct values", nameof(histogramConfiguration.BucketBounds));
94+
throw new ArgumentException($"Histogram boundaries must be in ascending order with distinct values", nameof(histogramConfiguration.Boundaries));
9595
}
9696
}
9797

src/OpenTelemetry/Metrics/MeterProviderSdk.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ internal MeterProviderSdk(
195195
Metric metric;
196196
var metricDescription = metricStreamConfig?.Description ?? instrument.Description;
197197
string[] tagKeysInteresting = metricStreamConfig?.TagKeys;
198-
double[] histogramBucketBounds = (metricStreamConfig is HistogramConfiguration histogramConfig
199-
&& histogramConfig.BucketBounds != null) ? histogramConfig.BucketBounds : null;
198+
double[] histogramBucketBounds = (metricStreamConfig is ExplicitBucketHistogramConfiguration histogramConfig
199+
&& histogramConfig.Boundaries != null) ? histogramConfig.Boundaries : null;
200200
metric = new Metric(instrument, temporality, metricName, metricDescription, histogramBucketBounds, tagKeysInteresting);
201201

202202
this.metrics[index] = metric;

test/OpenTelemetry.Tests/Metrics/AggregatorTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public void HistogramDistributeToAllBucketsDefault()
5959
[Fact]
6060
public void HistogramDistributeToAllBucketsCustom()
6161
{
62-
var bounds = new double[] { 10, 20 };
63-
var histogramPoint = new MetricPoint(AggregationType.Histogram, DateTimeOffset.Now, null, null, bounds);
62+
var boundaries = new double[] { 10, 20 };
63+
var histogramPoint = new MetricPoint(AggregationType.Histogram, DateTimeOffset.Now, null, null, boundaries);
6464

6565
// 5 recordings <=10
6666
histogramPoint.Update(-10);
@@ -80,7 +80,7 @@ public void HistogramDistributeToAllBucketsCustom()
8080

8181
// Count = # of recordings
8282
Assert.Equal(7, histogramPoint.LongValue);
83-
Assert.Equal(bounds.Length + 1, histogramPoint.BucketCounts.Length);
83+
Assert.Equal(boundaries.Length + 1, histogramPoint.BucketCounts.Length);
8484
Assert.Equal(5, histogramPoint.BucketCounts[0]);
8585
Assert.Equal(2, histogramPoint.BucketCounts[1]);
8686
Assert.Equal(0, histogramPoint.BucketCounts[2]);
@@ -89,8 +89,8 @@ public void HistogramDistributeToAllBucketsCustom()
8989
[Fact]
9090
public void HistogramWithOnlySumCount()
9191
{
92-
var bounds = new double[] { };
93-
var histogramPoint = new MetricPoint(AggregationType.HistogramSumCount, DateTimeOffset.Now, null, null, bounds);
92+
var boundaries = new double[] { };
93+
var histogramPoint = new MetricPoint(AggregationType.HistogramSumCount, DateTimeOffset.Now, null, null, boundaries);
9494

9595
histogramPoint.Update(-10);
9696
histogramPoint.Update(0);

test/OpenTelemetry.Tests/Metrics/MetricTestData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IEnumerable<object[]> ValidInstrumentNames
4141
new object[] { new string('m', 63) },
4242
};
4343

44-
public static IEnumerable<object[]> InvalidHistogramBounds
44+
public static IEnumerable<object[]> InvalidHistogramBoundaries
4545
=> new List<object[]>
4646
{
4747
new object[] { new double[] { 0, 0 } },

0 commit comments

Comments
 (0)