forked from mtusi2026/mtusi2026lab6
feat(http): lab6 add OTel spans, metrics, JSON logs and tracing readiness
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user