You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sequenceDiagram
participant C as Client
participant L as Logger Middleware
participant H as Handler
C->>L: Request
L->>L: Record start time
L->>H: Forward request
H-->>L: Response
L->>L: Calculate latency
L->>L: Write JSON log
L-->>C: Response
Loading
Acceptance Criteria
Add logging middleware to Gateway
Log request method, path, status, and latency
Log payment verification status (402/403/200)
Include client IP address (handle X-Forwarded-For)
Use JSON format for easy parsing by log aggregators
Add log level configuration via environment variable
Don't log sensitive data (signatures, API keys)
Include unit tests for the logging middleware
Technical Notes
Gin has built-in gin.Logger() middleware as reference
Consider using zerolog or zap for structured logging
Log to stdout for container compatibility
Testing
# Run gateway and observe logs
go run main.go
# Make request and verify log output
curl -X POST http://localhost:3000/api/ai/summarize \
-H "Content-Type: application/json" \
-d '{"text": "test"}'# Expected log entry in stdout
Summary
Add structured JSON logging for all API requests to improve debugging and monitoring in production.
Problem
Currently, the Gateway only logs basic startup messages. There's no visibility into:
Proposed Solution
Add middleware that logs every request in structured JSON format:
{ "timestamp": "2024-01-01T12:00:00Z", "method": "POST", "path": "/api/ai/summarize", "status": 200, "latency_ms": 45, "client_ip": "192.168.1.1", "payment_verified": true, "user_wallet": "0x123..." }Architecture
flowchart LR REQ[Incoming Request] --> LOG[Logging Middleware] LOG --> HANDLER[Route Handler] HANDLER --> LOG LOG --> RES[Response + Log Entry] LOG --> STDOUT[(stdout / JSON)]sequenceDiagram participant C as Client participant L as Logger Middleware participant H as Handler C->>L: Request L->>L: Record start time L->>H: Forward request H-->>L: Response L->>L: Calculate latency L->>L: Write JSON log L-->>C: ResponseAcceptance Criteria
Technical Notes
gin.Logger()middleware as referencezerologorzapfor structured loggingTesting