Skip to content

feat: add flag set ID to evaluation metrics - #2078

Merged
toddbaert merged 2 commits into
open-feature:mainfrom
gargsajal9:gargsajal9-flag-set-telemetry
Oct 19, 2026
Merged

toddbaert merged 2 commits into
open-feature:mainfrom
gargsajal9:gargsajal9-flag-set-telemetry

Conversation

@gargsajal9

Copy link
Copy Markdown
Contributor

Summary

  • add the OpenTelemetry feature_flag.set.id attribute to evaluation impression and reason/error metrics when a non-empty string ID is known
  • preserve per-result flag-set attribution across typed Connect/gRPC and OFREP single and bulk evaluations
  • attribute explicit-selector lookup errors while omitting unknown, empty, and non-string IDs
  • document the metric attribute and its bulk/omission behavior

Closes #2020

Validation

  • built and ran the real flagd binary with two flag sets
  • exercised Connect v1/v2 and OFREP single, unfiltered bulk, selected-error, and unknown-error paths; all 8 live metric assertions passed
  • go test -p=1 -parallel=1 ./core/... ./flagd/...
  • focused race tests for telemetry and flag-evaluation packages
  • go vet ./core/pkg/telemetry ./flagd/pkg/service/flag-evaluation/...
  • git diff --check

@gargsajal9
gargsajal9 requested review from a team as code owners October 2, 2026 20:26
@netlify

netlify Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for polite-licorice-3db33c ready!

Name Link
🔨 Latest commit 8ee77c3
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/6ad64875d52da7846cd97117
😎 Deploy Preview https://deploy-preview-2078--polite-licorice-3db33c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ce14901d-36f9-457c-999f-304b4eee0778
📥 Commits

Reviewing files that changed from the base of the PR and between 6399e6b and 8ee77c3.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ebeb4113-b896-4fb0-8c3e-f6b98b599d08
📥 Commits

Reviewing files that changed from the base of the PR and between d28ed20 and d11ac7c.

📒 Files selected for processing: 11
  • core/pkg/telemetry/metrics.go
  • core/pkg/telemetry/metrics_test.go
  • core/pkg/telemetry/utils.go
  • core/pkg/telemetry/utils_test.go
  • docs/reference/monitoring.md
  • flagd/pkg/service/flag-evaluation/evaluation_metrics_test.go
  • flagd/pkg/service/flag-evaluation/flag_evaluator.go
  • flagd/pkg/service/flag-evaluation/flag_evaluator_v1.go
  • flagd/pkg/service/flag-evaluation/flag_evaluator_v2.go
  • flagd/pkg/service/flag-evaluation/ofrep/handler.go
  • flagd/pkg/service/flag-evaluation/ofrep/handler_test.go
🚧 Files skipped from review as they are similar to previous changes: 1
  • docs/reference/monitoring.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Evaluation metric recording now receives metadata from flagd and OFREP evaluation paths. Telemetry extracts string flag-set IDs and adds non-empty IDs to impression and reason metrics, except for FLAG_NOT_FOUND reason metrics. The monitoring reference documents the feature_flag.set.id attribute.

Changes: Flag-set metric attribution

Layer / File(s) Summary
Telemetry contract and metric attributes
core/pkg/telemetry/metrics.go, core/pkg/telemetry/utils.go, core/pkg/telemetry/metrics_test.go, core/pkg/telemetry/utils_test.go, docs/reference/monitoring.md
Recorder methods accept metadata. The recorder extracts string flag-set IDs and adds non-empty IDs to impression and reason metrics, except for FLAG_NOT_FOUND reason metrics. Tests and monitoring documentation cover the attribute.
flagd evaluation recording
flagd/pkg/service/flag-evaluation/flag_evaluator.go, flagd/pkg/service/flag-evaluation/flag_evaluator_v1.go, flagd/pkg/service/flag-evaluation/flag_evaluator_v2.go, flagd/pkg/service/flag-evaluation/evaluation_metrics_test.go
Single and bulk evaluation paths pass metadata to the metrics recorder. Tests cover legacy and v2 single evaluations, bulk evaluations, and non-string metadata values.
OFREP evaluation recording
flagd/pkg/service/flag-evaluation/ofrep/handler.go, flagd/pkg/service/flag-evaluation/ofrep/handler_test.go
Single and bulk evaluation paths pass each result’s metadata to the metrics recorder. Tests cover per-result IDs and non-string metadata values.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant FlagEvaluator
  participant EvaluationMetadata
  participant MetricsRecorder
  participant TelemetryMetrics
  FlagEvaluator->>EvaluationMetadata: pass metadata for each evaluation
  EvaluationMetadata-->>FlagEvaluator: metadata with flagSetId
  FlagEvaluator->>MetricsRecorder: record evaluation with metadata
  MetricsRecorder->>TelemetryMetrics: add flag-set ID to eligible metric attributes
Loading

Suggested reviewers: toddbaert

Merge Risk: ⚪ Minimal · up to d11ac

Flag-set attribution appears ready to merge after normal checks; no unresolved issue is established by the supplied evidence.

Security architecture risk: 🔵 Low · up to d11ac

The change adds flag-set identifiers to existing evaluation metrics without demonstrating a new authorization bypass or privilege expansion. Unknown-set lookup failures suppress the new attribute. Remaining uncertainty concerns deployment-specific telemetry access, downstream interface compatibility, and synthetic identity handling for empty selectors.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new exposure is evaluation identity reaching readers of the instance's telemetry. The recorder adds attributes to existing metric instruments and uses the configured metrics reader. Actual destinations, audience, retention, and cross-environment aggregation are deployment-dependent and were not available.

Trust Boundaries and Controls

  • inferred — Caller-supplied selectors can reach lookup-error metadata, but the shown lookup-failure path produces FLAG_NOT_FOUND and suppresses the new label. Successful configured-set selection resolves against stored flags. The telemetry helper itself checks only type and emptiness, so provenance remains a producer responsibility rather than a recorder-enforced allowlist.

Resilience and Maintainability Implications

  • observed — The recorder retains its existing SDK cardinality limit of 2000. This provides cardinality containment but does not validate identifier provenance or redact exported values. Focused tests assert distinct set attribution and suppression of caller-controlled not-found metadata.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 10 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: adding the flag-set ID to evaluation metrics.
Description check Passed The description directly explains the metric attribute, attribution behavior, omission rules, documentation changes, and validation performed.
Linked Issues check Passed Issue #2020 requires OpenTelemetry metrics for flagd and OFREP to support filtering by flag-set ID. The PR adds feature_flag.set.id to evaluation and impression metrics when metadata contains a non-…
Out of Scope Changes check Passed The telemetry API changes, metadata extraction, evaluator and OFREP propagation, tests, and monitoring documentation directly support issue #2020. No unrelated change is demonstrated in the provided p…
Full details: Linked Issues check

Explanation

Issue #2020 requires OpenTelemetry metrics for flagd and OFREP to support filtering by flag-set ID. The PR adds feature_flag.set.id to evaluation and impression metrics when metadata contains a non-empty string ID. The evaluator and OFREP paths pass per-result metadata, including bulk and lookup-error paths. Tests cover known, missing, empty, and non-string IDs. The monitoring documentation describes the attribute and bulk behavior.

Full details: Out of Scope Changes check

Explanation

The telemetry API changes, metadata extraction, evaluator and OFREP propagation, tests, and monitoring documentation directly support issue #2020. No unrelated change is demonstrated in the provided pull request scope.

Full details: Docstring Coverage

Explanation

Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 10 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

Comment @coderabbitai help to get the list of available commands.

@erka erka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I have one question about the design. Can the context carry the flagSetID instead of adding a new parameter to all methods? This is just a thought.

@gargsajal9

Copy link
Copy Markdown
Contributor Author

@erka Yes, context could carry it. For bulk evaluation we would need to derive a child context for each result, because an unfiltered response can contain flags from different sets; single-evaluation and selector-error paths could similarly attach the ID immediately before recording.

I chose an explicit parameter because flagSetID is evaluation-result metadata rather than request-scoped state. Keeping it in the recorder signature makes the per-result attribution visible and type-checked, and avoids an implicit context key that every caller must populate correctly. The downside is the signature churn you noted, so I am happy to switch to the context approach if that is the preferred API tradeoff.

Comment thread core/pkg/telemetry/metrics.go Resolved
Comment thread core/pkg/telemetry/metrics.go Resolved

@toddbaert toddbaert left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question here.

I think this is a blocker though; there's a few ways around it, happy to approve once you decide on something.


Also, the CI failure is unrelated to your work I think, and has been fixed on main, so if you rebase/merge it should be resolved.

@gargsajal9
gargsajal9 requested a review from toddbaert October 16, 2026 21:56
gargsajal9 and others added 2 commits October 19, 2026 12:42
Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Sajal Garg <[email protected]>
Pass evaluation metadata through the recorder boundary and omit caller-derived flag set IDs for FLAG_NOT_FOUND results.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Sajal Garg <[email protected]>
@toddbaert
toddbaert force-pushed the gargsajal9-flag-set-telemetry branch from 6399e6b to 8ee77c3 Compare October 19, 2026 16:42
@sonarqubecloud

Copy link
Copy Markdown

@toddbaert
toddbaert merged commit 10f2ca0 into open-feature:main Oct 19, 2026
23 of 25 checks passed
toddbaert pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>flagd: 0.18.1</summary>

##
[0.18.1](flagd/v0.18.0...flagd/v0.18.1)
(2026-10-26)


### 🐛 Bug Fixes

* bound evaluation HTTP metric labels
([#2092](#2092))
([f2e7713](f2e7713))
* record OFREP and sync HTTP metrics once
([#2103](#2103))
([0a39a29](0a39a29))


### ✨ New Features

* add flag set ID to evaluation metrics
([#2078](#2078))
([10f2ca0](10f2ca0))
* strict numeric range opt, TYPE_MISMATCH on precision loss
([#2100](#2100))
([5cf6fff](5cf6fff))


### 🧹 Chore

* **deps:** update module golang.org/x/net to v0.61.0
([#2097](#2097))
([21db5c3](21db5c3))
* Update CHANGELOG with more details
([3f01794](3f01794))
</details>

<details><summary>flagd-proxy: 0.9.13</summary>

##
[0.9.13](flagd-proxy/v0.9.12...flagd-proxy/v0.9.13)
(2026-10-26)


### 🧹 Chore

* **deps:** update module golang.org/x/net to v0.61.0
([#2097](#2097))
([21db5c3](21db5c3))
</details>

<details><summary>core: 0.19.1</summary>

##
[0.19.1](core/v0.19.0...core/v0.19.1)
(2026-10-26)


### 🐛 Bug Fixes

* bound evaluation HTTP metric labels
([#2092](#2092))
([f2e7713](f2e7713))
* record OFREP and sync HTTP metrics once
([#2103](#2103))
([0a39a29](0a39a29))


### ✨ New Features

* add flag set ID to evaluation metrics
([#2078](#2078))
([10f2ca0](10f2ca0))
* strict numeric range opt, TYPE_MISMATCH on precision loss
([#2100](#2100))
([5cf6fff](5cf6fff))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Record flag set ID for OTEL metrics

3 participants