AOSSIE-Org / AOSSIE-Org/EduAid

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

Abierto
#547 1 comentario 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
JavaScript
Estrellas
171
Forks
425
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.