package observability import ( "fmt" "net/http" "github.com/prometheus/client_golang/prometheus/promhttp" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) // NewLogger creates a zap production logger at the given level. func NewLogger(level string) (*zap.Logger, error) { cfg := zap.NewProductionConfig() lvl, err := zapcore.ParseLevel(level) if err != nil { lvl = zapcore.InfoLevel } cfg.Level = zap.NewAtomicLevelAt(lvl) return cfg.Build() } // ServeMetrics starts a Prometheus /metrics endpoint on the given port. // It blocks until the server exits. func ServeMetrics(port int) error { mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte("ok")) }) addr := fmt.Sprintf(":%d", port) return http.ListenAndServe(addr, mux) }