telemetry

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	LifecycleStartSuccess = "start_success"
	LifecycleStop         = "stop"
	LifecycleStartError   = "start_error"
)

Lifecycle event type constants.

View Source
const (
	ErrCodePortConflict     = "port_conflict"
	ErrCodeImagePullFailed  = "image_pull_failed"
	ErrCodeLicenseInvalid   = "license_invalid"
	ErrCodeStartFailed      = "start_failed"
	ErrCodeStartTimeout     = "start_timeout"
	ErrCodeEmulatorMismatch = "emulator_mismatch"
)

Error codes for start_error lifecycle events.

View Source
const FlushCommandName = "__flush-telemetry"

FlushCommandName is the argv[1] sentinel for the detached flusher subprocess. cmd.Execute must short-circuit on it before constructing a telemetry client, otherwise the flusher would emit events and spawn flushers recursively.

Variables

This section is empty.

Functions

func LoadOrCreateMachineID

func LoadOrCreateMachineID(ctx context.Context) string

LoadOrCreateMachineID attempts to derive a stable, anonymized machine ID by trying in order: Docker daemon ID, /etc/machine-id, then a persisted random UUID. Prefixes (dkr_, sys_, gen_) indicate origin, matching the Python implementation in localstack-core so IDs can be correlated across tools.

func RunFlush added in v0.11.0

func RunFlush(ctx context.Context, endpoint string, in io.Reader) error

RunFlush reads JSON-line eventBody values from `in` and POSTs each one to `endpoint`. It runs in the detached subprocess, bounded by flushTimeout.

func ToMap added in v0.5.2

func ToMap(v any) map[string]any

ToMap converts a telemetry event struct to a map[string]any for use with Emit.

Types

type Client

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

func New

func New(endpoint string, disabled bool, opts ...Option) *Client

New builds a telemetry client. A disabled client ignores opts: it has no session.

func NewWithInProcessFlush added in v0.11.0

func NewWithInProcessFlush(endpoint string) *Client

NewWithInProcessFlush returns an enabled Client whose Close flushes synchronously in-process, so tests can verify event delivery without forking the binary.

func (*Client) Close

func (c *Client) Close()

Close hands pending events to a detached subprocess and returns immediately, so analytics endpoint latency never delays command exit.

func (*Client) Emit

func (c *Client) Emit(ctx context.Context, name string, payload map[string]any)

func (*Client) EmitCommand added in v0.5.2

func (c *Client) EmitCommand(ctx context.Context, command, subcommand string, flags []string, durationMS int64, exitCode int, errorMsg string)

EmitCommand emits an lstk_command telemetry event. The Environment block is populated automatically from the client state.

func (*Client) EmitEmulatorLifecycleEvent added in v0.5.2

func (c *Client) EmitEmulatorLifecycleEvent(ctx context.Context, event LifecycleEvent)

EmitEmulatorLifecycleEvent emits an lstk_lifecycle telemetry event. The Environment field is populated automatically from the client state; any value set by the caller is overwritten.

func (*Client) GetEnvironment added in v0.5.2

func (c *Client) GetEnvironment(ctx context.Context) Environment

GetEnvironment returns the common environment payload for telemetry events, using the auth token set via SetAuthToken. The machine id comes from MachineID, which owns the lazy derivation and its disabled-client guard.

func (*Client) MachineID added in v0.22.0

func (c *Client) MachineID(ctx context.Context) string

MachineID is the anonymized machine identity stamped on this client's events (the salted hash produced by LoadOrCreateMachineID, never a raw Docker or system id). It is conveyed to extension processes through the runtime context so an extension emitting its own telemetry reports the same machine without re-deriving it.

The value is computed lazily on first use and cached for the process; every consumer (this accessor and event building via GetEnvironment) goes through here. Always empty when telemetry is disabled: a disabled client emits no events, so there is no identity to share — and the guard precedes the computation, so a disabled client never dials Docker or persists a generated id to derive a value it would only mask.

func (*Client) SessionID added in v0.21.0

func (c *Client) SessionID() string

SessionID is the per-process correlation id stamped on every event this client emits. It is conveyed to extension processes through the runtime context so an extension's own telemetry joins to the lstk invocation that dispatched it. Empty when telemetry is disabled, since a disabled client has no session.

func (*Client) SetAuthToken added in v0.5.2

func (c *Client) SetAuthToken(token string)

SetAuthToken stores the resolved auth token for inclusion in telemetry events. Call this once the token is known (e.g. after keyring resolution or interactive login).

type CommandEvent added in v0.5.2

type CommandEvent struct {
	Environment Environment       `json:"environment"`
	Parameters  CommandParameters `json:"parameters"`
	Result      CommandResult     `json:"result"`
}

CommandEvent is the payload for an lstk_command telemetry event.

type CommandParameters added in v0.5.2

type CommandParameters struct {
	Command    string   `json:"command"`
	Subcommand string   `json:"subcommand,omitempty"`
	Flags      []string `json:"flags"`
}

CommandParameters holds the command name and set flags. Subcommand carries the safe leading command-path tokens of a proxied tool invocation (e.g. "s3 ls" for `lstk aws s3 ls`); empty for lstk's own commands.

type CommandResult added in v0.5.2

type CommandResult struct {
	DurationMS int64  `json:"duration_ms"`
	ExitCode   int    `json:"exit_code"`
	ErrorMsg   string `json:"error_msg,omitempty"`
}

CommandResult holds the outcome of a command invocation.

type Environment added in v0.5.2

type Environment struct {
	LstkVersion string `json:"lstk_version"`
	AuthTokenID string `json:"auth_token_id,omitempty"`
	MachineID   string `json:"machine_id,omitempty"`
	OS          string `json:"os"`
	Arch        string `json:"arch"`
}

Environment is the common environment block included in all telemetry events.

type LifecycleEvent added in v0.5.2

type LifecycleEvent struct {
	EventType      string              `json:"event_type"`
	Environment    Environment         `json:"environment"`
	Emulator       config.EmulatorType `json:"emulator"`
	Image          string              `json:"image,omitempty"`
	ContainerID    string              `json:"container_id,omitempty"`
	DurationMS     int64               `json:"duration_ms,omitempty"`
	Pulled         bool                `json:"pulled,omitempty"`
	LocalStackInfo *LocalStackInfo     `json:"localstack_info,omitempty"`
	ErrorCode      string              `json:"error_code,omitempty"`
	ErrorMsg       string              `json:"error_msg,omitempty"`
}

LifecycleEvent is the payload for an lstk_lifecycle telemetry event.

type LocalStackInfo added in v0.5.2

type LocalStackInfo struct {
	Version            string `json:"version"`
	Edition            string `json:"edition"`
	IsLicenseActivated bool   `json:"is_license_activated"`
	SessionID          string `json:"session_id"`
	MachineID          string `json:"machine_id"`
	System             string `json:"system"`
	IsDocker           bool   `json:"is_docker"`
	ServerTimeUTC      string `json:"server_time_utc"`
	Uptime             int    `json:"uptime"`
}

LocalStackInfo mirrors the /_localstack/info response.

type Option added in v1.3.0

type Option func(*Client)

Option configures a Client built by New.

func WithSessionID added in v1.3.0

func WithSessionID(id string) Option

WithSessionID replaces the generated session id with a caller-supplied one (LSTK_SESSION_ID), so lstk's events join the caller's analytics session. It is internal-only and deliberately undocumented. An empty id keeps the generated one.

Jump to

Keyboard shortcuts

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