mirror of
https://github.com/hanzoai/insights-go.git
synced 2026-09-30 22:46:12 +00:00
178217b14ae738b1e3933658b2e6e96bc3b73c76
Two of the eight workflows carry value that runs here; six were bound to
PostHog's own GitHub org and could never resolve on this forge.
Moved, with the two things that kept them from working:
fmt.yml, unit-tests.yml both pinned setup-go to 1.21 while go.mod declares
1.26.4, so the toolchain refused the module before any check ran. They read
go-version-file: go.mod now, and checkout moved ahead of setup-go so that
file exists when it is read. Their push filter also named only `main`, and
the default branch here is `master` -- pushes to the branch everything lands
on matched nothing. Both branches are listed.
Dropped, with what each cost:
release.yml PostHog's release pipeline end to end: a GitHub App
token, changeset-driven bumps of version.go,
planetscale/ghcommit-action, `gh release create`,
GitHub environment approvals read back through
`gh api .../approvals`, and Slack notifications
through posthog/.github reusables. None of those
surfaces exists here, so releases are cut by hand.
sdk-compliance.yml called PostHog/posthog-sdk-test-harness. Reusable
workflows resolve against this forge, where that repo
does not exist, so SDK compliance is untested in CI.
call-flags-project-board.yml, lint-pr.yml
PostHog/.github reusables driving a project board and
conventional-commit title checks off pull_request
metadata -- GitHub API surfaces with no local address.
codeql.yml uploaded SARIF to GitHub code scanning; no such
service here.
stale.yaml aged out issues and pull requests. It was the only
thing that had been going green on master, which is
the point: the repo now runs a build and a test
instead of an issue sweep.
Note for whoever picks this up: branch `main` is three commits ahead of master
and carries its own hanzo.yml plus .hanzo/workflows/cicd.yml. That lineage is
untouched here and still needs a merge decision.
Co-authored-by: Hanzo Dev <[email protected]>
Hanzo Insights Go SDK
Go client SDK for Hanzo Insights (product analytics).
Install
go get github.com/hanzoai/insights-go
Quick Start
package main
import (
"os"
insights "github.com/hanzoai/insights-go"
)
func main() {
client, _ := insights.NewWithConfig(
os.Getenv("INSIGHTS_API_KEY"),
insights.Config{
Endpoint: "https://insights.hanzo.ai",
},
)
defer client.Close()
// Capture an event
client.Enqueue(insights.Capture{
DistinctId: "user-123",
Event: "purchase",
Properties: insights.NewProperties().
Set("plan", "enterprise").
Set("amount", 99),
})
}
Common Operations
Capture Events
client.Enqueue(insights.Capture{
DistinctId: "user-123",
Event: "page_view",
Properties: insights.NewProperties().
Set("$current_url", "https://example.com/pricing"),
})
Identify Users
client.Enqueue(insights.Identify{
DistinctId: "user-123",
Properties: insights.NewProperties().
Set("email", "[email protected]").
Set("name", "Alice").
Set("plan", "pro"),
})
Feature Flags
// Check if a flag is enabled
enabled, err := client.IsFeatureEnabled(
insights.FeatureFlagPayload{
Key: "new-dashboard",
DistinctId: "user-123",
},
)
if enabled == true {
// Show new dashboard
}
// Get flag variant
variant, err := client.GetFeatureFlag(
insights.FeatureFlagPayload{
Key: "checkout-flow",
DistinctId: "user-123",
},
)
Group Analytics
// Associate a user with a group
client.Enqueue(insights.GroupIdentify{
Type: "company",
Key: "hanzo-ai",
Properties: insights.NewProperties().
Set("name", "Hanzo AI").
Set("industry", "technology"),
})
// Capture event with group context
client.Enqueue(insights.Capture{
DistinctId: "user-123",
Event: "deploy",
Groups: insights.NewGroups().
Set("company", "hanzo-ai"),
})
Alias Users
client.Enqueue(insights.Alias{
DistinctId: "user-123",
Alias: "user-456",
})
Configuration
client, _ := insights.NewWithConfig(
os.Getenv("INSIGHTS_API_KEY"),
insights.Config{
Endpoint: "https://insights.hanzo.ai",
PersonalApiKey: os.Getenv("INSIGHTS_PERSONAL_KEY"), // For local feature flag evaluation
BatchSize: 100,
Interval: 5 * time.Second,
MaxRetries: insights.Ptr(3),
RetryAfter: func(attempt int) time.Duration {
return time.Duration(100<<attempt) * time.Millisecond
},
},
)
Event Delivery
The SDK includes automatic retry logic with configurable backoff. Events are retried on transient network failures (EOF, connection reset, temporary unavailability). Events are dropped after max retries are exhausted (default: 10 attempts), on non-retryable errors (4xx responses), or if the client is closed during retry.
Monitor delivery with a callback:
type DeliveryLogger struct{}
func (d *DeliveryLogger) Success(msg insights.APIMessage) {
log.Printf("delivered: %v", msg)
}
func (d *DeliveryLogger) Failure(msg insights.APIMessage, err error) {
log.Printf("dropped: %v err=%v", msg, err)
}
client, _ := insights.NewWithConfig(apiKey, insights.Config{
Callback: &DeliveryLogger{},
})
Development
make dependencies # Install deps
make build # Run tests and build
make test # Run tests only
Attribution
License
MIT License. Copyright (c) Hanzo AI Inc.
Languages
Go
99.7%
Shell
0.1%