feat(logging): implement unified request ID logging across frontend and backend

Merged Zhaofang He requested to merge feature/request-id-logging into develop

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.

🔹 Backend (ML API - Flask):

  • 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.
  • Updated app.py:
    • Applied logging to /, /health, and /predict-all routes.
    • All key logic paths (token check, weather fetch, prediction loop) now emit contextual logs.
    • Logs are JSON-formatted for compatibility with log aggregation tools.

🔹 Frontend (Next.js Webapp):

  • Introduced src/utils/requestTracker.js and apiClient.js:
    • Automatically attaches X-Request-ID to all API calls.
    • Wraps fetch() with consistent error/logging handling.
    • Logs structured metadata (duration, endpoint, context, status).
  • Updated /api/directions, /api/weather to:
    • Include token validation logging
    • Return X-Request-ID in responses
    • Use shared logging & error utilities
  • Refactored Map component to use new apiClient.

🔧 CI/CD:

  • Updated .gitlab-ci.yml:
    • Allow feature/request-id-logging to deploy to staging
    • Improved output readability and debugging logs

🧪 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.)

Merge request reports