6 Commits
Author SHA1 Message Date
zeekay 42ac61f78d merge: upstream/main (preserve Hanzo brand, 55 commits) 2026-06-02 09:56:19 -07:00
Manoel Aranda NetoandGitHub 920035f38a docs: document public APIs and hide testing-only flag definitions method (#208)
* docs: add public API Go doc comments

* refactor: hide client feature flag definitions API
2026-05-27 17:48:42 +02:00
Dustin ByrneandGitHub 139d59d59a fix: dramatically reduce memory allocations in feature flag evaluation (#172)
Addresses high RAM usage and OOMs when using feature flags at scale.
Tested with 853 flags + 12 cohorts (production-like setup):

  Before: 17,463 allocs/op, 201 MB/op, 51 ms/op
  After:    139 allocs/op,  56 KB/op, 129 µs/op

Key changes:
- Cache flagsByKey in flagsState at load time (was O(N²) in GetAllFlags)
- sha1.Sum with stack buffer instead of sha1.New + hash.Write (zero heap escapes)
- Append '.' separator inside calculateHash buffer (avoid string concat alloc)
- Cache getSystemContext/getVersion with sync.Once
- Pre-compute at load time: variant lookup tables, decoded payloads, parsed cohort values
- Cache compiled regexps via sync.Map
- Eliminate double flag evaluation (single-pass GetFeatureFlagWithPayload)
- Lazy evaluationCache only for flags with dependencies
- Sentinel errors + direct type assertions replacing errors.As
- valueToString replacing fmt.Sprintf throughout matchProperty
- Defer empty map allocation in validate() to remote path only
- Pre-merge distinct_id once before GetAllFlags loop
- Embed payload/variant strings in FeatureFlagResult struct
- Skip Properties merge for flags without person property conditions
2026-03-26 09:55:28 +01:00
zeekay b4e1366340 rebrand: export Insights types instead of PostHog
Rename Go package from posthog to insights across all 80+ files.
Consumers now import as `insights "github.com/hanzoai/insights-go"`
and use insights.Client, insights.Config, insights.Capture, etc.

- Rename posthog.go -> insights.go, posthog_test.go -> insights_test.go
- Update package declaration from posthog to insights in all .go files
- Update SDKName from posthog-go to insights-go
- Update DefaultEndpoint from app.posthog.com to insights.hanzo.ai
- Update all FieldError/ConfigError type strings
- Update User-Agent headers, log prefixes, comments, and docs
- Update JSON test fixtures to match new SDK name
- Update CLI, examples, extras, and sdk_compliance_adapter
- Fix pre-existing go vet warnings (non-constant format strings)
2026-03-13 19:54:58 -07:00
AndersandGitHub 227dc9bb39 feat: Add device_id parameter to /flags requests (#157)
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
2026-02-04 14:30:37 +01:00
6d872f6582 Local Feature Flag Evaluation (#6)
* initial translation

* matching func

* consistency tests working

* working person test

* operator tests

* regex test

* handle groups

* getallflags func and more tests

* working tests

* working tests

* add onlyEvaluateLocally and sendFeatureFlagEvents

* consistency tests speedup

* more tets and stubs

* fix

* add map limit

* use struct payload

* fix payloads

* Update feature_flags_test.go

Co-authored-by: Neil Kakkar <[email protected]>

* test dict separately

* remove default result

* address comments

* condense

* reorg request functions

* make sure isfeatureenabled returns null

Co-authored-by: Neil Kakkar <[email protected]>
2022-08-16 20:03:21 -04:00