Skip to content

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

Merged
zhukaihan merged 1 commit into
mainfrom
feat/exposure-experiment-key
May 7, 2026
Merged

fix: include experiment key on local-eval exposure events#46
zhukaihan 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 toExposureEvents 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 a non-empty string, set 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 TestToExposureEvents. Asserts [Experiment] Experiment Key equals "exp-1" for that flag and is absent for the others.
  • Updated event count expectation accordingly.
  • go test ./pkg/experiment/local/ -run TestToExposureEvents -v — passes.

🤖 Generated with Claude Code


Note

Low Risk
Low risk: additive change that only sets an extra event property when variant.Metadata["experimentKey"] is present; existing event fields and filtering behavior are unchanged.

Overview
Local evaluation exposure tracking now lifts variant.Metadata["experimentKey"] into a top-level Amplitude event property ([Experiment] Experiment Key) in toExposureEvents, instead of leaving it only inside the metadata blob.

Tests were updated with a with_experiment_key fixture to assert the new property is set only when provided, and the expected event count was adjusted accordingly.

Reviewed by Cursor Bugbot for commit bcbd125. 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
`EventProperties["[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:13
@zhukaihan zhukaihan merged commit dc85e36 into main May 7, 2026
7 checks passed
github-actions Bot pushed a commit that referenced this pull request May 8, 2026
## [1.11.1](v1.11.0...v1.11.1) (2026-05-08)

### Bug Fixes

* include experiment key on local-eval exposure events ([#46](#46)) ([dc85e36](dc85e36)), 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.11.1 🎉

The release is available on GitHub release

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