Return a request ID with every API response

Aperta
#143 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à
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
72/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript

Direzione di ricerca

Start with the middleware order in apps/api/src/app.ts, then read apps/api/src/middleware/error.ts and apps/api/src/services/errorTracker.ts to see where errors are logged and tracked. Add a request-ID middleware that accepts a valid incoming X-Request-Id (up to 64 letters, digits or dashes), otherwise generates a UUID, and sets the response header. Done means every response carries the header, malformed input is replaced, 5xx JSON and the tracker record include the ID, and a test covers both cases, with a note in docs/MONITORING.md.

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

Descrizione

api enhancement good first issue

Difficulty: Beginner to Intermediate · Estimated size: half a day

Context

apps/api/src/middleware/error.ts and the monitoring code already deal with errors. When a person reports a problem, it is hard to match it with the server log line.

Problem or goal

Give every request an ID that is logged, returned in an X-Request-Id header and included in error responses.

Suggested approach

  • Add a middleware early in apps/api/src/app.ts that accepts a safe incoming X-Request-Id (max 64 characters of letters, numbers and dashes) or generates a UUID, stores it on req, and sets the response header.
  • Include it in the JSON of 5xx errors and in the error tracker record.
  • Expose the header to the browser via CORS only if needed (check Access-Control-Expose-Headers).

Where to look

  • apps/api/src/app.ts
  • apps/api/src/middleware/error.ts
  • apps/api/src/services/errorTracker.ts

Acceptance criteria

  • Every response has the header.
  • A malformed incoming ID is replaced, never echoed.
  • A test checks both cases.
  • docs/MONITORING.md mentions it.

How to work on it

  1. Comment here to claim it, so two people do not do the same work.
  2. Fork the repo and branch from main (feat/short-name or fix/short-name). Setup steps are in docs/DEVELOPMENT.md.
  3. Keep the change focused and add tests for backend logic.
  4. Run npm run typecheck, npm test and npm run lint and npm run format before opening the pull request.
  5. Use a Conventional Commits title (for example feat(web): add bookmarks). More in CONTRIBUTING.md.

Stuck? Ask in this issue. Questions are welcome.


Generated by Claude Code

Lingua principale
TypeScript
Stelle
6
Fork
6
Merge medio
1h 59m
PR unite (30g)
59

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 Haseeb-MernStack/commune

Tutte le issue di Haseeb-MernStack/commune

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.