Document how to configure exponential histograms (#4481)

This commit is contained in:
Alan West 2023-05-12 11:47:22 -07:00 committed by GitHub
parent 5768a7567a
commit 01f3891b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 1 deletions

View File

@ -234,7 +234,19 @@ with the metric are of interest to you.
})
```
#### Specify custom boundaries for Histogram
#### Configuring the aggregation of a Histogram
There are two types of
[Histogram aggregations](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#histogram-aggregations):
the
[Explicit bucket histogram aggregation](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation)
and the
[Base2 exponential bucket histogram aggregation](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#base2-exponential-bucket-histogram-aggregation).
Views can be used to select which aggregation is used and to configure the
parameters of the aggregation. By default, the explicit bucket aggregation is
used.
##### Explicit bucket histogram aggregation
By default, the boundaries used for a Histogram are [`{ 0, 5, 10, 25, 50, 75,
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).
@ -278,6 +290,37 @@ default boundaries. This requires the use of
})
```
##### Base2 exponential bucket histogram aggregation
By default, a Histogram is configured to use the
`ExplicitBucketHistogramConfiguration`. Views are used to switch a Histogram to
use the `Base2ExponentialBucketHistogramConfiguration`.
The bucket boundaries for a Base2 Exponential Bucket Histogram Aggregation
are determined dynamically based on the configured `MaxSize` and `MaxScale`
parameters. The parameters are used to adjust the resolution of the Histogram
buckets. Larger values of `MaxScale` enables higher resolution, however the
scale may be adjusted down such that the full range of recorded values fit
within the maximum number of buckets defined by `MaxSize`. The default
`MaxSize` is 160 buckets and the default `MaxScale` is 20.
```csharp
// Change the maximum number of buckets
.AddView(
instrumentName: "MyHistogram",
new Base2ExponentialBucketHistogramConfiguration { MaxSize = 40 })
```
```csharp
// Configure all histogram instruments to use the Base2 Exponential Histogram aggregation
.AddView((instrument) =>
{
return instrument.GetType().GetGenericTypeDefinition() == typeof(Histogram<>)
? new Base2ExponentialBucketHistogramConfiguration()
: null;
})
```
> **Note**
> The SDK currently does not support any changes to `Aggregation` type
by using Views.