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:
@@ -1,19 +1,28 @@
|
||||
package ofrep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
goffmodel "github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/model"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
|
||||
func (b *APIBuilder) evalAllFlagsStatic(isAuthedUser bool, w http.ResponseWriter, r *http.Request) {
|
||||
result, err := b.staticEvaluator.EvalAllFlags(r.Context())
|
||||
func (b *APIBuilder) evalAllFlagsStatic(ctx context.Context, isAuthedUser bool, w http.ResponseWriter) {
|
||||
_, span := tracer.Start(ctx, "ofrep.static.evalAllFlags")
|
||||
defer span.End()
|
||||
|
||||
result, err := b.staticEvaluator.EvalAllFlags(ctx)
|
||||
if err != nil {
|
||||
err = tracing.Error(span, err)
|
||||
b.logger.Error("Failed to evaluate all static flags", "error", err)
|
||||
http.Error(w, "failed to evaluate flags", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
span.SetAttributes(attribute.Int("total_flags_count", len(result.Flags)))
|
||||
|
||||
if !isAuthedUser {
|
||||
var publicOnly []goffmodel.OFREPFlagBulkEvaluateSuccessResponse
|
||||
|
||||
@@ -24,14 +33,21 @@ func (b *APIBuilder) evalAllFlagsStatic(isAuthedUser bool, w http.ResponseWriter
|
||||
}
|
||||
|
||||
result.Flags = publicOnly
|
||||
span.SetAttributes(attribute.Int("public_flags_count", len(publicOnly)))
|
||||
}
|
||||
|
||||
writeResponse(http.StatusOK, result, b.logger, w)
|
||||
}
|
||||
|
||||
func (b *APIBuilder) evalFlagStatic(flagKey string, w http.ResponseWriter, r *http.Request) {
|
||||
result, err := b.staticEvaluator.EvalFlag(r.Context(), flagKey)
|
||||
func (b *APIBuilder) evalFlagStatic(ctx context.Context, flagKey string, w http.ResponseWriter) {
|
||||
_, span := tracer.Start(ctx, "ofrep.static.evalFlag")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(attribute.String("flag_key", flagKey))
|
||||
|
||||
result, err := b.staticEvaluator.EvalFlag(ctx, flagKey)
|
||||
if err != nil {
|
||||
err = tracing.Error(span, err)
|
||||
b.logger.Error("Failed to evaluate static flag", "key", flagKey, "error", err)
|
||||
http.Error(w, "failed to evaluate flag", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user