mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
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.
21 lines
527 B
Go
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))
|
|
})
|
|
}
|