scylladb / cpp-rust-driver

API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.
GNU Lesser General Public License v2.1
11 stars 11 forks source link

Logging: propogate tracing subscriber for all threads #110

Closed Gor027 closed 1 year ago

Gor027 commented 1 year ago

Currently, the tracing::subscriber::set_default function sets our custom subscriber as the default subscriber for the duration of the lifetime of the returned DefaultGuard value. However, it does not propagate the current thread's default subscriber to all threads because of which some log events (including Rust driver's logs) are not captured. To check that, run a simple test example with RUNTIME in lib.rs built with new_current_thread:

pub static ref RUNTIME: Runtime =
            tokio::runtime::Builder::new_current_thread()
                    .enable_all()
                    .build()
                    .unwrap();

As the integration tests set a custom log callback, all logs from the test example will be written to a file in build/log/{TEST} directory which is not the case with a multithreaded environment.

One possible solution is to use the set_global_default function which will set the subscriber as default for all threads for the lifetime of the program. However, it can be called once and the subscriber cannot be changed later, for example, to change the log level during the runtime of the application. In fact, the C++ driver does not support dynamic configuration of logging, and the configuration must not be changed after any other driver function is called, e.g. cass_session_connect. So, the solution does not contradict to C++ driver's API requirements. Unfortunately, I could not find a way to have a dynamic logging configuration with the current tracing_subscriber API, so if you have an idea to accomplish that, please share it in the scope of this issue.