observability

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package observability builds safe, bounded token-accounting observations for future metrics and logging adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authority

type Authority string

Authority identifies how strongly a count should be trusted.

const (
	AuthorityAuthoritative Authority = "authoritative"
	AuthorityDelegated     Authority = "delegated"
	AuthorityEstimated     Authority = "estimated"
	AuthorityAdvisory      Authority = "advisory"
)

type Input

type Input struct {
	Labels            Labels
	Status            Status
	FallbackReason    string
	UnavailableReason string
	Err               error
	Duration          time.Duration
	OccurredAt        time.Time
}

Input is the untrusted input used to build an Observation.

type Labels

type Labels struct {
	Backend   string
	Model     string
	Plane     Plane
	Source    Source
	Authority Authority
}

Labels are bounded dimensions safe for metrics/logging adapters.

type Observation

type Observation struct {
	Labels            Labels
	Status            Status
	FallbackReason    Reason
	UnavailableReason Reason
	ErrorReason       Reason
	Duration          time.Duration
	OccurredAt        time.Time
}

Observation is a content-free, sanitized count-attempt record.

func NewObservation

func NewObservation(input Input) (Observation, error)

NewObservation validates labels, classifies unsafe details, and returns a bounded observation.

func (Observation) Attributes

func (o Observation) Attributes() map[string]string

Attributes returns a bounded string map suitable for future metrics/logging adapters.

type Plane

type Plane string

Plane identifies the usage plane represented by a count observation.

const (
	PlaneProviderBillable Plane = "provider_billable"
	PlaneClientVisible    Plane = "client_visible"
	PlaneProxyBillable    Plane = "proxy_billable"
)

type Reason

type Reason string

Reason is a bounded reason classification for fallback, unavailable, and error outcomes.

const (
	ReasonUnknown             Reason = "unknown"
	ReasonError               Reason = "error"
	ReasonCanceled            Reason = "canceled"
	ReasonDeadlineExceeded    Reason = "deadline_exceeded"
	ReasonProviderUnavailable Reason = "provider_unavailable"
	ReasonUnsupportedModel    Reason = "unsupported_model"
)

type Sink

type Sink interface {
	Record(Observation)
}

type Snapshot

type Snapshot struct {
	SourceSelections   map[Source]int
	FallbackReasons    map[Reason]int
	UnavailableReasons map[Reason]int
	LatencyCount       int
	LatencySum         time.Duration
	Latencies          []time.Duration
}

Snapshot is a point-in-time copy of accumulated observation stats.

type Source

type Source string

Source identifies where a token count came from.

const (
	SourceProviderReported      Source = "provider_reported"
	SourceProviderCountAPI      Source = "provider_count_api"
	SourceLocalTokenizer        Source = "local_tokenizer"
	SourceAdministratorSupplied Source = "administrator_supplied"
	SourceTransformedRecomputed Source = "transformed_recomputed"
	SourceRequestScopedReuse    Source = "request_scoped_reuse"
)

type Stats

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

Stats accumulates bounded token-accounting observability dimensions in memory.

func NewStats

func NewStats() *Stats

NewStats creates an empty in-memory stats accumulator.

func (*Stats) Record

func (s *Stats) Record(obs Observation)

Record adds one validated observation to the accumulator.

func (*Stats) SetSink

func (s *Stats) SetSink(sink Sink)

SetSink forwards future observations to sink in addition to the in-memory snapshot.

func (*Stats) Snapshot

func (s *Stats) Snapshot() Snapshot

Snapshot returns a copy of accumulated stats without payload or request identity fields.

type Status

type Status string

Status identifies the outcome of a counting attempt.

const (
	StatusSuccess     Status = "success"
	StatusUnavailable Status = "unavailable"
	StatusError       Status = "error"
)

Jump to

Keyboard shortcuts

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