AOSSIE-Org / AOSSIE-Org/EduAid

[FEATURE]: Add request ID tracing and structured logging for backend API requests

Đang mở
#547 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
JavaScript
Star
171
Fork
425
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Feature and its Use Cases

### Feature Description

Introduce request ID tracing for backend API requests to improve debugging and observability.

Currently, when multiple API requests are processed simultaneously (for example while generating quizzes or uploading files), the backend logs do not include any unique identifier for requests. This makes it difficult for maintainers and contributors to trace which logs belong to which request.

Adding a unique request ID to every incoming request would allow logs and error messages to be correlated with a specific API call.

### Proposed Implementation

- Generate a unique request ID (for example using `uuid4()`) for every incoming request.
- Attach the request ID to Flask’s request context (`flask.g`).
- Include the request ID in backend logs and optionally in API responses.

Example implementation:

```python
from uuid import uuid4
from flask import g

@app.before_request
def attach_request_id():
g.request_id = str(uuid4())

Benefits

Makes backend debugging significantly easier

Helps trace errors across concurrent requests

Improves observability for maintainers and contributors

Provides better insight when diagnosing API failures or slow requests

Use Cases

Debugging quiz generation failures

Tracking long-running model inference requests

Diagnosing backend errors reported by frontend clients

Improving developer experience when contributing to the backend

### Additional Context

This feature would improve the developer experience when debugging backend behavior, especially as more contributors interact with the API.

It also lays groundwork for better observability if the backend later integrates monitoring or logging tools.

### Code of Conduct

- [x] I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and will post updates there
- [x] I have searched existing issues to avoid duplicates

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.