metricspush

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package metricspush starts the OpenTelemetry SDK and an OTLP/JSON exporter that send a proxy's metrics to the central collector (R15). It is the only package that imports the SDK, so the metrics package stays API-only. Each proxy holds its own copy of this setup: the URL, the token and the exporter are settings of the host, not of the accountant.

The push is asynchronous (R16). The SDK aggregates in its own memory and exports from its own goroutine. A recording call never waits for the collector, and a failed push loses no count: the next push carries the totals (R20).

Index

Constants

View Source
const (
	DefaultInterval = 30 * time.Second
)

Defaults.

Variables

This section is empty.

Functions

func MachineID

func MachineID(path string) (string, error)

MachineID returns the random ID of this install (R43). It is made once and kept in path, so it survives a restart. It is random on purpose: it holds no host name, no user name and no address, so it names an install and nobody.

If path is empty or cannot be written, MachineID returns a fresh ID for this run and the error. The push still works. The same machine then shows up as a new `machine` value after each restart, which is a small, bounded cost.

Types

type Config

type Config struct {
	// URL is the collector base URL. There is no default: with no URL, Start logs one warning and
	// makes no connection.
	URL string
	// Token is the per-install access token, sent as a bearer token (R44).
	Token string
	// Interval is the time between pushes. Zero means DefaultInterval.
	Interval time.Duration
	// Disabled turns the push off. The proxy then makes no connection (R19).
	Disabled bool

	// Resource attributes (R30, R43). The collector turns them into the labels proxy and machine.
	Proxy   string // "cortex" or "context-guru"
	Machine string // random install ID
	Version string
	Preset  string

	// Logger receives the one start line and the first failure of a run. Nil means slog.Default().
	Logger *slog.Logger
}

Config is what a proxy gives Start.

type Shutdown

type Shutdown func(context.Context) error

Shutdown flushes the last totals and stops the exporter. Give it a short timeout.

func Start

Start builds the provider. It returns a no-op provider when the push is off or has no URL, so a caller never needs a nil check. It never returns an error for a bad collector: that is a runtime failure, and it is counted in llm_proxy_export_failures_total (R20, fail open).

Jump to

Keyboard shortcuts

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