Skip to content

chore(flags): Decide v4 support - adds version, id, reason, and requestId to $feature_flag_called events #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

haacked
Copy link
Collaborator

@haacked haacked commented Apr 3, 2025

This is follow on work for PostHog/posthog#29693. The work here is similar to PostHog/posthog-python#207 and PostHog/posthog-go#91.

Updates to the $feature_flag_called event

When capturing the $feature_flag_called event, additional information are now captured:

The end result is $feature_flag_called events will have additional properties:

Property Name Descirption
$feature_flag_version The version of the feature flag. This is visible in the diffs of the feature flag activity log.
$feature_flag_reason The reason the feature flag matched or didn't match.
$feature_flag_id The database id of the feature flag (Just in case a flag was deleted and then recreated with the same key, we can determine the difference.

Backwards compatibility:

The changes are all backwards compatible with /decide?v=3.

Testing

Unit tests and some manual testing

@haacked haacked requested a review from Copilot April 3, 2025 23:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Files not reviewed (2)
  • tests/UnitTests/Fixtures/decide-api-result-v4.json: Language not supported
  • tests/UnitTests/UnitTests.csproj: Language not supported
Comments suppressed due to low confidence (1)

tests/UnitTests/Json/FilterSerializationTests.cs:53

  • Square bracket array literal is not valid C# syntax. Consider using curly braces and the 'new[] { ... }' syntax for array initialization.
Value = new PropertyFilterValue([

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds Decide v4 support by enhancing the payload for $feature_flag_called events with version, id, and reason fields while preserving backward compatibility with v3 responses.

  • Updated /src/PostHog/Api/PostHogApiClient.cs to use the /decide?v=4 endpoint.
  • Introduced the new record in /src/PostHog/Api/FeatureFlagResult.cs to encapsulate additional flag metadata.
  • Modified /src/PostHog/Api/DecideApiResult.cs and /src/PostHog/Api/FeatureFlagResultExtensions.cs to normalize both v3 and v4 responses.
  • Enhanced /src/PostHog/Features/FeatureFlag.cs to create a FeatureFlagWithMetadata when applicable.
  • Revised tests in /tests/UnitTests/ to ensure correct handling and mapping of the new metadata.

18 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

This adds support for `/decide/v4` API endpoint
in a back-compat manner.
@haacked haacked force-pushed the haacked/decide-v4 branch from 1da82ad to 6104641 Compare April 4, 2025 02:02
@haacked haacked merged commit 3f33d70 into main Apr 4, 2025
4 checks passed
@haacked haacked deleted the haacked/decide-v4 branch April 4, 2025 02:10
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.

1 participant