From bceeabd6c3de3df6fb648acc142c676c82fbbd80 Mon Sep 17 00:00:00 2001 From: Tania <10127682+undef1nd@users.noreply.github.com> Date: Thu, 16 Oct 2025 18:28:54 +0200 Subject: [PATCH] Revert "OpenFeature: Include HTTP status code and evaluation context in traces" (#112527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert "OpenFeature: Include HTTP status code and evaluation context in trace…" This reverts commit ffee922fae8f58f868eacd28ed9b6c9f820b9b92. --- pkg/registry/apis/ofrep/register.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/pkg/registry/apis/ofrep/register.go b/pkg/registry/apis/ofrep/register.go index cac6fc444d8..49c755ecc92 100644 --- a/pkg/registry/apis/ofrep/register.go +++ b/pkg/registry/apis/ofrep/register.go @@ -13,7 +13,6 @@ import ( "github.com/grafana/grafana/pkg/infra/tracing" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - semconv "go.opentelemetry.io/otel/semconv/v1.21.0" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -253,7 +252,6 @@ func (b *APIBuilder) oneFlagHandler(w http.ResponseWriter, r *http.Request) { if !b.validateNamespace(r) { _ = tracing.Errorf(span, namespaceMismatchMsg) - span.SetAttributes(semconv.HTTPStatusCode(http.StatusUnauthorized)) b.logger.Error(namespaceMismatchMsg) http.Error(w, namespaceMismatchMsg, http.StatusUnauthorized) return @@ -262,7 +260,6 @@ func (b *APIBuilder) oneFlagHandler(w http.ResponseWriter, r *http.Request) { flagKey := mux.Vars(r)["flagKey"] if flagKey == "" { _ = tracing.Errorf(span, "flagKey parameter is required") - span.SetAttributes(semconv.HTTPStatusCode(http.StatusBadRequest)) http.Error(w, "flagKey parameter is required", http.StatusBadRequest) return } @@ -275,7 +272,6 @@ func (b *APIBuilder) oneFlagHandler(w http.ResponseWriter, r *http.Request) { // Unless the request is authenticated, we only allow public flags evaluations if !isAuthedReq && !isPublicFlag(flagKey) { _ = tracing.Errorf(span, "unauthorized to evaluate flag: %s", flagKey) - span.SetAttributes(semconv.HTTPStatusCode(http.StatusUnauthorized)) b.logger.Error("Unauthorized to evaluate flag", "flagKey", flagKey) http.Error(w, "unauthorized to evaluate flag", http.StatusUnauthorized) return @@ -297,7 +293,6 @@ func (b *APIBuilder) allFlagsHandler(w http.ResponseWriter, r *http.Request) { if !b.validateNamespace(r) { _ = tracing.Errorf(span, namespaceMismatchMsg) - span.SetAttributes(semconv.HTTPStatusCode(http.StatusUnauthorized)) b.logger.Error(namespaceMismatchMsg) http.Error(w, namespaceMismatchMsg, http.StatusUnauthorized) return @@ -362,10 +357,7 @@ func (b *APIBuilder) isAuthenticatedRequest(r *http.Request) bool { // validateNamespace checks if the namespace in the evaluation context matches the namespace in the request func (b *APIBuilder) validateNamespace(r *http.Request) bool { - ctx, span := tracer.Start(r.Context(), "ofrep.validateNamespace") - defer span.End() - r = r.WithContext(ctx) - + // Extract namespace from request context or URL path var namespace string user, ok := types.AuthInfoFrom(r.Context()) if !ok { @@ -378,25 +370,19 @@ func (b *APIBuilder) validateNamespace(r *http.Request) bool { namespace = mux.Vars(r)["namespace"] } - // Read request body for namespace validation and tracing + // Extract namespace from feature flag evaluation context body, err := io.ReadAll(r.Body) if err != nil { - _ = tracing.Errorf(span, "failed to read request body: %w", err) b.logger.Error("Error reading evaluation request body", "error", err) - span.SetAttributes(attribute.Bool("validation.success", false)) return false } r.Body = io.NopCloser(bytes.NewBuffer(body)) - span.SetAttributes(attribute.String("request.body", string(body))) - evalCtxNamespace := b.namespaceFromEvalCtx(body) // "default" namespace case can only occur in on-prem grafana if (namespace == "default" && evalCtxNamespace == "") || (evalCtxNamespace == namespace) { - span.SetAttributes(attribute.Bool("validation.success", true)) return true } - span.SetAttributes(attribute.Bool("validation.success", false)) return false }