Help us shape the future of Go! Take the 2026 Go Developer Survey

observability

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package observability defines tanGO's minimal backend-neutral metrics contract.

Index

Constants

View Source
const (
	MetricHTTPRequestDuration     = "tango_http_request_duration_seconds"
	MetricSchedulerJobInvocations = "tango_scheduler_job_invocations_total"
	MetricRealtimeRoomEvents      = "tango_realtime_room_events_total"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JobSummary added in v0.6.0

type JobSummary struct {
	Success, Error, Panic, Canceled int64
}

JobSummary counts scheduler job invocations by outcome.

type NopRecorder

type NopRecorder struct{}

NopRecorder discards every metric. Its zero value is ready for direct use.

func (NopRecorder) AddCounter

func (NopRecorder) AddCounter(string, int64, ...slog.Attr)

func (NopRecorder) ObserveHistogram

func (NopRecorder) ObserveHistogram(string, float64, ...slog.Attr)

type Recorder

type Recorder interface {
	AddCounter(name string, delta int64, attrs ...slog.Attr)
	ObserveHistogram(name string, value float64, attrs ...slog.Attr)
}

Recorder receives framework metrics. Implementations must be safe for concurrent use.

func Multi added in v0.6.0

func Multi(recorders ...Recorder) Recorder

Multi returns a Recorder that forwards every metric to each given recorder, in order, skipping nil ones. It does not recover panics: a broken exporter stays visible to the caller. It is safe for concurrent use when its recorders are.

type RequestSummary added in v0.6.0

type RequestSummary struct {
	Total                              int64
	Class2xx, Class3xx                 int64
	Class4xx, Class5xx                 int64
	LatencyP50, LatencyP95, LatencyP99 float64
}

RequestSummary counts HTTP requests by status class and reports latency percentiles in seconds. Total is the sample count behind the percentiles.

type Snapshot added in v0.6.0

type Snapshot struct {
	// Scope says what the numbers cover, for example "this instance only".
	// The source supplies it; a consumer displays it and never infers it.
	Scope string
	// Since is when the window of activity began. It is not the start time
	// of a process, which a status provider reports separately.
	Since time.Time
	// Window is how much recent activity the numbers span.
	Window time.Duration
	// Requests summarises HTTP requests across the whole window.
	Requests RequestSummary
	// Jobs counts scheduler job invocations by outcome.
	Jobs JobSummary
}

Snapshot is what a Snapshotter reports. Every number in it covers the window described by Scope, Since and Window and nothing wider.

type Snapshotter added in v0.6.0

type Snapshotter interface {
	Snapshot() (Snapshot, error)
}

Snapshotter is the read side of an activity source: a bounded, recent view of the numbers a Recorder was given. It is separate from Recorder on purpose, so a Recorder never has to store anything. A source that can fail (a shared store, say) reports it through the error.

type Window added in v0.6.0

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

Window is an in-process, in-memory activity source. It is both a Recorder and a Snapshotter: the framework records into it, and a dashboard reads a recent view of it. It keeps only aggregates for the last 60 minutes: HTTP requests by status class with latency, and scheduler job invocations by outcome. It retains no route, method, raw status code, job name, user id or room id. Counters reset when the process restarts.

A Window is safe for concurrent use. Create one with NewWindow.

func NewWindow added in v0.6.0

func NewWindow(opts ...WindowOption) *Window

NewWindow returns an empty Window that starts now, according to its clock.

func (*Window) AddCounter added in v0.6.0

func (w *Window) AddCounter(name string, delta int64, attrs ...slog.Attr)

AddCounter records one scheduler job invocation when name is MetricSchedulerJobInvocations and the outcome attribute is one of success, error, panic or canceled. Every other name, outcome and attribute is ignored. A non-positive delta is ignored.

func (*Window) ObserveHistogram added in v0.6.0

func (w *Window) ObserveHistogram(name string, value float64, attrs ...slog.Attr)

ObserveHistogram records one HTTP request when name is MetricHTTPRequestDuration and the status attribute is an integer in the 2xx to 5xx range. value is the duration in seconds. Only the status class and the latency bucket are kept. Every other name is ignored.

func (*Window) Snapshot added in v0.6.0

func (w *Window) Snapshot() (Snapshot, error)

Snapshot reports the activity in the last 60 minutes. It never returns an error. An empty window reports zero counts and zero percentiles.

type WindowOption added in v0.6.0

type WindowOption func(*windowConfig)

WindowOption configures a Window created by NewWindow.

func WithClock added in v0.6.0

func WithClock(now func() time.Time) WindowOption

WithClock sets the clock a Window reads when it records or snapshots. A nil clock is ignored. The default is time.Now.

Jump to

Keyboard shortcuts

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