Skip to content
Open
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
2 changes: 1 addition & 1 deletion crates/agent/src/ethernet_virtualization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ mod tests {
use crate::{HBNDeviceNames, dhcp, nvue};
#[ctor::ctor(unsafe)]
fn setup() {
carbide_host_support::init_logging().unwrap();
carbide_host_support::init_logging("nico-dpu-agent").unwrap();
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::time::Duration;

fn main() -> eyre::Result<()> {
carbide_host_support::init_logging()?;
carbide_host_support::init_logging("nico-dpu-agent")?;

// We need a multi-threaded runtime since background threads will queue work
// on it, and the foreground thread might not be blocked onto the runtime
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/tests/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async fn run_common_parts(
virtualization_type: VpcVirtualizationType,
test_metadata_service: bool,
) -> eyre::Result<TestOut> {
carbide_host_support::init_logging()?;
carbide_host_support::init_logging("nico-dpu-agent")?;

let state: Arc<Mutex<State>> = Arc::new(Mutex::new(Default::default()));
state.lock().await.virtualization_type = virtualization_type;
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/tests/test_network_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct State {

#[tokio::test]
pub async fn test_network_monitor() -> eyre::Result<()> {
carbide_host_support::init_logging()?;
carbide_host_support::init_logging("nico-dpu-agent")?;

let state: Arc<Mutex<State>> = Arc::new(Mutex::new(Default::default()));

Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ROOT_CERT_PATH: &str = "dev/certs/forge_developer_local_only_root_cert_pem

#[tokio::test]
async fn test_upgrade_check() -> eyre::Result<()> {
carbide_host_support::init_logging()?;
carbide_host_support::init_logging("nico-dpu-agent")?;

unsafe {
env::set_var("DISABLE_TLS_ENFORCEMENT", "true");
Expand Down
8 changes: 7 additions & 1 deletion crates/api-core/src/logging/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ pub fn setup_logging(

let (logfmt_stdout_filter, logfmt_stdout_reload_handle) =
reload::Layer::new(initial_log_filter.clone());
let logfmt_stdout_formatter = logfmt::layer().with_event_fields(extra_logfmt_event_fields);
let mut event_fields = vec![logfmt::EventField::with_default("component", "nico-api")];
event_fields.extend(
extra_logfmt_event_fields
.into_iter()
.map(logfmt::EventField::new),
);
let logfmt_stdout_formatter = logfmt::layer().with_event_fields(event_fields);
let spancount_layer = spancounter::layer();
let spancount_reader = spancount_layer.reader();

Expand Down
9 changes: 8 additions & 1 deletion crates/bmc-proxy/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ pub fn setup_logging(debug: bool) -> SetupResult<()> {
);

tracing_subscriber::registry()
.with(logfmt::layer().with_filter(log_filter))
.with(
logfmt::layer()
.with_event_fields([logfmt::EventField::with_default(
"component",
"nico-bmc-proxy",
)])
.with_filter(log_filter),
)
.try_init()?;

tracing::info!("current log level: {}", LevelFilter::current());
Expand Down
6 changes: 5 additions & 1 deletion crates/dhcp-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ fn setup_tracing() -> Result<(), Box<dyn Error>> {
.add_directive("hickory_proto=info".parse().unwrap());

tracing_subscriber::registry()
.with(logfmt::layer().with_filter(env_filter))
.with(
logfmt::layer()
.with_event_fields([logfmt::EventField::with_default("component", "nico-dhcp")])
.with_filter(env_filter),
)
.try_init()?;
Ok(())
}
Expand Down
9 changes: 8 additions & 1 deletion crates/dsx-exchange-consumer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ async fn main() -> Result<(), DsxConsumerError> {
.from_env_lossy();

tracing_subscriber::registry()
.with(logfmt::layer().with_filter(env_filter))
.with(
logfmt::layer()
.with_event_fields([logfmt::EventField::with_default(
"component",
"nico-dsx-exchange-consumer",
)])
.with_filter(env_filter),
)
.try_init()
.map_err(|e| DsxConsumerError::Config(e.to_string()))?;

Expand Down
3 changes: 2 additions & 1 deletion crates/fmds/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub fn subscriber() -> impl SubscriberInitExt {
.add_directive("hickory_resolver::name_server=info".parse().unwrap())
.add_directive("hickory_proto=info".parse().unwrap())
.add_directive("netlink_proto=warn".parse().unwrap());
let stdout_formatter = logfmt::layer();
let stdout_formatter = logfmt::layer()
.with_event_fields([logfmt::EventField::with_default("component", "nico-fmds")]);
Box::new(tracing_subscriber::registry().with(stdout_formatter.with_filter(env_filter)))
}

Expand Down
7 changes: 6 additions & 1 deletion crates/health/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ async fn main() -> Result<(), HealthError> {
.from_env_lossy();

tracing_subscriber::registry()
.with(logfmt::layer())
.with(
logfmt::layer().with_event_fields([logfmt::EventField::with_default(
"component",
"nico-hardware-health",
)]),
)
.with(env_filter)
.init();

Expand Down
2 changes: 1 addition & 1 deletion crates/health/src/sink/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl DataSink for TracingSink {
tracing::info!(
endpoint = %context.endpoint_key(),
collector = %context.collector_type,
component = %info.component,
firmware_component = %info.component,
version = %info.version,
"Firmware info event"
);
Expand Down
15 changes: 10 additions & 5 deletions crates/host-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ static LOG_SETUP: Once = Once::new();

/// Initialize global logging output to STDOUT. Applies to all threads.
/// Use `export RUST_LOG=trace|debug|info|warn|error` to change log level.
pub fn init_logging() -> eyre::Result<()> {
///
/// `component` tags every log line with `component=<value>` (e.g. `nico-scout`,
/// `nico-dpu-agent`) so logs can be filtered by the emitting binary. It must be
/// passed by the caller because this setup is shared across binaries.
pub fn init_logging(component: &str) -> eyre::Result<()> {
LOG_SETUP.call_once(|| {
subscriber()
subscriber(component)
.try_init()
.expect("tracing_subscriber setup failed");
});
Expand All @@ -47,9 +51,9 @@ pub fn init_logging() -> eyre::Result<()> {
// A logging subscriber for use on the current thread.
// Usually you want `init_logging()` instead.
//
// Usage: `let guard = subscriber().set_default()`
// Usage: `let guard = subscriber("nico-scout").set_default()`
// Subscriber is unregistered when guard is dropped.
pub fn subscriber() -> impl SubscriberInitExt {
pub fn subscriber(component: &str) -> impl SubscriberInitExt {
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy()
Expand All @@ -64,6 +68,7 @@ pub fn subscriber() -> impl SubscriberInitExt {
.add_directive("hickory_resolver::name_server=info".parse().unwrap())
.add_directive("hickory_proto=info".parse().unwrap())
.add_directive("netlink_proto=warn".parse().unwrap());
let stdout_formatter = logfmt::layer();
let stdout_formatter = logfmt::layer()
.with_event_fields([logfmt::EventField::with_default("component", component)]);
Box::new(tracing_subscriber::registry().with(stdout_formatter.with_filter(env_filter)))
}
Loading