Add request_id and user_id logging in nginx and services

Aperta
#10 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@ZolotarevAlexandr ci sta già lavorando.

Dal 18/4/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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

Lingua principale
Python
Stelle
0
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di one-zero-eight/server

Tutte le issue di one-zero-eight/server

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.