write-structured-tracing
Skill486 starsChanged 15 days agoApache-2.0View on GitHub
Standard for writing structured tracing logs behind debug flags.
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Make sure the flag you use is specifically scoped to the module or subsystem you are debugging.
- Very specific: line 16
Do NOT reuse a broad orchestrator flag (e.g., DEBUG_TUI_PTY_MUX) for a microscopic, high-volume subsystem (like a byte-stream parser).
- Very specific: line 17
If a suitable module-specific flag does not exist, create a new one (e.g., DEBUG_TUI_VT100_PARSER) to ensure developers can isolate and …
- Very specific: line 31
Do not use unstructured string formatting (e.g., tracing::info!("Hello {}", name)).
- Very specific: line 45
When you need to format complex strings within a tracing field, bind it to a field using the % (Display) modifier and follow this rule:
- Very specific: line 46
If the resulting string will be <= 16 bytes, use the inline_string!
- Very specific: line 47
If the resulting string will be > 16 bytes, use the standard format!
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Write Structured Tracing
This skill documents the project's standard for writing tracing logs (tracing::info!, tracing::debug!, etc.). It ensures logs are easily filterable, consistently formatted, and don't affect performance when disabled.
1. Gating Behind Debug Flags
All tracing::*! calls must be gated behind a specific debug flag from tui/src/tui/mod.rs (or similar location) using the .then(|| { ... }) pattern. This ensures the tracing macro and any string allocations are completely bypassed when the flag is disabled.
Choosing the right flag (Scope Specificity): Make sure the flag you use is specifically scoped to the module or subsystem you are debugging. This scope can be narrow or broad depending on the requirements.
- Do NOT reuse a broad orchestrator flag (e.g.,
DEBUG_TUI_PTY_MUX) for a microscopic, high-volume subsystem (like a byte-stream parser). Doing so would spam the orchestrator logs. - If a suitable module-specific flag does not exist, create a new one (e.g.,
DEBUG_TUI_VT100_PARSER) to ensure developers can isolate and filter logs effectively without overwhelming the IO overhead.
crate::DEBUG_TUI_MOD.then(|| {
// ... tracing call ...
});2. The // % is Display, ? is Debug. Comment
You MUST add the exact line comment // % is Display, ? is Debug. directly above every tracing::*! invocation. This serves as a quick syntax reminder.
3. Structured Fields and message
Do not use unstructured string formatting (e.g., tracing::info!("Hello {}", name)). Instead, use structured fields with an explicit message key that identifies the context (e.g., the struct and method name).
crate::DEBUG_TUI_MOD.then(|| {
// % is Display, ? is Debug.
tracing::info! {
message = "ComponentName::method_name",
status = "Something happened",
};
});4. Using inline_string! vs format! for Complex Formatting
When you need to format complex strings within a tracing field, bind it to a field using the % (Display) modifier and follow this rule:
- If the resulting string will be <= 16 bytes, use the
inline_string!macro to stack-allocate it. - If the resulting string will be > 16 bytes, use the standard
format!macro (sinceinline_string!would spill to the heap and allocate anyway).
crate::DEBUG_TUI_MOD.then(|| {
// % is Display, ? is Debug.
tracing::info! {
message = "AppNoLayout::handle_event",
input_event = %inline_string!(
"{a} {b:?}",
a = glyphs::USER_INPUT_GLYPH,
b = input_event
)
};
});Example Transformation
Bad (Unstructured and Un-gated):
tracing::debug!("Received input event: {:?}", input_event);Good (Structured and Gated):
crate::DEBUG_TUI_PTY_MUX.then(|| {
// % is Display, ? is Debug.
tracing::debug! {
message = "PTYMux::run_event_loop",
input_event = %format!("{:?}", input_event)
};
});In this repository30 other files it gives its agents.
- .agents/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- build-infra/AGENTS.mdAGENTS.md
- rust-analyzer-mcp-server/AGENTS.mdAGENTS.md
- task/AGENTS.mdAGENTS.md
- llms.txtllms.txt
- analyze-log-filesSkill
- analyze-performanceSkill
- audit-taskSkill
- batch-refactor-with-sub-agentsSkill
- check-bounds-safetySkill
- check-code-qualitySkill
- check-test-coverageSkill
- code-reviewSkill
- concurrency-safetySkill
- create-commit-messageSkill
- create-prSkill
- design-philosophySkill
- fast-string-allocationsSkill
- fix-issueSkill
- merge-prSkill
- organize-modulesSkill
- organize-testsSkill
- release-crateSkill
- remove-crate-prefixSkill
- review-prSkill
- run-clippySkill
- safe-renamingSkill
- test-cross-platformSkill
- write-documentationSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

