Logging có cấu trúc
Log dạng JSON với level, timestamp, message, context (request_id, user_id, extra). Dễ parse và query. Tránh log quá nhiều (performance) và tránh log thông tin nhạy cảm (password, token). Rotate log file theo size hoặc ngày.
Centralized logging
Ứng dụng gửi log đến service tập trung (ELK, Loki, Datadog, CloudWatch). Tìm kiếm và filter theo request_id giúp trace toàn bộ luồng. Có thể kết hợp với trace (OpenTelemetry) để theo dõi latency từng service.
Metrics và alerting
Thu thập metric: request rate, error rate, latency (p50, p95, p99), CPU, memory. Dashboard (Grafana, CloudWatch) để quan sát. Alert khi error tăng, latency vượt ngưỡng hoặc service down. On-call và runbook để xử lý nhanh.
Bình luận (0)
Đang tải bình luận...