diff --git a/opentelemetry/src/lib.rs b/opentelemetry/src/lib.rs index b5f4c27000..7c9d0ade5c 100644 --- a/opentelemetry/src/lib.rs +++ b/opentelemetry/src/lib.rs @@ -60,8 +60,9 @@ //! to use batch span processors where the spans will be sent in batch, reducing the number of requests //! and resource needed. //! -//! Batch span processors need to run a background task to collect and send spans. Different runtime -//! needs different ways to handle the background task. +//! Batch span processors need to run a background task to collect and send spans. Different runtimes +//! need different ways to handle the background task. Using a `Runtime` that's not compatible with the +//! underlying runtime can cause deadlock. //! //! ### Tokio //! @@ -72,6 +73,9 @@ //! task with other tasks in the same runtime. Thus, users should enable `rt-tokio-current-thread` feature //! to ask the background task be scheduled on a different runtime on a different thread. //! +//! Note that by default `#[tokio::test]` uses `current_thread_scheduler` and should use `rt-tokio-current-thread` +//! feature. +//! //! ## Related Crates //! //! In addition to `opentelemetry`, the [`open-telemetry/opentelemetry-rust`] diff --git a/opentelemetry/src/sdk/metrics/mod.rs b/opentelemetry/src/sdk/metrics/mod.rs index f76468811e..00816dc4f4 100644 --- a/opentelemetry/src/sdk/metrics/mod.rs +++ b/opentelemetry/src/sdk/metrics/mod.rs @@ -513,12 +513,20 @@ impl sdk_api::SyncBoundInstrumentCore for Record { } } -#[derive(Debug)] struct Instrument { descriptor: Descriptor, meter: Accumulator, } +impl std::fmt::Debug for Instrument { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Instrument") + .field("descriptor", &self.descriptor) + .field("meter", &"Accumulator") + .finish() + } +} + impl sdk_api::InstrumentCore for Instrument { fn descriptor(&self) -> &Descriptor { &self.descriptor @@ -579,3 +587,24 @@ impl sdk_api::MeterCore for Accumulator { self.0.register_runner(runner) } } + +#[cfg(test)] +mod tests { + use crate::metrics::MeterProvider; + use crate::sdk::export::metrics::ExportKindSelector; + use crate::sdk::metrics::controllers::pull; + use crate::sdk::metrics::selectors::simple::Selector; + + // Prevent the debug message to get into loop + #[test] + fn test_debug_message() { + let controller = pull( + Box::new(Selector::Exact), + Box::new(ExportKindSelector::Delta), + ) + .build(); + let meter = controller.provider().meter("test", None); + let counter = meter.f64_counter("test").init(); + println!("{:?}, {:?}, {:?}", controller, meter, counter); + } +}