Skip to content
Closed
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

> Note: this file did not exist until after `v0.5.6`.

## Unreleased

### CLI
- Logging: show source file locations only when running in debug mode (`RUST_LOG=*=debug`) ([#403](https://github.com/flashbots/contender/issues/403))
- Tests: add scoped environment variable tests for debug mode detection using `temp-env`


---

## [0.6.0](https://github.com/flashbots/contender/releases/tag/v0.6.0) - 2025-11-25
Expand All @@ -22,4 +29,4 @@ Internal changes:

- revamp error handling ([#378](https://github.com/flashbots/contender/pull/378))
- DB schema bumped to `user_version = 6` to record campaign/stage metadata in runs.
- If you see a DB version mismatch, export/reset your DB: `contender db export` (optional backup) then `contender db reset` (or `drop`) to recreate with the new schema.
- If you see a DB version mismatch, export/reset your DB: `contender db export` (optional backup) then `contender db reset` (or `drop`) to recreate with the new schema.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- we no longer require two-phase cancellation (CTRL-C once to stop spamming, CTRL-C again to stop result collection)
- result collection happens async, so when the user cancels, most results will have already been collected
- stopping quickly is a better UX than two-phase
- logging: show source file locations only when running in debug mode (`RUST_LOG=*=debug`) ([#403](https://github.com/flashbots/contender/issues/403))
- tests: add scoped environment variable tests for debug mode detection using `temp-env`

### Breaking changes

Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ uuid = { workspace = true }

[dev-dependencies]
tempfile = "3.15.0"
temp-env = "0.3"

[features]
default = []
Expand Down
56 changes: 35 additions & 21 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use error::CliError;
use std::{str::FromStr, sync::LazyLock};
use tokio::sync::OnceCell;
use tracing::{debug, info, warn};
use tracing_subscriber::EnvFilter;
use util::{data_dir, db_file, init_reports_dir};

static DB: LazyLock<SqliteDb> = std::sync::LazyLock::new(|| {
Expand Down Expand Up @@ -209,27 +208,42 @@ fn init_db(command: &ContenderSubcommand) -> Result<(), CliError> {
}

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...

Copy link
Author

Choose a reason for hiding this comment

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

Ah, that’s on me. I accidentally dropped the #[cfg(feature = "async-tracing")] guard when refactoring init_tracing(). Sorry about the oversight.

{
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, Layer};
let tokio_layer = console_subscriber::ConsoleLayer::builder()
.with_default_env()
.spawn();
let fmt_layer = fmt::layer()
.with_ansi(true)
.with_target(true)
.with_line_number(true)
.with_filter(filter);

tracing_subscriber::Registry::default()
.with(fmt_layer)
.with(tokio_layer)
.init();
use tracing_subscriber::{
fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer,
};

let rust_log = std::env::var("RUST_LOG").unwrap_or_default().to_lowercase();
let debug_mode = rust_log.contains("=debug");

let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));

let fmt_layer = fmt::layer()
.with_ansi(true)
.with_target(debug_mode)
.with_line_number(debug_mode)
.with_file(debug_mode)
.with_filter(filter);

tracing_subscriber::registry().with(fmt_layer).init();
}

#[cfg(test)]
mod tests {
use temp_env::with_var;

#[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.

let rust_log = std::env::var("RUST_LOG").unwrap_or_default().to_lowercase();
assert!(rust_log.contains("=debug"));
});
}

#[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

fn info_mode_does_not_trigger_debug() {
with_var("RUST_LOG", Some("contender=info"), || {
let rust_log = std::env::var("RUST_LOG").unwrap_or_default().to_lowercase();
assert!(!rust_log.contains("=debug"));
});
}
}