analytics

package
v0.79.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APITokenIDKey     = contextKey("api_token_id")
	TenantIDKey       = contextKey("tenant_id")
	OrganizationIDKey = contextKey("organization_id")
	UserIDKey         = contextKey("user_id")
	SourceKey         = contextKey("source")

	SourceMetadataKey = "x-hatchet-source"
)

Variables

This section is empty.

Functions

func DistinctID added in v0.79.36

func DistinctID(userID *uuid.UUID, tokenID *uuid.UUID, tenantID *uuid.UUID) string

func OrganizationIDFromContext added in v0.79.38

func OrganizationIDFromContext(ctx context.Context) *uuid.UUID

func TenantIDFromContext added in v0.79.36

func TenantIDFromContext(ctx context.Context) *uuid.UUID

func TokenIDFromContext added in v0.79.36

func TokenIDFromContext(ctx context.Context) *uuid.UUID

func UserIDFromContext added in v0.79.36

func UserIDFromContext(ctx context.Context) *uuid.UUID

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"
)

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 NewAggregator(l *zerolog.Logger, enabled bool, interval time.Duration, maxKeys int64, fn FlushFunc) *Aggregator

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 on the common case.

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)
	Identify(userId uuid.UUID, properties Properties)
	Tenant(tenantId uuid.UUID, data Properties)
	Group(groupType string, groupKey string, data Properties)
	Close() error
}

type FlushFunc added in v0.79.36

type FlushFunc func(resource Resource, action Action, tenantID uuid.UUID, tokenID *uuid.UUID, count int64, properties Properties)

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) 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) 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"
	Worker      Resource = "worker"
	RateLimit   Resource = "rate-limit"
	Webhook     Resource = "webhook"
	Log         Resource = "log"
	StreamEvent Resource = "stream-event"
)

type Source added in v0.79.36

type Source string
const (
	SourceUI   Source = "ui"
	SourceAPI  Source = "api"
	SourceGRPC Source = "grpc"
	SourceCLI  Source = "cli"
)

func SourceFromContext added in v0.79.36

func SourceFromContext(ctx context.Context) Source

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL