Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tokio based simple
Browse files Browse the repository at this point in the history
cijothomas committed Jan 17, 2025
1 parent 8343f4a commit bc1e600
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
@@ -123,6 +123,49 @@ mod logtests {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[cfg(any(feature = "tonic-client"))]
pub async fn logs_simple_tokio_multi_thread() -> Result<()> {
logs_simple_tokio_helper().await
}

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
#[cfg(any(feature = "tonic-client"))]
pub async fn logs_simple_tokio_multi_with_one_worker() -> Result<()> {
logs_simple_tokio_helper().await
}

// Ignored, to be investigated
#[ignore]
#[tokio::test(flavor = "current_thread")]
#[cfg(any(feature = "tonic-client"))]
pub async fn logs_simple_tokio_current() -> Result<()> {
logs_simple_tokio_helper().await
}

async fn logs_simple_tokio_helper() -> Result<()> {
use crate::{assert_logs_results, init_logs};
test_utils::start_collector_container().await?;

let logger_provider = init_logs(true).unwrap();
let layer = OpenTelemetryTracingBridge::new(&logger_provider);
let subscriber = tracing_subscriber::registry().with(layer);
info!("Tracing initialized");
// generate a random uuid and store it to expected guid
let expected_uuid = Uuid::new_v4().to_string();
{
let _guard = tracing::subscriber::set_default(subscriber);
info!("Tracing subscriber initialized");
info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99);
info!("Log emitted");
}

let _ = logger_provider.shutdown();
tokio::time::sleep(Duration::from_secs(5)).await;
assert_logs_results(test_utils::LOGS_FILE, expected_uuid.as_str())?;
Ok(())
}

#[test]
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
pub fn logs_batch_non_tokio_main() -> Result<()> {

0 comments on commit bc1e600

Please sign in to comment.