AOSSIE-Org / AOSSIE-Org/EduAid

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

Aperta
#547 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
JavaScript
Stelle
171
Fork
425
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.