Skip to content

[FEATURE] OFREP evaluation is missing tracing semconv attributes #1806

@apodgorbunschih

Description

@apodgorbunschih

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) {

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
Image
after
Image
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageThis issue needs to be investigated by a maintainerenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions