rum

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyWebVital

func ClassifyWebVital(name string, value float64) string

ClassifyWebVital returns "good", "needs-improvement", or "poor" for a given web vital metric, using Google's Core Web Vitals thresholds.

func FingerprintError

func FingerprintError(err *JSErrorEvent) string

FingerprintError computes a stable hash for grouping duplicate JS errors. Uses message + source + first non-empty stack frame line.

Types

type ClickEvent

type ClickEvent struct {
	Selector string `json:"selector"` // CSS selector of clicked element
	Text     string `json:"text"`     // inner text (truncated)
	X        int    `json:"x"`
	Y        int    `json:"y"`
	IsRage   bool   `json:"is_rage"` // 3+ clicks on same element in 1s
	URL      string `json:"url"`
}

ClickEvent records a user click interaction.

type Engine

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

Engine processes incoming RUM events: classifies web vitals, fingerprints errors, applies session sampling, and writes to the store.

func New

func New(store RUMStore, cfg EngineConfig) *Engine

New creates a RUM engine with the given store and configuration.

func (*Engine) IngestBatch

func (e *Engine) IngestBatch(events []RUMEvent) int

IngestBatch processes and stores a batch of RUM events. Returns the number of events actually stored (after sampling).

func (*Engine) IngestEvent

func (e *Engine) IngestEvent(event RUMEvent) bool

IngestEvent processes and stores a single RUM event. Returns false if the event was dropped by session sampling.

func (*Engine) Store

func (e *Engine) Store() RUMStore

Store returns the underlying RUM store.

type EngineConfig

type EngineConfig struct {
	SampleRate float64 // 0.0–1.0, fraction of sessions to keep
	MaxEvents  int     // circular buffer capacity
}

EngineConfig holds RUM engine configuration.

func DefaultEngineConfig

func DefaultEngineConfig() EngineConfig

DefaultEngineConfig returns sensible defaults.

type ErrorGroup

type ErrorGroup struct {
	Fingerprint string    `json:"fingerprint"`
	Message     string    `json:"message"`
	Source      string    `json:"source"`
	Count       int       `json:"count"`
	Sessions    int       `json:"sessions"`
	LastSeen    time.Time `json:"last_seen"`
	Stack       string    `json:"stack"`
	TraceID     string    `json:"trace_id,omitempty"` // most-recent event's backend trace, if any
}

ErrorGroup aggregates JS errors by fingerprint.

type EventType

type EventType string

EventType identifies the kind of RUM event.

const (
	EventPageLoad       EventType = "page_load"
	EventWebVital       EventType = "web_vital"
	EventJSError        EventType = "js_error"
	EventResourceTiming EventType = "resource_timing"
	EventClick          EventType = "click"
	EventNavigation     EventType = "navigation"
)

type JSErrorEvent

type JSErrorEvent struct {
	Message     string `json:"message"`
	Source      string `json:"source"`
	Lineno      int    `json:"lineno"`
	Colno       int    `json:"colno"`
	Stack       string `json:"stack"`
	Fingerprint string `json:"fingerprint"` // computed server-side
}

JSErrorEvent records a JavaScript error.

type NavigationEvent struct {
	FromURL string `json:"from_url"`
	ToURL   string `json:"to_url"`
	Type    string `json:"type"` // "push", "replace", "back", "forward"
}

NavigationEvent records a client-side page navigation.

type PageLoadEvent

type PageLoadEvent struct {
	Route            string  `json:"route"`
	DurationMs       float64 `json:"duration_ms"`
	TTFB             float64 `json:"ttfb_ms"`
	DOMContentLoaded float64 `json:"dom_content_loaded_ms"`
	Load             float64 `json:"load_ms"`
	TransferSizeKB   float64 `json:"transfer_size_kb"`
}

PageLoadEvent records a full page navigation.

type PagePerformance

type PagePerformance struct {
	Route             string  `json:"route"`
	Views             int     `json:"views"`
	AvgDurationMs     float64 `json:"avg_duration_ms"`
	P75DurationMs     float64 `json:"p75_duration_ms"`
	AvgTTFB           float64 `json:"avg_ttfb_ms"`
	AvgTransferSizeKB float64 `json:"avg_transfer_size_kb"`
}

PagePerformance summarises performance for a single page route.

type RUMEvent

type RUMEvent struct {
	ID        string    `json:"id"`
	Type      EventType `json:"type"`
	SessionID string    `json:"session_id"`
	URL       string    `json:"url"`
	UserAgent string    `json:"user_agent"`
	Timestamp time.Time `json:"timestamp"`
	TraceID   string    `json:"trace_id,omitempty"` // backend distributed trace this event belongs to

	// Exactly one of these will be populated, depending on Type.
	PageLoad       *PageLoadEvent       `json:"page_load,omitempty"`
	WebVital       *WebVitalEvent       `json:"web_vital,omitempty"`
	JSError        *JSErrorEvent        `json:"js_error,omitempty"`
	ResourceTiming *ResourceTimingEvent `json:"resource_timing,omitempty"`
	Click          *ClickEvent          `json:"click,omitempty"`
	Navigation     *NavigationEvent     `json:"navigation,omitempty"`
}

RUMEvent is the envelope for all events sent by the browser SDK.

type RUMStore

type RUMStore interface {
	// WriteEvent persists a single RUM event.
	WriteEvent(event RUMEvent) error

	// WriteBatch persists multiple RUM events atomically.
	WriteBatch(events []RUMEvent) error

	// WebVitalsOverview returns an aggregate view of core web vitals.
	WebVitalsOverview() (*WebVitalsOverview, error)

	// PageLoads returns per-route performance metrics.
	PageLoads() ([]PagePerformance, error)

	// ErrorGroups returns JS errors grouped by fingerprint.
	ErrorGroups() ([]ErrorGroup, error)

	// PagePerformance returns detailed performance for a specific route.
	PagePerformance(route string) (*PagePerformance, error)

	// Sessions returns a list of recent session summaries.
	Sessions(limit int) ([]SessionSummary, error)

	// SessionDetail returns all events for a given session.
	SessionDetail(sessionID string) ([]RUMEvent, error)

	// RageClicks returns rage click events from the last N minutes.
	RageClicks(minutes int) ([]ClickEvent, error)

	// UserJourneys returns navigation events for a given session, ordered by time.
	UserJourneys(sessionID string) ([]NavigationEvent, error)

	// PerformanceByRoute returns aggregated performance metrics per route.
	PerformanceByRoute() ([]RoutePerformance, error)
}

RUMStore defines the interface for persisting and querying RUM events.

type ResourceTimingEvent

type ResourceTimingEvent struct {
	Name           string  `json:"name"`           // URL of the resource
	InitiatorType  string  `json:"initiator_type"` // fetch, xmlhttprequest, script, css, img
	DurationMs     float64 `json:"duration_ms"`
	TransferSizeKB float64 `json:"transfer_size_kb"`
	StatusCode     int     `json:"status_code"`
}

ResourceTimingEvent records the timing of a single resource fetch.

type RoutePerformance

type RoutePerformance struct {
	Route         string  `json:"route"`
	AvgDurationMs float64 `json:"avg_duration_ms"`
	P75DurationMs float64 `json:"p75_duration_ms"`
	AvgTTFB       float64 `json:"avg_ttfb_ms"`
	Views         int     `json:"views"`
}

RoutePerformance aggregates performance metrics per route.

type SessionSummary

type SessionSummary struct {
	SessionID  string    `json:"session_id"`
	StartedAt  time.Time `json:"started_at"`
	LastSeen   time.Time `json:"last_seen"`
	PageViews  int       `json:"page_views"`
	ErrorCount int       `json:"error_count"`
	UserAgent  string    `json:"user_agent"`
}

SessionSummary is a lightweight view of a user session.

type VitalRating

type VitalRating struct {
	Good             int     `json:"good"`
	NeedsImprovement int     `json:"needs_improvement"`
	Poor             int     `json:"poor"`
	P75              float64 `json:"p75"`
}

VitalRating groups counts by good/needs-improvement/poor.

type WebVitalEvent

type WebVitalEvent struct {
	Name   string  `json:"name"`  // LCP, FID, CLS, TTFB, FCP, INP
	Value  float64 `json:"value"` // ms for timing metrics, unitless for CLS
	Delta  float64 `json:"delta"`
	Rating string  `json:"rating"` // "good", "needs-improvement", "poor"
}

WebVitalEvent records a single Core Web Vital measurement.

type WebVitalsOverview

type WebVitalsOverview struct {
	LCP           VitalRating `json:"lcp"`
	FID           VitalRating `json:"fid"`
	CLS           VitalRating `json:"cls"`
	TTFB          VitalRating `json:"ttfb"`
	FCP           VitalRating `json:"fcp"`
	INP           VitalRating `json:"inp"`
	TotalSessions int         `json:"total_sessions"`
}

WebVitalsOverview summarises all core web vitals.

Directories

Path Synopsis
Package dynamostore implements rum.RUMStore backed by DynamoDB via the generic dynamostore package.
Package dynamostore implements rum.RUMStore backed by DynamoDB via the generic dynamostore package.
Package filestore implements rum.RUMStore by wrapping the in-memory store with file-backed persistence.
Package filestore implements rum.RUMStore by wrapping the in-memory store with file-backed persistence.

Jump to

Keyboard shortcuts

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