Repository navigation
feat: Record exposures under local evaluation - #318
Conversation
Carry each feature state's experiment metadata from the environment document into the engine context, and set it and the variant 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.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Merging this PR will improve performance by 41.65%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
|
@codspeedbot fix this regression |
|
@themis-blindfold codespeed is under its benchmark, are you able to pinpoint the root cause of the performance loss ? |
|
I can't pinpoint the cause from the checkout: the CodSpeed results and profiles are not included, and the benchmark dependencies and fixtures are unavailable locally. The PR adds per-flag experiment conversion in |
Zaimwa9
left a comment
There was a problem hiding this comment.
We should skip the exposure without variant and try to see where the performance regression comes from
🤖 I have created a release *beep* *boop* --- ## [9.3.0](v9.2.0...v9.3.0) (2026-11-06) ### Features * Record exposures under local evaluation ([#318](#318)) ([467dc54](467dc54)) ### Other * **deps-dev:** bump undici from 6.28.0 to 6.29.1 ([#312](#312)) ([0cc92c2](0cc92c2)) * Let Renovate keep updating spec bumps the webhook handler commits to ([#319](#319)) ([ee89f5a](ee89f5a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.
Since Flagsmith/flagsmith#8532, the environment document carries
metadata.experimenton feature states. The SDK dropped it when building engine models, so under local evaluationflag.experimentwas always undefined andgetExperimentFlagnever recorded an exposure.Changes
FeatureStateModelkeepsmetadata.experiment; the mapper adds it to the engine context's feature metadata for environment and segment feature states. Identity overrides carry none, as on the API.Flags.fromEvaluationResultsetsexperiment, and alsovariant, which local evaluation dropped until now, so local exposures carry the variant key.Tests
getExperimentFlagunder 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 checked against a local Flagsmith with the events pipeline: local and remote evaluation give the same value, variant and experiment, and one exposure reached the warehouse.
Not included
Bumping
engine-test-datato v3.13.0, which adds the experiment cases: it also adds two numeric trait cases (Flagsmith/engine-test-data#63) the engine already fails, to be fixed separately.