Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Jan 24, 2025
1 parent 927a08c commit 4ce76df
Showing 1 changed file with 141 additions and 14 deletions.
155 changes: 141 additions & 14 deletions opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,35 @@ fn init_logs(is_simple: bool) -> Result<sdklogs::LoggerProvider> {
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);
//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())?;
Expand Down Expand Up @@ -110,6 +125,7 @@ fn assert_logs_results_contains(result: &str, expected_content: &str) -> Result<
let mut contents = String::new();
let mut reader = std::io::BufReader::new(&file);
reader.read_to_string(&mut contents)?;
println!("---->>>> Contents: {}", contents);
assert!(contents.contains(expected_content));
Ok(())
}
Expand Down Expand Up @@ -152,70 +168,179 @@ 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-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(any(feature = "reqwest-blocking-client"))]
#[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",
feature = "reqwest-client",
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",
feature = "reqwest-client",
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(
Expand All @@ -224,8 +349,10 @@ mod logtests {
feature = "hyper-client"
))]
pub async fn logs_simple_tokio_current() -> Result<()> {
logs_tokio_helper(true).await
logs_tokio_helper(true, false).await
}


}
///
/// Make sure we stop the collector container, otherwise it will sit around hogging our
Expand Down

0 comments on commit 4ce76df

Please sign in to comment.