AOSSIE-Org / AOSSIE-Org/EduAid

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

未关闭
#547 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
JavaScript
星标
171
派生
425
PR 合并指标
30 天内没有已合并 PR

描述

### 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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。