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
- Variables
- type Capture
- type Control
- func (c *Control) Capture() *Capture
- func (c *Control) Close()
- func (c *Control) Configure(settings protocol.TelemetrySettings)
- func (c *Control) Diagnostics(ctx context.Context) error
- func (c *Control) Errors() bool
- func (c *Control) FeatureUse(feature protocol.FeatureUse) (Observation, bool)
- func (c *Control) Metrics() bool
- func (c *Control) Model(provider protocol.ConversationProvider, model string) Model
- func (c *Control) Observe(observation Observation)
- func (c *Control) Permitted() bool
- func (c *Control) Record(level slog.Level, fields logging.Fields)
- func (c *Control) ReportCrash(crash *Crash)
- type Crash
- type Model
- type Observation
- func Launch() Observation
- func ModelRequest(model Model, result string, status *uint16, fault *protocol.ErrorCode, ...) Observation
- func Search(driver *protocol.SearchDriver, result string, fault *protocol.ErrorCode, ...) Observation
- func ToolCall(tool Tool, result string, fault *protocol.ErrorCode, elapsed time.Duration) Observation
- func Turn(result string, mode protocol.WorkMode, subagent bool, ...) Observation
- type Options
- type Tokens
- type Tool
- type Watchdog
- type WatchdogOptions
Constants ¶
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 ¶
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.
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 ¶
New reads the environment once. SAILRY_TELEMETRY=off and DO_NOT_TRACK=1 opt the process out whatever the saved settings say.
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 ¶
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) 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) 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) Record ¶
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 ¶
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 ¶
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 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 ¶
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.
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 ¶
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 ¶
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 OfficialTool ¶
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.
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.