Skip to content

feat: Add get_feature_flag_result, get_feature_flag_result! API#82

Merged
rafaeelaudibert merged 6 commits intomasterfrom
feat/get-feature-flag-result
Feb 12, 2026
Merged

feat: Add get_feature_flag_result, get_feature_flag_result! API#82
rafaeelaudibert merged 6 commits intomasterfrom
feat/get-feature-flag-result

Conversation

@dustinbyrne
Copy link
Contributor

Problem

When using PostHog feature flags, customers often need both the flag value and its payload. The current Elixir SDK has no way to retrieve payloads at all — check only returns the boolean/variant value. Other SDKs have separate getFeatureFlagPayload() methods that don't fire $feature_flag_called events, leading to missing analytics when customers skip calling getFeatureFlag() first.

Per PostHog/posthog#43520, all SDKs are normalizing around a single get_feature_flag_result method that returns the full flag evaluation (enabled, variant, and payload) and fires the $feature_flag_called event in one call.

Changes

  • Add PostHog.FeatureFlagResult struct with key, enabled, variant, payload fields and a value/1 helper that returns the variant (if present) or the enabled boolean
  • Add get_feature_flag_result which returns {:ok, %FeatureFlagResult{}}, {:ok, nil} (flag not found), or {:error, reason}
  • Add get_feature_flag_result!, a bang variant that returns the struct directly or raises
  • Support send_event: false option to suppress the $feature_flag_called event and context side-effects
  • Extract shared evaluate_flag helper used by both check and get_feature_flag_result to eliminate duplication
  • 550+ lines of new tests covering boolean flags, variant flags with payloads, disabled flags, missing flags, context handling, custom instances, event publishing, and the send_event option

@dustinbyrne dustinbyrne changed the title feat: Add ` feat: Add get_feature_flag_result, get_feature_flag_result! API Feb 11, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2026

posthog-elixir Compliance Report

Date: 2026-02-12 02:59:49 UTC
Duration: 105839ms

⚠️ Some Tests Failed

17/29 tests passed, 12 failed


Capture Tests

⚠️ 17/29 tests passed, 12 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 609ms
Format Validation.Event Has Uuid 609ms
Format Validation.Event Has Lib Properties 609ms
Format Validation.Distinct Id Is String 609ms
Format Validation.Token Is Present 608ms
Format Validation.Custom Properties Preserved 609ms
Format Validation.Event Has Timestamp 609ms
Retry Behavior.Retries On 503 5614ms
Retry Behavior.Does Not Retry On 400 2612ms
Retry Behavior.Does Not Retry On 401 2610ms
Retry Behavior.Respects Retry After Header 5614ms
Retry Behavior.Implements Backoff 15624ms
Retry Behavior.Retries On 500 5614ms
Retry Behavior.Retries On 502 5615ms
Retry Behavior.Retries On 504 5615ms
Retry Behavior.Max Retries Respected 15623ms
Deduplication.Generates Unique Uuids 618ms
Deduplication.Preserves Uuid On Retry 5614ms
Deduplication.Preserves Uuid And Timestamp On Retry 10619ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5616ms
Deduplication.No Duplicate Events In Batch 614ms
Deduplication.Different Events Have Different Uuids 611ms
Compression.Sends Gzip When Enabled 609ms
Batch Format.Uses Proper Batch Structure 609ms
Batch Format.Flush With No Events Sends Nothing 606ms
Batch Format.Multiple Events Batched Together 614ms
Error Handling.Does Not Retry On 403 2611ms
Error Handling.Does Not Retry On 413 2611ms
Error Handling.Retries On 408 5615ms

Failures

retry_behavior.retries_on_503

Expected at least 3 requests, got 1

retry_behavior.respects_retry_after_header

Expected at least 2 requests, got 1

retry_behavior.implements_backoff

Expected at least 3 requests, got 1

retry_behavior.retries_on_500

Expected at least 2 requests, got 1

retry_behavior.retries_on_502

Expected at least 2 requests, got 1

retry_behavior.retries_on_504

Expected at least 2 requests, got 1

retry_behavior.max_retries_respected

Expected 4 requests, got 1

deduplication.preserves_uuid_on_retry

Need at least 2 requests to check retry

deduplication.preserves_uuid_and_timestamp_on_retry

Expected at least 3 requests, got 1

deduplication.preserves_uuid_and_timestamp_on_batch_retry

Expected at least 2 requests, got 1

compression.sends_gzip_when_enabled

Header 'Content-Encoding' with value 'gzip' not found in requests

error_handling.retries_on_408

Expected at least 2 requests, got 1

Copy link
Member

@rafaeelaudibert rafaeelaudibert left a comment

Choose a reason for hiding this comment

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

Pushed a couple changes to make this slightly nicer + also added a changesets entry. Make sure you read the CONTRIBUTING section to know how we're handling this here in Elixir. My goal was to move all of the SDKs to this new sampo tooling. Would love if I could get buy-in from the new SDK team btw :)

@rafaeelaudibert rafaeelaudibert merged commit 473796e into master Feb 12, 2026
16 checks passed
@rafaeelaudibert rafaeelaudibert deleted the feat/get-feature-flag-result branch February 12, 2026 03:02
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