Move away from global tracers. (#6591)

* Move away from global tracers.

This PR moves away from global tracers and instead initialises
a tracer provider at Service setup and passes it where it needs to be.

* Change tracing provider to be set via options.

Also change name for GetServiceTraceProvider.

* Add changelog.
This commit is contained in:
Daniël Franke
2023-06-23 14:20:26 +02:00
committed by GitHub
parent c8f8bc55e2
commit 8f7521eff7
9 changed files with 82 additions and 47 deletions
@@ -8,7 +8,6 @@ import (
"strings"
"github.com/owncloud/ocis/v2/services/proxy/pkg/router"
proxytracing "github.com/owncloud/ocis/v2/services/proxy/pkg/tracing"
"github.com/owncloud/ocis/v2/services/proxy/pkg/webdav"
"go.opentelemetry.io/otel/trace"
"golang.org/x/text/cases"
@@ -50,7 +49,8 @@ type Authenticator interface {
func Authentication(auths []Authenticator, opts ...Option) func(next http.Handler) http.Handler {
options := newOptions(opts...)
configureSupportedChallenges(options)
tracer := proxytracing.TraceProvider.Tracer("proxy")
tracer := getTraceProvider(options).Tracer("proxy")
spanOpts := []trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindServer),
}
@@ -206,3 +206,10 @@ func evalRequestURI(l userAgentLocker, r regexp.Regexp) {
}
l.w.Header().Add(WwwAuthenticate, fmt.Sprintf("%v realm=\"%s\", charset=\"UTF-8\"", caser.String(l.fallback), l.r.Host))
}
func getTraceProvider(o Options) trace.TracerProvider {
if o.TraceProvider != nil {
return o.TraceProvider
}
return trace.NewNoopTracerProvider()
}