package middleware

import (
	"github.com/acp/interceptor/internal/tracing"
	"github.com/gin-gonic/gin"
)

// Tracing ensures a trace ID exists for the request and echoes it on the response when possible.
func Tracing() gin.HandlerFunc {
	return func(c *gin.Context) {
		id := tracing.EnsureTraceID(c)
		c.Writer.Header().Set(tracing.TraceIDHeader, id)
		c.Next()
	}
}
