telemetry

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package telemetry sends fire-and-forget product analytics events to PostHog.

Design notes:

  • All HTTP I/O is non-blocking via goroutines tracked by a sync.WaitGroup; callers must invoke Flush() at process exit (root.go does this) so events have a chance to land before the binary returns.
  • The anonymous distinct_id is generated on first run and persisted to ~/.config/airskills/telemetry.json so events from a single machine link together even before login.
  • On login, Identify() emits a PostHog $identify event with $anon_distinct_id so prior anonymous events get aliased to the real user.
  • Failures are swallowed: telemetry must never break a user-facing command.
  • Users can opt out with AIRSKILLS_NO_TELEMETRY=1.

Index

Constants

View Source
const APIKey = "phc_tJ5pdZxz6wrM4JcTAXH86PnSKWbCS5YjwZ6MeMD2GX8R"

PostHog project ingest key for the Airskills project (151269). This is the same kind of public key that PostHog embeds in client-side JS snippets — it only allows writing events, never reading data, so it's safe to ship in the binary.

Variables

View Source
var (

	// CLIVersion is set by root.go from the linker-injected version string so
	// every event carries the binary version as a super property. Assigned
	// once before Init() on the main goroutine, never mutated after.
	CLIVersion string
)

Functions

func AnonymousID

func AnonymousID() string

AnonymousID returns the stable anonymous ID for this machine. Safe to call on the HTTP hot path — reads a cached copy without taking the mutex. Set once by Init() and never mutated, so a plain read is race-free.

func Capture

func Capture(event string, properties map[string]interface{})

Capture queues an event for delivery. Non-blocking; the actual HTTP request runs in a goroutine and is awaited by Flush(). wg.Add happens under the mutex to guarantee it's ordered-before any subsequent Flush().

func Flush

func Flush(timeout time.Duration)

Flush waits up to the given timeout for all in-flight captures to finish. Called from root.Execute() before the binary exits.

func Identify

func Identify(userID, username string)

Identify links the current anonymous ID to a real user. Should be called once after a successful login. Persists the user ID so subsequent runs continue using it as the distinct ID.

func Init

func Init()

Init loads (or creates) the persisted identity. Safe to call multiple times. Errors are silently ignored — telemetry never blocks the user.

func Logout

func Logout()

Logout clears the persisted user ID so subsequent events fall back to the anonymous ID. The anonymous ID itself is preserved across logouts.

Types

This section is empty.

Jump to

Keyboard shortcuts

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