Skip to content

Commit ebf9bef

Browse files
committed
Code review.
1 parent d7bf628 commit ebf9bef

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

docs/core/diagnostics/metrics-instrumentation.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,16 +549,20 @@ Name Current Value
549549
550550
## Using Advice to customize Histogram instruments
551551

552-
Consumers of Histogram instruments can choose different aggregation strategies.
553-
The default mode when using OpenTelemetry is [Explicit Bucket Histogram
554-
Aggregation](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation).
555-
556-
When using explicit bucket aggregation the measurements recorded through a
557-
Histogram will be grouped into buckets which track the sum and count of values
558-
to that bucket.
559-
560-
The default bucket configuration is described in the OpenTelemetry
561-
Specification: `[ 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000,
552+
When using Histograms, it is the responsibility of the tool or library
553+
collecting the data to decide how best to represent the distribution of values
554+
that were recorded. A common strategy (and the [default mode when using
555+
OpenTelemetry](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation))
556+
is to divide up the range of possible values into sub-ranges called buckets and
557+
report how many recorded values were in each bucket. For example a tool might
558+
divide numbers into three buckets, those less than 1, those between 1-10, and
559+
those greater than 10. If your app recorded the values 0.5, 6, 0.1, 12 then
560+
there would be two data points the first bucket, one in the second, and one in
561+
the 3rd.
562+
563+
The tool or library collecting the Histogram data is responsible for defining
564+
the buckets it will use. The default bucket configuration when using
565+
OpenTelemetry is: `[ 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000,
562566
7500, 10000 ]`.
563567

564568
The default values may not lead to the best granularity for every Histogram. For
@@ -569,8 +573,17 @@ To solve this problem the `9.0.0` version of the
569573
(<xref:System.Diagnostics.Metrics.InstrumentAdvice%2A>) API.
570574

571575
The `InstrumentAdvice` API may be used by instrumentation authors to specify the
572-
set of recommended default bucket boundaries for a given Histogram. Consumers
573-
can then choose to use those values when configuring aggregation.
576+
set of recommended default bucket boundaries for a given Histogram. The tool or
577+
library collecting the Histogram data can then choose to use those values when
578+
configuring aggregation. This is supported in the OpenTelemetry .NET SDK as of
579+
version `1.10.0`.
580+
581+
> [!IMPORTANT]
582+
> In general more buckets will lead to more precise data for a given Histogram
583+
> but each bucket requires memory to store the aggregated details. It is
584+
> important to understand this tradeoff between precision and memory consumption
585+
> when choosing the number of buckets to recommend via the `InstrumentAdvice`
586+
> API.
574587
575588
The following code shows an example using the `InstrumentAdvice` API to set
576589
recommended default buckets.
@@ -583,12 +596,11 @@ using System.Threading;
583596
class Program
584597
{
585598
static Meter s_meter = new Meter("HatCo.Store");
586-
static readonly IReadOnlyList<double> s_shortSecondsBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10];
587599
static Histogram<double> s_orderProcessingTime = s_meter.CreateHistogram<double>(
588600
name: "hatco.store.order_processing_time",
589601
unit: "s",
590-
description: "Duration order processing.",
591-
advice: new InstrumentAdvice<double> { HistogramBucketBoundaries = s_shortSecondsBucketBoundaries });
602+
description: "Order processing duration",
603+
advice: new InstrumentAdvice<double> { HistogramBucketBoundaries = [0.01, 0.05, 0.1, 0.5, 1, 5] });
592604

593605
static Random s_rand = new Random();
594606

@@ -607,6 +619,14 @@ class Program
607619
}
608620
```
609621

622+
### Additional information
623+
624+
For more details about explicit bucket Histograms in OpenTelemetry see:
625+
626+
* [Why Histograms?](https://opentelemetry.io/blog/2023/why-histograms/)
627+
628+
* [Histograms vs Summaries](https://opentelemetry.io/blog/2023/histograms-vs-summaries/)
629+
610630
## Test custom metrics
611631

612632
Its possible to test any custom metrics you add using <xref:Microsoft.Extensions.Diagnostics.Metrics.Testing.MetricCollector%601>. This type makes it easy to record the measurements from specific instruments and assert the values were correct.

0 commit comments

Comments
 (0)