Documentation
¶
Overview ¶
Package observe is the ecosystem's request observability: one structured record and one metric observation per served request, applied as a decorator so every serving surface gets the same fields, the same level grading and the same counters rather than each one inventing its own (R17, R18).
It is a decorator rather than a handler feature because the obligation to log belongs to the *server* — the composition root that binds a port — while the handler's job is to route. The destination is always injected: this package owns the observations, never where they go, so a consumer picks slog's handler and any metrics backend without this package depending on either.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExpvarMetrics ¶
type ExpvarMetrics struct {
// contains filtered or unexported fields
}
ExpvarMetrics is the zero-dependency Metrics: request counts and total latency per method and status, published through the standard library's expvar registry and readable wherever the process serves /debug/vars.
It is the default rather than a Prometheus client because this package is a library on a public module path: an interface plus a stdlib implementation gives a real, queryable answer today and leaves any backend a consumer prefers a twenty-line adapter away, with nothing added to go.sum.
func NewExpvarMetrics ¶
func NewExpvarMetrics(prefix MetricsPrefix) ExpvarMetrics
NewExpvarMetrics publishes (or adopts, when a prefix repeats) the two maps. The value is copyable: both fields are already pointers into the expvar registry, so every copy counts into the same maps.
func (ExpvarMetrics) RequestServed ¶
func (m ExpvarMetrics) RequestServed(observed Observation)
RequestServed counts the request and adds its latency, keyed by method and status so a reader can see both the shape of the traffic and where the time goes.
type Metrics ¶
type Metrics interface {
RequestServed(observed Observation)
}
Metrics receives one Observation per served request. Implementations are called from every request goroutine and own their synchronisation; a nil Metrics collects nothing.
type MetricsPrefix ¶
type MetricsPrefix string
MetricsPrefix names an ExpvarMetrics' published variables, so two servers in one process do not share counters.
type Observation ¶
type Observation struct {
Method RequestMethod
Status StatusCode
Duration time.Duration
Bytes ByteCount
}
Observation is what one served request contributes to metrics: the request's shape and its cost, and nothing drawn from the document itself — an observability surface that carried sheet data would be an exfiltration surface. TestEveryRequestIsLoggedAndMeasured states that by serving a document whose contents it then looks for, and fails on finding.