From a857a2b978379ff0df66319a1eb6e1c1933cf11e Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Fri, 14 Jun 2024 11:59:43 +0200 Subject: feat(tvix/tracing): apply EnvFilter to all layers Currently we apply the EnvFilter only to the stderr output writer. This didn't affect any other layer, like the otlp layer, causing spans from `h2`, `tokio_util` or other third party crate dependencies to be always sent out via OTLP. This changes that behaviour, applying EnvFilter to all exports, leading to a lot less spans being exported. Change-Id: I9f3a7233e9d0aeaa81fe08914579f0b3c80d134e Reviewed-on: https://cl.tvl.fyi/c/depot/+/11813 Tested-by: BuildkiteCI Reviewed-by: flokli Autosubmit: Simon Hauser --- tvix/tracing/src/lib.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tvix/tracing/src/lib.rs b/tvix/tracing/src/lib.rs index 312c9a5a9a62..9cfe5afa52d2 100644 --- a/tvix/tracing/src/lib.rs +++ b/tvix/tracing/src/lib.rs @@ -125,7 +125,8 @@ impl Default for TracingBuilder { } impl TracingBuilder { - /// Set the log level of the stderr writer, RUST_LOG still has a higher priority over this + /// Set the log level for all layers: stderr und otlp if configured. RUST_LOG still has a + /// higher priority over this value. pub fn level(mut self, level: Level) -> TracingBuilder { self.level = level; self @@ -139,8 +140,9 @@ impl TracingBuilder { } /// This will setup tracing based on the configuration passed in. - /// It will setup a stderr writer with the provided log level as filter (RUST_LOG still has a - /// higher priority over the configured value) + /// It will setup a stderr writer output layer and a EnvFilter based on the provided log + /// level (RUST_LOG still has a higher priority over the configured value). + /// The EnvFilter will be applied to all configured layers, also otlp. /// /// It will also configure otlp if the feature is enabled and a service_name was provided. It /// will then correctly setup a channel which is later used for flushing the provider. @@ -148,16 +150,16 @@ impl TracingBuilder { // Set up the tracing subscriber. let indicatif_layer = IndicatifLayer::new().with_progress_style(PB_SPINNER_STYLE.clone()); let subscriber = tracing_subscriber::registry() + .with( + EnvFilter::builder() + .with_default_directive(self.level.into()) + .from_env() + .expect("invalid RUST_LOG"), + ) .with( tracing_subscriber::fmt::Layer::new() .with_writer(indicatif_layer.get_stderr_writer()) - .compact() - .with_filter( - EnvFilter::builder() - .with_default_directive(self.level.into()) - .from_env() - .expect("invalid RUST_LOG"), - ), + .compact(), ) .with(indicatif_layer.with_filter( // only show progress for spans with indicatif.pb_show field being set -- cgit 1.4.1