diff --git a/opentelemetry-otlp/tests/integration_test/tests/logs.rs b/opentelemetry-otlp/tests/integration_test/tests/logs.rs index 169df71601..26ad95c995 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/logs.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/logs.rs @@ -46,20 +46,36 @@ fn init_logs(is_simple: bool) -> Result { Ok(logger_provider) } -async fn logs_tokio_helper(is_simple: bool) -> Result<()> { +async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result<()> { use crate::{assert_logs_results_contains, init_logs}; test_utils::start_collector_container().await?; let logger_provider = init_logs(is_simple).unwrap(); let layer = OpenTelemetryTracingBridge::new(&logger_provider); - let subscriber = tracing_subscriber::registry().with(layer); // generate a random uuid and store it to expected guid - let expected_uuid = Uuid::new_v4().to_string(); + let expected_uuid = std::sync::Arc::new(Uuid::new_v4().to_string()); { - let _guard = tracing::subscriber::set_default(subscriber); - info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99); + let clone_uuid = expected_uuid.clone(); + if log_send_outside_rt { + std::thread::spawn(move || { + let subscriber = tracing_subscriber::registry().with(layer); + let _guard = tracing::subscriber::set_default(subscriber); + info!( + target: "my-target", + uuid = clone_uuid.as_str(), + "hello from {}. My price is {}.", + "banana", + 2.99 + ); + }) + .join() + .unwrap(); + } else { + let subscriber = tracing_subscriber::registry().with(layer); + let _guard = tracing::subscriber::set_default(subscriber); + info!(target: "my-target", uuid = expected_uuid.as_str(), "hello from {}. My price is {}.", "banana", 2.99); + } } - let _ = logger_provider.shutdown(); tokio::time::sleep(Duration::from_secs(5)).await; assert_logs_results_contains(test_utils::LOGS_FILE, expected_uuid.as_str())?; @@ -152,50 +168,155 @@ mod logtests { // Batch Processor + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 4 #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub async fn logs_batch_tokio_multi_thread() -> Result<()> { - logs_tokio_helper(false).await + logs_tokio_helper(false, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 1 #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub async fn logs_batch_tokio_multi_with_one_worker() -> Result<()> { - logs_tokio_helper(false).await + logs_tokio_helper(false, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // current thread #[tokio::test(flavor = "current_thread")] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub async fn logs_batch_tokio_current() -> Result<()> { - logs_tokio_helper(false).await + logs_tokio_helper(false, false).await } + // logger initialization - Inside RT + // Log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 4 + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] + #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] + pub async fn logs_batch_tokio_log_outside_rt_multi_thread() -> Result<()> { + logs_tokio_helper(false, true).await + } + + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 1 + #[tokio::test(flavor = "multi_thread", worker_threads = 1)] + #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] + pub async fn logs_batch_tokio_log_outside_rt_multi_with_one_worker() -> Result<()> { + logs_tokio_helper(false, true).await + } + + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // current thread + #[tokio::test(flavor = "current_thread")] + #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] + pub async fn logs_batch_tokio_log_outside_rt_current_thread() -> Result<()> { + logs_tokio_helper(false, true).await + } + + // logger initialization - Inside RT + // Log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // current thread #[test] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub fn logs_batch_non_tokio_main_init_logs_inside_rt() -> Result<()> { logs_non_tokio_helper(false, true) } + // logger initialization - Outside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // current thread #[test] #[cfg(feature = "reqwest-blocking-client")] pub fn logs_batch_non_tokio_main_with_init_logs_outside_rt() -> Result<()> { logs_non_tokio_helper(false, false) } - // Simple Processor + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // current thread + #[test] + #[cfg(feature = "reqwest-blocking-client")] + pub fn logs_batch_non_tokio_main_with_init_logs_inside_rt() -> Result<()> { + logs_non_tokio_helper(false, true) + } + + // **Simple Processor** + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking #[test] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt() -> Result<()> { logs_non_tokio_helper(true, true) } + // logger initialization - Inside RT + // log emission - Outside RT + // Client - reqwest, hyper + #[ignore] // request and hyper client does not work without tokio runtime #[test] - #[cfg(any(feature = "reqwest-blocking-client"))] + #[cfg(any(feature = "reqwest-client", feature = "hyper-client"))] + pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt() -> Result<()> { + logs_non_tokio_helper(true, true) + } + + // logger initialization - Outside RT + // log emission - Outside RT + // Client - Reqwest-blocking + #[test] + #[cfg(feature = "reqwest-blocking-client")] + pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> { + logs_non_tokio_helper(true, false) + } + + // logger initialization - Outside RT + // log emission - Outside RT + // Client - hyper, tonic, reqwest + #[ignore] // request, tonic and hyper client does not work without tokio runtime + #[test] + #[cfg(any( + feature = "hyper-client", + feature = "tonic-client", + feature = "reqwest-client" + ))] pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> { logs_non_tokio_helper(true, false) } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - reqwest-blocking + // Worker threads - 4 + #[ignore] // request-blocking client does not work with tokio + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] + #[cfg(feature = "reqwest-blocking-client")] + pub async fn logs_simple_tokio_multi_thread() -> Result<()> { + logs_tokio_helper(true, false).await + } + + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest, hyper + // Worker threads - 4 #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[cfg(any( feature = "tonic-client", @@ -203,9 +324,13 @@ mod logtests { feature = "hyper-client" ))] pub async fn logs_simple_tokio_multi_thread() -> Result<()> { - logs_tokio_helper(true).await + logs_tokio_helper(true, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest, hyper + // Worker threads - 1 #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[cfg(any( feature = "tonic-client", @@ -213,9 +338,13 @@ mod logtests { feature = "hyper-client" ))] pub async fn logs_simple_tokio_multi_with_one_worker() -> Result<()> { - logs_tokio_helper(true).await + logs_tokio_helper(true, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest, hyper + // Current thread #[ignore] // https://github.com/open-telemetry/opentelemetry-rust/issues/2539 #[tokio::test(flavor = "current_thread")] #[cfg(any( @@ -224,7 +353,7 @@ mod logtests { feature = "hyper-client" ))] pub async fn logs_simple_tokio_current() -> Result<()> { - logs_tokio_helper(true).await + logs_tokio_helper(true, false).await } } ///