@@ -123,6 +123,49 @@ mod logtests {
123123 Ok ( ( ) )
124124 }
125125
126+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
127+ #[ cfg( any( feature = "tonic-client" ) ) ]
128+ pub async fn logs_simple_tokio_multi_thread ( ) -> Result < ( ) > {
129+ logs_simple_tokio_helper ( ) . await
130+ }
131+
132+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
133+ #[ cfg( any( feature = "tonic-client" ) ) ]
134+ pub async fn logs_simple_tokio_multi_with_one_worker ( ) -> Result < ( ) > {
135+ logs_simple_tokio_helper ( ) . await
136+ }
137+
138+ // Ignored, to be investigated
139+ #[ ignore]
140+ #[ tokio:: test( flavor = "current_thread" ) ]
141+ #[ cfg( any( feature = "tonic-client" ) ) ]
142+ pub async fn logs_simple_tokio_current ( ) -> Result < ( ) > {
143+ logs_simple_tokio_helper ( ) . await
144+ }
145+
146+ async fn logs_simple_tokio_helper ( ) -> Result < ( ) > {
147+ use crate :: { assert_logs_results, init_logs} ;
148+ test_utils:: start_collector_container ( ) . await ?;
149+
150+ let logger_provider = init_logs ( true ) . unwrap ( ) ;
151+ let layer = OpenTelemetryTracingBridge :: new ( & logger_provider) ;
152+ let subscriber = tracing_subscriber:: registry ( ) . with ( layer) ;
153+ info ! ( "Tracing initialized" ) ;
154+ // generate a random uuid and store it to expected guid
155+ let expected_uuid = Uuid :: new_v4 ( ) . to_string ( ) ;
156+ {
157+ let _guard = tracing:: subscriber:: set_default ( subscriber) ;
158+ info ! ( "Tracing subscriber initialized" ) ;
159+ info ! ( target: "my-target" , uuid = expected_uuid, "hello from {}. My price is {}." , "banana" , 2.99 ) ;
160+ info ! ( "Log emitted" ) ;
161+ }
162+
163+ let _ = logger_provider. shutdown ( ) ;
164+ tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
165+ assert_logs_results ( test_utils:: LOGS_FILE , expected_uuid. as_str ( ) ) ?;
166+ Ok ( ( ) )
167+ }
168+
126169 #[ test]
127170 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
128171 pub fn logs_batch_non_tokio_main ( ) -> Result < ( ) > {
0 commit comments