diff --git a/zebrad/src/application.rs b/zebrad/src/application.rs index 1685ef9cc..50e97a495 100644 --- a/zebrad/src/application.rs +++ b/zebrad/src/application.rs @@ -84,11 +84,15 @@ impl Application for ZebradApp { &mut self, command: &Self::Cmd, ) -> Result>>, FrameworkError> { - let terminal = Terminal::new(self.term_colors(command)); - let tracing = self.tracing_component(command); color_eyre::install().unwrap(); - Ok(vec![Box::new(terminal), Box::new(tracing)]) + let terminal = Terminal::new(self.term_colors(command)); + if ZebradApp::command_is_server(&command) { + let tracing = self.tracing_component(command); + Ok(vec![Box::new(terminal), Box::new(tracing)]) + } else { + Ok(vec![Box::new(terminal)]) + } } /// Register all components used by this application. @@ -101,16 +105,10 @@ impl Application for ZebradApp { metrics::MetricsEndpoint, tokio::TokioComponent, tracing::TracingEndpoint, }; - // `None` outputs zebrad usage information and exits - let command_is_server = match &command.command { - None => false, - Some(c) => c.is_server(), - }; - let mut components = self.framework_components(command)?; - components.push(Box::new(TokioComponent::new()?)); // Launch network endpoints for long-running commands - if command_is_server { + if ZebradApp::command_is_server(&command) { + components.push(Box::new(TokioComponent::new()?)); components.push(Box::new(TracingEndpoint::new()?)); components.push(Box::new(MetricsEndpoint::new()?)); } @@ -132,12 +130,14 @@ impl Application for ZebradApp { self.state.components.after_config(&config)?; self.config = Some(config); - let level = self.level(command); - self.state - .components - .get_downcast_mut::() - .expect("Tracing component should be available") - .reload_filter(level); + if ZebradApp::command_is_server(&command) { + let level = self.level(command); + self.state + .components + .get_downcast_mut::() + .expect("Tracing component should be available") + .reload_filter(level); + } Ok(()) } @@ -198,4 +198,16 @@ impl ZebradApp { filter_handle.into() } + + /// Returns true if command is a server command. + /// + /// Server commands use long-running components such as tracing, metrics, + /// and the tokio runtime. + fn command_is_server(command: &EntryPoint) -> bool { + // `None` outputs zebrad usage information and exits + match &command.command { + None => false, + Some(c) => c.is_server(), + } + } }