Add debug mode to log all server-side API calls for monitoring and optimization
Problem
Currently there's no easy way to:
- See all API calls being made from the server side
- Identify excessive/redundant API calls
- Monitor API call patterns in production
- 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
- Identify spam: See if we're making redundant/duplicate calls
- Optimize performance: Find slow calls and unnecessary requests
- Debug production issues: Correlate errors with specific API calls
- Capacity planning: Understand API usage patterns
Future Enhancements
- Aggregate statistics (calls per minute, by endpoint)
- Request deduplication detection
- Cache hit/miss logging
- 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