zebrad: pass TracingSection to Tracing component
This commit is contained in:
parent
4544463059
commit
e8c16b172f
|
@ -139,16 +139,24 @@ impl Application for ZebradApp {
|
|||
.map(ZebradCmd::is_server)
|
||||
.unwrap_or(false);
|
||||
|
||||
// Launch network endpoints for long-running commands
|
||||
// Launch network endpoints only for long-running commands.
|
||||
if is_server {
|
||||
let filter = cfg_ref.tracing.filter.as_deref().unwrap_or(default_filter);
|
||||
let flame_root = cfg_ref.tracing.flamegraph.as_deref();
|
||||
components.push(Box::new(Tracing::new(filter, flame_root)?));
|
||||
// Override the default tracing filter based on the command-line verbosity.
|
||||
let mut tracing_config = cfg_ref.tracing.clone();
|
||||
tracing_config.filter = tracing_config
|
||||
.filter
|
||||
.or_else(|| Some(default_filter.to_owned()));
|
||||
|
||||
components.push(Box::new(Tracing::new(tracing_config)?));
|
||||
components.push(Box::new(TokioComponent::new()?));
|
||||
components.push(Box::new(TracingEndpoint::new(cfg_ref)?));
|
||||
components.push(Box::new(MetricsEndpoint::new(cfg_ref)?));
|
||||
} else {
|
||||
components.push(Box::new(Tracing::new(default_filter, None)?));
|
||||
// Don't apply the configured filter for short-lived commands.
|
||||
let mut tracing_config = cfg_ref.tracing.clone();
|
||||
tracing_config.filter = Some(default_filter.to_owned());
|
||||
tracing_config.flamegraph = None;
|
||||
components.push(Box::new(Tracing::new(tracing_config)?));
|
||||
}
|
||||
|
||||
self.state.components.register(components)
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
use std::path::Path;
|
||||
|
||||
use abscissa_core::{Component, FrameworkError, FrameworkErrorKind, Shutdown};
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::{
|
||||
fmt::Formatter, layer::SubscriberExt, reload::Handle, util::SubscriberInitExt, EnvFilter,
|
||||
FmtSubscriber,
|
||||
};
|
||||
|
||||
use abscissa_core::{Component, FrameworkError, FrameworkErrorKind, Shutdown};
|
||||
use crate::config::TracingSection;
|
||||
|
||||
use super::flame;
|
||||
|
||||
|
@ -18,7 +17,10 @@ pub struct Tracing {
|
|||
|
||||
impl Tracing {
|
||||
/// Try to create a new [`Tracing`] component with the given `filter`.
|
||||
pub fn new(filter: &str, flame_root: Option<&Path>) -> Result<Self, FrameworkError> {
|
||||
pub fn new(config: TracingSection) -> Result<Self, FrameworkError> {
|
||||
let filter = config.filter.unwrap_or_else(|| "".to_string());
|
||||
let flame_root = &config.flamegraph;
|
||||
|
||||
// Construct a tracing subscriber with the supplied filter and enable reloading.
|
||||
let builder = FmtSubscriber::builder()
|
||||
.with_ansi(true)
|
||||
|
|
Loading…
Reference in New Issue