rust-tracing-practices

Applies HASH tracing and instrumentation conventions to Rust code with spans, events, and attributes.

1.6k|122|Updated Jul 15, 2019
One-click install
npx skills add https://github.com/hashintel/hash --skill rust-tracing-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-tracing-practices
Source: https://github.com/hashintel/hash/tree/main/.agents/skills/rust-tracing-practices
Command: npx skills add https://github.com/hashintel/hash --skill rust-tracing-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust developers often add logging and instrumentation inconsistently, producing unstructured logs that are hard to filter, search, and correlate across services. This Skill codifies HASH's conventions for the tracing crate so spans and events follow a uniform, structured pattern.

Core Features & Use Cases

  • Structured Event Recording: Enforces level-specific macros (info!, debug!, trace!, warn!, error!) with named key-value fields for machine-processable log output.
  • Function Instrumentation: Standardizes use of the #[tracing::instrument] attribute, including err capture, skip for sensitive parameters, and custom context fields.
  • Use Case: When adding observability to a new authentication service, apply this Skill to instrument handlers with spans that capture user IDs while skipping passwords, and emit structured events for login successes and failures.

Quick Start

Add tracing instrumentation to my Rust authentication function following HASH tracing practices, capturing errors and skipping the password parameter.

Frequently Asked Questions about rust-tracing-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add tracing instrumentation to a Rust function?

Apply the #[tracing::instrument] attribute above the function to automatically create a span for each call. Add parameters like level = "debug", err to capture error returns, and fields(user_id = user.id) for custom context.

How do I log structured events with the Rust tracing crate?

Use level-specific macros such as tracing::info!, debug!, trace!, warn!, and error! with named key-value arguments. For example, tracing::info!(user_id = user.id, action = "login", "User logged in successfully") produces structured, filterable output.

How do I exclude sensitive parameters from tracing spans in Rust?

Pass skip(password) or skip_all to the #[tracing::instrument] attribute to prevent sensitive or large parameters from being recorded in span fields. This keeps credentials and bulky data out of your telemetry.

How do I capture errors in a tracing span?

Include the err parameter in #[tracing::instrument], which records the error return value in the span when the function fails. Pair it with tracing::error!(error = %e, ...) for detailed structured error events.

When should I use debug! vs trace! vs info! in Rust logging?

Use info! for notable operational events, debug! for development-level diagnostics, and trace! for the most granular execution detail. Choosing level-specific macros ensures appropriate visibility and lets subscribers filter output by severity.