telemetry

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 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 reports a runtime's own events to a PostHog-compatible batch endpoint: queued, sent a minute after the first of them (or at once when a batch is full), never more than a batch per request. Only a released runtime reports; a checkout stays quiet. Events carry technical properties only, never a prompt, a title or a path.

Index

Constants

View Source
const MaxEvents = 40

MaxEvents is the most events one request carries.

View Source
const MessageMax = 300

MessageMax is the most runes a reported message keeps.

Variables

View Source
var DefaultURL, DefaultKey string

Built in at release build time (-ldflags -X ...telemetry.DefaultURL=... -X ...telemetry.DefaultKey=...): where a released runtime sends its anonymous reports unless told otherwise. A checkout carries neither and sends nothing.

Functions

func Body

func Body(key, distinctID string, common *jsvalue.Object, events []Event) []byte

Body is what the batch endpoint takes: the person and the common properties go into every event.

func EnvOff

func EnvOff(getenv func(string) string) (bool, string)

EnvOff says whether the environment turns telemetry off, and by which variable: RUNTIME_TELEMETRY or HARNESSLY_TELEMETRY set to off (also 0, false, no, none, disabled), or DO_NOT_TRACK set to anything but 0 or false (https://consoledonottrack.com).

func Fingerprint

func Fingerprint(source, kind, message string) string

Fingerprint groups one error: where it was seen, its kind and its scrubbed text.

func Scrub

func Scrub(s string) string

Scrub makes an error's text fit to leave the machine: addresses, e-mails, home folders, IP addresses, ids and tokens, long numbers are masked, and the text is cut to MessageMax. What stays is the shape of the error, which is also what groups the same error from many machines into one.

Types

type Config

type Config struct {
	// URL is the batch endpoint ("" sends nothing); Key the project key it takes.
	URL, Key string
	// Common are the properties every event carries first, in their order.
	Common *jsvalue.Object
	// DistinctID names who the events are about, read at each send.
	DistinctID func() string
	// Allow, when set, is asked at every push and every send: false drops the events (the person turned it off).
	Allow  func() bool
	Delay  time.Duration
	Client *http.Client
	Log    func(level, msg string, kv ...any)
}

Config says where events go and what each of them carries.

type Consent struct {
	Path   string
	Getenv func(string) string
	// contains filtered or unexported fields
}

Consent is the machine's choice about telemetry, kept in a file of the data directory, with the random id its reports carry in place of a person (never an e-mail, a host name or a path). The environment's off wins over the file: an operator turns it off for every machine they set up, a person turns it off in Settings.

func (*Consent) Allowed

func (c *Consent) Allowed() bool

Allowed says whether reports may leave the machine now; it is read at every push and every send, so a change takes effect at once.

func (*Consent) ID

func (c *Consent) ID() string

ID is the machine's random id, made on first use.

func (*Consent) Set

func (c *Consent) Set(on bool) error

Set keeps the person's choice. Turning it off also forgets the id: turned on again, the machine is a new one.

func (*Consent) Why

func (c *Consent) Why() string

Why says what decides the state, for the settings and the start line: the variable that turns it off, "settings", or "" when it is on.

type Event

type Event struct {
	Name       string
	At         time.Time
	Properties *jsvalue.Object
}

Event is one event: its name, when it happened and its own properties.

type Queue

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

Queue batches events.

func New

func New(cfg Config) *Queue

func (*Queue) Enabled

func (q *Queue) Enabled() bool

Enabled says whether events are sent anywhere.

func (*Queue) Flush

func (q *Queue) Flush()

Flush sends what is queued now.

func (*Queue) Push

func (q *Queue) Push(e Event)

Push queues an event.

type Reporter

type Reporter struct {
	Queue   *Queue
	PerHour int
	Now     func() time.Time
	// contains filtered or unexported fields
}

Reporter sends errors as PostHog error tracking takes them ($exception): scrubbed, each distinct error once an hour, at most PerHour distinct errors an hour, so a loop on one machine costs nothing and floods nobody.

func (*Reporter) Error

func (r *Reporter) Error(source, kind, message string, props *jsvalue.Object) bool

Error reports one error: source is where it was seen (web, runtime, app, …), kind what happened (exception, http, mcp.call, …), message its text (scrubbed here), props more technical properties. It says whether it was queued.

Jump to

Keyboard shortcuts

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