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
+8 -1
View File
@@ -7,9 +7,11 @@ import (
"time"
"github.com/gin-gonic/gin"
"go.opentelemetry.io/otel/codes"
"high-loud-apps-labs/internal/domain"
"high-loud-apps-labs/internal/httpapi/dto"
"high-loud-apps-labs/internal/telemetry"
)
type HealthCheck func(ctx context.Context) error
@@ -33,12 +35,16 @@ func (h *HealthHandler) Live(c *gin.Context) {
}
func (h *HealthHandler) Ready(c *gin.Context) {
ctx, span := telemetry.Tracer("httpapi").Start(c.Request.Context(), "health.ready")
defer span.End()
if h.ready != nil && !h.ready.Load() {
span.SetStatus(codes.Error, "shutting down")
respondError(c, &domain.UnavailableError{Reason: "shutting down"})
return
}
ctx, cancel := context.WithTimeout(c.Request.Context(), 2*time.Second)
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
for _, check := range h.checks {
@@ -46,6 +52,7 @@ func (h *HealthHandler) Ready(c *gin.Context) {
continue
}
if err := check(ctx); err != nil {
span.SetStatus(codes.Error, "зависимость недоступна")
respondError(c, &domain.UnavailableError{Reason: "зависимость недоступна"})
return
}