15 Commits
Author SHA1 Message Date
zeekayandHanzo Dev 8ee8950230 Go 1.27.1, and the code it can say more simply
The module declares go 1.27.1 and the adapter image follows. go fix
applied the modernizers and left ptrString and ptrBool with no callers,
so they are gone; omitzero is not applied, since it changes what the
JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 19:52:31 -07:00
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
Dylan MartinandGitHub a3293aaa2f feat: add EvaluateFlags() API for single-call flag evaluation (#191)
Adds a Phase 1 implementation of the Server SDK Feature Flag
Evaluations RFC, mirroring posthog-js#3476 and posthog-python#539.

Client.EvaluateFlags returns a FeatureFlagEvaluations snapshot built
from at most one /flags request. The snapshot powers IsEnabled,
GetFlag, and GetFlagPayload checks, fires deduped $feature_flag_called
events with full v4 metadata (id, version, reason, request_id), and can
be attached to a Capture event via the new Capture.Flags field to
populate $feature/<key> and $active_feature_flags with no extra
network call.

The dedup logic for $feature_flag_called is extracted into
captureFlagCalledIfNeeded so the existing single-flag path and the new
snapshot path share the same per-distinct_id LRU cache and behave
identically.

OnlyAccessed and Only return filtered child snapshots with independent
access tracking, so filtering for a Capture does not back-propagate to
the parent. A new Config.FeatureFlagsLogWarnings option silences their
warnings for callers that prefer quieter helpers.

Capture.SendFeatureFlags is unchanged and not deprecated; Phase 2 will
follow up with deprecations and migration guidance.

Task-Id: b9d98122-fe61-462a-bfb3-6e1be3a8966a
2026-05-01 13:03:26 -07: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
Matheus BatistaandGitHub 80414db3e8 fix(flags): avoid setting flags to false on transient errors (#162)
* fix cache overwrite on transient errors

* add flagfailed field for better distinction
2026-01-30 16:26:41 -03:00
Dustin ByrneandGitHub f93ef34367 fix: Flag payloads can contain JSON types (#161)
Previously we expected serialized JSON strings. However, the API can
also return any valid JSON type
2026-01-30 12:44:01 -05:00
Eli ReismanandGitHub 8a6e9ae51e feat: refactor internal event submission pipeline and test suites (#151)
* intitial refactor:

- Add Context-based graceful shutdown and drain phase for enqueued requests
- Use buffered channels vs. mutex for concurrency mgmt.
- Use atomic.Pointer vs. locks for FF mgmt
- Use Callback ifc vs. lossy internal tracking for unit test result validation
- Add new APIs mirroring current that accept caller's Context to control
  operation timeouts

* expose batch submission timeout with default equiv to old hardcoded timeout

* restructure event submission and batching pipeline

* overhaul tests; implement new stress tests and address coverage gaps

* parallelize tests where safe to do so (3x CI time savings!)

* introduce faster pure Go JSON seralization library

* more refactors: unit tests & benchmarks

* DRY up shutdown req drain and prepareForSend serializer

* use go-json in CLI utils too; remove redundant helpers

* move error type to proper pkg

* DRY up loop() and fix deadlock in old test case

* normalize CI and Makefile test and benchmark target behavviors

* more realistic feature flags benchmark

* replace leaky time.After pattern with idiomatic safer Timers

* internal queue size minimums decoupled from batch and worker configs

* remove dead comments

* fix test bug

* update default http.Transport cfg to avoid conn pool as bottleneck; update batch enqueue limiting strategy and tests/benches

* adjust stress test defaults to match prod

* update flaky tests and rm stale file

* make graceful shutdown timeout opt-in for now

* fix tests that reverted to hold helper utils during rebase

* fix flaky test due to overhead from -race detector now default in test flags

* add more graceful shutdown test cases
2026-01-13 12:22:44 -08:00
Dustin ByrneandGitHub 5ce035676b feat: Set $feature_flag_error on $feature_flag_called (#142)
* feat: Set `$feature_flag_error` on `$feature_flag_called`

* test: Add integration tests for captured events
2026-01-09 12:42:02 -05:00
Dylan MartinandGitHub afca5e54a3 feat(flags): included evaluated_at properties in $feature_flag_called events (#136)
* fix tests

* fix version

* fix actions
2025-12-02 10:24:14 -05:00
Paweł SzczurandGitHub b14d84ea0b chore: move URL parsing errors to init (#109)
* Move URL parsing errors to init, validate endpoint when creating client
* Proper logger
* fix issues with timeout test
* do not waste go routines (fix bug with infinite goroutines / http requests)
* minor fixes to errors
2025-06-10 23:00:20 +02:00
7b79baa601 feat: add DisableGeoIP option (#104)
Co-authored-by: jackhopner <[email protected]>
2025-05-23 11:06:01 +02:00
Dylan MartinandGitHub e54dcc0ba7 chore(flags): use new /flags endpoint instead of /decide (#96)
* use /flags instead of /decide

* update version

* renamed file
2025-04-30 20:43:36 -04:00