My App
ServiceAPI Gateway

Observability API Gateway

Access logs, route logs và request/correlation id trong Go API Gateway.

Observability API Gateway

Access logs

Gateway ghi một structured access log cho mỗi request.

Source fields đã confirm:

FieldÝ nghĩa
request_idrequest id sau normalize
correlation_idcorrelation id sau normalize
methodHTTP method
pathrequest path
route_idGateway route id nếu request được proxy
service_namedownstream service name nếu request được proxy
statusresponse status
duration_msduration theo millisecond
outcomeSUCCESS, REDIRECT, CLIENT_ERROR, SERVER_ERROR, ERROR, unknown

Gateway README ghi rõ không log authorization headers, tokens, cookies, passwords, request bodies hoặc response bodies.

Route logs

Proxy handler set route context trước khi forward downstream.

Known successful select-branch route log:

method=POST
path=/api/auth/select-branch
route_id=identity-auth
service_name=identity-service
status=200
outcome=SUCCESS

Nếu request không match proxy route, route_idservice_name có thể rỗng trong access log.

Request/correlation id

Gateway normalize sớm:

  • X-Request-Id
  • X-Correlation-Id

Behavior đã confirm từ code:

  • Valid incoming X-Request-Id được giữ.
  • Missing/invalid X-Request-Id được generate mới.
  • Missing/invalid X-Correlation-Id fallback về request id.
  • Hai header này được set xuống downstream và trả về response.

CORS preflight

CORS preflight hợp lệ:

OPTIONS
→ Gateway CORS middleware
→ 204
→ not proxied downstream

Debug kỳ vọng:

  • method=OPTIONS
  • status=204
  • outcome=SUCCESS
  • route_id có thể rỗng vì xử lý local.

Debug nhanh

Gateway logs:

docker logs centeros-api-gateway --tail 100

Identity logs:

docker logs centeros-identity-service --tail 100

Khi debug auth/select-branch:

  1. Check Gateway log theo path.
  2. Check route_idservice_name.
  3. Check statusoutcome.
  4. So sánh X-Request-Id / X-Correlation-Id giữa Gateway và Identity logs nếu có.

TODO

  • Chưa đóng: exact production log query command.
  • Chưa đóng: metrics endpoint; Gateway README ghi metrics chưa implemented.

On this page