Add debug mode to log all server-side API calls for monitoring and optimization

Problem

Currently there's no easy way to:

  1. See all API calls being made from the server side
  2. Identify excessive/redundant API calls
  3. Monitor API call patterns in production
  4. Debug which requests are causing issues

Proposed Solution

Add a debug mode that logs all server-side API calls.

Log Information

  • Timestamp
  • API endpoint (method + URL)
  • Request payload
  • Response status
  • Response time (ms)
  • Caller context (which component/function initiated the call)

Log Format (single line per entry)

{"level":"DEBUG","type":"api_call","time":"2025-12-10T22:36:52.798Z","method":"POST","endpoint":"https://api.hive.blog","api":"condenser_api.get_accounts","params":["username"],"status":200,"duration_ms":150,"caller":"generateMetadata:/@username"}

Configuration

# Enable API call logging
DEBUG_API_CALLS=true

# Log level filter (all, slow, errors)
DEBUG_API_LEVEL=all

# Threshold for 'slow' calls (ms)
DEBUG_API_SLOW_THRESHOLD=1000

Benefits

  1. Identify spam: See if we're making redundant/duplicate calls
  2. Optimize performance: Find slow calls and unnecessary requests
  3. Debug production issues: Correlate errors with specific API calls
  4. Capacity planning: Understand API usage patterns

Future Enhancements

  1. Aggregate statistics (calls per minute, by endpoint)
  2. Request deduplication detection
  3. Cache hit/miss logging
  4. Export to monitoring systems (Prometheus, etc.)

Implementation Notes

  • Should be opt-in (disabled by default in production)
  • Use existing pino logger infrastructure
  • Could wrap wax client or create middleware layer
  • Hive blockchain data is public - no sanitization needed

Acceptance Criteria

  • Debug mode flag to enable API call logging
  • Single-line log format with all relevant information
  • Configuration via environment variables
  • Documentation for enabling/using debug mode
  • No performance impact when disabled
Edited by gandalf_automation