Skip to content

Don't trace tasks spawned through the console server #314

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

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions console-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tokio-stream = "0.1"
thread_local = "1.1.3"
console-api = { version = "0.2.0", path = "../console-api", features = ["transport"] }
tonic = { version = "0.7", features = ["transport"] }
tracing-core = "0.1.18"
tracing-core = "0.1.24"
tracing = "0.1.26"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["fmt", "registry"] }
futures = { version = "0.3", default-features = false }
Expand All @@ -58,4 +58,4 @@ futures = "0.3"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
21 changes: 21 additions & 0 deletions console-subscriber/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub struct Builder {

/// The filter environment variable to use for `tracing` events.
pub(super) filter_env_var: String,

/// Whether to trace events coming from the subscriber thread
self_trace: bool,
}

impl Default for Builder {
Expand All @@ -51,6 +54,7 @@ impl Default for Builder {
server_addr: SocketAddr::new(Server::DEFAULT_IP, Server::DEFAULT_PORT),
recording_path: None,
filter_env_var: "RUST_LOG".to_string(),
self_trace: false,
}
}
}
Expand Down Expand Up @@ -176,6 +180,15 @@ impl Builder {
}
}

/// Sets whether tasks, resources, and async ops from the console
/// subscriber thread are recorded.
///
/// By default, events from the console subscriber are discarded and
/// not exported to clients.
pub fn enable_self_trace(self, self_trace: bool) -> Self {
Self { self_trace, ..self }
}

/// Completes the builder, returning a [`ConsoleLayer`] and [`Server`] task.
pub fn build(self) -> (ConsoleLayer, Server) {
ConsoleLayer::build(self)
Expand Down Expand Up @@ -368,6 +381,8 @@ impl Builder {
meta.name().starts_with("runtime.") || meta.target().starts_with("tokio")
}

let self_trace = self.self_trace;

let (layer, server) = self.build();
let filter =
FilterFn::new(console_filter as for<'r, 's> fn(&'r tracing::Metadata<'s>) -> bool);
Expand All @@ -376,6 +391,12 @@ impl Builder {
thread::Builder::new()
.name("console_subscriber".into())
.spawn(move || {
let _subscriber_guard;
if !self_trace {
_subscriber_guard = tracing::subscriber::set_default(
tracing_core::subscriber::NoSubscriber::default(),
);
}
let runtime = runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
Expand Down