Skip to content

[Backend] Propagate requestId into all log lines via withContext helper #890

@ogazboiz

Description

@ogazboiz

Join the contributor Telegram: https://t.me/+DOylgFv1jyJlNzM0

Why this matters

logger.info calls across sorobanService.ts, eventIndexer.ts, and controllers do not consistently include the requestId. The middleware sets req.requestId and runWithRequestContext exists in utils/requestContext.ts, but many call sites bypass it. As a result, production tracing fails to correlate a user request to its downstream DB and RPC calls.

Acceptance criteria

  • Audit all logger.info|warn|error call sites and ensure they go through a helper that pulls requestId from AsyncLocalStorage.
  • Add a logger.withContext() helper that auto-merges requestId, userId, and loanId if present.
  • Replace the largest 20 call sites (controllers + services) to use the helper.
  • Add a Jest test using the supertest agent that asserts the response x-request-id matches the logged value.

Files to touch

  • backend/src/utils/logger.ts
  • backend/src/utils/requestContext.ts
  • backend/src/controllers/*.ts (incremental)
  • backend/src/services/*.ts (incremental)
  • backend/src/__tests__/requestId.test.ts

Out of scope

  • Switching to OpenTelemetry tracing (separate, larger effort).
  • Replacing winston with pino.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendIssues related to backend development

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions