mirror of
https://github.com/hanzoai/insights-go.git
synced 2026-09-30 22:46:12 +00:00
* 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
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package posthog
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
var _ Message = (*Identify)(nil)
|
|
|
|
// This type represents object sent in an identify call
|
|
type Identify struct {
|
|
// This field is exported for serialization purposes and shouldn't be set by
|
|
// the application, its value is always overwritten by the library.
|
|
Type string
|
|
|
|
DistinctId string
|
|
Timestamp time.Time
|
|
Properties Properties
|
|
DisableGeoIP bool
|
|
}
|
|
|
|
func (msg Identify) internal() {
|
|
panic(unimplementedError)
|
|
}
|
|
|
|
func (msg Identify) Validate() error {
|
|
if len(msg.DistinctId) == 0 {
|
|
return FieldError{
|
|
Type: "posthog.Identify",
|
|
Name: "DistinctId",
|
|
Value: msg.DistinctId,
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type IdentifyInApi struct {
|
|
Type string `json:"type"`
|
|
Library string `json:"library"`
|
|
LibraryVersion string `json:"library_version"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
|
|
Event string `json:"event"`
|
|
DistinctId string `json:"distinct_id"`
|
|
Properties Properties `json:"properties"`
|
|
Set Properties `json:"$set"`
|
|
}
|
|
|
|
func (msg Identify) APIfy() APIMessage {
|
|
myProperties := Properties{}.Set("$lib", SDKName).Set("$lib_version", getVersion())
|
|
if msg.DisableGeoIP {
|
|
myProperties.Set(propertyGeoipDisable, true)
|
|
}
|
|
|
|
apified := IdentifyInApi{
|
|
Type: msg.Type,
|
|
Event: "$identify",
|
|
Library: SDKName,
|
|
LibraryVersion: getVersion(),
|
|
Timestamp: msg.Timestamp,
|
|
DistinctId: msg.DistinctId,
|
|
|
|
Properties: myProperties,
|
|
Set: msg.Properties,
|
|
}
|
|
|
|
return apified
|
|
}
|
|
|