Skip to content

Commit 4c77c89

Browse files
lalitbcijothomas
andauthored
More integration tests added (#2545)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent 95fa209 commit 4c77c89

File tree

1 file changed

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

1 file changed

+143
-14
lines changed

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

Lines changed: 143 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,36 @@ 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);
5655
// generate a random uuid and store it to expected guid
57-
let expected_uuid = Uuid::new_v4().to_string();
56+
let expected_uuid = std::sync::Arc::new(Uuid::new_v4().to_string());
5857
{
59-
let _guard = tracing::subscriber::set_default(subscriber);
60-
info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99);
58+
let clone_uuid = expected_uuid.clone();
59+
if log_send_outside_rt {
60+
std::thread::spawn(move || {
61+
let subscriber = tracing_subscriber::registry().with(layer);
62+
let _guard = tracing::subscriber::set_default(subscriber);
63+
info!(
64+
target: "my-target",
65+
uuid = clone_uuid.as_str(),
66+
"hello from {}. My price is {}.",
67+
"banana",
68+
2.99
69+
);
70+
})
71+
.join()
72+
.unwrap();
73+
} else {
74+
let subscriber = tracing_subscriber::registry().with(layer);
75+
let _guard = tracing::subscriber::set_default(subscriber);
76+
info!(target: "my-target", uuid = expected_uuid.as_str(), "hello from {}. My price is {}.", "banana", 2.99);
77+
}
6178
}
62-
6379
let _ = logger_provider.shutdown();
6480
tokio::time::sleep(Duration::from_secs(5)).await;
6581
assert_logs_results_contains(test_utils::LOGS_FILE, expected_uuid.as_str())?;
@@ -152,70 +168,183 @@ 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
171199
}
172200

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
229+
}
230+
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+
}
260+
261+
// **Simple Processor**
186262

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
193276
#[test]
194-
#[cfg(any(feature = "reqwest-blocking-client"))]
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
285+
#[test]
286+
#[cfg(feature = "reqwest-blocking-client")]
287+
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> {
288+
logs_non_tokio_helper(true, false)
289+
}
290+
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(
297+
feature = "hyper-client",
298+
feature = "tonic-client",
299+
feature = "reqwest-client"
300+
))]
195301
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> {
196302
logs_non_tokio_helper(true, false)
197303
}
198304

305+
// logger initialization - Inside RT
306+
// log emission - Inside RT
307+
// Client - reqwest-blocking
308+
// Worker threads - 4
309+
#[ignore] // request-blocking client does not work with tokio
310+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
311+
#[cfg(feature = "reqwest-blocking-client")]
312+
pub async fn logs_simple_tokio_multi_thread() -> Result<()> {
313+
logs_tokio_helper(true, false).await
314+
}
315+
316+
// logger initialization - Inside RT
317+
// log emission - Inside RT
318+
// Client - Tonic, Reqwest, hyper
319+
// Worker threads - 4
199320
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
200321
#[cfg(any(
201322
feature = "tonic-client",
202323
feature = "reqwest-client",
203324
feature = "hyper-client"
204325
))]
205326
pub async fn logs_simple_tokio_multi_thread() -> Result<()> {
206-
logs_tokio_helper(true).await
327+
logs_tokio_helper(true, false).await
207328
}
208329

330+
// logger initialization - Inside RT
331+
// log emission - Inside RT
332+
// Client - Tonic, Reqwest, hyper
333+
// Worker threads - 1
209334
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
210335
#[cfg(any(
211336
feature = "tonic-client",
212337
feature = "reqwest-client",
213338
feature = "hyper-client"
214339
))]
215340
pub async fn logs_simple_tokio_multi_with_one_worker() -> Result<()> {
216-
logs_tokio_helper(true).await
341+
logs_tokio_helper(true, false).await
217342
}
218343

344+
// logger initialization - Inside RT
345+
// log emission - Inside RT
346+
// Client - Tonic, Reqwest, hyper
347+
// Current thread
219348
#[ignore] // https://github.com/open-telemetry/opentelemetry-rust/issues/2539
220349
#[tokio::test(flavor = "current_thread")]
221350
#[cfg(any(
@@ -224,7 +353,7 @@ mod logtests {
224353
feature = "hyper-client"
225354
))]
226355
pub async fn logs_simple_tokio_current() -> Result<()> {
227-
logs_tokio_helper(true).await
356+
logs_tokio_helper(true, false).await
228357
}
229358
}
230359
///

0 commit comments

Comments
 (0)