Skip to content

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

Merged
kyeh-amp merged 1 commit into
mainfrom
fix/local-eval-exposure-experiment-key
May 7, 2026
Merged

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

Conversation

@kyeh-amp
Copy link
Copy Markdown
Collaborator

@kyeh-amp kyeh-amp commented May 7, 2026

Summary

  • Local evaluation via evaluateV2 was emitting exposure events that included the variant metadata blob (containing metadata.experimentKey) but never lifted the experiment key onto a top-level event property. Custom reports that key off [Experiment] Experiment Key therefore saw no value for customers on local evaluation.
  • Fix: in toExposureEvents, when variant.metadata?.experimentKey is truthy, set event_properties['[Experiment] Experiment Key']. Additive and backwards-compatible — the existing metadata blob, [Experiment] Flag Key, [Experiment] Variant, user properties, and insert_id are unchanged.
  • Mirrors the equivalent behavior in the browser SDK (experiment-js-client/.../experimentClient.ts sets exposure.experiment_key = sourceVariant.variant?.expKey). Property name uses the bracketed-namespace convention already established in this file ([Experiment] Flag Key, [Experiment] Variant) rather than the browser SDK's snake_case, since the browser SDK emits via a typed Exposure object that gets translated downstream, whereas this file emits Amplitude events directly.

Test plan

  • Added with_experiment_key fixture to the existing toExposureEvents test in packages/node/test/local/exposure/exposure-service.test.ts. Asserts the new property equals 'exp-1' for that flag and is undefined for all other flags in the same exposure.
  • Updated the canonicalization expectation in the same test to account for the new fixture entry (with_experiment_key treatment appended in alphabetical order).
  • yarn workspace @amplitude/experiment-node-server test — 208 passed, 1 todo, 0 failures.
  • yarn workspace @amplitude/experiment-node-server lint — 0 errors (19 pre-existing warnings, none from this change).
  • yarn workspace @amplitude/experiment-node-server build — clean.

Note

Low Risk
Low risk additive change that only adds an extra event property when variant.metadata.experimentKey is present; main risk is minor downstream analytics/reporting impact from a new field.

Overview
Local-eval exposure events now lift variant.metadata.experimentKey into a top-level event property (event_properties['[Experiment] Experiment Key']) when present, aligning exposure reporting with other SDKs.

Tests extend the toExposureEvents fixture to include a flag with an experimentKey, assert the new property is set only for that flag, and update expected event count and insert_id canonicalization accordingly.

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

Local evaluation via evaluateV2 was emitting exposure events without a
top-level experiment key field, only embedding it inside the nested
metadata blob. Custom reports keying off "[Experiment] Experiment Key"
consequently saw no value for customers using local evaluation.

Lift metadata.experimentKey onto event_properties['[Experiment] Experiment Key']
when present, matching the convention used by the browser SDK (which sets
exposure.experiment_key from variant.expKey). Additive, backwards-compatible:
the metadata blob is unchanged.
@kyeh-amp kyeh-amp requested a review from a team May 7, 2026 20:59
@kyeh-amp kyeh-amp merged commit 0aee5e9 into main May 7, 2026
13 of 14 checks passed
@kyeh-amp kyeh-amp deleted the fix/local-eval-exposure-experiment-key branch May 7, 2026 22:50
zhukaihan added a commit to amplitude/experiment-go-server that referenced this pull request May 7, 2026
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>
github-actions Bot pushed a commit to amplitude/experiment-go-server 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)
kyeh-amp pushed a commit to amplitude/experiment-python-server that referenced this pull request May 8, 2026
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 pushed a commit to amplitude/experiment-jvm-server that referenced this pull request May 8, 2026
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 pushed a commit to amplitude/experiment-ruby-server that referenced this pull request May 8, 2026
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>
github-actions Bot pushed a commit to amplitude/experiment-ruby-server that referenced this pull request May 8, 2026
## [1.10.1](v1.10.0...v1.10.1) (2026-05-08)

### Bug Fixes

* include experiment key on local-eval exposure events ([#93](#93)) ([f821d35](f821d35)), closes [amplitude/experiment-node-server#83](amplitude/experiment-node-server#83)
github-actions Bot pushed a commit to amplitude/experiment-jvm-server 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)
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