telemetry

package
v1.27.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AppID = "ca9654da-ba0e-489c-ba2a-f81990c2f826"

Variables

View Source
var (
	ErrNotEnabled         = errors.New("telemetry is not enabled on this device")
	ErrAlreadyInitialized = errors.New("already initialized telemetry")
)

Functions

func UserID

func UserID() (string, error)

UserID generates a unique user ID based on the home dir and hostname.

Possibly, in the future, we store a global telemetry ID on the user's machine, such as in ~/.config/caproni/telemetry_id, so it is unique and not generated from a user's personal information.

func WithContext

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

Types

type Client

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

func FromContext

func FromContext(ctx context.Context) *Client

func NewFromEnv

func NewFromEnv(executor executor.CommandRunner) (*Client, error)

NewFromEnv initializes the telemetry tracker with the configured collector URI and user information. Returns ErrAlreadyInitialized if called more than once, or an error if user ID generation fails. Returns ErrNotEnabled if telemetry is not enabled.

func (*Client) FlushEvents

func (c *Client) FlushEvents()

FlushEvents flushes any pending telemetry events and stops the emitter. Does nothing if the emitter has not been initialized.

func (*Client) IsTeamMember

func (c *Client) IsTeamMember(ctx context.Context) bool

IsTeamMember returns true if we can reasonably assume that the user is a GitLab team member. It intentionally doesn't report errors and fails fast to avoid complaining to users, who aren't team members.

This should only be used for telemetry and NEVER for authentication.

The logic is based on GDK's `GDK::Telemetry.team_member?` function.

func (*Client) TrackCommand

func (c *Client) TrackCommand(ctx context.Context, startedAt time.Time, name string, args []string, err error)

TrackCommand tracks a command execution with its exit code and duration since the given start time.

type CommandEvent

type CommandEvent struct {
	Name       string   `json:"name"`
	Args       []string `json:"args"`
	Error      string   `json:"error,omitempty"`
	DurationMs int64    `json:"duration_ms"`
}

Jump to

Keyboard shortcuts

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