Skip to content

Commit d113ecf

Browse files
authored
[docs-metrics] Add content for histogram bucket configuration via advice api (#5965)
1 parent 2aae6e1 commit d113ecf

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

RELEASENOTES.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ directory of each individual package.
1414

1515
* [InstrumentAdvice<T>](https://learn.microsoft.com/dotnet/api/system.diagnostics.metrics.instrumentadvice-1)
1616

17+
For details see: [Explicit bucket histogram
18+
aggregation](./docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation).
19+
1720
* [Gauge<T>](https://learn.microsoft.com/dotnet/api/system.diagnostics.metrics.gauge-1)
1821

1922
* [ActivitySource.Tags](https://learn.microsoft.com/dotnet/api/system.diagnostics.activitysource.tags)

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

+48-21
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,56 @@ used.
200200

201201
##### Explicit bucket histogram aggregation
202202

203-
By default, the boundaries used for a Histogram are [`{ 0, 5, 10, 25, 50, 75,
204-
100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}`](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation).
205-
Views can be used to provide custom boundaries for a Histogram. The measurements
206-
are then aggregated using the custom boundaries provided instead of the
207-
default boundaries. This requires the use of
208-
`ExplicitBucketHistogramConfiguration`.
203+
By default, the [OpenTelemetry
204+
Specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation)
205+
defines explicit buckets (aka boundaries) for Histograms as: `[ 0, 5, 10, 25,
206+
50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000 ]`.
209207

210-
```csharp
211-
// Change Histogram boundaries to count measurements under the following buckets:
212-
// (-inf, 10]
213-
// (10, 20]
214-
// (20, +inf)
215-
.AddView(
216-
instrumentName: "MyHistogram",
217-
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { 10, 20 } })
208+
###### Customizing explicit buckets when using histogram aggregation
218209

219-
// If you provide an empty `double` array as `Boundaries` to the `ExplicitBucketHistogramConfiguration`,
220-
// the SDK will only export the sum, count, min and max for the measurements.
221-
// There are no buckets exported in this case.
222-
.AddView(
223-
instrumentName: "MyHistogram",
224-
new ExplicitBucketHistogramConfiguration { Boundaries = Array.Empty<double>() })
225-
```
210+
There are two mechanisms available to configure explicit buckets when using
211+
histogram aggregation:
212+
213+
* View API - Part of the OpenTelemetry .NET SDK.
214+
* Advice API - Part of the `System.Diagnostics.DiagnosticSource` package
215+
starting with version `9.0.0`.
216+
217+
> [!IMPORTANT]
218+
> When both the View API and Advice API are used, the View API takes precedence.
219+
If explicit buckets are not provided by either the View API or the Advice API
220+
then the SDK defaults apply.
221+
222+
* View API
223+
224+
Views can be used to provide custom explicit buckets for a Histogram. This
225+
requires the use of `ExplicitBucketHistogramConfiguration`.
226+
227+
```csharp
228+
// Change Histogram boundaries to count measurements under the following buckets:
229+
// (-inf, 10]
230+
// (10, 20]
231+
// (20, +inf)
232+
.AddView(
233+
instrumentName: "MyHistogram",
234+
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { 10, 20 } })
235+
236+
// If you provide an empty `double` array as `Boundaries` to the `ExplicitBucketHistogramConfiguration`,
237+
// the SDK will only export the sum, count, min and max for the measurements.
238+
// There are no buckets exported in this case.
239+
.AddView(
240+
instrumentName: "MyHistogram",
241+
new ExplicitBucketHistogramConfiguration { Boundaries = Array.Empty<double>() })
242+
```
243+
244+
* Advice API
245+
246+
Starting with the `1.10.0` SDK, explicit buckets for a Histogram may be provided
247+
by instrumentation authors when the instrument is created. This is generally
248+
recommended to be used by library authors when the SDK defaults don't match the
249+
required granularity for the histogram being emitted.
250+
251+
See:
252+
[InstrumentAdvice&lt;T&gt;](https://learn.microsoft.com/dotnet/api/system.diagnostics.metrics.instrumentadvice-1).
226253

227254
##### Base2 exponential bucket histogram aggregation
228255

0 commit comments

Comments
 (0)