/rewrite-rs-skills:rust-observabilityfrom rewrite-rs-skills
Guides structured logging and tracing in Rust: events with named fields over formatted strings, tracing spans for async context, and subscriber discipline. Use when adding or reviewing observability in Rust code.
Ships in rewrite-rs-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A log line is a structured event with named fields, and a library never installs
a subscriber. This skill governs how Rust code reports what it is doing; what
an error type contains is /rust-errors, and span behaviour across cancellation
is /async-rust.
The core move: fields stay fields.
error!(user_id, %path, "config load failed") is queryable — user_id and
path are named columns. The interpolated form,
error!("config load failed for user {user_id} at {path}"), is a string
someone will later write a regex against. The difference shows up the first
time somebody needs "all failures for one user" — the moment logging either
pays for itself or does not.
println! writes to stdout with no level, no filter, and no structure; it
belongs in a CLI producing output the user asked for, never in a library.
log is the older facade, right when the dependency budget is tight.
tracing is the default here: spans carry context across .await points,
which is the problem async code actually has.
component.operation.state — config.load.failed,
pool.connection.acquired. A consistent scheme is what makes a dashboard
possible; ad-hoc English messages are what make it impossible. Message
templates with placeholder syntax are one implementation of the field idea,
not the idea itself — a codebase already on templates is fine.
Name fields after the OpenTelemetry semantic attribute names where one
exists (http.request.method, url.full, error.type, server.address),
so a backend that understands them groups your data without a mapping layer;
invent a dotted name of your own only where no standard one fits.
#[tracing::instrument] on a function makes every event inside it inherit the
request context; skip keeps large or secret arguments out of the fields.
The rule: a span is a unit of work with a beginning and an end; an event is a
point in time.
error! — someone should look at this.warn! — something went wrong and the code handled it.info! — lifecycle events a reader wants without a bug.debug! / trace! — developer detail, off in production.The boundary that matters is error!: because it means someone should look, a
handled and expected failure is warn! or debug! at most. EnvFilter
gives per-module control, and in a library, filtering is the whole story:
A library emits and never installs a subscriber. Installing one is global
state the application owns: the binary installs the subscriber exactly once,
and a library that installs one too fights for the global — a panic at
startup with tracing, a re-formatted event stream with log.
Log at the boundary that handles the error, not at every level it passes
through, and log the whole source chain rather than the top-level Display
alone, which is usually the least specific sentence available. What the error
type contains is /rust-errors.
Tokens, passwords, keys, personal data. The structural answer, not a review
habit: a newtype whose Debug and Display print a redacted form, so the
secret cannot be logged even by a future careless call site. The ? form
prints via Debug, the % form via Display, and the bare form does not
compile for a custom type at all — every path redacted or absent:
struct ApiToken(String);
impl std::fmt::Debug for ApiToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ApiToken(<redacted>)")
}
}
impl std::fmt::Display for ApiToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("<redacted>")
}
}
Whether the newtype is the right model is /type-driven-design.
Keep telemetry out of hot inner loops altogether. Even a disabled event costs an enablement check per iteration, and an enabled one swamps the work. Emit one event around the loop, or one per batch, carrying a count.
Building an event that a filter discards still costs when the work is done
before the macro call. The macros take field values lazily, so do not
format! or allocate an argument eagerly for a debug! that is off in
production: let summary = summarize(); before debug!(?summary); runs on
every call, level or not, while debug!(summary = ?summarize()); runs only
when the event is enabled.
What an error type contains and how it chains is /rust-errors. Whether the
redacting newtype is the right model is /type-driven-design. Span behaviour
across cancellation is /async-rust.
cargo clippy --all-targets
rg 'println!|eprintln!' src/ # expect zero in a library
rg 'info!\("|warn!\("|error!\("' src/ # a message with interpolation and no fields is the smell
cargo test
Run clippy at the lint level the target repo configures —
cargo clippy -- -D warnings is the fallback only when the repo
configures no lints at all. The greps are a starting point, not a
verdict: a CLI printing its actual output is a legitimate println!.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub rewrite-rs/skills --plugin rewrite-rs-skills28 skills in this plugin
/async-rustWrite correct async Rust — runtime choice, Send and Sync bounds, cancellation safety, blocking work inside async contexts, and shared state across tasks. Use when writing or reviewing async code, when a future is held across an await point, when the user hits a Send bound error on a spawned task, when a runtime stalls or deadlocks, or when the user asks about tokio, select!, or spawn_blocking./idiomatic-rustWrite Rust that reads like Rust — iterator pipelines over index loops, From/Into over ad-hoc converters, derives over hand-written impls, newtypes over bare primitives. Use when writing new Rust, when reviewing Rust that reads like a translation from another language, when reaching for a classic design pattern (strategy, command, visitor) or a try/finally cleanup in Rust, when naming a constructor, accessor, iterator, or error type, or when the user asks how to make Rust code more idiomatic or less repetitive./ownership-not-cloneUse ownership and borrowing instead of reaching for clone, Rc, RefCell, or Arc<Mutex<_>> to silence the borrow checker. Every clone must be explainable. Use when code clones to make an error go away, when a borrow-checker fight is being resolved by copying data, when reviewing Rust dense with .clone() or Rc<RefCell<_>>, or when the user asks whether a clone is necessary./port-from-cPort C into Rust — recovering the ownership, lifetime, nullability, and length that C never recorded, mapping pointers to references and slices, tag-plus-union to enums, return codes and errno to Result, and linking Rust into the existing build with bindgen and cbindgen. Use when porting, rewriting, or migrating C, a C library, firmware, or a C application into Rust, when replacing C modules one at a time behind the existing build, or when the user asks how a C construct such as malloc, a char pointer, a union, or a preprocessor macro translates to Rust./port-from-cppPort C++ into Rust — RAII and smart pointers onto ownership, templates onto generics and traits, exceptions onto Result, the STL onto Rust collections, and the traps (move semantics, implicit conversions, undefined behaviour, iterator invalidation). Use when porting, rewriting, or migrating C++, a C++ library, or a C++ application into Rust, when replacing a C++ module with Rust behind the existing build, or when the user asks how a C++ construct such as unique_ptr, shared_ptr, a template, or an STL container translates to Rust./port-from-goPort Go into Rust — goroutines and channels onto tasks and async, interfaces onto traits, error values onto Result, and the value-semantics traps (zero values, integer wraparound, slice aliasing, nil). Use when porting, rewriting, or migrating Go, Golang, a Go service, or a Go CLI into Rust, when replacing a Go component with a Rust one behind the same interface, or when the user asks how a Go construct translates to Rust.Other plugins' skills for the same job