Skip to content

feat: Record exposures under local evaluation - #246

Merged
gagantrivedi merged 10 commits into
mainfrom
feat/local-evaluation-experiment-exposure
Nov 6, 2026
Merged

gagantrivedi merged 10 commits into
mainfrom
feat/local-evaluation-experiment-exposure

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Since Flagsmith/flagsmith#8532, the environment document carries metadata.experiment on feature states. The SDK dropped it when mapping the document for the engine, so under local evaluation Flag.Experiment was always nil and GetExperimentFlag never recorded an exposure.

Changes

  • FeatureStateModel reads metadata.experiment; the engine's FeatureMetadata gains Experiment.
  • The mapper copies it for environment and segment feature states. Identity overrides carry none, as on the API.
  • Flags built from evaluation results set Experiment.
  • Locally evaluated environment flags carry no experiment, matching the API, which only sends it for identity flags.
  • Bump engine-test-data to v3.13.0 for its experiment cases (feat: Add experiment metadata test cases engine-test-data#64).
  • README and doc comments no longer say exposures need remote evaluation.

Tests

GetExperimentFlag under local evaluation: an enrolled identity records one exposure with its variant and experiment ID; an identity outside the rollout, one with an identity override, and a feature with no experiment record none. Environment flags carry no experiment.

Also ran Flagsmith/sdk-spec#21 against this branch: 12 passed.

Carry each feature state's experiment metadata from the environment
document into the engine context, and set it on flags built from
evaluation results, so GetExperimentFlag records exposures under local
evaluation as it does under remote evaluation.

Environment flags carry no experiment, matching the API, which only
sends experiment metadata for identity flags. Bump engine-test-data to
v3.13.0 for its experiment cases.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The flag engine now decodes experiment metadata and maps it into evaluation results. Identity-evaluated flags copy the experiment ID, name, and enrollment status. Environment-level flags clear experiment metadata. The client skips exposure recording when a flag has no variant. Tests cover local treatment enrollment, non-enrollment, identity overrides, features without experiments, environment-level evaluation, and exposure event submission.

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

Merge Risk: Minimal · up to 2ddc2

No merge-blocking issue is identified; normal checks should run before merge.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d2d98b93-40a7-49d4-99ce-8ededd671905
Commits

Reviewing files that changed from the base of the PR and between 790c20d and 2ddc2eb.

Files selected for processing: 3

  • client.go
  • client_test.go
  • models.go

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

@gagantrivedi
gagantrivedi marked this pull request as ready for review November 5, 2026 08:58
@gagantrivedi
gagantrivedi requested a review from a team as a code owner November 5, 2026 08:58
@gagantrivedi
gagantrivedi requested review from Zaimwa9 and emyller and removed request for a team and emyller November 5, 2026 08:58
Zaimwa9
Zaimwa9 previously approved these changes Nov 5, 2026

@Zaimwa9 Zaimwa9 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Comment thread flagengine/engine_eval/context.go Resolved
@codspeed

codspeed Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks


Comparing feat/local-evaluation-experiment-exposure (2ddc2eb) with main (b8b7e88)

Open in CodSpeed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8328f800-680e-4d71-9815-6dfbdb738897
Commits

Reviewing files that changed from the base of the PR and between f31460b and 790c20d.

Files selected for processing: 7

  • client.go
  • client_test.go
  • fixtures/fixture.go
  • flagengine/engine_eval/context.go
  • flagengine/engine_eval/mappers.go
  • models_test.go
  • sdk-spec/steps.go

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

Comment thread client_test.go Resolved
@gagantrivedi
gagantrivedi requested a review from Zaimwa9 November 6, 2026 05:58
@gagantrivedi
gagantrivedi merged commit 4ef3277 into main Nov 6, 2026
7 checks passed
gagantrivedi pushed a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[5.5.0](v5.4.0...v5.5.0)
(2026-11-06)


### Features

* Record exposures under local evaluation
([#246](#246))
([4ef3277](4ef3277))


### Other

* Let Renovate keep updating spec bumps the webhook handler commits to
([#249](#249))
([b8b7e88](b8b7e88))

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

Co-authored-by: flagsmith-engineering[bot] <216534828+flagsmith-engineering[bot]@users.noreply.github.com>
gagantrivedi added a commit to Flagsmith/flagsmith-java-client that referenced this pull request Nov 6, 2026
Part of Flagsmith/flagsmith-private#325. Java counterpart of
Flagsmith/flagsmith-python-client#276, Flagsmith/flagsmith-go-client#246
and Flagsmith/flagsmith-nodejs-client#318.

`getExperimentFlag` only recorded exposures under remote evaluation. The
environment document carries `metadata.experiment` on feature states,
but local evaluation dropped it, along with the variant.

## Changes

- Map the multivariate option `key` into the evaluation context, and
carry `variant` from the evaluation result onto `Flag`. Locally
evaluated identity flags now report their variant.
- Map the feature state's `metadata.experiment` into the context's
feature metadata, and carry it onto identity flags.
- Environment flags carry no experiment: it is removed once, when the
environment evaluation context is built, so `getEnvironmentFlags` does
no extra work per call.
- `getExperimentFlag` records no exposure when the flag has no variant,
as the other SDKs do.

## Tests

- Local evaluation: an enrolled identity records one exposure with the
variant and `experiment_id`; outside the rollout, an identity override,
and a feature without an experiment record none.
- Environment flags carry no experiment under local evaluation.
- Remote: an enrolled flag without a variant records no exposure.
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.

2 participants