feat: Add device_id parameter to /flags requests#157
Merged
Conversation
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>
rodrigoi
reviewed
Jan 20, 2026
rodrigoi
reviewed
Jan 20, 2026
rodrigoi
approved these changes
Jan 20, 2026
dmarticus
approved these changes
Jan 20, 2026
Contributor
Author
|
@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! |
dmarticus
approved these changes
Jan 27, 2026
Contributor
dmarticus
left a comment
There was a problem hiding this comment.
looks good! No notes from my end
Contributor
posthog-go Compliance ReportDate: 2026-02-04 11:59:52 UTC
|
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
Testing
Tested the go SDK locally:
device_idto/flagswhen being passed. It's also being set as a property on the$feature_flag_calledevents when passed$feature_flag_calledevents are being sent as before the first time it is evaluated. Subsequent evaluation doesn't trigger a new event.