Skip to content

845 backend background indexer worker logs carry no correlation - #1173

Merged
ogazboiz merged 6 commits into
LabsCrypt:mainfrom
jotel-dev:845-backend-background-indexer-worker-logs-carry-no-correlation-id
Aug 8, 2026
Merged

845 backend background indexer worker logs carry no correlation#1173
ogazboiz merged 6 commits into
LabsCrypt:mainfrom
jotel-dev:845-backend-background-indexer-worker-logs-carry-no-correlation-id

Conversation

@jotel-dev

Copy link
Copy Markdown
Contributor

Description

Background Soroban event worker poll cycles and admin replays previously ran outside any requestContext, leaving worker log lines (including per-event error logs) without a shared correlation ID (requestId).

This PR wraps every worker poll cycle and admin replay batch in requestContext.run({ requestId: ... }, ...) via AsyncLocalStorage. All logs emitted within a cycle now share a unified requestId, and the correlation ID is returned in the response of the admin replay endpoint (POST /v1/admin/indexer/replay).

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 📚 Documentation update
  • 🧪 Test addition or update

Related Issues

Closes #845

Changes Made

  • backend/src/workers/soroban-event-worker.ts:
    • Wrapped scheduled poll() cycles and triggerPoll() in requestContext.run({ requestId }, ...).
    • Added fallback context binding inside fetchAndProcessEvents() to guarantee all RPC calls, event processing steps, and error logs carry the requestId.
  • backend/src/services/indexerService.ts:
    • Updated replayFromLedger() to accept an optional customRequestId, bind execution inside requestContext, pass requestId to triggerPoll(), and return the requestId.
  • backend/src/routes/v1/admin.routes.ts:
    • Updated POST /v1/admin/indexer/replay endpoint to return { ok: true, replayingFrom: ledger, requestId: "..." }.
  • Documentation:
    • Added Logging & Observability sections to docs/ARCHITECTURE.md and backend/README.md.
  • Tests:
    • Added backend/tests/worker-correlation-id.test.ts to test correlation ID binding across worker poll cycles and replay requests.

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

  1. Run backend unit tests: npm test (all 51 test suites / 355 tests pass).
  2. Trigger an admin replay via POST /v1/admin/indexer/replay?from_ledger=<ledger> and verify the HTTP response contains the requestId field.
  3. Observe JSON log output during a poll cycle or replay to confirm all log lines share the corresponding requestId.

Breaking Changes

None.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

closes #845

@ogazboiz
ogazboiz merged commit b38f208 into LabsCrypt:main Aug 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Background indexer/worker logs carry no correlation id - only HTTP requests get one

2 participants