Skip to content

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

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#67
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 Exposure::toEvents() 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 truthy, set event->eventProperties['[Experiment] Experiment Key']. Additive and backwards-compatible — metadata, [Experiment] Flag Key, [Experiment] Variant, user properties, and insertId are unchanged.
  • Mirrors amplitude/experiment-node-server#83.

Test plan

  • Added with_experiment_key fixture to ExposureServiceTest::testToEventsCreatesOneEventPerFlag. Asserts [Experiment] Experiment Key equals 'exp-1' for that flag and is absent for the others.
  • Updated event count expectation accordingly.
  • vendor/bin/phpunit tests/Exposure/ExposureServiceTest.php — 2 tests, 70 assertions, all pass.

🤖 Generated with Claude Code


Note

Low Risk
Low risk: additive event-property change gated on existing metadata['experimentKey'], with a focused unit test update.

Overview
Local-eval Exposure::toEvents() now copies variant->metadata['experimentKey'] onto a top-level event property, "[Experiment] Experiment Key", when present (while still including the full metadata blob).

Tests extend ExposureServiceTest::testToEventsCreatesOneEventPerFlag with a new with_experiment_key fixture, update the expected event count, and assert the property is set only for that flag and absent otherwise.

Reviewed by Cursor Bugbot for commit 79da2e9. 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>
@kyeh-amp kyeh-amp self-requested a review May 7, 2026 23:24
@kyeh-amp kyeh-amp merged commit 3a39ea2 into main May 8, 2026
21 checks passed
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