package middlewares

import (
	"net/http"

	"route256/cart/internal/infra/tracing"
)

func NewTracingMiddleware(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx, span := tracing.Tracer().Start(r.Context(),
			r.Method+" "+r.URL.Path)
		defer span.End()

		h.ServeHTTP(w, r.WithContext(ctx))
	})
}
