coder-rust-logging
<skill_overview> Implement structured logging and tracing for Rust services Adding logs or diagnostics Creating spans around operations Configuring tracing subscribers Ensuring sensitive data is not logged Tracing GitHub </skill_overview> <events_and_spans> Use spans for operations with duration Use events for point-in-time facts Attach structured fields to both spans and events </events_and_spans> <structured_logging> Prefer structured fields over string interpolation Use consistent field names and types tracing::info!(user_id, action = "login", "user action"); </structured_logging> Use #[instrument] to create spans automatically Skip sensitive fields with #[instrument(skip(secret))] #[tracing::instrument(skip(password))] fn authenticate(username: &str, password: &str) { /* ... */ } <subscriber_setup> Initialize a subscriber early in main Use env-based filtering for log levels Keep default level reasonable for production tracing_subscriber::fmt().with_env_filter("info").init(); </subscriber_setup> <sensitive_data> <never_log> Passwords and tokens API keys and secrets PII when not required </never_log> </sensitive_data> <anti_patterns> Avoid println! for production logging Avoid high-cardinality fields in info logs </anti_patterns>