open-feature / open-feature/flagd
[FEATURE] OFREP evaluation is missing tracing semconv attributes
Open
Nobody has claimed this yet.
enhancement
Needs Triage
- Dominant language
- Go
- Stars
- 998
- Forks
- 136
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 11
Description
Requirements
The ofrep handler is missing the least necessary data for attributes described here (feature_flag.key and feature_flag.result.variant) compared to the http\grpc evaluators.
func (h *handler) HandleFlagEvaluation(w http.ResponseWriter, r *http.Request) {
requestID := xid.New().String()
defer h.Logger.ClearFields(requestID)
// obtain flag key
vars := mux.Vars(r)
if vars == nil {
h.writeJSONToResponse(
http.StatusInternalServerError,
ofrep.InternalError{ErrorDetails: "failed to obtain the flag key from the request"}, w)
return
}
flagKey := vars[key]
request, err := extractOfrepRequest(r)
if err != nil {
h.writeJSONToResponse(http.StatusBadRequest, ofrep.ContextErrorResponseFrom(flagKey), w)
return
}
evaluationContext := flagdContext(h.Logger, requestID, request, h.contextValues, r.Header, h.headerToContextKeyMappings)
selectorExpression := r.Header.Get(service.FLAGD_SELECTOR_HEADER)
selector := store.NewSelector(selectorExpression)
ctx := context.WithValue(r.Context(), store.SelectorContextKey{}, selector)
ctx, span := h.tracer.Start(ctx, "handleFlagEvaluation", trace.WithSpanKind(trace.SpanKindServer))
evaluation := h.evaluator.ResolveAsAnyValue(ctx, requestID, flagKey, evaluationContext)
span.SetAttributes(telemetry.SemConvFeatureFlagAttributes(flagKey, evaluation.Variant)...)
defer span.End()
if evaluation.Error != nil {
span.SetStatus(codes.Error, "handleFlagEvaluation error")
span.RecordError(evaluation.Error)
status, evaluationError := ofrep.EvaluationErrorResponseFrom(evaluation)
h.writeJSONToResponse(status, evaluationError, w)
} else {
h.writeJSONToResponse(http.StatusOK, ofrep.SuccessResponseFrom(evaluation), w)
}
}
Something like that should yield the desired outcome
before
after
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in flagd/pkg/service/flag-evaluation/ofrep/handler.go at HandleFlagEvaluation, then compare the tracing attributes produced by the http and grpc evaluators. Ensure OFREP evaluation spans include the feature flag key and result variant attributes, and verify the resulting trace matches the documented semconv outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, observability
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100