telemetry

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComponentsFromUsage

func ComponentsFromUsage(usage any) []string

ComponentsFromUsage converts a ComponentUsage struct (or any struct with bool fields prefixed "Use") into a string slice of component names. For example, UseModal=true becomes "modal".

func Enabled

func Enabled() bool

Enabled returns true only when LVT_TELEMETRY is explicitly set to "true" or "1". Telemetry is opt-in: it is disabled by default to respect user privacy.

Types

type Capture

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

Capture accumulates data for a single generation event.

func NoopCapture

func NoopCapture() *Capture

NoopCapture returns a capture that silently discards all data.

func (*Capture) AttributeComponentErrors

func (cap *Capture) AttributeComponentErrors()

AttributeComponentErrors runs attribution logic on accumulated errors. Call this before Complete() to populate ComponentErrors. Safe to call multiple times; last call wins (overwrites previous results).

func (*Capture) Complete

func (cap *Capture) Complete(success bool, validationJSON string)

Complete finalises the capture, computes duration, and stores the event. It is always safe to call (noop if disabled).

func (*Capture) Event

func (cap *Capture) Event() *GenerationEvent

Event returns the underlying event (for testing). Returns nil on noop captures.

func (*Capture) RecordComponentsUsed

func (cap *Capture) RecordComponentsUsed(components []string)

RecordComponentsUsed sets the components involved in this generation.

func (*Capture) RecordError

func (cap *Capture) RecordError(err GenerationError)

RecordError adds an error to the capture.

func (*Capture) RecordFileGenerated

func (cap *Capture) RecordFileGenerated(path string)

RecordFileGenerated adds a generated file path. TODO: not yet wired into gen.go/auth.go integration points.

func (*Capture) SetKit

func (cap *Capture) SetKit(kit string)

SetKit records the kit used for generation.

type Collector

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

Collector tracks generation events. Safe to use even when disabled (noop).

func NewCollector

func NewCollector() *Collector

NewCollector opens the telemetry store. Returns a disabled (but valid) collector if telemetry is off or the store cannot be opened. The returned pointer is always non-nil — telemetry must not break generation.

func NewCollectorWithStore

func NewCollectorWithStore(store Store) *Collector

NewCollectorWithStore creates a collector with a custom store (for testing).

func (*Collector) Close

func (c *Collector) Close() error

Close releases the underlying store.

func (*Collector) IsEnabled

func (c *Collector) IsEnabled() bool

IsEnabled reports whether this collector is active.

func (*Collector) RunRetention

func (c *Collector) RunRetention(ctx context.Context, retentionDays int) error

RunRetention deletes events older than retentionDays.

func (*Collector) StartCapture

func (c *Collector) StartCapture(command string, inputs map[string]any) *Capture

StartCapture begins tracking a generation command. The returned Capture accumulates data until Complete() is called. If the collector is disabled the Capture is a silent noop.

func (*Collector) Store

func (c *Collector) Store() Store

Store returns the underlying Store (may be nil if disabled).

type ComponentError

type ComponentError struct {
	Component string `json:"component"`
	Phase     string `json:"phase"`
	Message   string `json:"message"`
	File      string `json:"file,omitempty"`
}

ComponentError links an error to a specific component.

func AttributeErrors

func AttributeErrors(errors []GenerationError, componentsUsed []string) []ComponentError

AttributeErrors scans GenerationErrors and matches them to components by checking file paths (e.g. "components/modal/modal.go") and error messages (e.g. "modal.New: invalid size"). Only components listed in componentsUsed are considered.

type GenerationError

type GenerationError struct {
	Phase   string `json:"phase"`             // "generation", "compilation", "runtime", "template"
	File    string `json:"file,omitempty"`    // file where error occurred
	Line    int    `json:"line,omitempty"`    // line number
	Message string `json:"message"`           // error message
	Context string `json:"context,omitempty"` // surrounding code or context
}

GenerationError records a single error captured during generation.

type GenerationEvent

type GenerationEvent struct {
	ID              string            `json:"id"`
	Timestamp       time.Time         `json:"timestamp"`
	Command         string            `json:"command"`                    // "gen resource", "gen view", "gen auth", "gen schema"
	Inputs          map[string]any    `json:"inputs"`                     // command args as key-value
	Kit             string            `json:"kit,omitempty"`              // e.g. "multi", "single"
	LvtVersion      string            `json:"lvt_version"`                // version of lvt used
	Success         bool              `json:"success"`                    // whether generation succeeded
	ValidationJSON  string            `json:"validation,omitempty"`       // JSON of validator.ValidationResult
	Errors          []GenerationError `json:"errors,omitempty"`           // errors captured during generation
	DurationMs      int64             `json:"duration_ms"`                // wall-clock duration
	FilesGenerated  []string          `json:"files_generated,omitempty"`  // paths of generated files
	ComponentsUsed  []string          `json:"components_used,omitempty"`  // component packages involved
	ComponentErrors []ComponentError  `json:"component_errors,omitempty"` // errors attributed to components
}

GenerationEvent records a single code generation invocation.

type ListOptions

type ListOptions struct {
	Since       time.Time
	SuccessOnly *bool
	Command     string
	Limit       int
}

ListOptions controls filtering when listing events.

type SQLiteStore

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

SQLiteStore implements Store using SQLite via modernc.org/sqlite.

func OpenSQLite

func OpenSQLite(dbPath string) (*SQLiteStore, error)

OpenSQLite opens (or creates) a telemetry database at the given path.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) CountBySuccess

func (s *SQLiteStore) CountBySuccess(ctx context.Context, since time.Time) (total, successes int, err error)

func (*SQLiteStore) DeleteBefore

func (s *SQLiteStore) DeleteBefore(ctx context.Context, before time.Time) (int64, error)

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, id string) (*GenerationEvent, error)

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context, opts ListOptions) ([]*GenerationEvent, error)

func (*SQLiteStore) Save

func (s *SQLiteStore) Save(ctx context.Context, event *GenerationEvent) error

type Store

type Store interface {
	Save(ctx context.Context, event *GenerationEvent) error
	Get(ctx context.Context, id string) (*GenerationEvent, error)
	List(ctx context.Context, opts ListOptions) ([]*GenerationEvent, error)
	CountBySuccess(ctx context.Context, since time.Time) (total, successes int, err error)
	DeleteBefore(ctx context.Context, before time.Time) (int64, error)
	Close() error
}

Store persists and retrieves generation events.

Jump to

Keyboard shortcuts

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