Record request IDs on axum request spans

Aperta Adatta ai principianti
#3,080 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Inizia con RedactedMakeSpan e il test dello span già presente in packages/axum-server/src/request_log.rs:126-134,247-270; l’issue descrive il comportamento che non funziona e l’asserzione prevista. Esegui il test dello span, poi estendilo con un ID di richiesta noto e un evento all’interno dello span, mantenendo i controlli di redazione dell’URI. Il lavoro è completato quando il test conferma che lo span contiene l’ID e la nuova verifica del log della richiesta a parità di condizioni è registrata in manual-verification-evidence.md.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug

Bug

The HTTP tracker, REST API, and health-check API each use RedactedMakeSpan for their request trace and call span.record("request_id", request_id) in both request and response hooks (packages/axum-http-server/src/v1/routes.rs:83, packages/axum-http-server/src/v1/routes.rs:94, packages/axum-http-server/src/v1/routes.rs:116; packages/axum-rest-api-server/src/routes.rs:77, packages/axum-rest-api-server/src/routes.rs:88, packages/axum-rest-api-server/src/routes.rs:110; packages/axum-health-check-api-server/src/server.rs:152, packages/axum-health-check-api-server/src/server.rs:163, packages/axum-health-check-api-server/src/server.rs:178).

The request span declares only method, redacted uri, and version; it does not declare request_id (packages/axum-server/src/request_log.rs:126-134). tracing::Span::record cannot add a field absent from the span's metadata, so these six calls have no effect on the span. Request and response events include their own request_id field, but other events cannot be correlated by request ID through the span context (packages/axum-http-server/src/v1/routes.rs:96-105, packages/axum-http-server/src/v1/routes.rs:118-139; packages/axum-rest-api-server/src/routes.rs:90-99, packages/axum-rest-api-server/src/routes.rs:112-133; packages/axum-health-check-api-server/src/server.rs:165-167, packages/axum-health-check-api-server/src/server.rs:180-187).

The span.record calls first appeared in 97233f57a (2024-12-23), when the request trace still used DefaultMakeSpan; 8cfc07be4 (2026-11-24) introduced the current RedactedMakeSpan without declaring request_id. The UDP handler shows the intended pattern: #[instrument(fields(request_id), ...)] declares the field before Span::current().record("request_id", ...) (packages/udp-server/src/handlers/mod.rs:80, packages/udp-server/src/handlers/mod.rs:89-92).

Expected behavior

An HTTP tracker, REST API, or health-check API request span should carry the same request ID that its hooks read from x-request-id, so an event emitted inside the span can be correlated with the request and response events by that ID (packages/axum-http-server/src/v1/routes.rs:88-103, packages/axum-rest-api-server/src/routes.rs:82-97, packages/axum-health-check-api-server/src/server.rs:157-167).

Bug-Fix Process

Reproduce with a request bearing a known x-request-id and capture a log event emitted inside its request span; record the initial log, runtime, and command in issue-local manual-verification-evidence.md. Add a failing regression test, declare request_id = tracing::field::Empty in RedactedMakeSpan, then rerun the test and the same request and record the final log (packages/axum-server/src/request_log.rs:126-134). Follow .claude/skills/fix-bug/SKILL.md for the red test and like-for-like recheck.

Regression Test Strategy

Extend the span test at the shared builder seam: create a request with a known ID, record it on the resulting span, emit an event inside it, and assert the captured span contains that ID. The existing test already captures an event inside RedactedMakeSpan and checks its redacted URI (packages/axum-server/src/request_log.rs:247-270). Prove the new assertion fails before the fix and passes after it; preserve the existing URI redaction assertions.

Acceptance criteria

  • RedactedMakeSpan declares a recordable request_id field while retaining the redacted URI (packages/axum-server/src/request_log.rs:126-134).
  • A regression test fails on the current implementation and then shows the known ID on the request span after the fix, with the URI redaction assertions still passing (packages/axum-server/src/request_log.rs:247-270).
  • A like-for-like request log recheck shows the ID on the request span; record the initial and final logs in issue-local manual-verification-evidence.md.

Related context

#3000 considers including a request ID in client error text and requires server-side error events to carry it; reliable span-level request IDs would support correlating those events with a request (docs/issues/open/3000-2993-si-b-client-error-text-policy/ISSUE.md:66-75).

Lingua principale
Rust
Stelle
532
Fork
56
Merge medio
11h 20m
PR unite (30g)
282

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di torrust/torrust-tracker

Tutte le issue di torrust/torrust-tracker

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.