Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/feature-enrollment-aspnetcore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"PostHog.AspNetCore": minor
---

Picks up the `PostHog` support for early access feature enrollment in local evaluation. With local evaluation, the PostHog feature manager now resolves a flag with `feature_enrollment` from the person property `$feature_enrollment/<flag key>` before the holdout and release conditions, as the flags service does.
5 changes: 5 additions & 0 deletions .changeset/feature-enrollment-local-evaluation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"PostHog": minor
---

Local feature flag evaluation now supports early access feature enrollment (`feature_enrollment`). Before the holdout and release conditions, the SDK reads the person property `$feature_enrollment/<flag key>`: `true` or `"true"` resolves the flag to `true`, and any other passed value, `null` included, resolves it to `false`. Group flags read the person property too. Without the property, the flag falls back to `/flags` (`missing_context` when `OnlyEvaluateLocally` is true). When the key is listed in `PersonPropertyKeysKnownAbsent`, evaluation continues through the holdout and release conditions.
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Select every package that needs a release:
- ASP.NET Core integration change: select `PostHog.AspNetCore`
- AI Observability change: select `PostHog.AI`

Changesets does not infer dependent-package releases from the `.csproj` project references. Select a dependent package when its next release must require the new `PostHog` version. For example, select both `PostHog` and `PostHog.AspNetCore` when users must receive a core fix by updating `PostHog.AspNetCore`. Apply the same rule to `PostHog.AI`. Do not select all dependent packages for every core change. The packages release independently by design.
Changesets does not infer dependent-package releases from the `.csproj` project references. Select a dependent package when its next release must require the new `PostHog` version. For example, select both `PostHog` and `PostHog.AspNetCore` when users must receive a core fix by updating `PostHog.AspNetCore`. Apply the same rule to `PostHog.AI`. When a `PostHog` change affects the behavior users get through a dependent package, also add a changeset for that package. For example, a local feature flag evaluation change in `PostHog` also changes the `PostHog.AspNetCore` feature manager, so it needs a `PostHog.AspNetCore` changeset as well. Do not select all dependent packages for every core change. The packages release independently by design.

Then choose the bump type:

Expand Down
24 changes: 23 additions & 1 deletion src/PostHog/Api/LocalEvaluationApiResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ internal record FeatureFlagFilters
[JsonPropertyName("early_exit")]
public bool? EarlyExit { get; init; } = false;

/// <summary>
/// The raw <c>feature_enrollment</c> marker of an early access feature. Kept as raw JSON so an unexpected value
/// does not fail the definitions. See <see cref="HasFeatureEnrollment"/>.
/// </summary>
[JsonPropertyName("feature_enrollment")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public JsonElement? FeatureEnrollment { get; init; }

/// <summary>
/// <c>true</c> only when <c>feature_enrollment</c> is the JSON boolean <c>true</c>.
/// </summary>
[JsonIgnore]
public bool HasFeatureEnrollment => FeatureEnrollment is { ValueKind: JsonValueKind.True };
Comment thread
marandaneto marked this conversation as resolved.
Resolved

/// <summary>
/// The flag's holdout, like <c>{"id": 42, "exclusion_percentage": 10}</c>. Kept as raw JSON so a malformed
/// holdout counts as no holdout instead of failing the definitions. See <see cref="HoldoutId"/> and
Expand Down Expand Up @@ -277,14 +291,22 @@ public virtual bool Equals(FeatureFlagFilters? other)
&& Multivariate == other.Multivariate
&& AggregationGroupTypeIndex == other.AggregationGroupTypeIndex
&& EarlyExit == other.EarlyExit
&& HasFeatureEnrollment == other.HasFeatureEnrollment
&& BucketingIdentifier == other.BucketingIdentifier;
}

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode() => HashCode.Combine(Groups, Payloads, Multivariate, AggregationGroupTypeIndex, EarlyExit, BucketingIdentifier);
public override int GetHashCode() => HashCode.Combine(
Groups,
Payloads,
Multivariate,
AggregationGroupTypeIndex,
EarlyExit,
HasFeatureEnrollment,
BucketingIdentifier);
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/PostHog/Features/FeatureFlagOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class AllFeatureFlagsOptions
/// <c>not_ends_with</c>, <c>not_regex</c>) match, and every other operator does not, so the flag resolves
/// locally without a <c>/flags</c> request. A key that is neither supplied nor listed still needs the
/// <c>/flags</c> fallback. Keys that start with <c>__posthog_person_metadata__</c> are ignored locally.
/// Listing <c>$feature_enrollment/&lt;flag key&gt;</c> treats the person as not enrolled in that flag's early
/// access feature, so local evaluation continues through its holdout and release conditions.
/// </para>
/// <para>
/// When the SDK calls <c>/flags</c>, it sends the listed keys as <c>person_property_keys_known_absent</c>. Calls
Expand Down
Loading