Fix nil-pointer issue with misconfigured tracing

Co-authored-by: Jörn Friedrich Dreyer <jfd@butonic.de>

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2024-07-16 14:46:49 +02:00
co-authored by Jörn Friedrich Dreyer
parent d98a05d2df
commit 505ed389b7
7 changed files with 39 additions and 72 deletions
-28
View File
@@ -1,28 +0,0 @@
package middleware
import (
"net/http"
ocstracing "github.com/owncloud/ocis/v2/services/ocs/pkg/tracing"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
var propagator = propagation.NewCompositeTextMapPropagator(
propagation.Baggage{},
propagation.TraceContext{},
)
// LogTrace Sets the initial trace in the ocs service.
func LogTrace(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
spanOpts := []trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindServer),
}
ctx, span := ocstracing.TraceProvider.Tracer("ocs").Start(r.Context(), r.URL.Path, spanOpts...)
defer span.End()
propagator.Inject(ctx, propagation.HeaderCarrier(r.Header))
next.ServeHTTP(w, r.WithContext(ctx))
})
}