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_id | request id sau normalize |
correlation_id | correlation id sau normalize |
method | HTTP method |
path | request path |
route_id | Gateway route id nếu request được proxy |
service_name | downstream service name nếu request được proxy |
status | response status |
duration_ms | duration theo millisecond |
outcome | SUCCESS, 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=SUCCESSNếu request không match proxy route, route_id và service_name có thể rỗng trong access log.
Request/correlation id
Gateway normalize sớm:
X-Request-IdX-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-Idfallback 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 downstreamDebug kỳ vọng:
method=OPTIONSstatus=204outcome=SUCCESSroute_idcó thể rỗng vì xử lý local.
Debug nhanh
Gateway logs:
docker logs centeros-api-gateway --tail 100Identity logs:
docker logs centeros-identity-service --tail 100Khi debug auth/select-branch:
- Check Gateway log theo
path. - Check
route_idvàservice_name. - Check
statusvàoutcome. - So sánh
X-Request-Id/X-Correlation-Idgiữ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.