馃煛 Priority: High
Difficulty: Hard
Estimated Effort: 2-3 days
Relevant Files: src/services/observability.service.ts, src/middleware/, src/index.ts
Labels: infrastructure, priority:high, observability
Requirements
-
Structured Logger
- Replace all
console.log() and console.error() calls across the entire codebase with a structured logger
- Create
src/lib/logger.ts using a logging library (e.g., pino or winston)
- Every log entry must be JSON with:
timestamp (ISO 8601)
level (DEBUG, INFO, WARN, ERROR, FATAL)
message
correlationId (unique per request/webhook)
service ("kolo-backend")
context (optional object with additional data)
-
Correlation ID Middleware
- Create
src/middleware/correlation-id.middleware.ts
- Generate a UUID v4 for each incoming request
- If the request includes an
X-Correlation-ID header, use that instead (for distributed tracing)
- Attach the correlation ID to
req.correlationId
- Pass the correlation ID through to all service calls using AsyncLocalStorage (Node.js
async_hooks)
- Include the correlation ID in the response header
X-Correlation-ID
-
Log Level Configuration
- Default log level from
LOG_LEVEL env var (default: INFO)
- In development:
DEBUG level, pretty-printed output
- In production:
INFO level, JSON output (for log aggregation)
- Never log at
DEBUG level in production unless explicitly enabled
-
Sensitive Data Redaction
- Automatically redact these fields from all log output:
stellarWallet, encryptedSecret, iv, authTag, secret, password, token
- Redact phone numbers: show only last 4 digits (
****5678)
- Redact Stellar public keys: show only first 4 and last 4 characters (
GABCD...WXYZ)
-
Performance Logging
- Log request duration for every HTTP request:
{ method, path, statusCode, durationMs }
- Log Stellar/Horizon API call latency:
{ endpoint, durationMs, statusCode }
- Log BullMQ job processing time:
{ jobName, durationMs, status }
-
Testing
- Unit test: verify JSON output format matches the schema
- Unit test: verify sensitive data is redacted
- Unit test: verify correlation ID is propagated through async operations
- Grep test: verify zero
console.log or console.error calls remain in src/
- Target: 100%
console.* elimination, >90% coverage on logger module
馃煛 Priority: High
Difficulty: Hard
Estimated Effort: 2-3 days
Relevant Files:
src/services/observability.service.ts,src/middleware/,src/index.tsLabels:
infrastructure,priority:high,observabilityRequirements
Structured Logger
console.log()andconsole.error()calls across the entire codebase with a structured loggersrc/lib/logger.tsusing a logging library (e.g.,pinoorwinston)timestamp(ISO 8601)level(DEBUG, INFO, WARN, ERROR, FATAL)messagecorrelationId(unique per request/webhook)service("kolo-backend")context(optional object with additional data)Correlation ID Middleware
src/middleware/correlation-id.middleware.tsX-Correlation-IDheader, use that instead (for distributed tracing)req.correlationIdasync_hooks)X-Correlation-IDLog Level Configuration
LOG_LEVELenv var (default:INFO)DEBUGlevel, pretty-printed outputINFOlevel, JSON output (for log aggregation)DEBUGlevel in production unless explicitly enabledSensitive Data Redaction
stellarWallet,encryptedSecret,iv,authTag,secret,password,token****5678)GABCD...WXYZ)Performance Logging
{ method, path, statusCode, durationMs }{ endpoint, durationMs, statusCode }{ jobName, durationMs, status }Testing
console.logorconsole.errorcalls remain insrc/console.*elimination, >90% coverage on logger module