OpenFeature: Add tracing to feature flags service (#111895)

* Add tracing to feature flags service

* Apply review feedback

* Apply suggestion from @hairyhenderson

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Apply suggestion from @hairyhenderson

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Apply suggestion from @hairyhenderson

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Apply suggestion from @hairyhenderson

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Apply suggestion from @hairyhenderson

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Apply suggestion from @hairyhenderson

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Fix issues

---------

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
Tania
2025-10-06 09:16:29 +02:00
committed by GitHub
co-authored by Dave Henderson
parent 64a483d112
commit 843956e795
3 changed files with 63 additions and 10 deletions
+16 -2
View File
@@ -2,6 +2,7 @@ package ofrep
import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
@@ -14,14 +15,21 @@ import (
"strconv"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/util/proxyutil"
goffmodel "github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/model"
)
func (b *APIBuilder) proxyAllFlagReq(isAuthedUser bool, w http.ResponseWriter, r *http.Request) {
func (b *APIBuilder) proxyAllFlagReq(ctx context.Context, isAuthedUser bool, w http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(ctx, "ofrep.proxy.evalAllFlags")
defer span.End()
r = r.WithContext(ctx)
proxy, err := b.newProxy(ofrepPath)
if err != nil {
err = tracing.Error(span, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -61,9 +69,15 @@ func (b *APIBuilder) proxyAllFlagReq(isAuthedUser bool, w http.ResponseWriter, r
proxy.ServeHTTP(w, r)
}
func (b *APIBuilder) proxyFlagReq(flagKey string, isAuthedUser bool, w http.ResponseWriter, r *http.Request) {
func (b *APIBuilder) proxyFlagReq(ctx context.Context, flagKey string, isAuthedUser bool, w http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(ctx, "ofrep.proxy.evalFlag")
defer span.End()
r = r.WithContext(ctx)
proxy, err := b.newProxy(path.Join(ofrepPath, flagKey))
if err != nil {
err = tracing.Error(span, err)
b.logger.Error("Failed to create proxy", "key", flagKey, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return