metrics

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: AGPL-3.0 Imports: 14 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*config)

Option configures Provider construction.

func WithMetricsAddr

func WithMetricsAddr(addr string) Option

WithMetricsAddr sets the TCP address for the Prometheus /metrics HTTP server (e.g. ":9090"). When not supplied, no HTTP server is started.

func WithOTLPEndpoint

func WithOTLPEndpoint(endpoint string) Option

WithOTLPEndpoint sets the OTLP gRPC endpoint URL (e.g. "http://otel-collector:4317"). When not supplied, no OTLP exporter is created.

type Provider

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

Provider manages metrics exporters: a Prometheus pull endpoint and/or an OTLP push exporter. Both are optional and independently controlled by the options passed to New.

func New

func New(ctx context.Context, opts ...Option) (*Provider, error)

New creates a Provider. If neither WithMetricsAddr nor WithOTLPEndpoint is supplied, a no-op MeterProvider is returned.

func NewFromEnv

func NewFromEnv(ctx context.Context) (*Provider, func(), error)

NewFromEnv creates a Provider using standard environment variables. METRICS_ADDR enables the Prometheus /metrics pull endpoint. OTEL_EXPORTER_OTLP_ENDPOINT enables OTLP gRPC push export. If neither variable is set, a no-op Provider is returned.

The returned shutdown func must be deferred by the caller. It shuts down all exporters with a 10-second deadline and writes any error to stderr.

func (*Provider) MeterProvider

func (p *Provider) MeterProvider() otelmetric.MeterProvider

MeterProvider returns the underlying OTel MeterProvider.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown stops all active exporters and flushes buffered metrics. It should be called before the process exits.

Jump to

Keyboard shortcuts

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