feat(http): lab6 add OTel spans, metrics, JSON logs and tracing readiness

This commit is contained in:
Голиков Maximillian Антон
2026-11-16 09:21:23 +03:00
parent 6bc501ca3e
commit c403b23595
5 changed files with 66 additions and 6 deletions
+13 -3
View File
@@ -1,6 +1,9 @@
package httpapi
import (
"log/slog"
"net/http"
"github.com/gin-gonic/gin"
"high-loud-apps-labs/internal/httpapi/handler"
@@ -20,12 +23,19 @@ func NewRouter(h Handlers, auth gin.HandlerFunc) *gin.Engine {
gin.EnableJsonDecoderDisallowUnknownFields()
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(middleware.RequestID())
r.Use(middleware.Instance())
r.Use(middleware.Metrics())
r.Use(middleware.OTel())
r.Use(middleware.Metrics())
r.Use(middleware.Logging())
r.Use(gin.CustomRecoveryWithWriter(nil, func(c *gin.Context, err any) {
slog.Error("Паника при обработке HTTP-запроса",
"panic", err,
"http.route", c.FullPath(),
"request_id", middleware.GetRequestID(c),
)
c.AbortWithStatus(http.StatusInternalServerError)
}))
r.GET("/health/live", h.Health.Live)
r.GET("/health/ready", h.Health.Ready)