Add request-id correlation to structured logs and `X-Request-Id` response header
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- backend, observability
Research direction
Start in src/main.ts, where the new middleware must be registered before routing, then read src/common/middleware/request-timing.middleware.ts (line 57) and src/common/middleware/profiling.middleware.ts (line 11), which each generate a request id. Consolidate those into one id from crypto.randomUUID(), reuse a valid inbound X-Request-Id, and echo it in the response header. Done means every response carries the header, a malformed inbound value is replaced, and a test covers all three cases. The logging-context binding depends on the logging-facade decision, so confirm that first.
Written by the indexing model from the issue text.
Description
Problem
src/main.ts does not set app.enableVersioning(), and there is no request-correlation middleware. Tracing exists — src/observability/tracing.interceptor.ts, request-timing.middleware.ts, and OpenTelemetry are all present — but a single log line cannot currently be tied back to one inbound request across services.
The middleware files do generate ids: src/common/middleware/request-timing.middleware.ts:57 and src/common/middleware/profiling.middleware.ts:11 both derive a request id, and both use Math.random() (see the Math.random() issue). There is no middleware that stamps an id onto the logging context or echoes it back to the caller.
Why it matters
During an incident, correlating a user report ("my submission failed around 14:32") to the right log lines is guesswork without a correlation id. The OpenTelemetry trace id exists but is not surfaced in the logs or in responses, so a support conversation cannot start from a trace id either.
This is also the single highest-value prerequisite for making the logging cleanup meaningful — a single facade is much less valuable without correlation.
Suggested Direction
- Add a
RequestIdMiddlewareregistered insrc/main.tsbefore routing:- Reuse an inbound
X-Request-Idif present (needed so a gateway or client can propagate it), otherwise generate one withcrypto.randomUUID(). - Attach it to the request so downstream handlers can read it.
- Reuse an inbound
- Echo it back as an
X-Request-Idresponse header. Low cost, high value for clients reporting problems. - Bind it into the logging context so every log line emitted during the request carries the id. This depends on the logging-facade decision in the logging issue — do that one first, or land this as the mechanism the facade will later consume.
- Include it in the OTel context so logs and traces join on the same id.
- Reconcile with the existing two middleware that each generate their own id. There should be exactly one request id, generated once.
Constraints
- Do not trust an inbound
X-Request-Idblindly. Validate its format (UUID or similar) and regenerate if it does not conform, otherwise a client can inject arbitrary content into every log line. - Generate with
crypto.randomUUID(), notMath.random(). - Correlation ids can end up in logs; do not place secrets in them.
Acceptance Criteria
- Every response carries an
X-Request-Idheader. - A valid inbound
X-Request-Idis reused; a malformed one is replaced. - The id appears on every log line emitted during the request.
- Only one request id is generated per request (the two existing
Math.random()sites are consolidated). - A test asserts header generation, pass-through, and rejection of a malformed inbound value.
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 55
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 5
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SourceXXL/alian_structure-api
-
good first issue help wanted security
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SourceXXL/alian_structure-api#266 ·
-
Parallelize the cache-warming loop in `cache-warming.service.ts` — warmers run strictly sequentiallyPossibly taken @syntaxsuuvam-spec claimed this 4 days ago. Opengood first issue performance
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SourceXXL/alian_structure-api#240 ·
-
documentation help wanted intermediate refactor
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
SourceXXL/alian_structure-api#215 ·
-
good first issue refactor tooling
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
SourceXXL/alian_structure-api#199 ·
-
help wanted intermediate refactor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
SourceXXL/alian_structure-api#196 ·
All issues in SourceXXL/alian_structure-api
Similar issues
-
area:ui effort:S enhancement priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
QuantumNous/new-api#7839 ·
Maintainers usually reply within 1 day
-
good first issue maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
dark-princezz/stellar-hooks#1010 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
interledger/rhyza#352 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day