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

More integration tests added #2545

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 143 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,36 @@ 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);
// 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 @@ -152,70 +168,183 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add link to the open issue for easy tracking.

#[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",
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,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
}
}
///
Expand Down
Loading