Skip to content

fix: include experiment key on local-eval exposure events#75

Merged
kyeh-amp merged 1 commit into
mainfrom
feat/exposure-experiment-key
May 8, 2026
Merged

fix: include experiment key on local-eval exposure events#75
kyeh-amp merged 1 commit into
mainfrom
feat/exposure-experiment-key

Conversation

@zhukaihan
Copy link
Copy Markdown
Collaborator

@zhukaihan zhukaihan commented May 7, 2026

Summary

  • Local evaluation exposure events from to_exposure_events carried experimentKey only inside the metadata blob — the top-level event property [Experiment] Experiment Key was never set, so custom reports keying off it saw no value for local-eval customers.
  • Fix: when variant.metadata['experimentKey'] is present, set event_properties['[Experiment] Experiment Key']. Additive and backwards-compatible — metadata, [Experiment] Flag Key, [Experiment] Variant, user properties, and insert_id are unchanged.
  • Mirrors amplitude/experiment-node-server#83.

Test plan

  • Added with_experiment_key fixture to ExposureServiceTestCase.test_to_exposure_events. Asserts [Experiment] Experiment Key equals 'exp-1' for that flag and is absent for the others.
  • Updated event count expectation accordingly.
  • python -m unittest tests.local.exposure.exposure_service_test — 2 tests pass.

🤖 Generated with Claude Code


Note

Low Risk
Low risk additive change to analytics event payloads: it only copies metadata.experimentKey into a new top-level event property and updates unit coverage.

Overview
Local-eval exposure events generated by to_exposure_events now lift variant.metadata['experimentKey'] into a top-level event property, setting [Experiment] Experiment Key when present (while still keeping the full metadata blob).

Tests extend ExposureServiceTestCase.test_to_exposure_events with a with_experiment_key fixture, update the expected event count, and assert the new property is present only for that flag and absent otherwise.

Reviewed by Cursor Bugbot for commit 4bc87f3. Bugbot is set up for automated code reviews on this repo. Configure here.

Local evaluation exposure events emit `metadata.experimentKey` inside the
metadata blob but never lift it onto a top-level event property. Custom
reports keying off `[Experiment] Experiment Key` therefore see no value
for customers using local evaluation.

When `variant.metadata['experimentKey']` is present, set
`event_properties['[Experiment] Experiment Key']`. Mirrors the equivalent
fix in the Node SDK (amplitude/experiment-node-server#83).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@zhukaihan zhukaihan requested a review from a team as a code owner May 7, 2026 22:59
@kyeh-amp kyeh-amp merged commit 6794cdf into main May 8, 2026
8 checks passed
@kyeh-amp kyeh-amp deleted the feat/exposure-experiment-key branch May 8, 2026 04:20
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