diff --git a/cmd/cleanup-controller/server.go b/cmd/cleanup-controller/server.go index 2661abb6bd..0d225cfcc1 100644 --- a/cmd/cleanup-controller/server.go +++ b/cmd/cleanup-controller/server.go @@ -77,7 +77,7 @@ func NewServer( WithSubResourceFilter(). WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookValidating). WithAdmission(policyLogger.WithName("validate")). - ToHandlerFunc(), + ToHandlerFunc("VALIDATE"), ) mux.HandlerFunc( "POST", @@ -87,7 +87,7 @@ func NewServer( WithSubResourceFilter(). WithMetrics(labelLogger, metricsConfig.Config(), metrics.WebhookValidating). WithAdmission(labelLogger.WithName("validate")). - ToHandlerFunc(), + ToHandlerFunc("VALIDATE"), ) mux.HandlerFunc( "GET", @@ -95,7 +95,7 @@ func NewServer( handlers.HttpHandler(cleanupHandlerFunc). WithMetrics(policyLogger). WithTrace("CLEANUP"). - ToHandlerFunc(), + ToHandlerFunc("CLEANUP"), ) mux.HandlerFunc("GET", config.LivenessServicePath, handlers.Probe(probes.IsLive)) mux.HandlerFunc("GET", config.ReadinessServicePath, handlers.Probe(probes.IsReady)) diff --git a/pkg/tracing/config.go b/pkg/tracing/config.go index 49747a4338..d707ded968 100644 --- a/pkg/tracing/config.go +++ b/pkg/tracing/config.go @@ -63,8 +63,8 @@ func NewTraceConfig(log logr.Logger, tracerName, address, certs string, kubeClie sdktrace.WithResource(res), ) // set global propagator to tracecontext (the default is no-op). - otel.SetTextMapPropagator(propagation.TraceContext{}) otel.SetTracerProvider(tp) + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) return func() { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() diff --git a/pkg/webhooks/handlers/types.go b/pkg/webhooks/handlers/types.go index ce6ba78c3c..03a98b7a4b 100644 --- a/pkg/webhooks/handlers/types.go +++ b/pkg/webhooks/handlers/types.go @@ -6,6 +6,7 @@ import ( "time" "github.com/go-logr/logr" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" admissionv1 "k8s.io/api/admission/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -35,6 +36,7 @@ func FromAdmissionFunc(name string, h AdmissionHandler) AdmissionHandler { return h.WithTrace(name) } -func (h HttpHandler) ToHandlerFunc() http.HandlerFunc { - return http.HandlerFunc(h) +func (h HttpHandler) ToHandlerFunc(operation string) http.HandlerFunc { + handler := otelhttp.NewHandler(http.HandlerFunc(h), operation) + return handler.ServeHTTP } diff --git a/pkg/webhooks/server.go b/pkg/webhooks/server.go index a418b68253..f12c8c500c 100644 --- a/pkg/webhooks/server.go +++ b/pkg/webhooks/server.go @@ -128,7 +128,7 @@ func NewServer( WithDump(debugModeOpts.DumpPayload). WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookMutating). WithAdmission(policyLogger.WithName("mutate")). - ToHandlerFunc(), + ToHandlerFunc("MUTATE"), ) mux.HandlerFunc( "POST", @@ -138,7 +138,7 @@ func NewServer( WithSubResourceFilter(). WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookValidating). WithAdmission(policyLogger.WithName("validate")). - ToHandlerFunc(), + ToHandlerFunc("VALIDATE"), ) mux.HandlerFunc( "POST", @@ -148,14 +148,14 @@ func NewServer( WithSubResourceFilter(). WithMetrics(exceptionLogger, metricsConfig.Config(), metrics.WebhookValidating). WithAdmission(exceptionLogger.WithName("validate")). - ToHandlerFunc(), + ToHandlerFunc("VALIDATE"), ) mux.HandlerFunc( "POST", config.VerifyMutatingWebhookServicePath, handlers.FromAdmissionFunc("VERIFY", handlers.Verify). WithAdmission(verifyLogger.WithName("mutate")). - ToHandlerFunc(), + ToHandlerFunc("VERIFY"), ) mux.HandlerFunc("GET", config.LivenessServicePath, handlers.Probe(runtime.IsLive)) mux.HandlerFunc("GET", config.ReadinessServicePath, handlers.Probe(runtime.IsReady)) @@ -280,7 +280,7 @@ func registerWebhookHandlers( return handlerFunc(ctx, logger, request, "fail", startTime) }, ) - mux.HandlerFunc("POST", basePath, builder(all).ToHandlerFunc()) - mux.HandlerFunc("POST", basePath+"/ignore", builder(ignore).ToHandlerFunc()) - mux.HandlerFunc("POST", basePath+"/fail", builder(fail).ToHandlerFunc()) + mux.HandlerFunc("POST", basePath, builder(all).ToHandlerFunc(name)) + mux.HandlerFunc("POST", basePath+"/ignore", builder(ignore).ToHandlerFunc(name)) + mux.HandlerFunc("POST", basePath+"/fail", builder(fail).ToHandlerFunc(name)) }