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
- func Init(appVersion string)
- func NewSessionID() string
- func WithContext(ctx context.Context, t *Tracker) context.Context
- type CommandEvent
- type EventName
- type ToolCallEvent
- type Tracker
- func (t *Tracker) CommandExecuted(e CommandEvent)
- func (t *Tracker) Flush(timeout time.Duration)
- func (t *Tracker) LoginCompleted(target string)
- func (t *Tracker) MCPSessionEnded(sessionID string, duration time.Duration, toolCalls int)
- func (t *Tracker) MCPSessionStarted(sessionID, clientName, clientVersion string)
- func (t *Tracker) MCPToolCalled(e ToolCallEvent)
Constants ¶
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.
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 ¶
CommandEventName maps a cobra command path ("cuni fetch theme") onto a typed event name ("command_fetch_theme").
func ToolCallEventName ¶
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 ¶
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) LoginCompleted ¶
LoginCompleted records a successful login; target is the auth backend: "lms", "gitlab", "time" or "ktalk".
func (*Tracker) MCPSessionEnded ¶
MCPSessionEnded records the end of an MCP session.
func (*Tracker) MCPSessionStarted ¶
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.