Skip to content

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

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#53
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.toAmplitudeEvent() 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 non-null, 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. Asserts [Experiment] Experiment Key equals "exp-1" for that flag and is absent for the others.
  • Updated event count and canonicalization expectation accordingly.
  • ./gradlew test --tests "com.amplitude.experiment.exposure.ExposureServiceTest" — passes.

🤖 Generated with Claude Code


Note

Low Risk
Low risk additive change: only adds an optional top-level event property derived from existing variant.metadata, with a small test update to cover it.

Overview
Local-eval exposure events now include a top-level [Experiment] Experiment Key in eventProperties when variant.metadata["experimentKey"] is present, instead of only embedding it inside the metadata blob.

Tests add a with-experiment-key fixture and assert the new field is set only for that flag, updating expected event count and insertId canonicalization accordingly.

Reviewed by Cursor Bugbot for commit 2314e1d. 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:14
@kyeh-amp kyeh-amp merged commit 8bd7645 into main May 8, 2026
8 of 12 checks passed
github-actions Bot pushed a commit that referenced this pull request May 8, 2026
## [1.8.3](1.8.2...1.8.3) (2026-05-08)

### Bug Fixes

* include experiment key on local-eval exposure events ([#53](#53)) ([8bd7645](8bd7645)), closes [amplitude/experiment-node-server#83](amplitude/experiment-node-server#83)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🎉 This PR is included in version 1.8.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants