Return a request ID with every API response

Open
#143 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
nodejs, typescript

Research direction

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.

Written by the indexing model from the issue text.

Description

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

Dominant language
TypeScript
Stars
6
Forks
6
Avg merge
1h 59m
Merged PRs (30d)
59

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Haseeb-MernStack/commune

All issues in Haseeb-MernStack/commune

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.