omnix-sopiga/framework/middleware/tracing.go

25 lines
520 B
Go
Raw Permalink Normal View History

2026-08-07 12:21:42 +07:00
package middleware
import (
"github.com/gin-gonic/gin"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
)
func Tracing(serviceName string) gin.HandlerFunc {
tracer := otel.Tracer(serviceName)
return func(c *gin.Context) {
ctx, span := tracer.Start(c.Request.Context(), c.FullPath())
defer span.End()
span.SetAttributes(
attribute.String("http.method", c.Request.Method),
attribute.String("http.path", c.Request.URL.Path),
)
c.Request = c.Request.WithContext(ctx)
c.Next()
}
}