AOSSIE-Org / AOSSIE-Org/EduAid

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

Offen
#547 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
JavaScript
Sterne
171
Forks
425
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.