telemetry

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 31 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 owns the process's reporting consent, its anonymous identity, the diagnostics report a controller asks for, automatic error reports (failed operations, interface hangs and crashes) and anonymous usage counters. Nothing is sent and nothing runs in the background while the matching switch is off.

Index

Constants

View Source
const (
	HangFile  = "interface-hang.txt"
	CrashFile = "interface-crash.txt"

	// HangAfter is how long the interface thread may leave a heartbeat
	// unanswered before it counts as hung.
	HangAfter = 5 * time.Second
)

The interface's two failures are kept in the application's log directory as reduced traces: every goroutine's state, and each frame's function name and line number. A reduced trace has no panic message, no argument, no file path and no register.

Variables

View Source
var (
	BuildRevision string
	BuildDSN      string
	BuildKey      string
)

Release builds set these with -ldflags -X. A build without a revision reports the dev channel, as a debug build does in the reference.

View Source
var UncountedBuiltins = map[string]string{
	"set_session_title": "The runtime asks for it once in every session; its count repeats the session count and says nothing about tool use",
}

UncountedBuiltins are the registered built-in tools left out of the counters, each with its reason. Every other built-in is counted by name, so a new one needs no entry here.

Functions

This section is empty.

Types

type Capture

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

Capture is the consent an operation started under: its observation is counted only if that consent still holds when it ends.

func (*Capture) Record

func (capture *Capture) Record(observation Observation)

Record counts the operation's one observation.

type Control

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

Control is the process's consent: the environment's opt-outs, the saved switches and the identity reports carry.

func New

func New(options Options) *Control

New reads the environment once. SAILRY_TELEMETRY=off and DO_NOT_TRACK=1 opt the process out whatever the saved settings say.

func (*Control) Capture

func (c *Control) Capture() *Capture

Capture is nil while usage metrics are off.

func (*Control) Close

func (c *Control) Close()

Close sends the pending usage window and waits for reports in flight, for two seconds at most, then withdraws consent for the rest of the process.

func (*Control) Configure

func (c *Control) Configure(settings protocol.TelemetrySettings)

Configure takes the saved settings. The first one counts the launch when usage metrics are on.

func (*Control) Diagnostics

func (c *Control) Diagnostics(ctx context.Context) error

Diagnostics sends the one report a controller asked for: the anonymous identity, release, channel, application, system and architecture, with the active log's recent records reduced to their public fields. It never carries requests, responses, prompts or file contents. The two switches do not gate it: only the environment's opt-outs and a missing endpoint do.

func (*Control) Errors

func (c *Control) Errors() bool

Errors reports whether automatic error reports are allowed.

func (*Control) FeatureUse

func (c *Control) FeatureUse(feature protocol.FeatureUse) (Observation, bool)

FeatureUse counts one use of a desktop feature. Only an identifier of the closed list is counted; an official plugin page only for a package the application ships. Anything else is refused.

func (*Control) Metrics

func (c *Control) Metrics() bool

Metrics reports whether usage counters are allowed.

func (*Control) Model

func (c *Control) Model(provider protocol.ConversationProvider, model string) Model

Model captures a provider's model for counting.

func (*Control) Observe

func (c *Control) Observe(observation Observation)

Observe counts an observation under the current consent. With usage metrics off it does nothing and starts nothing.

func (*Control) Permitted

func (c *Control) Permitted() bool

Permitted reports whether this process may report at all.

func (*Control) Record

func (c *Control) Record(level slog.Level, fields logging.Fields)

Record receives the log's warnings and errors. While error reports are on, a warning is kept for the next report and a failed operation is reported, at most ten times an hour for one fingerprint. While they are off it does nothing.

func (*Control) ReportCrash

func (c *Control) ReportCrash(crash *Crash)

ReportCrash sends the previous run's crash once, while error reports are on. While they are off the trace stays in the log directory only.

type Crash

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

Crash is the reduced trace of the fatal panic that ended the previous run.

func CatchCrashes

func CatchCrashes(directory string) (*Crash, error)

CatchCrashes makes the runtime copy a fatal panic's traceback into the application's log directory, besides printing it and exiting as before. MyGo offers no hook that recovers a panic on the interface thread or in an interface callback, so the process still ends; the next launch calls this again, which reduces the copy into CrashFile, removes the copy and returns the reduced trace for ReportCrash. It returns nil when the previous run did not crash.

type Model

type Model struct {
	API            protocol.ConversationModelApi `json:"api"`
	Authentication protocol.Authentication       `json:"authentication"`
	Model          string                        `json:"model"`
}

Model is a request's interface, authentication and model. A model outside the built-in presets' static lists is "custom".

type Observation

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

Observation is one counted fact.

func Launch

func Launch() Observation

Launch counts the process's start.

func ModelRequest

func ModelRequest(model Model, result string, status *uint16, fault *protocol.ErrorCode, retries *uint64, tokens Tokens) Observation

ModelRequest counts a model request. result is success, error or cancelled.

func Search(driver *protocol.SearchDriver, result string, fault *protocol.ErrorCode, elapsed time.Duration) Observation

Search counts a web search. result is success, error or cancelled.

func ToolCall

func ToolCall(tool Tool, result string, fault *protocol.ErrorCode, elapsed time.Duration) Observation

ToolCall counts a tool call. result is success, error, denied or cancelled.

func Turn

func Turn(result string, mode protocol.WorkMode, subagent bool, fault *protocol.ErrorCode) Observation

Turn counts a finished task turn. result is completed, failed or cancelled.

type Options

type Options struct {
	Application string              // "desktop" (default) or "host"
	Lookup      func(string) string // environment; os.Getenv by default
	Transport   http.RoundTripper   // http.DefaultTransport by default
	// RetryDirectory is the owned profile's private temporary directory.
	RetryDirectory string
	// Timer schedules usage flushes and operation retries; time.AfterFunc by default.
	Timer func(time.Duration, func()) (stop func())
	// Models are the built-in presets' static model identifiers by preset.
	// Any other model is counted as "custom".
	Models map[string][]string
	// Packages are the names of the packages the application ships. Only
	// these may be named by a feature counter.
	Packages []string
}

Options names the application and replaces the process boundaries in tests.

type Tokens

type Tokens struct {
	Input      uint64 `json:"input"`
	Output     uint64 `json:"output"`
	CacheRead  uint64 `json:"cache_read"`
	CacheWrite uint64 `json:"cache_write"`
}

Tokens are a model request's reported usage.

type Tool

type Tool struct {
	Source string `json:"source"`
	Name   string `json:"name,omitempty"`
}

Tool names a called tool without its arguments: a built-in by the name the Node registered it under, a tool of a package the application ships as "official" with <package>.<tool> from the shipped catalog, a connected server only as "mcp", any other package only as "third_party".

func BuiltinTool

func BuiltinTool(name string) (Tool, bool)

BuiltinTool counts a tool the Node registered itself, by its registered name. The caller passes only names found in the turn's captured tools, never a name a model or a package chose.

func MCPTool

func MCPTool() Tool

MCPTool counts a connected server's tool, unnamed.

func OfficialTool

func OfficialTool(pack, tool string) (Tool, bool)

OfficialTool counts a tool of a package the application ships. The caller has matched the package to the shipped catalog by name and digest.

func ThirdPartyTool

func ThirdPartyTool() Tool

ThirdPartyTool counts any other package's tool, unnamed.

type Watchdog

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

Watchdog notices an interface thread that stops answering. While the interface draws frames, and for watchLinger after its last one, it asks the thread for a heartbeat every second. A heartbeat left unanswered for HangAfter while a window is visible and the system is awake is one hang: every goroutine's reduced trace is written to HangFile, and reported once while error reports are on. A second without the watchdog's own tick (the system slept, a debugger stopped the process) restarts the measurement instead. An idle interface has no heartbeat and no timer.

func NewWatchdog

func NewWatchdog(options WatchdogOptions) *Watchdog

NewWatchdog returns a stopped watchdog; Touch starts it.

func (*Watchdog) Close

func (w *Watchdog) Close()

Close stops the heartbeat.

func (*Watchdog) Extend

func (w *Watchdog) Extend(limit time.Duration) func()

Extend adds a bounded grace window for expected long warmup work (such as first-frame GPU shader compilation), returning a release callback.

func (*Watchdog) Pause

func (w *Watchdog) Pause() func()

Pause increments the modal pause count while an OS-owned loop (such as a native dialog) blocks the interface thread, returning a release callback.

func (*Watchdog) Suspended

func (w *Watchdog) Suspended(suspended bool)

Suspended records whether the system is asleep.

func (*Watchdog) Touch

func (w *Watchdog) Touch()

Touch records interface activity: a frame was drawn.

func (*Watchdog) Visible

func (w *Watchdog) Visible(visible bool)

Visible records whether any window is on screen.

type WatchdogOptions

type WatchdogOptions struct {
	// Ping runs done on the interface thread without drawing anything. It
	// may block until done has run.
	Ping func(done func())
	// ProbeNativeWindow samples native message dispatch after a hang stack
	// is captured. A bounded probe returns (replied, measured).
	ProbeNativeWindow func() (bool, bool)
	// Directory is the application's log directory.
	Directory string
	// Control sends the report; nil sends nothing.
	Control *Control
	// Clock is the real clock by default.
	Clock clockwork.Clock
}

WatchdogOptions configures a Watchdog.

Jump to

Keyboard shortcuts

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