Documentation
¶
Index ¶
- Constants
- func AccountIDFromContext(ctx context.Context) *uuid.UUID
- func DistinctID(userID *uuid.UUID, tokenID *uuid.UUID, tenantID *uuid.UUID) string
- func OrganizationIDFromContext(ctx context.Context) *uuid.UUID
- func TenantIDFromContext(ctx context.Context) *uuid.UUID
- func TokenIDFromContext(ctx context.Context) *uuid.UUID
- func UserIDFromContext(ctx context.Context) *uuid.UUID
- type Action
- type Aggregator
- type Analytics
- type FeatureFlagUser
- type FlushFunc
- type NoOpAnalytics
- func (a NoOpAnalytics) Close() error
- func (a NoOpAnalytics) Count(ctx context.Context, resource Resource, action Action, props ...Properties)
- func (a NoOpAnalytics) CountN(ctx context.Context, resource Resource, action Action, n int64, totals Totals, ...)
- func (a NoOpAnalytics) Enqueue(ctx context.Context, resource Resource, action Action, resourceId string, ...)
- func (a NoOpAnalytics) Group(groupType string, groupKey string, data Properties)
- func (a NoOpAnalytics) Identify(userId uuid.UUID, properties Properties)
- func (a NoOpAnalytics) IsFeatureEnabled(_ context.Context, _ string, _ uuid.UUID, _ *FeatureFlagUser, ...) (bool, error)
- func (a NoOpAnalytics) Tenant(tenantId uuid.UUID, data Properties)
- type Properties
- type Resource
- type Source
- type Totals
Constants ¶
const ( APITokenIDKey = contextKey("api_token_id") TenantIDKey = contextKey("tenant_id") OrganizationIDKey = contextKey("organization_id") AccountIDKey = contextKey("account_id") UserIDKey = contextKey("user_id") SourceKey = contextKey("source") SourceMetadataKey = "x-hatchet-source" // CLIVersionMetadataKey and CLICommandMetadataKey carry CLI build and // subcommand details alongside SourceMetadataKey. They are advisory: a client // can set them to anything, so treat the values as reporting detail rather // than as anything to branch on. CLIVersionMetadataKey = "x-hatchet-cli-version" CLICommandMetadataKey = "x-hatchet-cli-command" )
Variables ¶
This section is empty.
Functions ¶
func AccountIDFromContext ¶ added in v0.101.32
AccountIDFromContext returns the account an event belongs to, if one was set. An account groups the users, organizations and tenants of a single customer. Unlike a tenant or token it is not an actor, so it never contributes a distinct id — see DistinctID.
func DistinctID ¶ added in v0.79.36
func OrganizationIDFromContext ¶ added in v0.79.38
func TenantIDFromContext ¶ added in v0.79.36
Types ¶
type Action ¶ added in v0.79.36
type Action string
const ( Create Action = "create" Revoke Action = "revoke" Accept Action = "accept" Reject Action = "reject" Login Action = "login" Delete Action = "delete" Cancel Action = "cancel" Replay Action = "replay" List Action = "list" Get Action = "get" Register Action = "register" Subscribe Action = "subscribe" Listen Action = "listen" Release Action = "release" Refresh Action = "refresh" Send Action = "send" Evict Action = "evict" Restore Action = "restore" Branch Action = "branch" Memo Action = "memo" WaitFor Action = "wait-for" Connect Action = "connect" Publish Action = "publish" )
type Aggregator ¶ added in v0.79.36
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator batches Count calls into periodic flushes. It is intended to be embedded inside an Analytics implementation (e.g. PosthogAnalytics) so that the implementation's Count method is non-blocking and high-throughput.
func NewAggregator ¶ added in v0.79.36
func (*Aggregator) Count ¶ added in v0.79.36
func (a *Aggregator) Count(resource Resource, action Action, tenantID uuid.UUID, tokenID *uuid.UUID, n int64, props ...Properties)
Count increments the aggregated counter for the given resource/action/tenant/token and optional properties. Properties are hashed into the bucket key so that different feature combinations (e.g. priority=1 vs priority=3) are counted separately. This is the non-blocking hot path: sync.Map.Load + atomic.Add + the marker update on the common case.
func (*Aggregator) CountTotals ¶ added in v0.120.1
func (a *Aggregator) CountTotals(resource Resource, action Action, tenantID uuid.UUID, tokenID *uuid.UUID, n int64, totals map[string]int64, props ...Properties)
CountTotals is Count plus additive totals. Totals are summed into the bucket and flushed as properties; they are not part of the bucket key.
func (*Aggregator) Shutdown ¶ added in v0.79.36
func (a *Aggregator) Shutdown()
func (*Aggregator) Start ¶ added in v0.79.36
func (a *Aggregator) Start()
type Analytics ¶
type Analytics interface {
Enqueue(ctx context.Context, resource Resource, action Action, resourceId string, properties Properties)
Count(ctx context.Context, resource Resource, action Action, props ...Properties)
// CountN records n occurrences, plus totals summed into the same bucket as Count.
CountN(ctx context.Context, resource Resource, action Action, n int64, totals Totals, props ...Properties)
Identify(userId uuid.UUID, properties Properties)
Tenant(tenantId uuid.UUID, data Properties)
Group(groupType string, groupKey string, data Properties)
IsFeatureEnabled(ctx context.Context, flagKey string, tenantID uuid.UUID, user *FeatureFlagUser, isEnabledIfNoPosthog bool) (bool, error)
Close() error
}
type FeatureFlagUser ¶ added in v0.106.3
type FlushFunc ¶ added in v0.79.36
type FlushFunc func(resource Resource, action Action, tenantID uuid.UUID, tokenID *uuid.UUID, count int64, firstEventAt, lastEventAt time.Time, properties Properties)
FlushFunc receives one bucket's totals for the interval since the previous flush: the number of events counted, and approximate times of the first and last events. The times are sampled independently of the count and of each other: they are zero when unknown, events that arrive during a flush can have their count and their times attributed to different intervals, and lastEventAt can precede firstEventAt when writers interleave.
type NoOpAnalytics ¶
type NoOpAnalytics struct{}
func (NoOpAnalytics) Close ¶ added in v0.79.36
func (a NoOpAnalytics) Close() error
func (NoOpAnalytics) Count ¶ added in v0.79.36
func (a NoOpAnalytics) Count(ctx context.Context, resource Resource, action Action, props ...Properties)
func (NoOpAnalytics) CountN ¶ added in v0.120.1
func (a NoOpAnalytics) CountN(ctx context.Context, resource Resource, action Action, n int64, totals Totals, props ...Properties)
func (NoOpAnalytics) Enqueue ¶
func (a NoOpAnalytics) Enqueue(ctx context.Context, resource Resource, action Action, resourceId string, properties Properties)
func (NoOpAnalytics) Group ¶ added in v0.79.38
func (a NoOpAnalytics) Group(groupType string, groupKey string, data Properties)
func (NoOpAnalytics) Identify ¶ added in v0.79.36
func (a NoOpAnalytics) Identify(userId uuid.UUID, properties Properties)
func (NoOpAnalytics) IsFeatureEnabled ¶ added in v0.83.6
func (a NoOpAnalytics) IsFeatureEnabled(_ context.Context, _ string, _ uuid.UUID, _ *FeatureFlagUser, isEnabledIfNoPosthog bool) (bool, error)
func (NoOpAnalytics) Tenant ¶
func (a NoOpAnalytics) Tenant(tenantId uuid.UUID, data Properties)
type Properties ¶ added in v0.79.36
type Properties map[string]interface{}
func Props ¶ added in v0.79.36
func Props(kvs ...interface{}) Properties
Props builds a property map from variadic key-value pairs, keeping all non-nil values regardless of type. Keys must be strings; non-string keys are skipped. Nil values are omitted.
type Resource ¶ added in v0.79.36
type Resource string
const ( User Resource = "user" Invite Resource = "user-invite" Tenant Resource = "tenant" Token Resource = "api-token" Workflow Resource = "workflow" Event Resource = "event" WorkflowRun Resource = "workflow-run" TaskRun Resource = "task-run" DurableTask Resource = "durable-task" Worker Resource = "worker" RateLimit Resource = "rate-limit" Webhook Resource = "webhook" Log Resource = "log" StreamEvent Resource = "stream-event" DurableStream Resource = "durable-stream" OtelSpan Resource = "otel-span" )