diff --git a/Cargo.toml b/Cargo.toml index a91ecbb4e0..e08de8187d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ hyper-util = "0.1" log = "0.4.21" once_cell = "1.13" ordered-float = "4.0" -pin-project-lite = "0.2" +pin-project-lite = "=0.2.14" # 0.2.15 is failing for cargo-check-external-types prost = "0.13" prost-build = "0.13" prost-types = "0.13" diff --git a/opentelemetry-sdk/benches/metrics_counter.rs b/opentelemetry-sdk/benches/metrics_counter.rs index 24a4403266..8361c423ef 100644 --- a/opentelemetry-sdk/benches/metrics_counter.rs +++ b/opentelemetry-sdk/benches/metrics_counter.rs @@ -12,7 +12,7 @@ | ThreadLocal_Random_Generator_5 | 37 ns | */ -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use opentelemetry::{ metrics::{Counter, MeterProvider as _}, KeyValue, @@ -57,62 +57,72 @@ fn criterion_benchmark(c: &mut Criterion) { fn counter_add_sorted(c: &mut Criterion) { let counter = create_counter("Counter_Add_Sorted"); c.bench_function("Counter_Add_Sorted", |b| { - b.iter(|| { - // 4*4*10*10 = 1600 time series. - let rands = CURRENT_RNG.with(|rng| { - let mut rng = rng.borrow_mut(); - [ - rng.gen_range(0..4), - rng.gen_range(0..4), - rng.gen_range(0..10), - rng.gen_range(0..10), - ] - }); - let index_first_attribute = rands[0]; - let index_second_attribute = rands[1]; - let index_third_attribute = rands[2]; - let index_fourth_attribute = rands[3]; - counter.add( - 1, - &[ - KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), - KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), - KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), - KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), - ], - ); - }); + b.iter_batched( + || { + // 4*4*10*10 = 1600 time series. + CURRENT_RNG.with(|rng| { + let mut rng = rng.borrow_mut(); + [ + rng.gen_range(0..4), + rng.gen_range(0..4), + rng.gen_range(0..10), + rng.gen_range(0..10), + ] + }) + }, + |rands| { + let index_first_attribute = rands[0]; + let index_second_attribute = rands[1]; + let index_third_attribute = rands[2]; + let index_fourth_attribute = rands[3]; + counter.add( + 1, + &[ + KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), + KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), + KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), + KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), + ], + ); + }, + BatchSize::SmallInput, + ); }); } fn counter_add_unsorted(c: &mut Criterion) { let counter = create_counter("Counter_Add_Unsorted"); c.bench_function("Counter_Add_Unsorted", |b| { - b.iter(|| { - // 4*4*10*10 = 1600 time series. - let rands = CURRENT_RNG.with(|rng| { - let mut rng = rng.borrow_mut(); - [ - rng.gen_range(0..4), - rng.gen_range(0..4), - rng.gen_range(0..10), - rng.gen_range(0..10), - ] - }); - let index_first_attribute = rands[0]; - let index_second_attribute = rands[1]; - let index_third_attribute = rands[2]; - let index_fourth_attribute = rands[3]; - counter.add( - 1, - &[ - KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), - KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), - KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), - KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), - ], - ); - }); + b.iter_batched( + || { + // 4*4*10*10 = 1600 time series. + CURRENT_RNG.with(|rng| { + let mut rng = rng.borrow_mut(); + [ + rng.gen_range(0..4), + rng.gen_range(0..4), + rng.gen_range(0..10), + rng.gen_range(0..10), + ] + }) + }, + |rands| { + let index_first_attribute = rands[0]; + let index_second_attribute = rands[1]; + let index_third_attribute = rands[2]; + let index_fourth_attribute = rands[3]; + counter.add( + 1, + &[ + KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), + KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), + KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), + KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), + ], + ); + }, + BatchSize::SmallInput, + ); }); } diff --git a/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs b/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs index c23b441663..e85e0ece55 100644 --- a/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs +++ b/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, f64::consts::LOG2_E, sync::Mutex, time::SystemTime}; use once_cell::sync::Lazy; -use opentelemetry::{metrics::MetricsError, KeyValue}; +use opentelemetry::{otel_debug, KeyValue}; use crate::{ metrics::data::{self, Aggregation, Temporality}, @@ -100,9 +100,18 @@ impl ExpoHistogramDataPoint { if (self.scale - scale_delta as i8) < EXPO_MIN_SCALE { // With a scale of -10 there is only two buckets for the whole range of f64 values. // This can only happen if there is a max size of 1. - opentelemetry::global::handle_error(MetricsError::Other( - "exponential histogram scale underflow".into(), - )); + + // TODO - to check if this should be logged as an error if this is auto-recoverable. + otel_debug!( + name: "ExponentialHistogramDataPoint.Scale.Underflow", + current_scale = self.scale, + scale_delta = scale_delta, + max_size = self.max_size, + min_scale = EXPO_MIN_SCALE, + value = format!("{:?}", v), + message = "The measurement will be dropped due to scale underflow. Check the histogram configuration" + ); + return; } // Downscale diff --git a/opentelemetry-sdk/src/metrics/manual_reader.rs b/opentelemetry-sdk/src/metrics/manual_reader.rs index e1cb571ec3..b79b1d7ae7 100644 --- a/opentelemetry-sdk/src/metrics/manual_reader.rs +++ b/opentelemetry-sdk/src/metrics/manual_reader.rs @@ -4,8 +4,8 @@ use std::{ }; use opentelemetry::{ - global, metrics::{MetricsError, Result}, + otel_debug, }; use super::{ @@ -77,9 +77,9 @@ impl MetricReader for ManualReader { if inner.sdk_producer.is_none() { inner.sdk_producer = Some(pipeline); } else { - global::handle_error(MetricsError::Config( - "duplicate reader registration, did not register manual reader".into(), - )) + otel_debug!( + name: "ManualReader.DuplicateRegistration", + message = "The pipeline is already registered to the Reader. Registering pipeline multiple times is not allowed."); } }); } diff --git a/opentelemetry-sdk/src/metrics/meter_provider.rs b/opentelemetry-sdk/src/metrics/meter_provider.rs index 591be34165..c91773434b 100644 --- a/opentelemetry-sdk/src/metrics/meter_provider.rs +++ b/opentelemetry-sdk/src/metrics/meter_provider.rs @@ -8,9 +8,8 @@ use std::{ }; use opentelemetry::{ - global, metrics::{Meter, MeterProvider, MetricsError, Result}, - KeyValue, + otel_debug, otel_error, KeyValue, }; use crate::{instrumentation::Scope, Resource}; @@ -137,13 +136,21 @@ impl Drop for SdkMeterProviderInner { fn drop(&mut self) { // If user has already shutdown the provider manually by calling // shutdown(), then we don't need to call shutdown again. - if !self.is_shutdown.load(Ordering::Relaxed) { - if let Err(err) = self.shutdown() { - global::handle_error(err); - } + if self.is_shutdown.load(Ordering::Relaxed) { + otel_debug!( + name: "MeterProvider.AlreadyShutdown", + message = "Meter provider was already shut down; drop will not attempt shutdown again." + ); + } else if let Err(err) = self.shutdown() { + otel_error!( + name: "MeterProvider.ShutdownFailed", + message = "Shutdown attempt failed during drop of MeterProvider.", + reason = format!("{}", err) + ); } } } + impl MeterProvider for SdkMeterProvider { fn versioned_meter( &self,