one-zero-eight / one-zero-eight/server
Add request_id and user_id logging in nginx and services
Open
@ZolotarevAlexandr is already working on this.
Since Apr 18, 2026.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Describe the feature
We want to trace users requests to debug issues. For this, we need to add user ids and request ids to each log line: both in Nginx logs and FastAPI logs.
Suggested solution
Пример log_format:
(блок http)
log_format main '[$time_local] "$http_x_forwarded_for" $remote_addr '
'"$server_name" "$request" $status '
'"$http_referer" "$http_user_agent" '
'$body_bytes_sent $request_time '
'auth_user="$remote_user" '
'session_id="$session_id"';
Пример пробрасывания переменных в сервис:
(блок server)
proxy_set_header X-Request-ID $requestid;
Пример возврата переменных клиенту:
(блок server)
add_header X-Request-ID $requestid;
Пример куки для трекинга браузера:
(блок http)
map $cookie_session_id $session_id {
"" $request_id.$msec;
default $cookie_session_id;
}
add_header Set-Cookie "session_id=$session_id; Path=/; HttpOnly; SameSite=Strict; Max-Age=31536000";
Also FastAPI should add header for user id, and Nginx can use this header in log.
FastAPI logging should also print user ids and request ids.
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.