Radar · Rust · Archive · Week 4 · Jan 19 – 25, 2026
Throttled‑Tracing Crate of the Week
Nice to knowecosystem
- What changed
- The crate
throttled-tracingprovides periodic and throttled logging macros. - Production impact
- The source does not say.
- Try it
- Add
throttled-tracing = "0.1"to a Cargo.toml and experiment with its macros. - Source
- this-week-in-rust.org/blog/2026/01/21/this-week-in-rust-635/
Understand it, then run it
Run it now
// This program demonstrates a simple throttled logging mechanism.
// It prints a message only once every 5 calls to `log_throttled!`.
// The `throttled-tracing` crate is not available in this sandbox,
// so we implement the core idea manually using a static counter.
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Duration, Instant};
static CALL_COUNT: AtomicUsize = AtomicUsize::new(0);
static LAST_LOG: AtomicUsize = AtomicUsize::new(0);
/// Log a message only if at least `interval` calls have occurred
/// since the last log. This mimics the behaviour of the
/// `throttled_info!` macro from `throttled-tracing`.
macro_rules! log_throttled {
($interval:expr, $msg:expr) => {{
let count = CALL_COUNT.fetch_add(1, Ordering::SeqCst) + 1;
let last = LAST_LOG.load(Ordering::SeqCst);
if count - last >= $interval {
println!("[throttled] {}", $msg);
LAST_LOG.store(count, Ordering::SeqCst);
}
}};
}
fn main() {
// Simulate many log calls
for i in 1..=20 {
log_throttled!(5, format!("Iteration {}", i));
}
}
What it printed when we ran it on Rust 1.98.1 (edition 2024)
[throttled] Iteration 5 [throttled] Iteration 10 [throttled] Iteration 15 [throttled] Iteration 20
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed