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
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)
Пример пробрасывания переменных в сервис:
(блок server)
Пример возврата переменных клиенту:
(блок server)
Пример куки для трекинга браузера:
(блок http)
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