Help us shape the future of Go! Take the 2026 Go Developer Survey

telemetry

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package telemetry is Flow-I's opt-in usage reporting.

It is off unless the user sets the telemetry setting to minimal or full, and nothing leaves the machine unless telemetry_endpoint is also set. What may be reported is fixed by Catalogue: every event and every value is listed there, either as a closed set of words or as a bucket, so a URL, a body, a name, an id or a path cannot be sent by mistake — Record and Payload.Validate refuse anything the catalogue does not name. There is no install id; payloads carry the day, not the time.

`flowi telemetry show` and the GUI dialog print exactly what Sample and Payload would send, and docs/reference/telemetry.md is generated from Catalogue.

Index

Constants

View Source
const (
	EventAppStarted  = "app_started"
	EventCommandRun  = "command_run"
	EventRunFinished = "run_finished"
)

Event names.

Variables

View Source
var ErrNoEndpoint = errors.New("telemetry: no endpoint configured")

ErrNoEndpoint is returned when no telemetry_endpoint is configured: a build or installation without an endpoint sends nothing.

View Source
var ErrNotInCatalogue = errors.New("telemetry: not in the catalogue")

ErrNotInCatalogue is returned for an event, field or value the catalogue does not name.

Functions

func CommandNames

func CommandNames() []string

CommandNames is the closed set of command names a command_run event may carry. The CLI maps any other command to "other".

func Explanation

func Explanation() string

Explanation is the plain-language statement shown wherever the user chooses a level.

func Reference

func Reference() string

Reference renders the catalogue as the markdown reference page.

Types

type Client

type Client struct {
	App     string `json:"app"` // cli | gui
	Version string `json:"version"`
	OS      string `json:"os"`
	Arch    string `json:"arch"`
}

Client describes the running program.

func (Client) Sanitised

func (c Client) Sanitised() Client

Sanitised returns c with every value squeezed into its closed set.

type Collector

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

Collector gathers the events of one program run. It is safe for concurrent use. With LevelOff it keeps nothing.

func NewCollector

func NewCollector(level Level, client Client, now func() time.Time) *Collector

NewCollector returns a collector for level; client is made safe first.

func (*Collector) Level

func (c *Collector) Level() Level

Level is the level the collector currently collects at.

func (*Collector) Lower

func (c *Collector) Lower(l Level)

Lower reduces the level, dropping events the new level does not allow. It never raises it: turning telemetry down while the program runs must stop what was collected under the higher level from being sent.

func (*Collector) Observe

func (c *Collector) Observe(ev engine.Event)

Observe reports finished runs from the engine's events. It matches engine.Deps.Observe; it keeps only counts, never the events themselves.

func (*Collector) Payload

func (c *Collector) Payload() (Payload, bool)

Payload returns what would be sent. ok is false when nothing should be sent: telemetry is off, or there is nothing to report.

func (*Collector) Record

func (c *Collector) Record(name string, fields map[string]string) error

Record adds an event. Anything the catalogue does not name is refused with ErrNotInCatalogue and not kept; an event above the level is dropped silently.

func (*Collector) Started

func (c *Collector) Started()

Started records that the application started.

type Event

type Event struct {
	Name   string            `json:"name"`
	Fields map[string]string `json:"fields,omitempty"`
}

Event is one reported occurrence.

type EventSpec

type EventSpec struct {
	Name   string
	Doc    string
	Level  Level // the lowest level that reports it
	Fields []FieldSpec
}

EventSpec is one reportable event.

func Catalogue

func Catalogue() []EventSpec

Catalogue lists every event that can ever be reported.

type FieldSpec

type FieldSpec struct {
	Name    string
	Doc     string
	Allowed []string
	Example string
}

FieldSpec is one field of an event: its value must be one of Allowed.

type Level

type Level int

Level is how much the user allows to be reported.

const (
	LevelOff Level = iota
	LevelMinimal
	LevelFull
)

Levels, in increasing order of what is reported.

func ParseLevel

func ParseLevel(s string) Level

ParseLevel reads the telemetry setting; anything unknown is off.

func (Level) String

func (l Level) String() string

type Payload

type Payload struct {
	Schema int     `json:"schema"`
	Date   string  `json:"date"` // YYYY-MM-DD, UTC; no time of day
	Level  string  `json:"level"`
	Client Client  `json:"client"`
	Events []Event `json:"events"`
}

Payload is everything one report contains.

func Sample

func Sample(level Level, c Client) Payload

Sample is an example payload for level, with example values, for `flowi telemetry show` and the GUI dialog. At LevelOff it has no events.

func (Payload) Validate

func (p Payload) Validate() error

Validate reports whether p contains only what the catalogue allows.

type Sender

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

Sender posts a payload to the configured endpoint.

func NewSender

func NewSender(endpoint string, client *http.Client) *Sender

NewSender returns a sender for endpoint; a nil client gets a timeout of its own.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, p Payload) error

Send validates and posts p once, without retries. A report that does not arrive is simply lost.

Jump to

Keyboard shortcuts

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