Skip to content

Commit 4ce76df

Browse files
committed
more tests
1 parent 927a08c commit 4ce76df

File tree

1 file changed

+141
-14
lines changed
  • opentelemetry-otlp/tests/integration_test/tests

1 file changed

+141
-14
lines changed

opentelemetry-otlp/tests/integration_test/tests/logs.rs

Lines changed: 141 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,35 @@ fn init_logs(is_simple: bool) -> Result<sdklogs::LoggerProvider> {
4646
Ok(logger_provider)
4747
}
4848

49-
async fn logs_tokio_helper(is_simple: bool) -> Result<()> {
49+
async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result<()> {
5050
use crate::{assert_logs_results_contains, init_logs};
5151
test_utils::start_collector_container().await?;
5252

5353
let logger_provider = init_logs(is_simple).unwrap();
5454
let layer = OpenTelemetryTracingBridge::new(&logger_provider);
55-
let subscriber = tracing_subscriber::registry().with(layer);
55+
//let subscriber = tracing_subscriber::registry().with(layer);
5656
// generate a random uuid and store it to expected guid
57-
let expected_uuid = Uuid::new_v4().to_string();
57+
let expected_uuid = std::sync::Arc::new(Uuid::new_v4().to_string());
5858
{
59-
let _guard = tracing::subscriber::set_default(subscriber);
60-
info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99);
59+
let clone_uuid = expected_uuid.clone();
60+
if log_send_outside_rt {
61+
std::thread::spawn( move || {
62+
let subscriber = tracing_subscriber::registry().with(layer);
63+
let _guard = tracing::subscriber::set_default(subscriber);
64+
info!(
65+
target: "my-target",
66+
uuid = clone_uuid.as_str(),
67+
"hello from {}. My price is {}.",
68+
"banana",
69+
2.99
70+
);
71+
}).join().unwrap();
72+
} else {
73+
let subscriber = tracing_subscriber::registry().with(layer);
74+
let _guard = tracing::subscriber::set_default(subscriber);
75+
info!(target: "my-target", uuid = expected_uuid.as_str(), "hello from {}. My price is {}.", "banana", 2.99);
76+
}
6177
}
62-
6378
let _ = logger_provider.shutdown();
6479
tokio::time::sleep(Duration::from_secs(5)).await;
6580
assert_logs_results_contains(test_utils::LOGS_FILE, expected_uuid.as_str())?;
@@ -110,6 +125,7 @@ fn assert_logs_results_contains(result: &str, expected_content: &str) -> Result<
110125
let mut contents = String::new();
111126
let mut reader = std::io::BufReader::new(&file);
112127
reader.read_to_string(&mut contents)?;
128+
println!("---->>>> Contents: {}", contents);
113129
assert!(contents.contains(expected_content));
114130
Ok(())
115131
}
@@ -152,70 +168,179 @@ mod logtests {
152168

153169
// Batch Processor
154170

171+
// logger initialization - Inside RT
172+
// log emission - Inside RT
173+
// Client - Tonic, Reqwest-blocking
174+
// Worker threads - 4
155175
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
156176
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
157177
pub async fn logs_batch_tokio_multi_thread() -> Result<()> {
158-
logs_tokio_helper(false).await
178+
logs_tokio_helper(false, false).await
159179
}
160180

181+
// logger initialization - Inside RT
182+
// log emission - Inside RT
183+
// Client - Tonic, Reqwest-blocking
184+
// Worker threads - 1
161185
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
162186
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
163187
pub async fn logs_batch_tokio_multi_with_one_worker() -> Result<()> {
164-
logs_tokio_helper(false).await
188+
logs_tokio_helper(false, false).await
165189
}
166190

191+
// logger initialization - Inside RT
192+
// log emission - Inside RT
193+
// Client - Tonic, Reqwest-blocking
194+
// current thread
167195
#[tokio::test(flavor = "current_thread")]
168196
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
169197
pub async fn logs_batch_tokio_current() -> Result<()> {
170-
logs_tokio_helper(false).await
198+
logs_tokio_helper(false, false).await
199+
}
200+
201+
// logger initialization - Inside RT
202+
// Log emission - Outside RT
203+
// Client - Tonic, Reqwest-blocking
204+
// Worker threads - 4
205+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
206+
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
207+
pub async fn logs_batch_tokio_log_outside_rt_multi_thread() -> Result<()> {
208+
logs_tokio_helper(false, true).await
209+
}
210+
211+
// logger initialization - Inside RT
212+
// log emission - Outside RT
213+
// Client - Tonic, Reqwest-blocking
214+
// Worker threads - 1
215+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
216+
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
217+
pub async fn logs_batch_tokio_log_outside_rt_multi_with_one_worker() -> Result<()> {
218+
logs_tokio_helper(false, true).await
219+
}
220+
221+
// logger initialization - Inside RT
222+
// log emission - Outside RT
223+
// Client - Tonic, Reqwest-blocking
224+
// current thread
225+
#[tokio::test(flavor = "current_thread")]
226+
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
227+
pub async fn logs_batch_tokio_log_outside_rt_current_thread() -> Result<()> {
228+
logs_tokio_helper(false, true).await
171229
}
172230

231+
// logger initialization - Inside RT
232+
// Log emission - Inside RT
233+
// Client - Tonic, Reqwest-blocking
234+
// current thread
173235
#[test]
174236
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
175237
pub fn logs_batch_non_tokio_main_init_logs_inside_rt() -> Result<()> {
176238
logs_non_tokio_helper(false, true)
177239
}
178240

241+
// logger initialization - Outside RT
242+
// log emission - Outside RT
243+
// Client - Tonic, Reqwest-blocking
244+
// current thread
179245
#[test]
180246
#[cfg(feature = "reqwest-blocking-client")]
181247
pub fn logs_batch_non_tokio_main_with_init_logs_outside_rt() -> Result<()> {
182248
logs_non_tokio_helper(false, false)
183249
}
184250

185-
// Simple Processor
251+
// logger initialization - Inside RT
252+
// log emission - Outside RT
253+
// Client - Tonic, Reqwest-blocking
254+
// current thread
255+
#[test]
256+
#[cfg(feature = "reqwest-blocking-client")]
257+
pub fn logs_batch_non_tokio_main_with_init_logs_inside_rt() -> Result<()> {
258+
logs_non_tokio_helper(false, true)
259+
}
186260

261+
// **Simple Processor**
262+
263+
// logger initialization - Inside RT
264+
// log emission - Outside RT
265+
// Client - Tonic, Reqwest-blocking
187266
#[test]
188267
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
189268
pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt() -> Result<()> {
190269
logs_non_tokio_helper(true, true)
191270
}
192271

272+
// logger initialization - Inside RT
273+
// log emission - Outside RT
274+
// Client - reqwest, hyper
275+
#[ignore] // request and hyper client does not work without tokio runtime
276+
#[test]
277+
#[cfg(any(feature = "reqwest-client", feature = "hyper-client"))]
278+
pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt() -> Result<()> {
279+
logs_non_tokio_helper(true, true)
280+
}
281+
282+
// logger initialization - Outside RT
283+
// log emission - Outside RT
284+
// Client - Reqwest-blocking
193285
#[test]
194-
#[cfg(any(feature = "reqwest-blocking-client"))]
286+
#[cfg(feature = "reqwest-blocking-client")]
195287
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> {
196288
logs_non_tokio_helper(true, false)
197289
}
198290

291+
// logger initialization - Outside RT
292+
// log emission - Outside RT
293+
// Client - hyper, tonic, reqwest
294+
#[ignore] // request, tonic and hyper client does not work without tokio runtime
295+
#[test]
296+
#[cfg(any(feature = "hyper-client", feature = "tonic-client", feature = "reqwest-client"))]
297+
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> {
298+
logs_non_tokio_helper(true, false)
299+
}
300+
301+
// logger initialization - Inside RT
302+
// log emission - Inside RT
303+
// Client - reqwest-blocking
304+
// Worker threads - 4
305+
#[ignore] // request-blocking client does not work with tokio
306+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
307+
#[cfg(feature = "reqwest-blocking-client")]
308+
pub async fn logs_simple_tokio_multi_thread() -> Result<()> {
309+
logs_tokio_helper(true, false).await
310+
}
311+
312+
// logger initialization - Inside RT
313+
// log emission - Inside RT
314+
// Client - Tonic, Reqwest, hyper
315+
// Worker threads - 4
199316
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
200317
#[cfg(any(
201318
feature = "tonic-client",
202319
feature = "reqwest-client",
203320
feature = "hyper-client"
204321
))]
205322
pub async fn logs_simple_tokio_multi_thread() -> Result<()> {
206-
logs_tokio_helper(true).await
323+
logs_tokio_helper(true, false).await
207324
}
208325

326+
// logger initialization - Inside RT
327+
// log emission - Inside RT
328+
// Client - Tonic, Reqwest, hyper
329+
// Worker threads - 1
209330
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
210331
#[cfg(any(
211332
feature = "tonic-client",
212333
feature = "reqwest-client",
213334
feature = "hyper-client"
214335
))]
215336
pub async fn logs_simple_tokio_multi_with_one_worker() -> Result<()> {
216-
logs_tokio_helper(true).await
337+
logs_tokio_helper(true, false).await
217338
}
218339

340+
// logger initialization - Inside RT
341+
// log emission - Inside RT
342+
// Client - Tonic, Reqwest, hyper
343+
// Current thread
219344
#[ignore] // https://github.com/open-telemetry/opentelemetry-rust/issues/2539
220345
#[tokio::test(flavor = "current_thread")]
221346
#[cfg(any(
@@ -224,8 +349,10 @@ mod logtests {
224349
feature = "hyper-client"
225350
))]
226351
pub async fn logs_simple_tokio_current() -> Result<()> {
227-
logs_tokio_helper(true).await
352+
logs_tokio_helper(true, false).await
228353
}
354+
355+
229356
}
230357
///
231358
/// Make sure we stop the collector container, otherwise it will sit around hogging our

0 commit comments

Comments
 (0)