Skip to content

backend(all routes): missing request correlation ID propagation from HTTP layer to database and logs #668

@ogazboiz

Description

@ogazboiz

Join our community: https://t.me/+DOylgFv1jyJlNzM0

Description

The backend generates requestId values via createRequestId() and uses runWithRequestContext() for log correlation in the event indexer. However, HTTP route handlers do not appear to propagate the requestId from the HTTP request into database queries or downstream service calls.

This means when debugging a production issue, you cannot trace a specific user request through logs from the HTTP layer to the DB query to the Soroban RPC call. You can see each layer's logs independently but cannot correlate them.

Expected Behavior

  1. Generate or extract a requestId (from X-Request-ID header or generate one) at the middleware level for every incoming HTTP request
  2. Pass it through runWithRequestContext() so all subsequent log statements in that request's lifecycle include the same requestId
  3. Include the requestId in error responses so users can report it to support

Suggested Fix

Add a requestId middleware that runs before all routes:

app.use((req, res, next) => {
  const requestId = req.headers['x-request-id'] ?? createRequestId();
  runWithRequestContext(requestId, () => {
    res.setHeader('X-Request-ID', requestId);
    next();
  });
});

Impact

Low-Medium. Not a bug but a significant observability gap that makes production incident investigation very slow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions