metermod

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

README

metermod

Using metermod takes care of exporting metrics to otel endpoint and flushing buffers before the application exits.

package main

import (
	"github.com/go-srvc/mods/metermod"
	"github.com/go-srvc/srvc"
)

func main() {
	srvc.RunAndExit(
		// By default metermod exports go runtime metrics to otel endpoint.
		metermod.New(),
	)
}

Documentation

Overview

Package metermod provides OpenTelemetry meter provider as a module.

Index

Examples

Constants

View Source
const (
	ErrMissingProvider = errStr("meter provider not set")
	ErrFlushFailed     = errStr("failed to flush remaining metrics")
)
View Source
const ID = "metermod"

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*Provider) error

func WithEnv added in v0.1.5

func WithEnv() Opt

WithEnv uses OTEL_EXPORTER_OTLP_TRACES_PROTO and OTEL_EXPORTER_OTLP_PROTO environment variable to set exporter. Accepted values are:

  • http
  • grpc
  • stdout

If no value is provided, stdout is used.

func WithGRPC

func WithGRPC() Opt

WithGRPC creates meter provider with periodic reader using grpc exporter from OTEL_* env configs. Env variables: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc

func WithHTTP

func WithHTTP() Opt

WithHTTP creates meter provider with periodic reader using http exporter from OTEL_* env configs. Env variables: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp

func WithProvider

func WithProvider(exp *metric.MeterProvider) Opt

WithProvider sets the underlying meter provider for module.

func WithProviderFn

func WithProviderFn(fn func() (*metric.MeterProvider, error)) Opt

WithProviderFn sets the underlying meter provider for module using given function.

func WithRuntimeMetrics added in v0.1.2

func WithRuntimeMetrics(opts ...runtime.Option) Opt

WithRuntimeMetrics starts runtime metrics collection.

func WithStdout added in v0.1.5

func WithStdout(opt ...stdoutmetric.Option) Opt

WithStdout creates meter provider with stdout exporter.

type Provider

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

func New

func New(opts ...Opt) *Provider

New creates meter provider module with sane defaults. Default options are: WithEnv and WithRuntimeMetrics.

Example
package main

import (
	"github.com/go-srvc/mods/metermod"
	"github.com/go-srvc/srvc"
)

func main() {
	srvc.RunAndExit(
		metermod.New(),
	)
}

func (*Provider) ID

func (p *Provider) ID() string

func (*Provider) Init

func (p *Provider) Init() error

func (*Provider) Run

func (p *Provider) Run() error

func (*Provider) Stop

func (p *Provider) Stop() error

Jump to

Keyboard shortcuts

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