mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-03 09:20:50 -05:00
enable traces in proxy
This commit is contained in:
+11
-13
@@ -2,6 +2,7 @@ package proxy
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -10,21 +11,19 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis/proxy/pkg/proxy/policy"
|
||||
"go.opencensus.io/plugin/ochttp/propagation/tracecontext"
|
||||
"go.opencensus.io/trace"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
"github.com/owncloud/ocis/proxy/pkg/proxy/policy"
|
||||
proxytracing "github.com/owncloud/ocis/proxy/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// MultiHostReverseProxy extends httputil to support multiple hosts with diffent policies
|
||||
// MultiHostReverseProxy extends "httputil" to support multiple hosts with different policies
|
||||
type MultiHostReverseProxy struct {
|
||||
httputil.ReverseProxy
|
||||
Directors map[string]map[config.RouteType]map[string]func(req *http.Request)
|
||||
PolicySelector policy.Selector
|
||||
logger log.Logger
|
||||
propagator tracecontext.HTTPFormat
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
@@ -214,17 +213,16 @@ func (p *MultiHostReverseProxy) AddHost(policy string, target *url.URL, rt confi
|
||||
}
|
||||
|
||||
func (p *MultiHostReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
var span *trace.Span
|
||||
var (
|
||||
ctx = r.Context()
|
||||
span trace.Span
|
||||
)
|
||||
|
||||
// Start root span.
|
||||
if p.config.Tracing.Enabled {
|
||||
ctx, span = trace.StartSpan(ctx, r.URL.String())
|
||||
tracer := proxytracing.TraceProvider.Tracer("proxy")
|
||||
ctx, span = tracer.Start(ctx, fmt.Sprintf("%s %v", r.Method, r.URL.Path))
|
||||
defer span.End()
|
||||
p.propagator.SpanContextToRequest(span.SpanContext(), r)
|
||||
}
|
||||
|
||||
// Call upstream ServeHTTP
|
||||
p.ReverseProxy.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user