telemetry

package
v0.2.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package telemetry provides opt-in anonymous usage analytics for the StackEye CLI.

Telemetry is disabled by default and requires explicit user consent. When enabled, it collects anonymous usage data to help improve the CLI: - Command names and exit codes - Execution duration - CLI version and platform info - Anonymized organization ID (SHA-256 hash prefix)

NO personal data, API keys, error messages, or identifiable information is collected.

Environment variable STACKEYE_TELEMETRY=0 disables telemetry regardless of config.

Index

Constants

View Source
const ConsentMessage = `` /* 193-byte string literal not displayed */

ConsentMessage is the message shown to users when prompting for telemetry consent.

View Source
const ConsentPrompt = "Enable telemetry? [y/N]: "

ConsentPrompt is the prompt shown after the consent message.

View Source
const DefaultEndpoint = "https://api.stackeye.io/v1/telemetry/cli"

DefaultEndpoint is the telemetry API endpoint.

View Source
const EnvTelemetry = "STACKEYE_TELEMETRY"

EnvTelemetry is the environment variable to override telemetry settings. Set to "0" or "false" to disable telemetry regardless of config.

Variables

This section is empty.

Functions

func CheckAndPromptConsent

func CheckAndPromptConsent(stdin io.Reader, stdout io.Writer) (bool, error)

CheckAndPromptConsent checks if the user has been prompted for telemetry consent. If not, it prompts them and saves their preference. Returns true if telemetry is enabled after the check.

This should be called early in CLI initialization, but only for interactive sessions. Non-interactive sessions (piped input, CI/CD) should skip the prompt.

func MarkPrompted

func MarkPrompted() error

MarkPrompted marks the user as having been prompted for telemetry consent, without changing their telemetry preference. This is useful when the user explicitly enables/disables via command.

func ResetClient

func ResetClient()

ResetClient resets the global client for testing.

Types

type Client

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

Client handles telemetry event collection and transmission.

func GetClient

func GetClient() *Client

GetClient returns the global telemetry client. The client is initialized once and reused across the CLI lifetime.

func (*Client) Flush

func (c *Client) Flush(timeout time.Duration)

Flush waits for all pending telemetry events to be sent. Call this before exiting the CLI to ensure events are not lost. Returns after all pending sends complete or timeout expires.

func (*Client) GetLastEvent

func (c *Client) GetLastEvent() *Event

GetLastEvent returns the most recent event for debugging purposes. Returns nil if no event has been tracked.

func (*Client) IsEnabled

func (c *Client) IsEnabled() bool

IsEnabled returns whether telemetry is currently enabled.

func (*Client) Reload

func (c *Client) Reload()

Reload refreshes telemetry settings from config. Call this after changing telemetry preferences.

func (*Client) SetEnabled

func (c *Client) SetEnabled(enabled bool)

SetEnabled enables or disables telemetry. This does NOT persist the setting - use config.Save() for that.

func (*Client) SetEndpoint

func (c *Client) SetEndpoint(endpoint string)

SetEndpoint overrides the telemetry endpoint (for testing).

func (*Client) Track

func (c *Client) Track(ctx context.Context, command string, exitCode int, duration time.Duration)

Track records a telemetry event. If telemetry is disabled, this is a no-op. Events are sent asynchronously to avoid blocking the CLI. Call Flush() before exit to ensure events are sent.

type Event

type Event struct {
	// CLIVersion is the version of the CLI (e.g., "1.2.3").
	CLIVersion string `json:"cli_version"`

	// Command is the command name (e.g., "probe create").
	Command string `json:"command"`

	// ExitCode is the command's exit code (0 for success).
	ExitCode int `json:"exit_code"`

	// DurationMs is the execution time in milliseconds.
	DurationMs int64 `json:"duration_ms,omitempty"`

	// OS is the operating system (e.g., "linux", "darwin", "windows").
	OS string `json:"os"`

	// Arch is the architecture (e.g., "amd64", "arm64").
	Arch string `json:"arch"`

	// OrgIDHash is the first 16 characters of the SHA-256 hash of the org ID.
	// Empty if not authenticated.
	OrgIDHash string `json:"org_id_hash,omitempty"`
}

Event represents a telemetry event to be sent to the backend.

Jump to

Keyboard shortcuts

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