Documentation
¶
Index ¶
- Constants
- func Close()
- func DistinctID() string
- func Enabled() bool
- func Enqueue(msg posthog.Message)
- func ExitedEvent() posthog.Capture
- func Notice(goos string) string
- func PanicEvent(r any) posthog.Exception
- func ScreenOpened(id, name string)
- func ShowNoticeOnce(w io.Writer, interactive bool)
- func Start()
- func StartedEvent() posthog.Capture
Constants ¶
const ( // EnvTelemetry turns telemetry off unless it is empty or one of 1, true, on // or yes (any case): 0, false, off, no and any value this list does not // know turn it off, so a typo never leaves a person measured. EnvTelemetry = "DATATUG_TELEMETRY" // EnvDoNotTrack set to anything but an empty string or 0 turns telemetry // off (https://consoledonottrack.com). EnvDoNotTrack = "DO_NOT_TRACK" // EnvCI set to anything but an empty string or false turns telemetry off. EnvCI = "CI" )
The variables that turn telemetry off. Enabled is the only place that reads them: every sender in this package asks it, and nothing outside this package can send, because nothing outside it imports the PostHog client (a test walks the module to prove it).
const ( EventStarted = "DataTug CLI started" EventExited = "DataTug CLI exited" EventScreen = "Screen opened" PanicEventTitle = "panic" )
The names and the title of what is sent. Notice summarises the fields of each and the README lists every one; a test builds each event and fails when the fields change.
Variables ¶
This section is empty.
Functions ¶
func DistinctID ¶ added in v0.0.14
func DistinctID() string
func Enabled ¶ added in v0.58.0
func Enabled() bool
Enabled reports whether telemetry is on for this process. It is the one function that decides: Start, Enqueue and so every event ask it, and when it says no no client is created, no event is queued and no request leaves.
func Enqueue ¶
Enqueue queues msg for delivery once the PostHog client has finished initializing (see postInitFlush), or delivers it immediately once it has. Before Start has been called, Enqueue is a no-op: there is no client to deliver to, and queuing forever without a Start call would leak memory for an invocation that deliberately never starts telemetry (`version --json`; see Start's own doc comment).
func ExitedEvent ¶ added in v0.58.0
ExitedEvent is the event sent when a command ends.
func Notice ¶ added in v0.58.0
Notice returns the text printed on stderr the first time the CLI runs with telemetry on, in a terminal. At most six lines; a test holds it to that and to what it must say. The line that turns telemetry off is the one that lasts: a shell profile line (setx on Windows, which has no export), because a variable set in one terminal is gone in the next.
func PanicEvent ¶ added in v0.58.0
PanicEvent is the crash report for a recovered panic value r. It carries the Go type of r (for a panic of the Go runtime itself, such as an index out of range, its message, which names numbers and types only) and the stack, with each frame's source file reduced to its name. The text of a panic can hold a path, a host or an argument a person typed, so it is never sent, and neither is the path of the binary or of any file.
func ScreenOpened ¶
func ScreenOpened(id, name string)
func ShowNoticeOnce ¶ added in v0.58.0
ShowNoticeOnce prints Notice on w the first time it runs with telemetry on and leaves a marker in the CLI's state folder (~/datatug) so it is printed once per user. interactive says whether w is a terminal a person reads: when it is not (a script, a service, shell completion with stderr discarded) the notice is not printed and no marker is written, so it waits for the first run in a terminal. Until the notice has been shown and recorded nothing is sent: not on the run that printed it, not on a run that could not print it and not when the marker cannot be written (the notice is then printed again next time and the run does not fail). With telemetry off it does nothing at all: nothing printed, nothing created.
func Start ¶ added in v0.31.0
func Start()
Start begins PostHog client initialization: session bookkeeping plus an asynchronous goroutine that resolves the API key (reading the local config file, and — when the cached key is stale — fetching a fresh one from raw.githubusercontent.com over the network) and, when a distinct id or refreshed key needs saving, writes ~/datatug/.posthog.yaml.
It MUST be called at most once, and only by a caller that actually wants telemetry for this invocation — this package used to do all of that from a package init() unconditionally, which meant every invocation, including `datatug version --json`, silently made a network request and could write a file merely by importing this package. Before Start runs, Enqueue and Close are no-ops (cli-install#req:version-json-side-effect-free, json-output-side-effect-free): main.go calls Start only when telemetry is not skipped for this invocation, after resolving isVersionJSONInvocation, so `version --json` never reaches getPostHogClient at all.
func StartedEvent ¶ added in v0.58.0
StartedEvent is the event sent when a command starts. It has no fields of its own: what it carries is added by prepare.
Types ¶
This section is empty.