Skip to content

[BUG] OFREP endpoints never record flag evaluation metrics (feature_flag.flagd.impression / .result.reason) #2015

Closed

Description

@mohitkothari

Observed behavior

Description

flagd's OFREP HTTP handlers (/ofrep/v1/evaluate/flags/{key} and the bulk endpoint) never emit the feature_flag.flagd.impression and feature_flag.flagd.result.reason metrics, even though /metrics is healthy and these metrics work correctly for the same flags evaluated over Connect/gRPC.

Root cause

In flagd/pkg/service/flag-evaluation/ofrep/handler.go:

  • NewOfrepHandler (line 40) accepts a metricsRecorder telemetry.IMetricsRecorder parameter, but only passes it into metricsmw.NewHTTPMetric(...) (lines 58-63, 67-72) for generic HTTP request count/duration middleware.
  • The handler struct (line 32) never stores the recorder as a field.
  • HandleFlagEvaluation (line 78) and HandleBulkEvaluation (line 120) call h.evaluator.ResolveAsAnyValue / h.evaluator.ResolveAllValues directly and return, without ever calling RecordEvaluation.

Compare this to the Connect/gRPC evaluation path, which does call it after every resolve:

  • flagd/pkg/service/flag-evaluation/flag_evaluator_v1.go:94 — s.metrics.RecordEvaluation(ctx, resolved.Error, resolved.Reason, resolved.Variant, resolved.FlagKey)
  • flagd/pkg/service/flag-evaluation/flag_evaluator_v2.go:257 — same pattern
  • flagd/pkg/service/flag-evaluation/flag_evaluator.go:92,386 — same pattern

So any flag evaluated only through OFREP is invisible to the impression/result.reason metrics, while identical flags evaluated over gRPC record correctly. Since these two metrics are flagd's primary evaluation-rate/error-rate signal, this makes evaluation observability silently incomplete for any OFREP-only client — with no error or log to indicate it.

Expected behavior

HandleFlagEvaluation should call RecordEvaluation once per evaluation, and HandleBulkEvaluation should call it once per flag in the batch — mirroring the gRPC handlers.

Suggested fix

Store the metricsRecorder on the handler struct in NewOfrepHandler, then call h.metricsRecorder.RecordEvaluation(ctx, evaluation.Error, evaluation.Reason, evaluation.Variant, flagKey) after ResolveAsAnyValue in HandleFlagEvaluation, and loop over each result calling the same in HandleBulkEvaluation.

How we found this

Confirmed by deploying a real OpenFeature-Operator-injected sidecar (flagd v0.15.4-patched) and comparing: a client evaluating the same three flags over OFREP showed zero feature_flag.flagd.impression/.result.reason samples, while switching the same client to the gRPC/Connect provider produced correct metrics immediately, with no other configuration change.

Expected Behavior

No response

Steps to reproduce

No response

Activity

  1. added
    bug
    Needs Triage
    on Aug 12, 2026
  2. toddbaert commented on Aug 12, 2026

    @toddbaert
    Member

    Confirmed.

    The OFREP handler takes a metricsRecorder but only uses it for the generic HTTP request middleware, never calls RecordEvaluation, so impression/result.reason never fire for OFREP-only clients. gRPC path calls it correctly. Good catch, and thanks for the report.

    Fix is as you described: store the recorder on the handler struct, call RecordEvaluation after ResolveAsAnyValue in the single handler, and once per flag in the bulk handler.

    One thing for whoever picks this up: in the bulk loop, pass each flag's own error/reason/variant/key (not the top-level batch error), so per-flag results record accurately.

    Removing "needs triage", PR welcome.

  3. removed
    Needs Triage
    on Aug 12, 2026
  4. added a commit that references this issue on Aug 14, 2026
    8dd34dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions