axum-impl-tracing

Configure tracing-subscriber and tower-http TraceLayer for structured logging in Axum services.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-tracing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-impl-tracing
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-tracing
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-tracing

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents misleading, interleaved, or incorrect tracing output in Axum by guiding you to install a tracing-subscriber correctly and emit structured spans and events safely in async code.

Core Features & Use Cases

  • Safe subscriber initialization: install the global subscriber exactly once in main using EnvFilter and fmt layers.
  • Deterministic request tracing middleware: instrument every HTTP request with tower-http TraceLayer::new_for_http and its span naming via MatchedPath.
  • Async-safe span creation and logging: use #[tracing::instrument] or Future::instrument instead of holding Span::enter guards across await, and emit key/value fields (with %/? sigils) rather than interpolated messages.
  • Optional distributed tracing export: compose tracing-opentelemetry onto the same registry for OpenTelemetry backends (OTLP).
  • Use cases: debugging “no logs appear,” startup panics from double init, incorrect span nesting/parenting, broken span cardinality caused by using the raw URI, and exporting traces to Jaeger/Tempo/Grafana.

Quick Start

Configure your Axum app by wiring tracing-subscriber in main, add TraceLayer::new_for_http to your router, and instrument handlers with #[tracing::instrument] while emitting structured tracing::info!/error! fields.

Frequently Asked Questions about axum-impl-tracing

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

FAQPage Schema
How do I add structured logging and distributed request tracing to an Axum service?

To add structured logging and distributed request tracing to an Axum service, install a tracing-subscriber globally in main and use tower-http TraceLayer::new_for_http to instrument HTTP requests, grouping spans by MatchedPath rather than raw URI to maintain correct cardinality.

Why are my Axum tracing spans nested under the wrong parent or interleaved in async code?

Axum tracing spans nest incorrectly or interleave when holding Span::enter guards across await points. Use #[tracing::instrument] or Future::instrument instead to ensure async-safe span creation and proper parent-child relationships in your tracing output.

How do I configure RUST_LOG filtering and tracing-subscriber layers for an Axum app?

Configure RUST_LOG filtering and tracing-subscriber layers by using SubscriberExt and SubscriberInitExt to compose EnvFilter and fmt layers with .with()/.init() methods, ensuring the global subscriber is installed exactly once in main to prevent startup panics.

Can I export Axum tracing spans to an OpenTelemetry backend like Jaeger or Tempo?

Yes, you can export Axum tracing spans to an OpenTelemetry backend by composing tracing-opentelemetry onto the same subscriber registry, configuring a matching OTLP pipeline to send distributed traces to platforms like Jaeger, Tempo, or Grafana.

What is the correct way to emit structured tracing events in Rust async handlers?

The correct way to emit structured tracing events in Rust async handlers is to declare span fields before recording and use tracing::info!/error! macros with key/value field sigils like %/?, avoiding format!-interpolated messages that reduce structured logging quality.