This commit introduces a unified request tracking system across both the Flask ML backend and the Next.js frontend. Each incoming API request is assigned a unique request ID (X-Request-ID) to enable consistent log correlation and structured debugging across services.
- Added
ml/utils/request_tracker.py:- Implements decorators (
@with_request_tracking) for automatic logging. - Adds structured logging with
log_with_context(). - Generates
req_<timestamp>_<random>format IDs.
- Implements decorators (
- Updated
app.py:- Applied logging to
/,/health, and/predict-allroutes. - All key logic paths (token check, weather fetch, prediction loop) now emit contextual logs.
- Logs are JSON-formatted for compatibility with log aggregation tools.
- Applied logging to
- Introduced
src/utils/requestTracker.jsandapiClient.js:- Automatically attaches
X-Request-IDto all API calls. - Wraps
fetch()with consistent error/logging handling. - Logs structured metadata (duration, endpoint, context, status).
- Automatically attaches
- Updated
/api/directions,/api/weatherto:- Include token validation logging
- Return
X-Request-IDin responses - Use shared logging & error utilities
- Refactored
Mapcomponent to use newapiClient.
- Updated
.gitlab-ci.yml:- Allow
feature/request-id-loggingto deploy to staging - Improved output readability and debugging logs
- Allow
🧪 Added:
-
scripts/test-request-tracking.sh: Tests request ID propagation and structured logs -
scripts/test-complete-system.sh: Verifies container health and request chain
Benefits:
- Enables end-to-end traceability for each user request
- Makes debugging across microservices easier and more reliable
- Lays foundation for future observability integrations (ELK, Datadog, etc.)