Skip to content

Add Structured Logging with Pino Across the API #365

Description

@vjuliaife

Description:
TariffShield currently uses bare console.log calls with no structure, correlation IDs, or log levels, making it impossible to trace requests across services or filter logs by severity in production. Every API request, error, and Soroban RPC call needs a consistent JSON log line with a request-scoped correlation ID so operators can reconstruct the full lifecycle of any transaction. Without structured logging, debugging production incidents requires guesswork rather than log queries.

Acceptance Criteria:

  • Install pino and pino-http as production dependencies; install pino-pretty as a dev dependency for local formatting
  • Mount pino-http middleware in apps/api/src/index.ts before all route handlers so every HTTP request logs method, path, status code, response time, and correlationId
  • Generate a UUID v4 correlationId per request (via pino-http's genReqId option) and attach it to req.log so child loggers in downstream handlers inherit it automatically
  • Replace all console.log / console.error calls in apps/api/src/routes/importers.ts and apps/api/src/stellar.ts with req.log.info / req.log.error child loggers
  • Set log level via LOG_LEVEL environment variable (default info); support trace, debug, info, warn, error, fatal
  • Emit JSON output in production (NODE_ENV=production) and pretty-printed output in development via pino-pretty transport
  • Log Soroban RPC call duration in milliseconds on every call in apps/api/src/stellar.ts with fields { rpcMethod, durationMs, success }

Relevant Files:

  • apps/api/src/index.ts — mount pino-http middleware here
  • apps/api/src/routes/importers.ts — replace console calls with structured child logger
  • apps/api/src/stellar.ts — instrument RPC calls with duration logging
  • apps/api/src/db.ts — replace any console calls with structured logger

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programfeatAuto-created by repotool publish-folderinfrastructureDocker / CI / deployperfAuto-created by repotool publish-folder

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions