Files
ocis/ocis-pkg/middleware/tracing.go
Juan Pablo Villafáñez a388c8d642 feat: Homogenize tracing of requests to other services
The "tracing.GetNewRequest" and "tracing.GetNewRequestWithContext" aims
to replace the "http.NewRequest" and "http.NewRequestWithContext"
respectively by including tracing data.

For requests that have been already created, such as the case of some
reva requests, "tracing.InjectTracingHeaders" is provided.

Note that some outgoing requests might be required NOT to use tracing
headers.
2025-07-18 14:40:55 +02:00

21 lines
527 B
Go

package middleware
import (
"net/http"
"go.opentelemetry.io/otel/propagation"
)
var propagator = propagation.NewCompositeTextMapPropagator(
propagation.Baggage{},
propagation.TraceContext{},
)
// TraceContext unpacks the request context looking for an existing trace id.
func TraceContext(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := propagator.Extract(r.Context(), propagation.HeaderCarrier(r.Header))
next.ServeHTTP(w, r.WithContext(ctx))
})
}