telemetry

package
v0.7.122 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package telemetry sends anonymous command-usage events to Segment.

Telemetry is opt-out: it fires unless disabled via a well-known opt-out environment variable or the persisted telemetry config preference (see internal/config.IsTelemetry). Only the command path, the names (never values) of flags the user set, and a per-install anonymous instance ID are ever collected — no flag values, argument values, file paths, or other PII.

Modeled on circleci-cli's internal/telemetry package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableTelemetry

func DisableTelemetry(cmd *cobra.Command)

DisableTelemetry marks cmd so RecordForSubcommands skips wrapping it. Used for commands that should never report their own invocation, such as the hidden receive-telemetry command.

func IsTelemetryDisabled

func IsTelemetryDisabled(cmd *cobra.Command) bool

IsTelemetryDisabled reports whether DisableTelemetry was called on cmd.

func RecordForSubcommands

func RecordForSubcommands(cmd *cobra.Command)

RecordForSubcommands wraps every descendant command's RunE so it reports a chunk_command_invocation event after running, without requiring per-command changes.

func RecordNow

func RecordNow(cmd *cobra.Command)

RecordNow reports a chunk_command_invocation event immediately: the full command path and the sorted, comma-joined names (never values) of flags the user explicitly set.

The event name is prefixed with "chunk_" (rather than the more generic "command_invocation" that circleci-cli's own telemetry package uses) because both tools currently send to the same Segment write key/workspace; the prefix keeps chunk-cli's events unambiguous in the event stream without requiring anyone to inspect the nested Context.App.Name field.

func WithSender

func WithSender(ctx context.Context, s *Sender) context.Context

WithSender attaches s to ctx so descendant commands can record events via RecordNow.

Types

type Config

type Config struct {
	// Send enables sending events to Segment via the delegate subprocess.
	Send bool
	// Log enables logging events to stderr for debugging.
	Log bool

	// Binary is re-exec'd with JSON-encoded events on stdin when Send is true.
	Binary string
	// WriteKey is the Segment write key used by the delegate subprocess.
	WriteKey string
	// Endpoint is the Segment endpoint. Optional; defaults to segment.io.
	// Normally only set for testing.
	Endpoint string

	// TestDestination, when non-nil, is added as an event destination so
	// tests can record events and assert on them synchronously without
	// spawning a subprocess or hitting the network.
	TestDestination destination

	Metadata Meta
}

Config configures a Sender.

type Meta

type Meta struct {
	Version    string
	InstanceID uuid.UUID
}

Meta describes the fields attached to every tracked event.

type Sender

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

Sender tracks anonymous command-usage events. A nil *Sender is valid and silently drops events, so callers never need to nil-check it.

func FromContext

func FromContext(ctx context.Context) *Sender

FromContext returns the Sender attached to ctx, or nil if none was attached.

func NewSender

func NewSender(cfg Config) (*Sender, error)

NewSender creates a new Sender per cfg.

func (*Sender) Close

func (s *Sender) Close() error

Close flushes buffered events to their destinations. Safe to call multiple times and on a nil Sender.

func (*Sender) Track

func (s *Sender) Track(eventName string, props map[string]any) error

Track records an analytics event. Safe to call on a nil Sender.

Directories

Path Synopsis
Package receiver forwards buffered telemetry events to Segment.
Package receiver forwards buffered telemetry events to Segment.

Jump to

Keyboard shortcuts

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