telemetry

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package telemetry is the single entry point for product analytics. CLI and MCP code call its measurement methods (CommandExecuted, MCPToolCalled, ...) and never see the underlying clickstream client or event wire format. Events are sent in background goroutines; call Flush before the process exits.

Telemetry is disabled (all methods become no-ops) when CU_NO_TELEMETRY is set or the embedded credentials are missing.

Index

Constants

View Source
const (
	DefaultFlushTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

func Init

func Init(appVersion string)

Init builds the process-wide tracker from embedded configuration and fires the first-run events if the device ID was just created. Safe to skip: without Init every telemetry call is a no-op.

func NewSessionID

func NewSessionID() string

NewSessionID returns a random ID that groups all events of one MCP session.

func WithContext

func WithContext(ctx context.Context, t *Tracker) context.Context

WithContext stores the tracker in ctx for handlers that prefer DI over the package default.

Types

type CommandEvent

type CommandEvent struct {
	Command   string        // full cobra path, e.g. "cuni fetch theme"
	Flags     []string      // names of flags explicitly set, no values
	Duration  time.Duration //
	Success   bool          //
	ErrorKind string        // "auth" | "runtime" | "usage"; empty when Success
}

CommandEvent describes one finished CLI command invocation.

type EventName

type EventName string

EventName is a typed name of an analytics event. Values come only from the constants and constructor functions declared here.

const (
	// EventFirstRun fires once per device, when the device-id file is created.
	EventFirstRun EventName = "first_run"
	// EventLoginCompleted fires after a successful `cuni login` of any kind.
	EventLoginCompleted EventName = "login_completed"
	// EventMCPSessionStarted fires when an MCP host initializes a session.
	EventMCPSessionStarted EventName = "mcp_session_started"
	// EventMCPSessionEnded fires when the MCP server stops.
	EventMCPSessionEnded EventName = "mcp_session_ended"
)

func CommandEventName

func CommandEventName(commandPath string) EventName

CommandEventName maps a cobra command path ("cuni fetch theme") onto a typed event name ("command_fetch_theme").

func ToolCallEventName

func ToolCallEventName(tool string) EventName

ToolCallEventName maps an MCP tool name onto a typed event name ("tool_list_courses").

type ToolCallEvent

type ToolCallEvent struct {
	SessionID  string        // ID from NewSessionID, shared by all calls of the session
	ClientName string        // LLM host from the initialize handshake
	Tool       string        // tool name, e.g. "list_courses"
	Seq        int           // 1-based index of the call within the session
	SincePrev  time.Duration // time since the previous tool call; 0 for the first
	Duration   time.Duration //
	IsError    bool          //
	ArgKeys    []string      // names of arguments the host passed, no values
}

ToolCallEvent describes one finished MCP tools/call.

type Tracker

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

Tracker sends analytics events. The zero value is unusable; a nil *Tracker is a valid no-op, so callers never guard their calls.

func Default

func Default() *Tracker

Default returns the tracker built by Init, or nil (a valid no-op tracker).

func FromContext

func FromContext(ctx context.Context) *Tracker

FromContext returns the tracker stored by WithContext, falling back to Default().

func (*Tracker) CommandExecuted

func (t *Tracker) CommandExecuted(e CommandEvent)

CommandExecuted records a finished CLI command.

func (*Tracker) Flush

func (t *Tracker) Flush(timeout time.Duration)

Flush waits until in-flight events are delivered, at most timeout.

func (*Tracker) LoginCompleted

func (t *Tracker) LoginCompleted(target string)

LoginCompleted records a successful login; target is the auth backend: "lms", "gitlab", "time" or "ktalk".

func (*Tracker) MCPSessionEnded

func (t *Tracker) MCPSessionEnded(sessionID string, duration time.Duration, toolCalls int)

MCPSessionEnded records the end of an MCP session.

func (*Tracker) MCPSessionStarted

func (t *Tracker) MCPSessionStarted(sessionID, clientName, clientVersion string)

MCPSessionStarted records an MCP initialize handshake; clientName and clientVersion identify the LLM host (e.g. "claude-code").

func (*Tracker) MCPToolCalled

func (t *Tracker) MCPToolCalled(e ToolCallEvent)

MCPToolCalled records a finished MCP tool call.

Jump to

Keyboard shortcuts

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