meter

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForceFlush added in v0.0.5

func ForceFlush(ctx context.Context) error

ForceFlush flushes the global meter provider immediately.

func Init added in v0.0.3

func Init(ctx context.Context, cfg Config, res *resource.Resource) error

Init configures the meter provider and stores it as the package-level singleton.

func Meter added in v0.0.3

func Meter(name string, opts ...metric.MeterOption) metric.Meter

Meter yields a metric meter backed by the global provider.

func RegisterRuntimeMetrics added in v0.0.3

func RegisterRuntimeMetrics(ctx context.Context, cfg RuntimeConfig) error

RegisterRuntimeMetrics instruments runtime metrics using the global provider.

func Shutdown added in v0.0.3

func Shutdown(ctx context.Context) error

Shutdown flushes and tears down the global meter provider.

func Use added in v0.0.3

func Use(provider *Provider)

Use replaces the global meter provider with the supplied instance. Passing nil installs a no-op placeholder.

Types

type Config

type Config struct {
	Enabled        bool
	Endpoint       string `validate:"required_if=Enabled true"`
	Insecure       bool
	Exporter       string `default:"http" validate:"oneof=http grpc"`
	Async          bool
	UseSpool       bool
	ServiceName    string        `default:"unknown-service"`
	ExportInterval time.Duration `default:"10s" validate:"gt=0"`
	QueueDir       string
	Runtime        RuntimeConfig
	Credentials    auth.Credentials
	UseGlobal      bool
}

Config governs metric provider setup. Endpoint accepts a base URL (host[:port] with optional path). Provided schemes decide TLS mode; when absent, the Insecure flag controls whether HTTP is used.

func (Config) ApplyDefaults added in v0.0.3

func (c Config) ApplyDefaults() Config

ApplyDefaults returns a copy of the config with default values populated.

func (Config) Validate added in v0.0.3

func (c Config) Validate() error

Validate ensures the configuration is complete when metrics are enabled.

type Provider

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

Provider wraps the SDK meter provider.

func Global added in v0.0.3

func Global() *Provider

Global returns the current global meter provider pointer. Panics if provider has not been initialized via Init() or Use().

func Setup

func Setup(ctx context.Context, cfg Config, res *resource.Resource) (*Provider, error)

Setup configures an OTLP meter provider and registers it globally. Selects HTTP or gRPC exporters based on the Exporter config field.

func (*Provider) ForceFlush added in v0.0.5

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

ForceFlush ensures metrics are exported immediately. No-op if provider is disabled.

func (*Provider) RegisterRuntimeMetrics

func (p *Provider) RegisterRuntimeMetrics(ctx context.Context, cfg RuntimeConfig) error

RegisterRuntimeMetrics adds basic Go runtime metrics if enabled.

func (*Provider) Shutdown

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

Shutdown flushes measurements and releases resources.

type RuntimeConfig

type RuntimeConfig struct {
	Enabled bool
}

RuntimeConfig controls optional runtime metric instrumentation.

Jump to

Keyboard shortcuts

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