📊 Capítulo 17: Observabilidade com Zap & Prometheus
Especialização Backend com Go & Gin Gonic
🗺️ O Pipeline de Telemetria e Logs Estruturados no Gin
flowchart LR
REQ["HTTP Request"]
--> ZAP_MW["Uber Zap Logger Middleware (JSON Estruturado / Zero Alocação)"]
--> PROM_MW["Prometheus Middleware (Contadores & Histograma de Latência)"]
--> HANDLER["Gin Handler"]
PROM_MW --> METRICS_EP["GET /metrics (Scraping do Servidor Prometheus)"]
ZAP_MW --> STDOUT["stdout / ElasticSearch / Loki"]
METRICS_EP --> GRAFANA["Grafana Dashboards em Tempo Real"]
style REQ fill:#ede7f6,stroke:#512da8,stroke-width:2px
style ZAP_MW fill:#fff3e0,stroke:#ff9800,stroke-width:2px
style PROM_MW fill:#e8f5e9,stroke:#4caf50,stroke-width:2px
style HANDLER fill:#e1f5fe,stroke:#03a9f4,stroke-width:1.5px
style METRICS_EP fill:#c8e6c9,stroke:#2e7d32,stroke-width:1.5px
style STDOUT fill:#ede7f6,stroke:#7e57c2,stroke-width:1.5px
style GRAFANA fill:#fff9c4,stroke:#fbc02d,stroke-width:2px
🎯 Slide 1: Por Que Usar o go.uber.org/zap?
-
Performance Imbatível: O logger mais rápido do ecossistema Go, projetado para evitar alocações de Heap em caminhos críticos de código (Hot Paths).
- Campos Fortemente Tipados:
zap.String("path", c.Request.URL.Path),zap.Int("status", c.Writer.Status()).
🎯 Slide 2: Exportando Métricas para o Prometheus
import "github.com/prometheus/client_golang/prometheus/promhttp"
// Registra endpoint de scraping padrão
r.GET("/metrics", gin.WrapH(promhttp.Handler()))
🎯 Slide 3: Métricas Golden Signals
- Latência: Duração das requisições via Histograma Prometheus.
- Tráfego: Requisições por segundo (RPS) via Contador.
- Erros: Contagem de respostas HTTP 4xx e 5xx.
- Saturação: Uso de memória Heap e contagem de Goroutines ativas.
Slide 1 de 1
Atalhos: ← → Navegar • Espaço Avançar • F Tela Cheia • Home Início • End Fim