Skip to content

feat: Add device_id parameter to /flags requests#157

Merged
andehen merged 8 commits intomasterfrom
send-device-id
Feb 4, 2026
Merged

feat: Add device_id parameter to /flags requests#157
andehen merged 8 commits intomasterfrom
send-device-id

Conversation

@andehen
Copy link
Contributor

@andehen andehen commented Jan 20, 2026

Problem

Need consistent feature-flag evaluation and reporting when flags use device-based bucketing; local evaluation and event metadata were missing device_id support.

Changes

  • Add device_id to flags requests and SendFeatureFlagsOptions.
  • Use device_id for local evaluation bucketing when configured.
  • Include device_id in events and the feature-flag dedupe key.
  • Refactor remote flags request tests.
  • User-facing: no code changes required unless you want device_id bucketing; to opt in, pass device_id in feature-flag evaluation (payload/options) so server + local evaluation can bucket by device_id.

Testing

  • Existing and updated unit tests for flags/local evaluation.
  • Remote flags request tests refactored.

Tested the go SDK locally:

  • verified that getFeatureFlag sends device_id to /flags when being passed. It's also being set as a property on the $feature_flag_called events when passed
  • local evaluation works, and returns the same result. $feature_flag_called events are being sent as before the first time it is evaluated. Subsequent evaluation doesn't trigger a new event.

Add support for passing device_id to the PostHog /flags endpoint.
This allows clients to identify devices separately from users when
evaluating feature flags.

- Add DeviceId field to FlagsRequestData (omitted when nil)
- Add DeviceId to FeatureFlagPayload and FeatureFlagPayloadNoKey
- Thread device_id through all flag evaluation paths
- Add tests verifying device_id is passed in request payload

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@andehen andehen added release Add this label to trigger a release from a PR bump-minor Trigger a minor bump when merging this PR labels Jan 20, 2026
@andehen andehen requested a review from a team January 20, 2026 19:30
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Jan 20, 2026
@andehen andehen requested a review from a team January 20, 2026 19:32
Copy link

@rodrigoi rodrigoi left a comment

Choose a reason for hiding this comment

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

Image
dusting off my C, with is as close as Go as I can ... go.

Approving to unblock. The only things I've found are those little things on the tests and the getFeatureVariantsWithOptions situation. Otherwise, looks consistent and well tested.

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Jan 20, 2026
@andehen
Copy link
Contributor Author

andehen commented Jan 22, 2026

@dmarticus @rodrigoi I first planned to skip support for local evaluation, but realized it's better to just support it from the beginning (it's not that much code, really).

Great if you can take another look!

@andehen andehen requested review from dmarticus and rodrigoi January 22, 2026 09:30
@posthog-project-board-bot posthog-project-board-bot bot moved this from Approved to In Review in Feature Flags Jan 22, 2026
Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

looks good! No notes from my end

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Jan 27, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

posthog-go Compliance Report

Date: 2026-02-04 11:59:52 UTC
Duration: 105783ms

⚠️ Some Tests Failed

22/29 tests passed, 7 failed


Capture Tests

⚠️ 22/29 tests passed, 7 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 607ms
Format Validation.Event Has Uuid 607ms
Format Validation.Event Has Lib Properties 607ms
Format Validation.Distinct Id Is String 608ms
Format Validation.Token Is Present 607ms
Format Validation.Custom Properties Preserved 607ms
Format Validation.Event Has Timestamp 607ms
Retry Behavior.Retries On 503 5608ms
Retry Behavior.Does Not Retry On 400 2609ms
Retry Behavior.Does Not Retry On 401 2610ms
Retry Behavior.Respects Retry After Header 5613ms
Retry Behavior.Implements Backoff 15623ms
Retry Behavior.Retries On 500 5612ms
Retry Behavior.Retries On 502 5613ms
Retry Behavior.Retries On 504 5613ms
Retry Behavior.Max Retries Respected 15622ms
Deduplication.Generates Unique Uuids 616ms
Deduplication.Preserves Uuid On Retry 5611ms
Deduplication.Preserves Uuid And Timestamp On Retry 10618ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5614ms
Deduplication.No Duplicate Events In Batch 610ms
Deduplication.Different Events Have Different Uuids 609ms
Compression.Sends Gzip When Enabled 607ms
Batch Format.Uses Proper Batch Structure 607ms
Batch Format.Flush With No Events Sends Nothing 605ms
Batch Format.Multiple Events Batched Together 609ms
Error Handling.Does Not Retry On 403 2609ms
Error Handling.Does Not Retry On 413 2609ms
Error Handling.Retries On 408 5610ms

Failures

retry_behavior.does_not_retry_on_400

Expected 1 requests, got 2

retry_behavior.does_not_retry_on_401

Expected 1 requests, got 2

retry_behavior.respects_retry_after_header

Retry delay too short: 102ms < 2500ms

retry_behavior.max_retries_respected

Expected 4 requests, got 6

compression.sends_gzip_when_enabled

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

error_handling.does_not_retry_on_403

Expected 1 requests, got 2

error_handling.does_not_retry_on_413

Expected 1 requests, got 2

@andehen andehen merged commit 3fc9731 into master Feb 4, 2026
11 checks passed
@andehen andehen deleted the send-device-id branch February 4, 2026 13:30
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bump-minor Trigger a minor bump when merging this PR release Add this label to trigger a release from a PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants