Documentation
¶
Overview ¶
Package analytics is the official, opt-in error reporting and product analytics pack. Server panics and 500s, frontend errors and named events land in Postgres (app_error, app_event) through a bounded queue, and optionally go out as OTLP log records to any collector. Nothing leaves the app unless ANALYTICS_OTLP_URL is set; no IP addresses are stored.
Index ¶
- Constants
- func Fingerprint(e report.Error) string
- func Handler() http.Handler
- func Pack() lidza.Pack
- type Analytics
- func (a *Analytics) Name() string
- func (a *Analytics) Report(ctx context.Context, e report.Error)
- func (a *Analytics) Run()
- func (a *Analytics) Start(ctx context.Context, s *lidza.Services) error
- func (a *Analytics) Stop(ctx context.Context) error
- func (a *Analytics) TelemetryStats() map[string]float64
- func (a *Analytics) Track(ctx context.Context, name string, props map[string]any)
- type Config
- type Event
- type StoredError
Constants ¶
const Tables = `` /* 857-byte string literal not displayed */
Tables is the DDL matching the schema fragment `lidza pack add analytics` appends to schema.lidza (models AppError and AppEvent). Tests create it.
Variables ¶
This section is empty.
Functions ¶
func Fingerprint ¶
Fingerprint groups the same failure: source, route and the first line of the message.
Types ¶
type Analytics ¶
type Analytics struct {
// contains filtered or unexported fields
}
Analytics is the running pack.
func (*Analytics) Start ¶
Start reads the configuration, takes the pool, applies retention and starts the writer.
func (*Analytics) TelemetryStats ¶
TelemetryStats reports the queue to /metrics.
type Config ¶
type Config struct {
// OTLPURL is an OTLP/HTTP logs endpoint (http://collector:4318/v1/logs).
// Empty keeps everything in Postgres.
OTLPURL string `env:"ANALYTICS_OTLP_URL"`
// Queue bounds records waiting to be written; the rest are dropped and
// counted.
Queue int `env:"ANALYTICS_QUEUE" default:"1024"`
// ClientRPS limits what one client may post per second.
ClientRPS float64 `env:"ANALYTICS_CLIENT_RPS" default:"5"`
// Retention drops rows older than this on start; 0 keeps them.
Retention time.Duration `env:"ANALYTICS_RETENTION" default:"720h"`
}
Config comes from the environment.
type Event ¶
type Event struct {
Name string `json:"name"`
Props map[string]any `json:"props,omitempty"`
URL string `json:"url,omitempty"`
SessionID string `json:"sessionId,omitempty"`
UserID string `json:"userId,omitempty"`
At time.Time `json:"at"`
}
Event is a named product event.
type StoredError ¶
type StoredError struct {
ID string `json:"id"`
Source string `json:"source"`
Message string `json:"message"`
Stack *string `json:"stack,omitempty"`
Route *string `json:"route,omitempty"`
Method *string `json:"method,omitempty"`
URL *string `json:"url,omitempty"`
RequestID *string `json:"requestId,omitempty"`
UserID *string `json:"userId,omitempty"`
Fingerprint string `json:"fingerprint"`
CreatedAt time.Time `json:"createdAt"`
}
StoredError is a row of app_error.