Add request IDs and include them in every log line
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- api, authentication, backend, documentation, observability, testing
Direzione di ricerca
Read CONTRIBUTING.md first, then inspect middleware and logging setup in app/app.py, request handling in app/pesu.py, and the README. Check how FastAPI middleware ordering and asyncio.create_task context propagation work before implementing the specified request-ID behavior. Done means the listed header, validation, logging, concurrency, error-response, README, and coverage tests pass; wait for assignment before starting.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔄 Updated for v5.0.0 (2026-10-08). Still open. The only change is in the background: 5.0.0 (#241) removed the CSRF prefetch, so the note about background tasks inheriting the request ID now refers to the client close.
Summary
When a caller reports "my login failed at 10:42", there's no reliable way to find their request in the logs. Lines from concurrent requests interleave, and nothing ties them together. Give every request an ID: accept one from the caller or the proxy, or generate one; put it on every log line written while handling that request; and return it in an X-Request-ID response header, so a caller can quote it in a bug report.
Background
- Logging is configured in
main()(app/app.py) withlogging.basicConfig(format="%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)d - %(message)s"). - One login writes several lines across
app/app.pyandapp/pesu.py("Authenticating user=…", "Connecting to PESU Academy…", "Login successful…"), and many requests run concurrently on one event loop. - Since 5.0.0 a request starts no background work of its own. The one task that can outlive it, the client close in
_close_client_quietly(app/pesu.py, viaasyncio.ensure_future), copies the currentcontextvarscontext, so its log line would inherit the request's ID automatically. That's useful, but say so in a comment.
Proposed change
- Middleware (
app/request_id.pyor similar, registered inapp/app.py):- Use the incoming
X-Request-IDif it's present and safe: at most 128 characters, matching[A-Za-z0-9._-]+. Anything else is ignored and replaced; the value ends up in logs, so it must not allow log injection (for example newlines). - Otherwise generate one with
uuid.uuid4().hex. - Check on staging whether Render's proxy adds its own request ID header, and prefer it if it does (write down what you find in the PR).
- Store the ID in a
contextvars.ContextVar, and setX-Request-IDon the response.
- Use the incoming
- Logging: a
logging.Filterthat addsrecord.request_id(or-outside a request), attached inmain(), with%(request_id)sadded to the format. Coordinate with #201, which changes the log format, so the two don't conflict. - Ordering with the metrics middleware: the request ID should be set before anything logs. Check the order in which FastAPI applies
@app.middlewaredecorators (the last one registered runs first), and comment on the choice. - Document the header in the README (for callers: "quote this ID when reporting a problem").
Tests
- A valid incoming ID is echoed back, and a missing, too-long or unsafe one is replaced with a generated one.
- Log records written during a request carry the ID (
caplog), and records outside a request get-. - Two concurrent requests get different IDs, and their log lines don't mix (use
asyncio.gatherwith the app). - Error responses (400, 401, 502) also carry the header.
Acceptance criteria
- Every response has
X-Request-ID, and every log line written during a request contains it - Caller-supplied IDs are validated
- README updated
How to contribute
- Wait until you're assigned. Comment to ask for this issue, then wait for a maintainer to assign it to you before writing any code. PRs for unassigned issues are closed without review.
- Read
CONTRIBUTING.mdfirst. It covers forking, setting up withuv, and running the tests. - Branch from
devin your fork, and open the PR againstdevwith a Conventional Commit title andCloses #200in the description. - Bump the minor version in
pyproject.tomland runuv lock(CI checks this).uv run pre-commit run --all-filesmust pass, and coverage must stay at 100%. - Update the README,
app/docs/and comments in the same PR as the behaviour they describe. - Never log, print, store or echo a password or token, including in tests, PR descriptions and screenshots.
- Lingua principale
- Python
- Stelle
- 22
- Fork
- 29
- Merge medio
- 1g 3h
- PR unite (30g)
- 19
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pesu-dev/auth
-
Check the README for dead links and fix the misleading Docker Hub badgeForse di nuovo libera @knownshah l’ha presa 19 giorni fa e non c’è nessuna pull request aperta. Apertadocumentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pesu-dev/auth#220 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug documentation enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 54/100
I maintainer di solito rispondono entro 1 giorno
-
Commit SHA should be used instead of tag git based deployForse già presa @aditeyabaral l’ha presa 13 giorni fa. Apertabug
pesu-dev/auth#236 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Private Functions in `app.py` needs to be in separate fileForse già presa @aditeyabaral l’ha presa 13 giorni fa. Apertaapi enhancement
pesu-dev/auth#235 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Gather the campus mapping and other shared values into constants modulesForse già presa @edgelordlinux l’ha presa 13 giorni fa. Apertaapi enhancement good first issue pesuacademy student profile tests and ci/cd
pesu-dev/auth#230 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pesu-dev/auth
Issue simili
-
docs: the dev-setup table and AGENTS.md name the reviewed_by guard that CI's Changelog job runsApertaarea: tools documentation good first issue ready for a contributor
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
eyalgolan/statecraft-israel#873 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add cover art to song rowsApertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 5 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno