Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug loop, add notes for #[tokio::test] #552

Merged
merged 2 commits into from May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions opentelemetry/src/lib.rs
Expand Up @@ -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
//!
Expand All @@ -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`]
Expand Down
31 changes: 30 additions & 1 deletion opentelemetry/src/sdk/metrics/mod.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}