Learn / Rust Practical Systems
Tracing, Health, and Runtime Diagnostics
Expose typed health checks, tracing spans, and runtime diagnostics so async Rust services can be debugged under load.
Course: Rust Practical Systems. Level: Intermediate. Topic: Systems reliability.
Stage: advanced - Advanced runtime diagnostics - Tracing, health, and runtime diagnostics. Make runtime behavior visible through spans, health endpoints, diagnostic commands, and failure breadcrumbs.
Outcomes
- Add structured tracing spans.
- Map health checks to dependency readiness.
- Capture async failure context without panics.
Concepts
- tracing span
- health check
- JoinError
- runtime diagnostics
Concept flow
Show how tracing, health, and runtime diagnostics moves from trigger to implementation outcome in Rust Systems.
- Request span
- Handler
- Repository future
- Health state
- Tracing subscriber
Session flow
- Model tracing span (concept, 12 min) — Name the decisions behind tracing span before writing code.
- Add structured tracing spans.
- Explain where tracing span belongs in job orchestration service.
- Build the vertical slice (walkthrough, 21 min) — Implement the smallest useful slice in src/observability.rs.
- Map health checks to dependency readiness.
- Connect health check to a working example.
- Verify and harden (exercise, 14 min) — Map one async task failure into a typed service error.
- Capture async failure context without panics.
- Record one risk or follow-up before moving on.
Code example
Rust in src/observability.rs.
#[tracing::instrument(skip(state), fields(job_id = %job_id))]
pub async fn load_job(state: AppState, job_id: Uuid) -> Result<Job, AppError> {
let job = state.repo.find(job_id).await?;
tracing::info!(status = %job.status, "job loaded");
Ok(job)
}
Walkthrough examples
- Tracing, Health, and Runtime Diagnostics in a job orchestration service — A team is extending an Axum service with a companion CLI and needs this lesson's pattern to be clear enough for review, testing, and future maintenance.
- File: src/observability.rs
- File: tests/tracing-health-and-runtime-diagnostics.spec
- File: docs/rust-systems/tracing-health-and-runtime-diagnostics.md
- Start from the provided Rust snippet and make the intent visible in names and boundaries.
- Apply the checklist item "Spans include stable fields" before adding extra behavior.
- Write down how the implementation changes when health check fails or becomes slow.
Practice
- Add a tracing span around one handler.
- Expose readiness for one external dependency.
- Map one async task failure into a typed service error.
Checklist
- Spans include stable fields
- Health avoids expensive work
- Async errors keep context
- Logs do not include secrets
Quiz prompts
- Why use tracing spans instead of scattered println calls in a Rust service? — Structured spans keep request, job, and operation context attached as work moves through async code.
- A teammate wants to hide tracing span inside a convenient helper. What should you check first? — Place tracing span at the boundary that keeps job orchestration service behavior explicit, testable, and reviewable.
- Which artifact best proves this Rust Systems lesson is ready for review? — Production-ready learning needs evidence: a test, trace, command, screenshot, or log that catches the risk again.
- Advanced runtime diagnostics: a teammate says the happy path works, but "Span taxonomy" is still implicit. What should you ask for before merging? — Span taxonomy belongs in the advanced stage only when the decision is visible, testable, and tied to a realistic failure mode.
- A reviewer has five minutes to evaluate this advanced Rust Systems slice. Which evidence is strongest? — Upgrade the Rust runtime diagnostics with spans, readiness fields, sanitized trace evidence, and a failure drill.
Flashcards
- Advanced runtime diagnostics: what decision does "Span taxonomy" force you to make? Choose span names and fields that describe requests, jobs, dependencies, and expensive operations. Evidence prompt: Add spans to one request path and capture a sanitized trace sample.
- Advanced runtime diagnostics: what decision does "Health diagnostics" force you to make? Expose liveness, readiness, config version, and dependency state without leaking secrets. Evidence prompt: Add one readiness response and document what each field proves.
- Advanced runtime diagnostics: what decision does "Runtime failure drill" force you to make? Practice diagnosing config, dependency, timeout, and serialization failures from runtime evidence. Evidence prompt: Write an investigation path for one failing health or tracing signal.
- In Rust Systems, what should you remember about tracing span? tracing span matters here because it supports "Add structured tracing spans.".
- In Rust Systems, what should you remember about health check? health check matters here because it supports "Map health checks to dependency readiness.".
- In Rust Systems, what should you remember about JoinError? JoinError matters here because it supports "Capture async failure context without panics.".
- In Rust Systems, what should you remember about runtime diagnostics? runtime diagnostics matters here because it supports "Add structured tracing spans.".
Labs
- Ship a tracing, health, and runtime diagnostics slice — Extend an Axum service with a companion CLI with a small but reviewable feature that proves the lesson's architecture in code.
- Upgrade the Rust runtime diagnostics with spans, readiness fields, sanitized trace evidence, and a failure drill.
- Add spans to one request path and capture a sanitized trace sample.
- Add one readiness response and document what each field proves.
- Write an investigation path for one failing health or tracing signal.
- Add a tracing span around one handler.
- Expose readiness for one external dependency.
- The lab demonstrates the advanced runtime diagnostics outcome without skipping earlier contract evidence.
- Each subtopic has a concrete artifact: Span taxonomy, Health diagnostics, Runtime failure drill.
- The review notes explain how this level changes ownership, verification, or operational risk.
Challenge
- Review-ready tracing, health, and runtime diagnostics (Core) — Upgrade the Rust runtime diagnostics with spans, readiness fields, sanitized trace evidence, and a failure drill.
- All checklist items are either implemented or documented with a reason.
- The change can be understood from src/observability.rs plus one short note.
- The concept diagram names ownership, failure handling, and verification points.
- A teammate could run the verification steps without asking for hidden context.
Canonical lesson URL