Skip to content

feat(flags): add $feature_flag_has_experiment to $feature_flag_called events#261

Merged
haacked merged 2 commits into
mainfrom
haacked/feature-flag-has-experiment
Jul 15, 2026
Merged

feat(flags): add $feature_flag_has_experiment to $feature_flag_called events#261
haacked merged 2 commits into
mainfrom
haacked/feature-flag-has-experiment

Conversation

@haacked

@haacked haacked commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Part of a cross-SDK effort to shrink $feature_flag_called events. This first phase adds a $feature_flag_has_experiment boolean property to every $feature_flag_called event, reflecting the server's has_experiment signal: metadata.has_experiment in the /flags?v=2 response and has_experiment on /api/feature_flag/local_evaluation flag definitions. When the server does not report the field (older deployments, bootstrapped flags), the property is omitted, so it is tri-state: true, false, or absent (unknown).

This lets ingestion distinguish experiment-linked flag events (which need the full property set for exposure analysis) from the rest, and lets us measure the split before a later phase strips the expensive properties ($feature/<key>, $feature_flag_payload, per-event system metadata) from non-experiment flag events. This PR intentionally minimizes nothing: no properties are removed, no config options are added, and dedupe behavior is unchanged.

Changes

  • FeatureFlagMetadata.HasExperiment (has_experiment) on the /flags DTO and the same property on LocalFeatureFlag for /local_evaluation; both factories thread it onto the shared FeatureFlag record (included in record equality).
  • Both send paths funnel through BuildFeatureFlagCalledProperties, which now always sets $feature_flag_has_experiment; synthetic missing/error flags report false. Legacy v3 responses and missing metadata safely default to false.
  • PublicAPI.Unshipped.txt updated (RS0016); minor changeset.

💚 How did you test it?

dotnet build PostHog.sln: 0 errors, 0 warnings. dotnet test: 1,012 passed (UnitTests 944 + AspNetCore 49 + PostHog.AI 19), 0 failures. Two new theories cover true / false / absent from flags metadata and local evaluation, and 20 exact-JSON expectations were updated. bin/fmt clean.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-07-15 23:25:47 UTC
Duration: 4486ms

✅ All Tests Passed!

17/17 tests passed


Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 250ms
Request Payload.Flags Request Uses V2 Query Param 125ms
Request Payload.Flags Request Hits Flags Path Not Decide 113ms
Request Payload.Flags Request Omits Authorization Header 110ms
Request Payload.Token In Flags Body Matches Init 109ms
Request Payload.Groups Round Trip 113ms
Request Payload.Groups Default To Empty Object 112ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 111ms
Request Payload.Disable Geoip Omitted Defaults To False 111ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 109ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 115ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 215ms
Request Lifecycle.Mock Response Value Is Returned To Caller 115ms
Retry Behavior.Retries Flags On 502 1116ms
Retry Behavior.Retries Flags On 504 1113ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 213ms

@haacked haacked changed the title Add $feature_flag_has_experiment to $feature_flag_called events feat(flags): add $feature_flag_has_experiment to $feature_flag_called events Jul 15, 2026
@haacked
haacked marked this pull request as ready for review July 15, 2026 18:29
@haacked
haacked requested a review from a team as a code owner July 15, 2026 18:29
@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Add $feature_flag_has_experiment to $fea..." | Re-trigger Greptile

@turnipdabeets turnipdabeets left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Both send paths covered (flags metadata + local evaluation), null-safe defaults to false on older deployments, and the test matrix covers true/false/absent for both sources.

@haacked
haacked merged commit a329a13 into main Jul 15, 2026
21 checks passed
@haacked
haacked deleted the haacked/feature-flag-has-experiment branch July 15, 2026 23:38
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