telemetry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package telemetry provides anonymous usage tracking for the tapes CLI using PostHog. A persistent UUID is stored in ~/.tapes/telemetry.json and all events are anonymous by default. Telemetry can be disabled through the config.toml telemetry.disabled key, the --disable-telemetry flag, the TAPES_TELEMETRY_DISABLED environment variable (all handled by Viper), or by running in a detected CI environment.

Index

Constants

View Source
const (
	EventInstall        = "tapes_cli_installed"
	EventCommandRun     = "tapes_cli_command_run"
	EventInit           = "tapes_cli_init"
	EventSessionCreated = "tapes_cli_session_created"
	EventSearch         = "tapes_cli_search"
	EventServerStarted  = "tapes_cli_server_started"
	EventMCPTool        = "tapes_cli_mcp_tool"
	EventSyncPush       = "tapes_cli_sync_push"
	EventSyncPull       = "tapes_cli_sync_pull"
	EventError          = "tapes_cli_error"
)

Event name constants for all tracked telemetry events.

Variables

View Source
var (
	// PostHogAPIKey is the PostHog write-only project API key.
	// Injected at build time via ldflags; defaults to empty (telemetry disabled).
	PostHogAPIKey = ""

	// PostHogEndpoint is the PostHog ingestion endpoint.
	// Injected at build time via ldflags; defaults to the US region.
	PostHogEndpoint = "https://us.i.posthog.com"
)

Functions

func CommonProperties

func CommonProperties() posthog.Properties

CommonProperties returns properties that are included with every event.

func IsCI

func IsCI() bool

IsCI returns true if the process appears to be running in a CI environment.

func WithContext

func WithContext(ctx context.Context, c *Client) context.Context

WithContext returns a copy of ctx with the telemetry Client attached.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the PostHog SDK client for capturing telemetry events. All capture methods are nil-safe: calling them on a nil *Client is a no-op.

func FromContext

func FromContext(ctx context.Context) *Client

FromContext returns the telemetry Client from ctx, or nil if none is set.

func NewClient

func NewClient(distinctID string, l *slog.Logger) (*Client, error)

NewClient creates a new telemetry Client that sends events to PostHog. The distinctID should be the persistent UUID from the telemetry Manager. Returns nil (not an error) when PostHogAPIKey is empty so callers can treat a nil *Client as "telemetry disabled" without extra checks.

func (*Client) CaptureCommandRun

func (c *Client) CaptureCommandRun(command string)

CaptureCommandRun records a CLI command execution.

func (*Client) CaptureError

func (c *Client) CaptureError(command, errType string)

CaptureError records an error event.

func (*Client) CaptureInit

func (c *Client) CaptureInit(preset string)

CaptureInit records a tapes init event.

func (*Client) CaptureInstall

func (c *Client) CaptureInstall()

CaptureInstall records a first-run install event.

func (*Client) CaptureMCPTool

func (c *Client) CaptureMCPTool(tool string)

CaptureMCPTool records an MCP tool invocation.

func (*Client) CaptureSearch

func (c *Client) CaptureSearch(resultCount int)

CaptureSearch records a search operation.

func (*Client) CaptureServerStarted

func (c *Client) CaptureServerStarted(mode string)

CaptureServerStarted records a server startup event.

func (*Client) CaptureSessionCreated

func (c *Client) CaptureSessionCreated(provider string)

CaptureSessionCreated records a new recording session.

func (*Client) CaptureSyncPull

func (c *Client) CaptureSyncPull()

CaptureSyncPull records a sync pull event.

func (*Client) CaptureSyncPush

func (c *Client) CaptureSyncPush()

CaptureSyncPush records a sync push event.

func (*Client) Close

func (c *Client) Close() error

Close flushes any pending events and shuts down the PostHog client.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages the persistent telemetry identity stored in the .tapes/ directory.

func NewManager

func NewManager(configDir string) (*Manager, error)

NewManager creates a new telemetry Manager. If configDir is non-empty it is used as the .tapes/ directory; otherwise standard dotdir resolution applies. When no .tapes/ directory is found, one is created at ~/.tapes/.

func (*Manager) LoadOrCreate

func (m *Manager) LoadOrCreate() (*State, bool, error)

LoadOrCreate reads the existing telemetry state or creates a new one with a fresh UUID and the current time as first_run. Returns the state and a bool indicating whether this was a first run (i.e. the file was just created).

type State

type State struct {
	UUID     string `json:"uuid"`
	FirstRun string `json:"first_run"`
}

State is the persistent telemetry state stored in ~/.tapes/telemetry.json.

Jump to

Keyboard shortcuts

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