telemetry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dashboard

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

Dashboard manages the in-memory observability data for developers.

func NewDashboard

func NewDashboard(maxEntries int) *Dashboard

NewDashboard creates a new Dashboard service.

func (*Dashboard) Clear

func (d *Dashboard) Clear()

Clear removes all entries from the dashboard.

func (*Dashboard) Entries

func (d *Dashboard) Entries() []DashboardEntry

Entries returns a copy of the recent dashboard entries.

func (*Dashboard) Subscribe

func (d *Dashboard) Subscribe() (<-chan DashboardEntry, func())

Subscribe returns a channel that receives new dashboard entries. The caller must call the returned unsubscribe function when done.

func (*Dashboard) Track

func (d *Dashboard) Track(typ, message string, data any)

Track adds a new entry to the dashboard.

func (*Dashboard) TrackEvent

func (d *Dashboard) TrackEvent(name string, payload any)

TrackEvent adds a framework event entry to the dashboard.

func (*Dashboard) TrackJob

func (d *Dashboard) TrackJob(name, status string, data any, duration time.Duration)

TrackJob adds a background job entry to the dashboard.

func (*Dashboard) TrackLog

func (d *Dashboard) TrackLog(level, message string, data any)

TrackLog adds a log entry to the dashboard.

func (*Dashboard) TrackMail

func (d *Dashboard) TrackMail(to, subject string, data any)

TrackMail adds a mail entry to the dashboard.

func (*Dashboard) TrackQuery

func (d *Dashboard) TrackQuery(query string, args []any, duration time.Duration)

TrackQuery adds a database query entry to the dashboard.

func (*Dashboard) TrackRedis

func (d *Dashboard) TrackRedis(command string, args any, duration time.Duration)

TrackRedis adds a Redis command entry to the dashboard.

func (*Dashboard) TrackRequest

func (d *Dashboard) TrackRequest(method, path string, status int, duration time.Duration)

TrackRequest adds an HTTP request entry to the dashboard.

type DashboardEntry

type DashboardEntry struct {
	ID        int64     `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Type      string    `json:"type"`     // "event", "log", "http", "query", "job", "mail", "redis"
	Category  string    `json:"category"` // more specific e.g. "auth", "db", "cache"
	Level     string    `json:"level,omitempty"`
	Message   string    `json:"message"`
	Data      any       `json:"data,omitempty"`
	Duration  int64     `json:"duration_ms,omitempty"`
}

DashboardEntry represents a single item in the dev dashboard.

type LogHandler

type LogHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

LogHandler is a slog.Handler that pushes records to the dashboard.

func NewLogHandler

func NewLogHandler(h slog.Handler, dash *Dashboard) *LogHandler

NewLogHandler wraps an existing slog.Handler.

func (*LogHandler) Handle

func (h *LogHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new LogHandler with the given attributes added.

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

WithGroup returns a new LogHandler with the given group added.

type QueueMonitor

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

QueueMonitor introspects the Redis data structures used by the Astra Queue package to provide real-time visibility into queue depth and failures.

It supports three queue key patterns (all configurable via KeyPrefix):

  • List <prefix>:<name> — main pending queue (LLEN)
  • List <prefix>:<name>:retry — in-flight / processing
  • List <prefix>:<name>:failed — dead-letter list
  • ZSet <prefix>:<name>:delayed — scheduled future jobs (ZCARD)

func NewQueueMonitor

func NewQueueMonitor(client goredis.UniversalClient, keyPrefix string, queueNames ...string) *QueueMonitor

NewQueueMonitor creates a QueueMonitor backed by the provided Redis client. keyPrefix should match the prefix used by the queue package (default: "astra:queue"). queueNames is the list of queue names to monitor (e.g. ["default", "mail", "notifications"]).

func (*QueueMonitor) PurgeQueue

func (m *QueueMonitor) PurgeQueue(ctx context.Context, name string) (int64, error)

PurgeQueue removes all pending jobs from a specific queue (destructive!).

func (*QueueMonitor) QueueStats

func (m *QueueMonitor) QueueStats(ctx context.Context) ([]QueueStat, error)

QueueStats polls Redis and returns current stats for all registered queues. The call is synchronous and typically completes in < 1ms for local Redis.

func (*QueueMonitor) RegisterQueue

func (m *QueueMonitor) RegisterQueue(name string)

RegisterQueue adds a queue name to the monitor's watch list.

func (*QueueMonitor) RetryFailed

func (m *QueueMonitor) RetryFailed(ctx context.Context, queueName string) (int64, error)

RetryFailed moves all failed jobs back to the pending queue for re-processing. queueName must match a registered queue. Passing "" retries all queues.

func (*QueueMonitor) ScheduledJobs

func (m *QueueMonitor) ScheduledJobs(ctx context.Context, queueName string, n int) ([]ScheduledJob, error)

ScheduledJobs returns the first n jobs from the delayed sorted-set for a queue.

func (*QueueMonitor) TotalFailed

func (m *QueueMonitor) TotalFailed(ctx context.Context) int64

TotalFailed returns the total number of failed jobs across all queues.

type QueueStat

type QueueStat struct {
	Name       string `json:"name"`
	Pending    int64  `json:"pending"`    // jobs waiting to be processed
	Processing int64  `json:"processing"` // jobs currently in-flight (reserved)
	Failed     int64  `json:"failed"`     // jobs in the dead-letter list
	Scheduled  int64  `json:"scheduled"`  // jobs in the delayed sorted-set
	LastPolled string `json:"last_polled"`
}

QueueStat holds aggregate stats for a single named queue.

type ScheduledJob

type ScheduledJob struct {
	Payload   string    `json:"payload"`
	RunAt     time.Time `json:"run_at"`
	RunAtUnix string    `json:"run_at_unix"`
}

ScheduledJob represents a single entry in the delayed sorted-set.

Jump to

Keyboard shortcuts

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