@@ -46,20 +46,36 @@ fn init_logs(is_simple: bool) -> Result<sdklogs::LoggerProvider> {
46
46
Ok ( logger_provider)
47
47
}
48
48
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 < ( ) > {
50
50
use crate :: { assert_logs_results_contains, init_logs} ;
51
51
test_utils:: start_collector_container ( ) . await ?;
52
52
53
53
let logger_provider = init_logs ( is_simple) . unwrap ( ) ;
54
54
let layer = OpenTelemetryTracingBridge :: new ( & logger_provider) ;
55
- let subscriber = tracing_subscriber:: registry ( ) . with ( layer) ;
56
55
// 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 ( ) ) ;
58
57
{
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
+ }
61
78
}
62
-
63
79
let _ = logger_provider. shutdown ( ) ;
64
80
tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
65
81
assert_logs_results_contains ( test_utils:: LOGS_FILE , expected_uuid. as_str ( ) ) ?;
@@ -152,70 +168,183 @@ mod logtests {
152
168
153
169
// Batch Processor
154
170
171
+ // logger initialization - Inside RT
172
+ // log emission - Inside RT
173
+ // Client - Tonic, Reqwest-blocking
174
+ // Worker threads - 4
155
175
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
156
176
#[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
157
177
pub async fn logs_batch_tokio_multi_thread ( ) -> Result < ( ) > {
158
- logs_tokio_helper ( false ) . await
178
+ logs_tokio_helper ( false , false ) . await
159
179
}
160
180
181
+ // logger initialization - Inside RT
182
+ // log emission - Inside RT
183
+ // Client - Tonic, Reqwest-blocking
184
+ // Worker threads - 1
161
185
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
162
186
#[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
163
187
pub async fn logs_batch_tokio_multi_with_one_worker ( ) -> Result < ( ) > {
164
- logs_tokio_helper ( false ) . await
188
+ logs_tokio_helper ( false , false ) . await
165
189
}
166
190
191
+ // logger initialization - Inside RT
192
+ // log emission - Inside RT
193
+ // Client - Tonic, Reqwest-blocking
194
+ // current thread
167
195
#[ tokio:: test( flavor = "current_thread" ) ]
168
196
#[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
169
197
pub async fn logs_batch_tokio_current ( ) -> Result < ( ) > {
170
- logs_tokio_helper ( false ) . await
198
+ logs_tokio_helper ( false , false ) . await
171
199
}
172
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
229
+ }
230
+
231
+ // logger initialization - Inside RT
232
+ // Log emission - Inside RT
233
+ // Client - Tonic, Reqwest-blocking
234
+ // current thread
173
235
#[ test]
174
236
#[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
175
237
pub fn logs_batch_non_tokio_main_init_logs_inside_rt ( ) -> Result < ( ) > {
176
238
logs_non_tokio_helper ( false , true )
177
239
}
178
240
241
+ // logger initialization - Outside RT
242
+ // log emission - Outside RT
243
+ // Client - Tonic, Reqwest-blocking
244
+ // current thread
179
245
#[ test]
180
246
#[ cfg( feature = "reqwest-blocking-client" ) ]
181
247
pub fn logs_batch_non_tokio_main_with_init_logs_outside_rt ( ) -> Result < ( ) > {
182
248
logs_non_tokio_helper ( false , false )
183
249
}
184
250
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**
186
262
263
+ // logger initialization - Inside RT
264
+ // log emission - Outside RT
265
+ // Client - Tonic, Reqwest-blocking
187
266
#[ test]
188
267
#[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
189
268
pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt ( ) -> Result < ( ) > {
190
269
logs_non_tokio_helper ( true , true )
191
270
}
192
271
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
193
276
#[ 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
+ ) ) ]
195
301
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt ( ) -> Result < ( ) > {
196
302
logs_non_tokio_helper ( true , false )
197
303
}
198
304
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
199
320
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
200
321
#[ cfg( any(
201
322
feature = "tonic-client" ,
202
323
feature = "reqwest-client" ,
203
324
feature = "hyper-client"
204
325
) ) ]
205
326
pub async fn logs_simple_tokio_multi_thread ( ) -> Result < ( ) > {
206
- logs_tokio_helper ( true ) . await
327
+ logs_tokio_helper ( true , false ) . await
207
328
}
208
329
330
+ // logger initialization - Inside RT
331
+ // log emission - Inside RT
332
+ // Client - Tonic, Reqwest, hyper
333
+ // Worker threads - 1
209
334
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
210
335
#[ cfg( any(
211
336
feature = "tonic-client" ,
212
337
feature = "reqwest-client" ,
213
338
feature = "hyper-client"
214
339
) ) ]
215
340
pub async fn logs_simple_tokio_multi_with_one_worker ( ) -> Result < ( ) > {
216
- logs_tokio_helper ( true ) . await
341
+ logs_tokio_helper ( true , false ) . await
217
342
}
218
343
344
+ // logger initialization - Inside RT
345
+ // log emission - Inside RT
346
+ // Client - Tonic, Reqwest, hyper
347
+ // Current thread
219
348
#[ ignore] // https://github.com/open-telemetry/opentelemetry-rust/issues/2539
220
349
#[ tokio:: test( flavor = "current_thread" ) ]
221
350
#[ cfg( any(
@@ -224,7 +353,7 @@ mod logtests {
224
353
feature = "hyper-client"
225
354
) ) ]
226
355
pub async fn logs_simple_tokio_current ( ) -> Result < ( ) > {
227
- logs_tokio_helper ( true ) . await
356
+ logs_tokio_helper ( true , false ) . await
228
357
}
229
358
}
230
359
///
0 commit comments