Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging: propogate tracing subscriber for all threads #110

Closed
Gor027 opened this issue Apr 23, 2023 · 0 comments · Fixed by #111
Closed

Logging: propogate tracing subscriber for all threads #110

Gor027 opened this issue Apr 23, 2023 · 0 comments · Fixed by #111
Assignees
Labels
bug Something isn't working

Comments

@Gor027
Copy link
Contributor

Gor027 commented Apr 23, 2023

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.

@Gor027 Gor027 added the bug Something isn't working label Apr 24, 2023
Gor027 added a commit to Gor027/cpp-rust-driver that referenced this issue Apr 26, 2023
Set default tracing subscriber globally for all threads for the duration
of the entire program. This can be set only once, so subsequent attemps
to set the log level through `cass_log_set_level` will be ignored. The logging
configuration must be done before any other driver function is called,
otherwise, the default logging callback will be used, and logs will
appear on stderr.

Fixes scylladb#110
@Gor027 Gor027 self-assigned this Apr 26, 2023
Gor027 added a commit to Gor027/cpp-rust-driver that referenced this issue Apr 26, 2023
Set default tracing subscriber globally for all threads for the duration
of the entire program. This can be set only once, so subsequent attemps
to set the log level through `cass_log_set_level` will be ignored. The logging
configuration must be done before any other driver function is called,
otherwise, the default logging callback will be used, and logs will
appear on stderr.

Fixes scylladb#110
Gor027 added a commit to Gor027/cpp-rust-driver that referenced this issue Jun 11, 2023
Set default tracing subscriber globally for all threads for the duration
of the entire program. This can be set only once, so subsequent attemps
to set the log level through `cass_log_set_level` will be ignored. The logging
configuration must be done before any other driver function is called,
otherwise, the default logging callback will be used, and logs will
appear on stderr.

Fixes scylladb#110
syuu1228 pushed a commit to syuu1228/cpp-rust-driver that referenced this issue Apr 11, 2024
Set default tracing subscriber globally for all threads for the duration
of the entire program. This can be set only once, so subsequent attemps
to set the log level through `cass_log_set_level` will be ignored. The logging
configuration must be done before any other driver function is called,
otherwise, the default logging callback will be used, and logs will
appear on stderr.

Fixes scylladb#110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant