telemetry

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitWide

func EmitWide(event WideEvent)

func Event

func Event(name string, attrs Attributes)

func IncCounter

func IncCounter(name string, labels map[string]string)

IncCounter increments a process-local counter. Values are rendered in Prometheus text format by RenderPrometheus; label keys/values outside the bounded vocabulary are collapsed to "other".

func Organization

func Organization(ctx context.Context) string

func RenderPrometheus

func RenderPrometheus() string

RenderPrometheus returns a complete Prometheus text exposition. A stable trailing newline and deterministic ordering make scrape output easy to diff and test.

func ReplaceGaugeSnapshot

func ReplaceGaugeSnapshot(name, labelName string, values map[string]float64)

ReplaceGaugeSnapshot replaces every series for a gauge in one operation. Callers that aggregate a database table should use this instead of SetGauge so labels that disappeared from the latest snapshot cannot retain stale non-zero values forever.

func SetGauge

func SetGauge(name string, value float64, labels map[string]string)

SetGauge sets a process-local gauge with bounded labels.

func SetOutput

func SetOutput(w io.Writer) (restore func())

SetOutput redirects emitted telemetry to w and returns a function that restores the previous sink. It exists so tests can capture and assert on the JSON events; production always writes to stderr.

func WithOrganization

func WithOrganization(ctx context.Context, organizationID string) context.Context

Types

type Attributes

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

func Attrs

func Attrs(fields ...Field) Attributes

type Collector

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

Collector accumulates wide-event annotations for a single unit of work. The wide-event interceptor stores a pointer in the request context so handlers can enrich the one event emitted per RPC without each re-plumbing timing, status, or emission. It is safe for concurrent use.

func CollectorFrom

func CollectorFrom(ctx context.Context) (*Collector, bool)

CollectorFrom returns the Collector attached to ctx, if any. Handlers should tolerate its absence so they remain callable from tests and non-RPC paths.

func NewCollector

func NewCollector(ctx context.Context) (context.Context, *Collector)

NewCollector returns a context carrying a fresh Collector and the Collector itself, so the caller (the interceptor) can read the accumulated annotations after the handler returns.

func (*Collector) Dimension

func (c *Collector) Dimension(key, value string)

Dimension records a low-cardinality string attribute. Empty values are ignored so the emitted event matches the previous "non-empty only" behavior.

func (*Collector) Measurement

func (c *Collector) Measurement(key string, value int64)

Measurement records a numeric attribute (counts, sizes, durations).

func (*Collector) SetOrganization

func (c *Collector) SetOrganization(organization string)

SetOrganization records the tenant boundary once authentication resolves it.

func (*Collector) Snapshot

func (c *Collector) Snapshot() (organization string, dimensions map[string]string, measurements map[string]int64)

Snapshot returns copies of the accumulated annotations that are safe to read after the handler returns.

type Field

type Field struct {
	Key   string
	Value any
}

type WideEvent

type WideEvent struct {
	Name         string
	Organization string
	Service      string
	Dimensions   map[string]string
	Measurements map[string]int64
}

Jump to

Keyboard shortcuts

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