Add debug mode for logging server-side API calls

Summary

Implements issue #762: Add debug logging for all Hive API calls to help identify excessive calls and debug production issues.

Features

  • Logs all wax API calls (bridge, condenser_api, database_api, network_broadcast_api, search-api, rest APIs)
  • Logs third-party API calls (hiveposh, hivebuzz, peakd)
  • Configurable via environment variables
  • Zero performance impact when disabled (proxy only created when enabled)

Configuration

DEBUG_API_CALLS=true           # Enable API call logging
DEBUG_API_LEVEL=all            # all, slow, errors
DEBUG_API_SLOW_THRESHOLD=1000  # Slow call threshold in ms

Log Format (single-line JSON)

{"level":"INFO","time":"...","name":"api-calls","api":"bridge.get_post","params":{"author":"user","permlink":"post"},"status":"success","duration_ms":150,"msg":"API call"}

Implementation

Uses JavaScript Proxy pattern to intercept all API calls at the getChain() entry point:

getChain() → wrapChainWithLogging() → Proxy intercepts → logApiCall()

Files Changed

  • packages/transaction/lib/api-logger.ts - NEW: Logging utility
  • packages/transaction/lib/chain-proxy.ts - NEW: Proxy wrapper
  • packages/transaction/lib/chain.ts - Integrate proxy wrapper
  • packages/transaction/lib/custom-api.ts - Instrument third-party calls

Testing

  1. Set DEBUG_API_CALLS=true in .env
  2. Run the app and observe logs
  3. Test different log levels

Closes #762

Merge request reports

Loading