Skip to content

Conversation

@LilSuperUser
Copy link

Motivation (#403)

The CLI’s tracing output was previously verbose, always including file, line, and target information regardless of log level. This added noise for normal usage at info level.

We wanted to improve UX by showing full source context only when explicitly running in debug mode.

Additionally, the detection logic for debug mode (contains("=debug")) is custom, so it requires test coverage to ensure correctness.

Finally, changelogs needed to be updated to reflect the enhancement and its associated tests.

Solution

  • Logging enhancement

    • Parse RUST_LOG env var and normalize to lowercase.
    • Detect debug mode by checking for any substring matching =debug.
    • Construct EnvFilter from RUST_log with fallback to "info" if unset.
    • Configure tracing_subscriber::fmt::Layer with conditional toggles:
      • with_file(true/false)
      • with_line_number(true/false)
      • with_target(true/false)
  • Scoped test case

    • Add temp-env as a dev-dependency.
    • Introduce a ``#[cfs(test)]moduele incrates/cli/src/main.rs`.
    • Use temp_env::with_var to set RUST_LOG temp in each test scope.
    • Verificatio detection logic:
      • RUST_LOG="contender=debug"debug_mode is true.
      • RUST_LOG="contender=info"debug_mode is false.

PR Checklist

  • Added Tests
  • Added Documentation
  • Ran cargo +nightly clippy --workspace --lib --examples --tests --benches --all-features --locked --fix
  • Ran cargo fmt --all
  • Note breaking changes in PR description, if applicable
  • update changelogs
    • Update CHANGELOG.md in each affected crate
    • add a high-level description in the root changelog

- parse RUST_LOG env var and normalize to lowercase
- detect debug mode by checking for any substring matching `=debug`
- construct EnvFilter from RUST_LOG with fallback to "info" if unset
- configure tracing_subscriber::fmt::Layer with conditional toggles:
    * with_file(true/false)
    * with_line_number(true/false)
    * with_target(true/false)
- registry initialized with fmt_layer to apply formatting globally

Implements enhancement requested in flashbots#403
- add temp-env as a dev-dependency
- add #[cfg(test)] module in crates/cli/src/main.rs
- use temp_env::with_var to set RUST_LOG temporarily
- verify debug mode detection logic:
    * RUST_LOG="contender=debug" → assert contains("=debug")
    * RUST_LOG="contender=info" → assert !contains("=debug")
- ensures environment isolation between tests without global state
leakage

Adds test case for the enhancement implemented in flashbots#403
- add entry under Unreleased in crates/cli/CHANGELOG.md
- add corresponding summary under Unreleased in root CHANGELOG.md

Adds changelog entries for enhancement implemented in flashbots#403
Copy link
Member

@zeroXbrock zeroXbrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the quick turnaround @LilSuperUser, left a few comments

#[cfg(not(feature = "async-tracing"))]
{
contender_core::util::init_core_tracing(filter);
#[test]
Copy link
Member

@zeroXbrock zeroXbrock Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below, we don't need to test the functionality of an external crate ourselves


#[test]
fn debug_mode_detected_from_rust_log() {
with_var("RUST_LOG", Some("contender=debug"), || {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is really necessary, all it does is test the with_var function.


fn init_tracing() {
let filter = EnvFilter::try_from_default_env().ok(); // fallback if RUST_LOG is unset
#[cfg(feature = "async-tracing")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need the async-tracing conditional, looks like it was just removed...

@zeroXbrock
Copy link
Member

closing in favor of #406

@zeroXbrock zeroXbrock closed this Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants