Skip to content

Commit 19bba98

Browse files
examples/metrics-advanced: add explanation
1 parent 5eb0601 commit 19bba98

File tree

1 file changed

+10
-0
lines changed
  • examples/metrics-advanced/src

1 file changed

+10
-0
lines changed

examples/metrics-advanced/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
3434
};
3535

3636
// for example 3
37+
// Unlike a regular OpenTelemetry histogram with fixed buckets, which can be
38+
// specified explicitly, an exponential histogram calculates bucket widths
39+
// automatically, growing them exponentially. The configuration is
40+
// controlled by two parameters: max_size defines the maximum number of
41+
// buckets, while max_scale adjusts the resolution, with higher values
42+
// providing greater precision.
43+
// https://opentelemetry.io/docs/specs/otel/metrics/data-model/#exponentialhistogram
3744
let my_view_change_aggregation = |i: &Instrument| {
3845
if i.name() == "my_third_histogram" {
3946
Stream::builder()
@@ -130,6 +137,9 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
130137
histogram2.record(1.8, &[KeyValue::new("mykey1", "v7")]);
131138

132139
// Example 3 - Use exponential histogram.
140+
// Internally the exponential histogram puts values either into a list of
141+
// negative buckets or a set of positive buckets. Based on the values which
142+
// are added the buckets are adjusted.
133143
let histogram3 = meter
134144
.f64_histogram("my_third_histogram")
135145
.with_description("My histogram example description")

0 commit comments

Comments
 (0)